Ejemplo n.º 1
0
 /**
  * 编译模板内容
  * @param String $tplfile 模板文件
  * @param String $tmpfile 编译文件
  * @return Void
  */
 public static function execute($tplfile, $tmpfile)
 {
     self::$start = preg_quote(self::$delimiter[0]);
     self::$close = preg_quote(self::$delimiter[1]);
     self::$contents = file_get_contents($tplfile);
     //清除phpcode
     self::$contents = preg_replace("/\\<\\?php.*\\?\\>(\r\n)*/i", '', self::$contents);
     Ada_Template_Compile_Include::incfile(self::$start, self::$close);
     Ada_Template_Compile_Syntax::compile();
     Ada_Template_Compile_Include::compile();
     Ada_Template_Compile_Loop::compile();
     Ada_Template_Compile_Choose::compile();
     file_put_contents($tmpfile, self::$tplscript . self::$contents);
 }
Ejemplo n.º 2
0
 /**
  * 编译和显示指定模板内容
  *+---------------------------
  * $this->display('demo.tpl');
  *+---------------------------
  * @param String $tplfile
  * @return Boolean
  */
 public function display($tplfile)
 {
     $tplfile = $this->checked($tplfile);
     $name = md5($tplfile);
     $path = self::$tmpfolder . DIRECTORY_SEPARATOR . substr($name, 0, 1);
     $tmpfile = $path . DIRECTORY_SEPARATOR . $name . '.' . self::$tmpsuffix;
     //编译临时文件
     if (!is_dir($path)) {
         mkdir($path, 0777, TRUE);
     }
     if (is_file($tmpfile)) {
         $timestamp = time();
         $modfiyTime = filemtime($tplfile);
         $accessTime = filemtime($tmpfile);
         //检测模板文件修改状态与缓存时间有效状态
         if ($modfiyTime > $accessTime || $timestamp - $accessTime >= self::$lifetimes) {
             Ada_Template_Compile::execute($tplfile, $tmpfile);
             //重新编译模板文件
         }
     } else {
         Ada_Template_Compile::execute($tplfile, $tmpfile);
         //第一次编译模板文件
     }
     include $tmpfile;
 }