phpcms 2008 sp4的模板原理,tag的解析原理

phpcms中模板解析主要是通过global.func.php,的

function template($module = 'phpcms', $template = 'index', $istag = 0)
{
	$compiledtplfile = TPL_CACHEPATH.$module.'_'.$template.'.tpl.php';
  //  echo "$compiledtplfile";
	if(TPL_REFRESH && (!file_exists($compiledtplfile)
            || @filemtime(TPL_ROOT.TPL_NAME.'/'.$module.'/'.$template.'.html') > @filemtime($compiledtplfile) ||
                    @filemtime(TPL_ROOT.TPL_NAME.'/tag.inc.php') > @filemtime($compiledtplfile)))
	{
		require_once PHPCMS_ROOT.'include/template.func.php';
		template_compile($module, $template, $istag);
	}
	return $compiledtplfile;
}

函数来实现的,这其中比较重要的是template_compile函数来实现的对模板的编译,编译过过程中使用了preg_replace这个函数并加了个/e参数,对tag,get这样的标签进行了替换

	$str = preg_replace("/\{tag_([^}]+)\}/e", "get_tag('\\1')", $str);
	$str = preg_replace("/\{get\s+([^}]+)\}/e", "get_parse('\\1')", $str);

举个例子,对于<div id="slide">{tag_首页幻灯片}</div>这个标签的解析的结果为, 

<!--幻灯片-->
<div id="slide"><?php echo tag('phpcms', 'tag_content_slide', "SELECT a.contentid,a.catid,a.typeid,a.areaid,a.title,a.style,a.thumb,a.keywords,a.description,a.userid,a.updatetime,a.inputtime,a.url FROM `pc_content` a, `pc_content_position` p WHERE a.contentid=p.contentid AND p.posid=2 AND a.status=99   AND  `thumb`!=''  ORDER BY a.contentid DESC", 0, 5, array (  'class' => 'url',  'target' => '_blank',  'width' => '296',  'height' => '164',));?></div>
<!--热点文章-->

function get_tag($tagname)
{
	global $TAG;
    if(!isset($TAG)) $TAG = cache_read('tag.inc.php', TPL_ROOT.TPL_NAME.'/');
	return isset($TAG[$tagname]) ? '<?php echo '.$TAG[$tagname].';?>' : '{tag_'.$tagname.'}';
}

模板解析后,使用了inlude并解析后的文件包含进来,解析的内容默认是从template/default/tag.inc.php中取出的内容
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值