优化模板变量渲染

This commit is contained in:
Karson
2026-03-12 22:50:56 +08:00
parent f0774ddd5a
commit 43e36f91ba

View File

@@ -936,12 +936,13 @@ class Template
$args = explode('=', $varArray[$i], 2); $args = explode('=', $varArray[$i], 2);
// 模板函数过滤 // 模板函数过滤
$fun = trim($args[0]); $fun = trim($args[0]);
switch ($fun) { if (in_array($fun, $template_deny_funs)) {
continue;
}
switch (strtolower($fun)) {
case 'raw': case 'raw':
break; break;
case 'htmlentities':
$name = 'htmlentities((string) ' . $name . ')';
break;
case 'default': // 特殊模板函数 case 'default': // 特殊模板函数
if (false === strpos($name, '(')) { if (false === strpos($name, '(')) {
$name = '(isset(' . $name . ') && (' . $name . ' !== \'\')?' . $name . ':' . $args[1] . ')'; $name = '(isset(' . $name . ') && (' . $name . ' !== \'\')?' . $name . ':' . $args[1] . ')';
@@ -950,26 +951,25 @@ class Template
} }
break; break;
default: // 通用模板函数 default: // 通用模板函数
if (!in_array($fun, $template_deny_funs)) { if (isset($args[1])) {
if (isset($args[1])) { if (strstr($args[1], '###')) {
if (strstr($args[1], '###')) { $args[1] = str_replace('###', $name, $args[1]);
$args[1] = str_replace('###', $name, $args[1]); $name = "$fun($args[1])";
$name = "$fun($args[1])";
} else {
$name = "$fun($name ?? '',$args[1])";
}
} else { } else {
if (!empty($args[0])) { $name = "$fun($name,$args[1])";
$name = "$fun($name ?? '')"; }
} } else {
if (!empty($args[0])) {
$name = "$fun($name)";
} }
} }
} }
} }
$_varFunctionList[$_key] = $name; $_varFunctionList[$_key] = $name;
$varStr = $name; $varStr = $name;
} }
return; return $varStr;
} }
/** /**