|
如果你了解PHP,可以按一下方法操作,如果不了解,请直接下载附件里的三个文件覆盖include里的同名文件即可
PHPCMS版本:phpcms2007SP6
移植方法:
1:打开/include/template.func.php,
查找
$str = preg_replace("/\{tag_([^}]+)\}/e", "get_tag('\\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);
在最后加入:
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($return) || !preg_match("/^\w+$/i", $return)) $return = 'r';
if(isset($page))
{
$str = "<?php \$ARRAY = get(\"$sql\", $rows, $page, \"$dbname\", \"$dbsource\");\$DATA=\$ARRAY['data'];\$total=\$ARRAY['total'];\$count=\$ARRAY['count'];\$pages=\$ARRAY['pages'];unset(\$ARRAY);foreach(\$DATA AS \$n=>\${$return}){\$n++;?>";
}
else
{
$str = substr($str, -1) == '/' ? "<?php \${$return} = get(\"$sql\", -1, 0, \"$dbname\", \"$dbsource\");?>" : "<?php \$DATA = get(\"$sql\", $rows, 0, \"$dbname\", \"$dbsource\");foreach(\$DATA AS \$n => \${$return}) { \$n++;?>";
}
return $str;
}
2:打开/include/global.func.php,
在最后加入:
function get($sql, $rows = 0, $page = 0)
{
if(!$sql) return false;
global $db;
if(DB_PRE != 'phpcms_') $sql = str_replace('phpcms_', DB_PRE, $sql);
$rows = intval($rows);
if(!isset($page)) $page = 1;
$page = max(intval($page), 0);
$pages = $limit = '';
if($page)
{
$offset = $rows*($page-1);
$limit = " LIMIT $offset, $rows";
$total = cache_count("SELECT COUNT(*) AS `count` ".stristr($sql, 'from'));
$pages = pages($total, $page, $rows);
}
elseif($rows > 0)
{
$limit = " LIMIT $rows";
}
$data = $rows == -1 ? $db->get_one($sql) : $db->select($sql.$limit);
if(isset($s['dbcharset']) && $s['dbcharset'] != DB_CHARSET) $data = str_charset($s['dbcharset'], CHARSET, $data);
if($page)
{
$count = count($data);
if(!isset($total)) $total = $count;
return array('data'=>$data, 'total'=>$total, 'count'=>count($data), 'pages'=>$pages);
}
else
{
return $data;
}
}
3:打开/include/db_mysql.class.php,
查找:
function query(
在此函数后面增加一下函数:
function select($sql, $keyfield = '')
{
$array = array();
$result = $this->query($sql);
while($r = $this->fetch_array($result))
{
if($keyfield)
{
$key = $r[$keyfield];
$array[$key] = $r;
}
else
{
$array[] = $r;
}
}
$this->free_result($result);
return $array;
}
移植完成!
注明:移植后不会影响之前功能,新功能GET使用方法[暂不支持跨库调用和分页]:
1、调用本系统单条数据,示例(调用ID为1的信息,标题长度不超过25个汉字,显示更新日期):
{get sql="select * from phpcms_content where contentid=1" /}
标题:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
2、调用本系统多条数据,示例(调用栏目ID为1通过审核的10条信息,标题长度不超过25个汉字,显示更新日期):
{get sql="select * from phpcms_content where catid=1 and status=99 order by updatetime desc" rows="10"}
标题:{str_cut($r[title], 50)} URL:{$r[url]} 更新日期:{date('Y-m-d', $r[updatetime])}
{/get}
|
|