template_edit.func.php
来自「Phpcms2008 是一款基于 PHP+Mysql 架构的网站内容管理系统」· PHP 代码 · 共 95 行
PHP
95 行
<?php
function template_edit_compile($module, $template, $istag = 0)
{
$tplfile = TPL_ROOT.TPL_NAME.'/'.$module.'/'.$template.'.html';
$content = @file_get_contents($tplfile);
if($content === false) showmessage("$tplfile is not exists!");
$compiledtplfile = TPL_CACHEPATH.$module.'_'.$template.'.edit.php';
$content = ($istag || substr($template, 0, 4) == 'tag_') ? '<?php function _tag_'.$module.'_'.$template.'($data, $number, $rows, $count, $page, $pages, $setting){ global $PHPCMS,$MODULE,$M,$CATEGORY,$TYPE,$AREA,$GROUP,$MODEL,$templateid,$_userid,$_username;@extract($setting);?>'.template_edit_parse($content, 1).'<?php } ?>' : template_edit_parse($content);
$strlen = file_put_contents($compiledtplfile, $content);
@chmod($compiledtplfile, 0777);
return $strlen;
}
function template_edit_parse($str, $istag = 0)
{
global $file, $action;
$str = preg_replace("/([\n\r]+)\t+/s","\\1",$str);
$str = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}",$str);
$str = preg_replace("/\{template\s+(.+)\}/","<?php include admin_template(\\1); ?>",$str);
$str = preg_replace("/\{include\s+(.+)\}/","<?php include \\1; ?>",$str);
$str = preg_replace("/\{php\s+(.+)\}/","<?php \\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\}/","<?php } unset(\$DATA); ?>",$str);
if($file.'-'.$action == 'template-tag')
{
$str = preg_replace("/\{tag_([^}]+)\}/e", "get_edit_tag('\\1')", $str);
$str = preg_replace("/\{block\((.+)\)\}/e", "get_block('\\1')", $str);
}
else
{
$str = preg_replace("/\{tag_([^}]+)\}/e", "get_edit_tag('\\1')", $str);
$str = preg_replace("/\{block\((.+)\)\}/", "{block_edit(\\1)}", $str);
}
$str = preg_replace("/\{get\s+([^}]+)\}/e", "get_edit_parse('\\1')", $str);
$str = preg_replace("/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$str);
$str = preg_replace("/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$str);
$str = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/","<?php echo \\1;?>",$str);
$str = preg_replace("/\{(\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/es", "addquote_edit('<?php echo \\1;?>')",$str);
$str = preg_replace("/\{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)\}/s", "<?php echo \\1;?>",$str);
if(!$istag) $str = "<?php defined('IN_PHPCMS') or exit('Access Denied'); ?>".$str;
return $str;
}
function template_edit_block($blockid)
{
$tplfile = TPL_ROOT.TPL_NAME.'/phpcms/block/'.$blockid.'.html';
$compiledtplfile = TPL_CACHEPATH.'phpcms_block_'.$blockid.'.tpl.php';
if(TPL_REFRESH && (!file_exists($compiledtplfile) || @filemtime($tplfile) > @filemtime($compiledtplfile)))
{
$str = file_get_contents($tplfile);
$str = template_edit_parse($str);
$strlen = file_put_contents($compiledtplfile, $str);
@chmod($compiledtplfile, 0777);
}
return $compiledtplfile;
}
function get_edit_tag($tagname)
{
global $TAG, $file, $action, $module;
if(!isset($TAG)) $TAG = cache_read('tag.inc.php', TPL_ROOT.TPL_NAME.'/');
if(isset($TAG[$tagname]))
{
preg_match("/^tag\(\'([0-9a-z_-]+)\'/", $TAG[$tagname], $m);
$module = $m[1];
if($file.'-'.$action == 'template-tag' && strpos($TAG[$tagname], '$') !== false)
{
$data = '<div class="show_tag" module="'.$module.'" tagname="'.$tagname.'" forward="'.urlencode(URL).'">{tag_'.$tagname.'}</div>';
}
else
{
preg_match("/select(.*)\"/i",$TAG[$tagname],$mn);
$data = "<div id='tag_$tagname'>";
if(strpos($mn[0], '$')===false)
{
$data .= '<?php echo '.$TAG[$tagname].';?>';
}
else
{
preg_match_all("/(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/", $TAG[$tagname], $matches, PREG_PATTERN_ORDER);
$vars = '';
foreach($matches[1] as $var)
{
if($var !== '$page') $vars .= "&& isset($var)";
}
$vars = substr($vars, 3);
$data .= '<?php if('.$vars.') echo '.$TAG[$tagname].';?>';
}
$data .= "</div><div class='tag_float_div' id='tag_float_div_$tagname' tagname='$tagname' module='$module' title='鐐瑰嚮淇
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?