Heim  >  Artikel  >  Backend-Entwicklung  >  wecis 2.0 RC 版

wecis 2.0 RC 版

WBOY
WBOYOriginal
2016-07-25 09:08:48910Durchsuche

调试bug 请通知本人,谢谢!
新版功能:
1. 添加{-script lang='php'-} 模板也可以写php代码
2.修改1.0 细节错误 : 如无用功代码,优化核心代码,提高运行编译速度。
3.添加模板格式化函数{-$string|subistr(12):'...'-} ,时间格式化 {-$time|time('ymd')-}

  1. /**
  2. * [Wecis] (C)2012-2099 Haowei Inc.
  3. * This is NOT a freeware, use is subject to license terms
  4. * version: 2.0 RC
  5. **/
  6. class wecis{
  7. private $assign=array();
  8. public $tpl_cache_dir = 'cache/';
  9. public $tpl_cache_open = TRUE;
  10. public $tpl_cache_time = 5 ;
  11. public $tpl_tpl_dir = 'template/';
  12. public $tpl_rw_left = '{-';
  13. public $tpl_rw_right = '-}';
  14. public function wecis(){
  15. return '[{name:\'wecis 2.0 rc\'}]';
  16. }
  17. public function assign($tplvar,$value){
  18. if(empty($tplvar) || empty($value)){
  19. $this->error('wecis-> assign() Parameters are missing');
  20. }
  21. return $this->assign[$tplvar]=$value;
  22. }
  23. public function display($tplfile){
  24. if(empty($tplfile)){ $this->error('wecis-> display() Parameters are missing'); }
  25. if($this->tpl_cache_open){
  26. if(file_exists($this->tpl_cache_dir.$this->cahce_format($tplfile))){
  27. if($this->cahce_timeout($tplfile)) {
  28. $this->cache_delete($tplfile);
  29. include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
  30. }else{
  31. include $this->tpl_cache_dir.$this->cahce_format($tplfile);
  32. }
  33. }else{
  34. include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
  35. }
  36. }else{
  37. include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
  38. }
  39. }
  40. public function cache($tplfile){
  41. $data = file_get_contents($this->tpl_tpl_dir.$tplfile);
  42. $data = preg_replace('/'.$this->tpl_rw_left.'script lang=\'php\''.$this->tpl_rw_right.'/',' $data = preg_replace('/'.$this->tpl_rw_left.'\/script'.$this->tpl_rw_right.'/','?>',$data);
  43. $data = preg_replace('/'.$this->tpl_rw_left.'loop (\$(.*)?) as (\$(.*)?)'.$this->tpl_rw_right.'/','',$data);
  44. $data = preg_replace('/'.$this->tpl_rw_left.'\/loop'.$this->tpl_rw_right.'/','',$data);
  45. $data = preg_replace('/'.$this->tpl_rw_left.'(\$(.*)?)\[((.*)?)\]'.$this->tpl_rw_right.'/','',$data);
  46. $data = preg_replace('/'.$this->tpl_rw_left.'if((.*)?)'.$this->tpl_rw_right.'/','',$data);
  47. $data = preg_replace('/'.$this->tpl_rw_left.'else'.$this->tpl_rw_right.'/','',$data);
  48. $data = preg_replace('/'.$this->tpl_rw_left.'\/if'.$this->tpl_rw_right.'/','',$data);
  49. $data = preg_replace('/'.$this->tpl_rw_left.'(\$(.*)?)\|subistr\(((.*)?)\)\:((.*)?)'.$this->tpl_rw_right.'/','',$data);
  50. $data = preg_replace('/'.$this->tpl_rw_left.'(\$(.*)?)\|time\:\(((.*)?)\)'.$this->tpl_rw_right.'/',"",$data);
  51. $data = preg_replace('/'.$this->tpl_rw_left.'(\$(.*)?)'.$this->tpl_rw_right.'/','',$data);
  52. $arr='';
  53. foreach($this->assign as $k=>$v) {
  54. if(!is_array($v)) {
  55. $data = !is_numeric($v) ? str_replace('$'.$k,'\''.$v.'\'',$data) : str_replace('$'.$k,$v,$data);
  56. }else{
  57. $arr.='';
  58. }
  59. }
  60. return file_put_contents($this->tpl_cache_dir.$this->cahce_format($tplfile),$arr.$data) ? 1 : 0;
  61. }
  62. public function cahce_timeout($tplfile){
  63. $time = time();
  64. $filetime = fileatime($this->tpl_cache_dir.$this->cahce_format($tplfile));
  65. return $time-$filetime > ($this->tpl_cache_time*60) ? 1 : 0;
  66. }
  67. public function cahce_format($tplfile){
  68. return md5($this->version()).str_replace('/','.',$tplfile).'.php';
  69. }
  70. public function cache_delete($tplfile){
  71. return unlink($this->tpl_cache_dir.$this->cahce_format($tplfile)) ? 1 : 0;
  72. }
  73. private function error($str){
  74. return exit($str);
  75. }
  76. public function version(){
  77. return 'wecis 2.0 RC';
  78. }
  79. }
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn