Please notify me when debugging bugs, thank you! New version features: 1. Add {-script lang='php'-} template and you can also write PHP code 2. Modify 1.0 detailed errors: If there is no hard work code, optimize the core code to improve the running and compilation speed. 3. Add template formatting function {-$string|subistr(12):'...'-}, time formatting {-$time|time('ymd')-}
- /**
- * [Wecis] (C)2012-2099 Haowei Inc.
- * This is NOT a freeware, use is subject to license terms
- * version: 2.0 RC
- **/
- class wecis{
-
- private $assign=array();
- public $tpl_cache_dir = 'cache/';
- public $tpl_cache_open = TRUE;
- public $tpl_cache_time = 5 ;
- public $tpl_tpl_dir = 'template/';
- public $tpl_rw_left = '{-';
- public $tpl_rw_right = '-}';
-
- public function wecis(){
- return '[{name:'wecis 2.0 rc'}]';
- }
-
- public function assign($tplvar,$value){
- if(empty($tplvar) || empty($value)){
- $this->error('wecis-> assign() Parameters are missing');
- }
- return $this->assign[$tplvar]=$value;
- }
-
- public function display($tplfile){
- if(empty($tplfile)){ $this->error('wecis-> display() Parameters are missing'); }
- if($this->tpl_cache_open){
- if(file_exists($this->tpl_cache_dir.$this->cahce_format($tplfile))){
- if($this->cahce_timeout($tplfile)) {
- $this->cache_delete($tplfile);
- include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
- }else{
- include $this->tpl_cache_dir.$this->cahce_format($tplfile);
-
- }
- }else{
- include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
- }
- }else{
- include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
- }
- }
-
- public function cache($tplfile){
- $data = file_get_contents($this->tpl_tpl_dir.$tplfile);
- $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);
- $data = preg_replace('/'.$this->tpl_rw_left.'loop ($(.*)?) as ($(.*)?)'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'/loop'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)[((.*)?)]'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'if((.*)?)'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'else'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'/if'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)|subistr(((.*)?)):((.*)?)'.$this->tpl_rw_right.'/','',$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)|time:(((.*)?))'.$this->tpl_rw_right.'/',"",$data);
- $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)'.$this->tpl_rw_right.'/','',$data);
- $arr='';
- foreach($this->assign as $k=>$v) {
- if(!is_array($v)) {
- $data = !is_numeric($v) ? str_replace('$'.$k,'''.$v.''',$data) : str_replace('$'.$k,$v,$data);
- }else{
- $arr.='';
- }
- }
- return file_put_contents($this->tpl_cache_dir.$this->cahce_format($tplfile),$arr.$data) ? 1 : 0;
- }
-
- public function cahce_timeout($tplfile){
- $time = time();
- $filetime = fileatime($this->tpl_cache_dir.$this->cahce_format($tplfile));
- return $time-$filetime > ($this->tpl_cache_time*60) ? 1 : 0;
- }
-
- public function cahce_format($tplfile){
- return md5($this->version()).str_replace('/','.',$tplfile).'.php';
- }
-
- public function cache_delete($tplfile){
- return unlink($this->tpl_cache_dir.$this->cahce_format($tplfile)) ? 1 : 0;
- }
-
- private function error($str){
- return exit($str);
- }
-
- public function version(){
- return 'wecis 2.0 RC';
- }
-
- }
-
复制代码
|