//note 默认目录
if(@filemtime($this->tplfile) === FALSE) {
$this->tplfile = $this->defaulttpldir.'/'.($subdir ? $subdir.'/' : '').$file.'.htm';
}
//note 判断是否比较过期
if(!file_exists($this->objfile) || DEBUG && @filemtime($this->objfile) < filemtime($this->tplfile)) {
$this->compile();
}
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("/[nrt]*{subtpls+([a-z0-9_:/]+)}[nrt]*/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/", "<?= ?>", $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("/[nrt]*{echos+(.+?)}[nrt]*/ies", "$this->stripvtag('<? echo 1; ?>','')", $template);
$template = preg_replace("/{for (.*?)}/ies", "$this->stripvtag('<? for(1) {?>')", $template);
$template = preg_replace("/{elseifs+(.+?)}/ies", "$this->stripvtag('<? } elseif(1) { ?>')", $template);
for($i=0; $i<2; $i++) {
$template = preg_replace("/{loops+$vtag_regexps+$vtag_regexps+$vtag_regexp}(.+?){/loop}/ies", "$this->loopsection('1', '2', '3', '4')", $template);
$template = preg_replace("/{loops+$vtag_regexps+$vtag_regexp}(.+?){/loop}/ies", "$this->loopsection('1', '', '2', '3')", $template);







