phpcms template函数分析
来源:互联网 发布:手机单机飞机游戏 知乎 编辑:程序博客网 时间:2024/06/05 16:35
/////////////////////////////////////
// template(模板调用)函数分析
//
/////////////////////////////////////
function template 位于 libs/functions/globel.func.php
一. 参数分析
参数($module$template $style)
模块名 模板名 模板风格
下面会以$module='content',$template='index',$style=''为例
二. 代码分段分析
1. if(strpos($module, 'plugin/')!== false){
$plugin = str_replace('plugin/', '',$module);
return p_template($plugin,$template,$style);
}
//检测是否是插件调用如果是调用p_template()函数处理(分析在p_template函数分析.txt)
-------------------------------------------------------------------------------------------------
2. $module = str_replace('/',DIRECTORY_SEPARATOR, $module);
//把$module中原本的'/'替换成系统分隔符
-------------------------------------------------------------------------------------------------
3. if(!empty($style) &&preg_match('/([a-z0-9\-_]+)/is',$style)) {
} elseif(empty($style) && !defined('STYLE')) {
if(defined('SITEID')) {
$siteid = SITEID;
} else {
$siteid = param::get_cookie('siteid');
}
if (!$siteid) $siteid = 1;
$sitelist = getcache('sitelist','commons');
if(!empty($siteid)) {
$style =$sitelist[$siteid]['default_style'];
}
} elseif(empty($style) && defined('STYLE')) {
$style = STYLE;
} else{
$style = 'default';
}
如果$style不为空$style没有特殊字符
如果$style为空 和 未定义STYLE常量
得到$siteid(站点ID)
通过sitelist缓存得到$style
如果$style为空 和 已定义STYLE常量
$style = STYLE;
其他状况 $style ='default';(采用默认)
-------------------------------------------------------------------------------------------------
4. if(!$style) $style ='default'; //如果$style为空 $style用默认风格(那上面在干嘛?)
-------------------------------------------------------------------------------------------------
5. $template_cache =pc_base::load_sys_class('template_cache'); //实例化template_cache类
-------------------------------------------------------------------------------------------------
6. $compiledtplfile =PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
//得到缓存路径,以$module='content',$template='index'为例, 实际字符串(路径)为D:\xampp\htdos\www\caches\caches_template\defalut\content\index.php
-------------------------------------------------------------------------------------------------
7. 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');
// template(模板调用)函数分析
//
/////////////////////////////////////
function template 位于 libs/functions/globel.func.php
一. 参数分析
参数($module
二. 代码分段分析
1.
-------------------------------------------------------------------------------------------------
2.
-------------------------------------------------------------------------------------------------
3.
-------------------------------------------------------------------------------------------------
4.
-------------------------------------------------------------------------------------------------
5.
-------------------------------------------------------------------------------------------------
6.
-------------------------------------------------------------------------------------------------
7.