当前位置: 网学 > 编程文档 > PHP > 正文

从康盛产品(discuz)提取出来的模板类

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/22

return $this->objfile;
}
function getTpl($file) {
$subdir = ($pos = strpos($file, ''/'')) === false ? '''' : substr($file, 0, $pos);
$file = $subdir ? substr($file, $pos + 1) : $file;
$tplfile = $this->tpldir.''/''.($subdir ? $subdir.''/'' : '''').$file.''.htm'';
if(@filemtime($tplfile) === FALSE) {
$tplfile = $this->defaulttpldir.''/''.($subdir ? $subdir.''/'' : '''').$file.''.htm'';
}
return $tplfile;
}
function compile() {
$var_regexp = "\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\''\[\]\$]+\])*";
$vtag_regexp = "\<\?=(\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\''\[\]\$]+\])*)\?\>";
$const_regexp = "\{([\w]+)\}";
$template = file_get_contents($this->tplfile);
for($i = 1; $i <= 3; $i++) {
if(strpos($template, ''{subtpl'') !== FALSE) {
if(DEBUG == 2) {
$template = str_replace(''{subtpl '', ''{tpl '', $template);
} else {
$template = preg_replace("/[\n\r\t]*\{subtpl\s+([a-z0-9_:\/]+)\}[\n\r\t]*/ies", "file_get_contents(\$this->getTpl(''\\1''))", $template);
}
}
}
$remove = array(
''/(^|\r|\n)\/\*.+?(\r|\n)\*\/(\r|\n)/is'',
''/\/\/note.+?(\r|\n)/i'',
''/\/\/debug.+?(\r|\n)/i'',
''/(^|\r|\n)(\s|\t)+/'',
''/(\r|\n)/'',
);
$this->removeblanks && $template = preg_replace($remove, '''', $template);
$template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template);
$template = preg_replace("/\{($var_regexp)\}/", "<?=\\1?>", $template);
$template = preg_replace("/\{($const_regexp)\}/", "<?=\\1?>", $template);
$template = preg_replace("/(?<!\<\?\=|\\\\)$var_regexp/", "<?=\\0?>", $template);
$template = preg_replace("/\<\?=(\@?\\\$[a-zA-Z_]\w*)((\[[\\$\[\]\w]+\])+)\?\>/ies", "\$this->arrayindex(''\\1'', ''\\2'')", $template);
$template = preg_replace("/\{\{eval (.*?)\}\}/ies", "\$this->stripvtag(''<? \\1?>'')", $template);
$template = preg_replace("/\{eval (.*?)\}/ies", "\$this->stripvtag(''<? \\1?>'')", $template);
$template = preg_replace("/[\n\r\t]*\{echo\s+(.+?)\}[\n\r\t]*/ies", "\$this->stripvtag(''<? echo \\1; ?>'','''')", $template);
$template = preg_replace("/\{for (.*?)\}/ies", "\$this->stripvtag(''<? for(\\1) {?>'')", $template);
$template = preg_replace("/\{elseif\s+(.+?)\}/ies", "\$this->stripvtag(''<? } elseif(\\1) { ?>'')", $template);
for($i=0; $i<2; $i++) {
$template = preg_replace("/\{loop\s+$vtag_regexp\s+$vtag_regexp\s+$vtag_regexp\}(.+?)\{\/loop\}/ies", "\$this->loopsection(''\\1'', ''\\2'', ''\\3'', ''\\4'')", $template);
$template = preg_replace("/\{loop\s+$vtag_regexp\s+$vtag_regexp\}(.+?)\{\/loop\}/ies", "\$this->loopsection(''\\1'', '''', ''\\2'', ''\\3'')", $template);
}
$template = preg_replace("/\{if\s+(.+?)\}/ies", "\$this->stripvtag(''<? if(\\1) { ?>'')", $template);
$template = preg_replace("/\{tpl\s+(\w+?)\}/is", "<? include \$this->getObj(\"\\1\");?>", $template);
$template = preg_replace("/\{tpl\s+(.+?)\}/ise", "\$this->stripvtag(''<? include \$this->getObj(\"\\1\"); ?>'')", $template);
$

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号