龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php 已经过期,请看wecis模板引擎

时间:2015-03-25 11:43来源:网络整理 作者:网络 点击:
分享到:
已经过期,请看wecis模板引擎 webtmp 模板引擎,已过期。 请注意wecis**QQ截图20111028170856.png**[代码片段(1行)]**QQ截图20111028170914.png**[代码片段(1行)]**[PHP]代码**[代码片段(64行)]

webtmp 模板引擎,已过期。 请注意wecis

QQ截图20111028170856.png

imgs/asCode/28170930_Xs4O.png

QQ截图20111028170914.png

imgs/asCode/28170930_JPLD.png

[PHP]代码

<?php

class template{

    private $assign = array();
    public $tplfile_pre;
    public $tplfile_path_dir = 'template';  //模板路径
    public $tplfile_cache_dir = 'cache';    //缓存路径
    public $tplfile_cache_open = TRUE;  //是否开启缓存
    public $tplfile_cache_time = 300;   //设置缓存时间
    public $tplstring_left = '{-';  //模板中左标签
    public $tplstring_right = '-}'; //模板中右标签

    function template($tplpre) {
        if(empty($tplpre)) {
            exit('Lost Parameter');
        }
        $this->tplfile_pre = md5($tplpre).'.';
    }

    public function assign($tplvar,$value){
        $this->assign[$tplvar]=$value; 
    }

    public function display($tpl) {
        if($this->tplfile_cache_open) {
            if(file_exists($this->tplfile_cache_dir.'/'.$this->tplfile_pre.$tpl.'.php')) {
                $tmpfiletime = fileatime($this->tplfile_cache_dir.'/'.$this->tplfile_pre.$tpl.'.php');
                if((time() - $tmpfiletime) >$this->tplfile_cache_time) {
                    unlink($this->tplfile_cache_dir.'/'.$this->tplfile_pre.$tpl.'.php');
                    include $this->createTemp($tpl);
                }else{
                    include $this->tplfile_cache_dir.'/'.$this->tplfile_pre.$tpl.'.php';
                }
            }else{
                include $this->createTemp($tpl);
            }
        }else{
            include $this->createTemp($tpl);
        }
    }

    private function createTemp($tpl) {
        $content = file_get_contents($this->tplfile_path_dir.'/'.$tpl);
        $data = preg_replace('/'.$this->tplstring_left.'if\(((.*)+)\)'.$this->tplstring_right.'/',"<?php if(\\1) { ?>",$content);
        $data = preg_replace('/'.$this->tplstring_left.'else'.$this->tplstring_right.'/','<?php }else{ ?>',$data);
        $data = preg_replace('/'.$this->tplstring_left.'\/if'.$this->tplstring_right.'/','<?php } ?>',$data);
        $data = preg_replace('/'.$this->tplstring_left.'/','<?php echo ',preg_replace('/'.$this->tplstring_right.'/',' ?>',$data));
        foreach($this->assign as $k=>$v) {
            if(!is_numeric($v)) {
                $data = preg_replace('/\$'.$k.'/','\''.$v.'\';',$data);
            }
            $data = preg_replace('/\$'.$k.'/',$v,$data);
        }
        if($data) {
            file_put_contents($this->tplfile_cache_dir.'/'.$this->tplfile_pre.$tpl.'.php',$data);
            return $this->tplfile_cache_dir.'/'.$this->tplfile_pre.$tpl.'.php';
        }
    }
    public function version() {
        return 'webtmp 1.0';
    }
}
?>
收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!
按钮 内容不能为空!
立刻说两句吧! 查看0条评论
精彩图集

赞助商链接