最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
简单的模板函数
时间:2022-07-02 10:47:26 编辑:袖梨 来源:一聚教程网
简单的模板函数
define('DEFAULT_TEMPLATE', 'templates');
define('DEFAULT_TEMPLATE_C', 'templates_c');
define('TEMPLATE_DEPLOY', true);
function template($FileName, $TemplateDir='', $ComplieDir='', $op = ''){
$str = '';
$TemplateDir = empty($TemplateDir) ? DEFAULT_TEMPLATE : $TemplateDir;
$ComplieDir = empty($ComplieDir) ? DEFAULT_TEMPLATE_C : $ComplieDir;
if(TEMPLATE_DEPLOY === false) {
$comtime = @filemtime($ComplieDir . "/" . md5($FileName).".php");
$temtime = @filemtime($TemplateDir . "/" . $FileName);
$str = file_get_contents($TemplateDir . "/" . $FileName);
$checktemplate = preg_match('|{template (.*)}|isU', $str);
}
if(($temtime > $comtime && TEMPLATE_DEPLOY === false) || $checktemplate){
if(empty($str)) {
$str = file_get_contents($TemplateDir . "/" . $FileName);
}
$str = preg_replace('||isU', '\1){ ?>', $str);
$str = preg_replace('||isU', '', $str);
$str = preg_replace('|{_(.*)}|isU', '\1; ?>', $str);
$str = preg_replace('|{$lang_(.*)}|isU', '\1"]; ?>', $str);
$str = preg_replace('|{$(.*)}|isU', '', $str);
$str = preg_replace('||isU', '', $str);
$str = preg_replace('||isU', '\1){ ?>', $str);
$str = preg_replace('|{eval (.*)}|isU', '\1; ?>', $str);
$str = preg_replace('|{echo (.*)}|isU', '\1; ?>', $str);
if(preg_match_all('|{include_php (.*)}|isU', $str, $phparray)) {
$phpfilename = $phparray[1][0] . ".php";
if(is_file($phpfilename)) {
$phpcontent = str_replace("
$phpcontent = str_replace("?>", " ?>", $phpcontent);
$phpcontent = str_replace("", "
$str = $str . $phpcontent;
}
$str = preg_replace('|{include_php (.*)}|isU', '', $str);
}
$str = preg_replace('|{include_htm(.*) (.*)}|isU', '', $str);
$str = preg_replace('||isU', '\1)){ foreach(\1 as \2 => \3){ ?>', $str);
$str = preg_replace('||isU', '\1) { ?>', $str);
$str = preg_replace('||isU', '', $str);
$str = preg_replace('||isU', '', $str);
if(preg_match_all('|{template (.*)}|isU', $str, $templatearray)) {
$str = preg_replace('|{template (.*)}|isU', '', $str);
$templatefilename = $templatearray[1][0];
if(is_file($TemplateDir . '/' .$templatefilename)) {
$templatecontent = template($templatefilename, $TemplateDir, $ComplieDir, 1);
$str = $str . $templatecontent;
}
}
$str = preg_replace('|t|isU', '', $str);
$str = preg_replace('|rn|isU', '', $str);
$str = preg_replace('|n|isU', '', $str);
$str = preg_replace('|(?>
if(!$op) {
@file_put_contents($ComplieDir . "/" . md5($FileName) . '.php', $str);
}
}
if($op) {
return $str;
}
return $ComplieDir . "/" . md5($FileName) . '.php';
}
相关文章
- 《无限暖暖》织衣蛛获得方法 12-26
- 《无限暖暖》美食家蜜蜂获得方法 12-26
- 《无限暖暖》泳镜蝽获得方法 12-26
- 《无限暖暖》芭蕾豆娘获得方法 12-26
- 《无限暖暖》刺绣蛾获得方法 12-26
- 《无限暖暖》尖帽仙获得方法 12-26