phpcms网站修改模板中如何使get标签实现嵌套调用?

phpcms网站修改模板中如何使get标签实现嵌套调用?

在phpcms中get标签的使用非常的方便灵活,是大多数站长们的最爱,一般懂一点sql语句的朋友使用,都没有任何问题.
但完美中也存在着不足,在官方的版本中get标签是不能嵌套调用的,下面就提供一种实现get标签嵌套调用的方法:
在这个方法中,主要改动的是  include/template.func.php这个文件,
首先打开这个文件,
找到这个函数  function template_parse
换成
function template_parse($str, $istag = 0)
{
$str = preg_replace(“/([]+)\t+/s”,”\\1″,$str);
$str = preg_replace(“/\<\!\-\-\{(.+?)\}\-\-\>/s”, “{\\1}”,$str);
$str = preg_replace(“/\{template\s+(.+)\}/”,”<?php include template(\\1); ?>”,$str);
$str = preg_replace(“/\{include\s+(.+)\}/”,”<?php include \\1; ?>”,$str);
$str = preg_replace(“/\{php\s+(.+)\}/”,”<?php “,$str’>\\1?>”,$str);
$str = preg_replace(“/\{if\s+(.+?)\}/”,”<?php if(\\1) { ?>”,$str);
$str = preg_replace(“/\{else\}/”,”<?php } else { ?>”,$str);
$str = preg_replace(“/\{elseif\s+(.+?)\}/”,”<?php } elseif (\\1) { ?>”,$str);
$str = preg_replace(“/\{\/if\}/”,”<?php } ?>”,$str);
$str = preg_replace(“/\{loop\s+(\S+)\s+(\S+)\}/”,”<?php if(is_array(\\1)) foreach(\\1 AS \\2) { ?>”,$str);
$str = preg_replace(“/\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}/”,”<?php if(is_array(\\1)) foreach(\\1 AS \\2 => \\3) { ?>”,$str);
$str = preg_replace(“/\{\/loop\}/”,”<?php } ?>”,$str);
$str = preg_replace(“/\{\/get\s+dr=\”([^\"\}]+)\”\s+\}/”,”<?php } unset(\$\\1); ?>”,$str);
$str = preg_replace(“/\{\/get\}/”,”<?php } unset(\$DATA); ?>”,$str);
$str = preg_replace(“/\{tag_([^}]+)\}/e”, “get_tag(‘\\1′)”, $str);
$str = preg_replace(“/\{get\s+([^}]+)\}/e”, “get_parse(‘\\1′)”, $str);
$str = preg_replace(“/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/”,”<?php echo “,$str’>\\1;?>”,$str);
$str = preg_replace(“/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/”,”<?php echo “,$str’>\\1;?>”,$str);
$str = preg_replace(“/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/”,”<?php echo “,$str’>\\1;?>”,$str);
$str = preg_replace(“/\{(\\$[a-zA-Z0-9_\[\]\’\”\$\x7f-\xff]+)\}/es”, “addquote(‘<?php echo ‘)&quot;,$str”>\\1;?>’)”,$str);
$str = preg_replace(“/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s”, “<?php echo “,$str’>\\1;?>”,$str);
if(!$istag) $str = “<?php defined(‘IN_PHPCMS’) or exit(‘Access Denied’); ?>”.$str;
return $str;
}

找到function get_parse换成
function get_parse($str)
{
preg_match_all(“/([a-z]+)\=\”([^\"]+)\”/i”, stripslashes($str), $matches, PREG_SET_ORDER);
foreach($matches as $v)
{
$r[$v[1]] = $v[2];
}
extract($r);
if(!isset($dbsource)) $dbsource = ”;
if(!isset($dbname)) $dbname = ”;
if(!isset($sql)) $sql = ”;
if(!isset($rows)) $rows = 0;
if(!isset($urlrule)) $urlrule = ”;
if(!isset($catid)) $catid = 0;
if(!isset($distinctfield)) $distinctfield = ”;
if(!isset($return) || !preg_match(“/^\w+$/i”, $return)) $return = ‘r’;
if(!isset($dr)) $dr = ‘DATA’;
if(!isset($sn)) $sn = ‘n’;
if(isset($page))
{
$str = “<?php \$ARRAY = get(\”$sql\”, $rows, $page, \”$dbname\”, \”$dbsource\”, \”$urlrule\”,\”$distinctfield\”,\”$catid\”);\${$dr}=\$ARRAY['data'];\$total=\$ARRAY['total'];\$count=\$ARRAY['count'];\$pages=\$ARRAY['pages'];unset(\$ARRAY);foreach(\${$dr} AS \${$sn}=>\${$return}){\${$sn}++;?>”;
}
else
{
$str = substr($str, -1) == ‘/’ ? “<?php \${$return} = get(\”$sql\”, -1, 0, \”$dbname\”, \”$dbsource\”);?>” : “<?php \${$dr} = get(\”$sql\”, $rows, 0, \”$dbname\”, \”$dbsource\”);foreach(\${$dr} AS \${$sn} => \${$return}) { \${$sn}++;?>”;
}
return $str;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值