麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
我用的一个模板类
悬赏分:20 - 2007年08月22日

[php]if(!defined("__CLASS_TEMPLATE__"))
{

define("__CLASS_TEMPLATE__",1);


function EvalTemplate($templatefile, $vars, $is_admin=1)
{
global $BASE_ADMIN_TEMPLATE_PATH,$BASE_THEME_PATH,$BASE_PATH;

if($is_admin == 1)
{

$read_templatefile = $BASE_ADMIN_TEMPLATE_PATH.$templatefile;

}
elseif($is_admin == 0)
{

if(file_exists($BASE_THEME_PATH.$templatefile))
{

$read_templatefile = $BASE_THEME_PATH.$templatefile;

}
elseif(file_exists($BASE_PATH."themes/default/".$templatefile))
{

$read_templatefile = $BASE_PATH."themes/default/".$templatefile;

}
else
{

$msg = "没有找到模板文件:".$BASE_THEME_PATH.$templatefile;

email_error($msg);

}

}

$read = file($read_templatefile);

$i = 0;
while($i {
$read[$i] = chop($read[$i])."\n";
$i++;
}

$line=implode($read, "");
eval("global $vars;");

$vars = str_replace(",","",$vars);
$var_list = explode("\$",$vars);
$i=0;
while($i <= sizeof($var_list))
{
$line = str_replace("<%$var_list[$i]%>",$$var_list[$i],$line);
$i++;
}

global $cat;
$line = str_replace("<%cat%>",$cat,$line);

return $line;
}


function DisplayTemplate($templatefile, $vars, $is_admin=1)
{

global $BASE_ADMIN_TEMPLATE_PATH,$BASE_THEME_PATH,$BASE_PATH,$theme_path;

if($is_admin == 1)
{

$read_templatefile = $BASE_ADMIN_TEMPLATE_PATH.$templatefile;

}
elseif($is_admin == 0)
{
if(file_exists($BASE_THEME_PATH.$templatefile))
{

$read_templatefile = $BASE_THEME_PATH.$templatefile;

}
else
{

$read_templatefile = $BASE_PATH."themes/default/".$templatefile;

}
}

$read = file($read_templatefile);

$i = 0;

while($i {
$read[$i] = chop($read[$i])."\n";
$i++;
}

$line=implode($read, "");

eval("global $vars;");

$vars = str_replace(",","",$vars);
$var_list = explode("\$",$vars);
$i = 0;
while($i<=sizeof($var_list))
{
$line = str_replace("<%$var_list[$i]%>",$$var_list[$i],$line);
$i++;
}

global $cat;
$line = str_replace("<%cat%>",$cat,$line);

//$line = str_replace("\n","\r",$line);

$preg = "/(.*)<\/php>/U";
//$preg = "/.*<\/php>/m";
preg_match_all($preg,$line,$out,PREG_SET_ORDER);
$lines = preg_split($preg,$line);

if(sizeof($lines)>1)
{
$loop_line=0;
while(!empty($out[$loop_line][1]))
{

print $lines[$loop_line];
eval($out[$loop_line][1]);

$loop_line++;

if(empty($out[$loop_line][1]))
{
print $lines[$loop_line];
}
}
}
else
{
print $lines[0];
}

}


function revers_htmlspecialchars($msg)
{

$msg = str_replace("/>/i", ">", $msg);
$msg = str_replace("/</i", "<", $msg);
$msg = str_replace("/"/i", "\"", $msg);
$msg = str_replace("/&/i", "&", $msg);
return $msg;

}

function email_error($msg)
{

global $technical_email;

$message = "有一个模板错误: $msg\n";
$message .= "日期: ".date("Y-m-d H:i:s")."\n";
$message .= "脚本: ".getenv("REQUEST_URI")."\n";
$message .= "来自: ".getenv("HTTP_REFERER")."\n";
$message.="所在行: ".getenv("__LINE__")."\n";
//echo $message;
@mail ($technical_email,"有一个模板错误!",$message);

echo "\n\n";

echo "\n

看上去发生了轻微的错误.\n";
echo "请再刷新尝试一下.

";
echo "一封电邮已经发送给我们的technical_email\">技术人员, 如果问题依然, 您也可以联系他.

";
echo "

如有不便, 敬请原谅.

";
die("");
}

}
[/php]

提问者:ml188   08-22 16:04
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
20 + 14 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM