/** * 架构函数 * @access public */ public function __construct() { $this->tagLib = strtolower(substr(get_class($this), 6)); $this->tpl = \Any\Any::instance('Any\\Template'); }
/** * 检查静态HTML文件是否有效 * 如果无效需要重新更新 * @access public * @param string $cacheFile 静态文件名 * @param integer $cacheTime 缓存有效期 * @return boolean */ public static function checkHTMLCache($cacheFile = '', $cacheTime = '') { if (!is_file($cacheFile) && 'sae' != APP_MODE) { return false; } elseif (filemtime(\Any\Any::instance('Any\\View')->parseTemplate()) > Storage::get($cacheFile, 'mtime', 'html')) { // 模板文件如果更新静态文件需要更新 return false; } elseif (!is_numeric($cacheTime) && function_exists($cacheTime)) { return $cacheTime($cacheFile); } elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile, 'mtime', 'html') + $cacheTime) { // 文件是否在有效期 return false; } //静态文件有效 return true; }
/** * TagLib库解析 * @access public * @param string $tagLib 要解析的标签库 * @param string $content 要解析的模板内容 * @param boolean $hide 是否隐藏标签库前缀 * @return string */ public function parseTagLib($tagLib, &$content, $hide = false) { $begin = $this->config['taglib_begin']; $end = $this->config['taglib_end']; if (strpos($tagLib, '\\')) { // 支持指定标签库的命名空间 $className = $tagLib; $tagLib = substr($tagLib, strrpos($tagLib, '\\') + 1); } else { $className = 'Any\\Template\\TagLib\\' . ucwords($tagLib); } $tLib = \Any\Any::instance($className); $that = $this; foreach ($tLib->getTags() as $name => $val) { $tags = array($name); if (isset($val['alias'])) { // 别名设置 $tags = explode(',', $val['alias']); $tags[] = $name; } $level = isset($val['level']) ? $val['level'] : 1; $closeTag = isset($val['close']) ? $val['close'] : true; foreach ($tags as $tag) { $parseTag = !$hide ? $tagLib . ':' . $tag : $tag; // 实际要解析的标签名称 if (!method_exists($tLib, '_' . $tag)) { // 别名可以无需定义解析方法 $tag = $name; } $n1 = empty($val['attr']) ? '(\\s*?)' : '\\s([^' . $end . ']*)'; $this->tempVar = array($tagLib, $tag); if (!$closeTag) { $patterns = '/' . $begin . $parseTag . $n1 . '\\/(\\s*?)' . $end . '/is'; $content = preg_replace_callback($patterns, function ($matches) use($tLib, $tag, $that) { return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]); }, $content); } else { $patterns = '/' . $begin . $parseTag . $n1 . $end . '(.*?)' . $begin . '\\/' . $parseTag . '(\\s*?)' . $end . '/is'; for ($i = 0; $i < $level; $i++) { $content = preg_replace_callback($patterns, function ($matches) use($tLib, $tag, $that) { return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]); }, $content); } } } } }