Browse Source

init

master
heavenK 3 years ago
parent
commit
3a0a578a14
  1. 22
      includes/cls_template.php

22
includes/cls_template.php

@ -323,7 +323,10 @@ class cls_template
$source= str_replace('%%%SMARTYSP'.$curr_sp.'%%%', '<?php echo \''.str_replace("'", "\'", $sp_match[1][$curr_sp]).'\'; ?>'."\n", $source);
}
}*/
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
//return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
return preg_replace_callback("/{([^\}\{]*)}/", function($r) { return $this->select($r[1]); }, $source);
}
/**
@ -521,7 +524,9 @@ class cls_template
case 'insert' :
$t = $this->get_para(substr($tag, 7), false);
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
//$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
$out = "<?php " . '$k = ' . preg_replace_callback("/(\'\\$[^,] )/" , function($match){return stripslashes(trim($match[1],'\''));}, var_export($t, true)) . ";\n";
$out .= 'echo $this->_echash . $k[\'name\'] . \'|\' . serialize($k) . $this->_echash;' . "\n?>";
return $out;
@ -580,7 +585,9 @@ class cls_template
{
if (strrpos($val, '[') !== false)
{
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
//$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
$val = preg_replace_callback('/\[([^\[\]]*)\]/is',function ($matches) {return '.'.str_replace('$','\$',$matches[1]);},$val);
}
if (strrpos($val, '|') !== false)
@ -1097,9 +1104,12 @@ class cls_template
if ($file_type == '.dwt')
{
/* 将模板中所有library替换为链接 */
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
$replacement = "'{include file='.strtolower('\\1'). '}'";
$source = preg_replace($pattern, $replacement, $source);
// $pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
// $replacement = "'{include file='.strtolower('\\1'). '}'";
// $source = preg_replace($pattern, $replacement, $source);
$pattern = '/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s';
$replacement = function($r){return '{include file='.strtolower($r[1]). '}';};
$source = preg_replace_callback($pattern, $replacement, $source);
/* 检查有无动态库文件,如果有为其赋值 */
$dyna_libs = get_dyna_libs($GLOBALS['_CFG']['template'], $this->_current_file);

Loading…
Cancel
Save