/**  
* 模板调用  
*  
* @param $module  
* @param $template  
* @param $istag  
* @return unknown_type  
*/
function template($module = 'content', $template = 'index', $style = '') {  
 
if(strpos($module, 'plugin/')!== false) {  
$plugin = str_replace('plugin/', '', $module);  
return p_template($plugin, $template,$style);  
}  
$module = str_replace('/', DIRECTORY_SEPARATOR, $module);  
if(!emptyempty($style) && preg_match('/([a-z0-9/-_]+)/is',$style)) {  
} elseif (emptyempty($style) && !defined('STYLE')) {  
if(defined('SITEID')) {  
$siteid = SITEID;  
} else {  
$siteid = param::get_cookie('siteid');  
}  
if (!$siteid) $siteid = 1;  
$sitelist = getcache('sitelist','commons');  
if(!emptyempty($siteid)) {  
$style = $sitelist[$siteid]['default_style'];  
}  
} elseif (emptyempty($style) && defined('STYLE')) {  
$style = STYLE;  
} else {  
$style = 'default';  
}  
if(!$style) $style = 'default';  
$template_cache = pc_base::load_sys_class('template_cache');  
$compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';  
if(file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {  
if(!file_exists($compiledtplfile) || (@filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > @filemtime($compiledtplfile))) {  
$template_cache->template_compile($module, $template, $style);  
}  
} else {  
$compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';  
if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) {  
$template_cache->template_compile($module, $template, 'default');  
} elseif (!file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {  
showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html');  
}  
}  
return $compiledtplfile;  
}  
 
   
 
/**
* 模板解析缓存  
*/
final class template_cache {  
 
/**
* 编译模板  
*  
* @param $module    模块名称  
* @param $template  模板文件名  
* @param $istag 是否为标签模板  
* @return unknown  
*/
 
public function template_compile($module, $template, $style = 'default') {  
if(strpos($module, '/')=== false) {  
$tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';  
} elseif (strpos($module, 'yp/') !== false) {  
$module = str_replace('/', DIRECTORY_SEPARATOR, $module);  
$tplfile = $_tpl = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';  
} else {  
$plugin = str_replace('plugin/', '', $module);  
$module = str_replace('/', DIRECTORY_SEPARATOR, $module);  
$tplfile = $_tpl = PC_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html';  
}  
if ($style != 'default' && !file_exists ( $tplfile )) {  
$style = 'default';  
$tplfile = PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html';  
}  
if (! file_exists ( $tplfile )) {  
showmessage ( "templates".DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.".html is not exists!" );  
}  
$content = @file_get_contents ( $tplfile );  
 
$filepath = CACHE_PATH.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR;  
if(!is_dir($filepath)) {  
mkdir($filepath, 0777, true);  
}  
$compiledtplfile = $filepath.$template.'.php';  
$content = $this->template_parse($content);  
$strlen = file_put_contents ( $compiledtplfile, $content );  
chmod ( $compiledtplfile, 0777 );  
return $strlen;  
}  
 
/**
* 更新模板缓存  
*  
* @param $tplfile   模板原文件路径  
* @param $compiledtplfile   编译完成后,写入文件名  
* @return $strlen 长度  
*/
public function template_refresh($tplfile, $compiledtplfile) {  
$str = @file_get_contents ($tplfile);  
$str = $this->template_parse ($str);  
$strlen = file_put_contents ($compiledtplfile, $str );  
chmod ($compiledtplfile, 0777);  
return $strlen;  
}  
/**
* 解析模板  
*  
* @param $str   模板内容  
* @return ture  
*/
public function template_parse($str) {  
$str = preg_replace ( "//{template/s+(.+)

dawei

【声明】:站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。