www.gusucode.com > 网猫影视系统NetMao Movie 4.6.6 开源版源码程序 > upload/inc/template.func.php

    <?php
/*
*######################################
* Netmao Movie 4.x - NetMao Movie System
* Copyright (c) 2007-2008 NetMao.cn
* For further information go to http://www.netmao.cn/
* This copyright notice must stay intact for use.
*######################################
*/
if(!defined('IN_NetMao')) exit('Access Denied');

function parse_template($file, $templateid, $tpldir) {
    $tplfile = NetMao_ROOT."./$tpldir/$file.htm";
    $objfile = NetMao_ROOT."./mdata/templates/{$templateid}_$file.tpl.php";
   if(!@$fp = fopen($tplfile, 'r')) {
        exit("Current template file '$tpldir/$file.htm' not found or have no access!");
    }
    $template = @fread($fp, filesize($tplfile));
    fclose($fp);
    $template=preg_replace("/([\n\r]+)\t+/s","\\1",$template);
    $template=preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}",$template);
    $template = "<? if(!defined('IN_NetMao')) exit('Access Denied'); ?>\n$template";
    $template=preg_replace("/\{template\s+(.+)\}/","\n<?php include template(\\1); ?>\n",$template);
    $template=preg_replace("/\{include\s+(.+)\}/","\n<?php include \\1; ?>\n",$template);
    $template=preg_replace("/\{if\s+(.+?)\}/","\n<? if(\\1) { ?>\n",$template);
    $template=preg_replace("/\{else\}/","\n<? } else { ?>\n",$template);
    $template=preg_replace("/\{elseif\s+(.+?)\}/","\n<? } elseif (\\1) { ?>\n",$template);
    $template=preg_replace("/\{\/if\}/","<? } ?>",$template);
    $template=preg_replace("/\{loop\s+(\S+)\s+(\S+)\}/","<? if(is_array(\\1)) foreach(\\1 AS \\2) { ?>",$template);
    $template=preg_replace("/\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}/","\n<? if(is_array(\\1)) foreach(\\1 AS \\2 => \\3) { ?>\n",$template);
    $template=preg_replace("/\{\/loop\}/","\n<? } ?>\n",$template);
    $template=preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/","<?=\\1?>",$template);
    $template=preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s", "<?=\\1?>",$template);
    $template=preg_replace("/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/s", "<?=\\1?>",$template);
    $template=preg_replace("/[\n\r\t]*\{eval\s+(.+?)\}[\n\r\t]*/ies", "stripvtags('\n<? \\1 ?>\n','')", $template);
    if(!@$fp = fopen($objfile, 'w')) {
        exit("Directory './mdata/templates/' not found or have no access!");
    }
    flock($fp, 2);
    fwrite($fp, $template);
    fclose($fp);
}

function stripvtags($expr, $statement) {
    $expr = str_replace("\\\"", "\"", preg_replace("/\<\?\=(\\\$.+?)\?\>/s", "\\1", $expr));
    $statement = str_replace("\\\"", "\"", $statement);
    return $expr.$statement;
}
?>