diff --git a/src/Compile/smarty_internal_compile_continue.php b/src/Compile/ContinueTag.php similarity index 67% rename from src/Compile/smarty_internal_compile_continue.php rename to src/Compile/ContinueTag.php index 1eefb7c7..105c4908 100644 --- a/src/Compile/smarty_internal_compile_continue.php +++ b/src/Compile/ContinueTag.php @@ -8,6 +8,8 @@ * @author Uwe Tews */ +namespace Smarty\Compile; + use Smarty\Compile\BreakTag; /** @@ -16,12 +18,12 @@ use Smarty\Compile\BreakTag; * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Continue extends BreakTag -{ - /** - * Tag name - * - * @var string - */ - public $tag = 'continue'; +class ContinueTag extends BreakTag { + + /** + * Tag name + * + * @var string + */ + public $tag = 'continue'; } diff --git a/src/Compile/ForeachSection.php b/src/Compile/ForeachSection.php new file mode 100644 index 00000000..2ed4a760 --- /dev/null +++ b/src/Compile/ForeachSection.php @@ -0,0 +1,213 @@ +propertyPreg = '~('; + $this->startOffset = 1; + $this->resultOffsets = []; + $this->matchResults = ['named' => [], 'item' => []]; + if (isset($attributes['name'])) { + $this->buildPropertyPreg(true, $attributes); + } + if (isset($this->itemProperties)) { + if ($this->isNamed) { + $this->propertyPreg .= '|'; + } + $this->buildPropertyPreg(false, $attributes); + } + $this->propertyPreg .= ')\W~i'; + // Template source + $this->matchTemplateSource($compiler); + // Parent template source + $this->matchParentTemplateSource($compiler); + } + + /** + * Build property preg string + * + * @param bool $named + * @param array $attributes + */ + private function buildPropertyPreg($named, $attributes) { + if ($named) { + $this->resultOffsets['named'] = $this->startOffset = $this->startOffset + 3; + $this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . + ($this->tagName === 'section' ? "|[\[]\s*" : '') . + "){$attributes['name']}[.]("; + $properties = $this->nameProperties; + } else { + $this->resultOffsets['item'] = $this->startOffset = $this->startOffset + 2; + $this->propertyPreg .= "([\$]{$attributes['item']}[@]("; + $properties = $this->itemProperties; + } + $propName = reset($properties); + while ($propName) { + $this->propertyPreg .= "{$propName}"; + $propName = next($properties); + if ($propName) { + $this->propertyPreg .= '|'; + } + } + $this->propertyPreg .= '))'; + } + + /** + * Find matches in source string + * + * @param string $source + */ + private function matchProperty($source) { + preg_match_all($this->propertyPreg, $source, $match); + foreach ($this->resultOffsets as $key => $offset) { + foreach ($match[$offset] as $m) { + if (!empty($m)) { + $this->matchResults[$key][smarty_strtolower_ascii($m)] = true; + } + } + } + } + + /** + * Find matches in template source + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler + */ + private function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) { + $this->matchProperty($compiler->parser->lex->data); + } + + /** + * Find matches in all parent template source + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler + * + * @throws \SmartyException + */ + private function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) { + // search parent compiler template source + $nextCompiler = $compiler; + while ($nextCompiler !== $nextCompiler->parent_compiler) { + $nextCompiler = $nextCompiler->parent_compiler; + if ($compiler !== $nextCompiler) { + // get template source + $_content = $nextCompiler->template->source->getContent(); + if ($_content !== '') { + // run pre filter if required + if (isset($nextCompiler->smarty->registered_filters['pre'])) { + $_content = $nextCompiler->smarty->ext->_filterHandler->runFilter( + 'pre', + $_content, + $nextCompiler->template + ); + } + $this->matchProperty($_content); + } + } + } + } + + /** + * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter + * + * @return string compiled code + * @throws \SmartyCompilerException + */ + public function compileSpecialVariable(Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { + $tag = smarty_strtolower_ascii(trim($parameter[0], '"\'')); + $name = isset($parameter[1]) ? $compiler->getId($parameter[1]) : false; + if (!$name) { + $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); + } + $property = isset($parameter[2]) ? smarty_strtolower_ascii($compiler->getId($parameter[2])) : false; + if (!$property || !in_array($property, $this->nameProperties)) { + $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); + } + $tagVar = "'__smarty_{$tag}_{$name}'"; + return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; + } +} diff --git a/src/Compile/Include.php b/src/Compile/IncludeTag.php similarity index 100% rename from src/Compile/Include.php rename to src/Compile/IncludeTag.php diff --git a/src/Compile/MakeNocache.php b/src/Compile/MakeNocache.php new file mode 100644 index 00000000..c1844c8a --- /dev/null +++ b/src/Compile/MakeNocache.php @@ -0,0 +1,66 @@ +getAttributes($compiler, $args); + if ($compiler->template->caching) { + $output = "smarty->ext->_make_nocache->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n"; + $compiler->template->compiled->has_nocache_code = true; + $compiler->suppressNocacheProcessing = true; + return $output; + } else { + return true; + } + } +} diff --git a/src/Compile/PrivateBlockPlugin.php b/src/Compile/PrivateBlockPlugin.php new file mode 100644 index 00000000..53529bdb --- /dev/null +++ b/src/Compile/PrivateBlockPlugin.php @@ -0,0 +1,125 @@ +getAttributes($compiler, $args); + $this->nesting++; + unset($_attr['nocache']); + [$callback, $_paramsArray, $callable] = $this->setup($compiler, $_attr, $tag, $function); + $_params = 'array(' . implode(',', $_paramsArray) . ')'; + // compile code + $output = "nesting} = isset({$callback[0]}) ? {$callback[0]} : null;\n"; + $callback = "\$_block_plugin{$this->nesting}{$callback[1]}"; + } + if (isset($callable)) { + $output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n"; + } + $output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();?>"; + $this->openTag($compiler, $tag, [$_params, $compiler->nocache, $callback]); + // maybe nocache because of nocache variables or nocache plugin + $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; + } else { + // must endblock be nocache? + if ($compiler->nocache) { + $compiler->tag_nocache = true; + } + // closing tag of block plugin, restore nocache + [$_params, $compiler->nocache, $callback] = $this->closeTag($compiler, substr($tag, 0, -5)); + // compile code + if (!isset($parameter['modifier_list'])) { + $mod_pre = $mod_post = $mod_content = ''; + $mod_content2 = 'ob_get_clean()'; + } else { + $mod_content2 = "\$_block_content{$this->nesting}"; + $mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n"; + $mod_pre = "ob_start();\n"; + $mod_post = 'echo ' . $compiler->compileTag( + 'private_modifier', + [], + [ + 'modifierlist' => $parameter['modifier_list'], + 'value' => 'ob_get_clean()', + ] + ) . ";\n"; + } + $output = + "'; + } + return $output; + } + + /** + * Setup callback and parameter array + * + * @param \Smarty_Internal_TemplateCompilerBase $compiler + * @param array $_attr attributes + * @param string $tag + * @param string $function + * + * @return array + */ + protected function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) { + $_paramsArray = []; + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + return [$function, $_paramsArray, null]; + } +} diff --git a/src/Compile/PrivateFunctionPlugin.php b/src/Compile/PrivateFunctionPlugin.php new file mode 100644 index 00000000..9fdbee3b --- /dev/null +++ b/src/Compile/PrivateFunctionPlugin.php @@ -0,0 +1,82 @@ +getAttributes($compiler, $args); + unset($_attr['nocache']); + // convert attributes into parameter array string + $_paramsArray = []; + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $_params = 'array(' . implode(',', $_paramsArray) . ')'; + // compile code + $output = "{$function}({$_params},\$_smarty_tpl)"; + if (!empty($parameter['modifierlist'])) { + $output = $compiler->compileTag( + 'private_modifier', + [], + [ + 'modifierlist' => $parameter['modifierlist'], + 'value' => $output, + ] + ); + } + $output = "\n"; + return $output; + } +} diff --git a/src/Compile/PrivateObjectBlockFunction.php b/src/Compile/PrivateObjectBlockFunction.php new file mode 100644 index 00000000..4945cb76 --- /dev/null +++ b/src/Compile/PrivateObjectBlockFunction.php @@ -0,0 +1,46 @@ + $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $callback = ["\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$function}"]; + return [$callback, $_paramsArray, "array(\$_block_plugin{$this->nesting}, '{$function}')"]; + } +} diff --git a/src/Compile/PrivateObjectFunction.php b/src/Compile/PrivateObjectFunction.php new file mode 100644 index 00000000..ca82b3a9 --- /dev/null +++ b/src/Compile/PrivateObjectFunction.php @@ -0,0 +1,88 @@ +getAttributes($compiler, $args); + unset($_attr['nocache']); + $_assign = null; + if (isset($_attr['assign'])) { + $_assign = $_attr['assign']; + unset($_attr['assign']); + } + // method or property ? + if (is_callable([$compiler->smarty->registered_objects[$tag][0], $function])) { + // convert attributes into parameter array string + if ($compiler->smarty->registered_objects[$tag][2]) { + $_paramsArray = []; + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $_params = 'array(' . implode(',', $_paramsArray) . ')'; + $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params},\$_smarty_tpl)"; + } else { + $_params = implode(',', $_attr); + $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params})"; + } + } else { + // object property + $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}"; + } + if (!empty($parameter['modifierlist'])) { + $output = $compiler->compileTag( + 'private_modifier', + [], + ['modifierlist' => $parameter['modifierlist'], 'value' => $output] + ); + } + if (empty($_assign)) { + return "\n"; + } else { + return "assign({$_assign},{$output});?>\n"; + } + } +} diff --git a/src/Compile/PrivatePrintExpression.php b/src/Compile/PrivatePrintExpression.php new file mode 100644 index 00000000..49aa13e8 --- /dev/null +++ b/src/Compile/PrivatePrintExpression.php @@ -0,0 +1,152 @@ +getAttributes($compiler, $args); + $output = $parameter['value']; + // tag modifier + if (!empty($parameter['modifierlist'])) { + $output = $compiler->compileTag( + 'private_modifier', + [], + [ + 'modifierlist' => $parameter['modifierlist'], + 'value' => $output, + ] + ); + } + if (isset($_attr['assign'])) { + // assign output to variable + return "assign({$_attr['assign']},{$output});?>"; + } else { + // display value + if (!$_attr['nofilter']) { + // default modifier + if (!empty($compiler->smarty->default_modifiers)) { + if (empty($compiler->default_modifier_list)) { + $modifierlist = []; + foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) { + preg_match_all( + '/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', + $single_default_modifier, + $mod_array + ); + for ($i = 0, $count = count($mod_array[0]); $i < $count; $i++) { + if ($mod_array[0][$i] !== ':') { + $modifierlist[$key][] = $mod_array[0][$i]; + } + } + } + $compiler->default_modifier_list = $modifierlist; + } + $output = $compiler->compileTag( + 'private_modifier', + [], + [ + 'modifierlist' => $compiler->default_modifier_list, + 'value' => $output, + ] + ); + } + // autoescape html + if ($compiler->template->smarty->escape_html) { + $output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(\Smarty\Smarty::$_CHARSET) . "')"; + } + // loop over registered filters + if (!empty($compiler->template->smarty->registered_filters[\Smarty\Smarty::FILTER_VARIABLE])) { + foreach ($compiler->template->smarty->registered_filters[\Smarty\Smarty::FILTER_VARIABLE] as $key => + $function) { + if (!is_array($function)) { + $output = "{$function}({$output},\$_smarty_tpl)"; + } elseif (is_object($function[0])) { + $output = + "\$_smarty_tpl->smarty->registered_filters[\Smarty\Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)"; + } else { + $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)"; + } + } + } + foreach ($compiler->variable_filters as $filter) { + if (count($filter) === 1 + && ($result = $this->compile_variable_filter($compiler, $filter[0], $output)) !== false + ) { + $output = $result; + } else { + $output = $compiler->compileTag( + 'private_modifier', + [], + ['modifierlist' => [$filter], 'value' => $output] + ); + } + } + } + $output = "\n"; + } + return $output; + } + + /** + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param string $name name of variable filter + * @param string $output embedded output + * + * @return string + * @throws \SmartyException + */ + private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output) { + $function = $compiler->getPlugin($name, 'variablefilter'); + if ($function) { + return "{$function}({$output},\$_smarty_tpl)"; + } else { + // not found + return false; + } + } +} diff --git a/src/Compile/PrivateRegisteredFunction.php b/src/Compile/PrivateRegisteredFunction.php new file mode 100644 index 00000000..06c50ed7 --- /dev/null +++ b/src/Compile/PrivateRegisteredFunction.php @@ -0,0 +1,94 @@ +getAttributes($compiler, $args); + unset($_attr['nocache']); + if (isset($compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag])) { + $tag_info = $compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag]; + $is_registered = true; + } else { + $tag_info = $compiler->default_handler_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag]; + $is_registered = false; + } + // not cacheable? + $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1]; + // convert attributes into parameter array string + $_paramsArray = []; + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) { + $_value = str_replace('\'', "^#^", $_value); + $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $_params = 'array(' . implode(',', $_paramsArray) . ')'; + // compile code + if ($is_registered) { + $output = + "call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[\\Smarty\\Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )"; + } else { + $function = $tag_info[0]; + if (!is_array($function)) { + $output = "{$function}({$_params},\$_smarty_tpl)"; + } else { + $output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)"; + } + } + if (!empty($parameter['modifierlist'])) { + $output = $compiler->compileTag( + 'private_modifier', + [], + [ + 'modifierlist' => $parameter['modifierlist'], + 'value' => $output, + ] + ); + } + $output = "\n"; + return $output; + } +} diff --git a/src/Compile/PrivateSpecialVariable.php b/src/Compile/PrivateSpecialVariable.php new file mode 100644 index 00000000..8963e1cf --- /dev/null +++ b/src/Compile/PrivateSpecialVariable.php @@ -0,0 +1,127 @@ +getId($_index[0])); + if ($variable === false) { + $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); + } + if (!isset($compiler->smarty->security_policy) + || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) + ) { + switch ($variable) { + case 'foreach': + return (new Smarty_Internal_Compile_Foreach())->compileSpecialVariable($compiler, $_index); + case 'section': + return (new Smarty_Internal_Compile_Section())->compileSpecialVariable($compiler, $_index); + case 'capture': + return (new _Capture())->compileSpecialVariable($compiler, $_index); + case 'now': + return 'time()'; + case 'cookies': + if (isset($compiler->smarty->security_policy) + && !$compiler->smarty->security_policy->allow_super_globals + ) { + $compiler->trigger_template_error("(secure mode) super globals not permitted"); + break; + } + $compiled_ref = '$_COOKIE'; + break; + case 'get': + case 'post': + case 'env': + case 'server': + case 'session': + case 'request': + if (isset($compiler->smarty->security_policy) + && !$compiler->smarty->security_policy->allow_super_globals + ) { + $compiler->trigger_template_error("(secure mode) super globals not permitted"); + break; + } + $compiled_ref = '$_' . smarty_strtoupper_ascii($variable); + break; + case 'template': + return 'basename($_smarty_tpl->source->filepath)'; + case 'template_object': + if (isset($compiler->smarty->security_policy)) { + $compiler->trigger_template_error("(secure mode) template_object not permitted"); + break; + } + return '$_smarty_tpl'; + case 'current_dir': + return 'dirname($_smarty_tpl->source->filepath)'; + case 'version': + return "\\Smarty\\Smarty::SMARTY_VERSION"; + case 'const': + if (isset($compiler->smarty->security_policy) + && !$compiler->smarty->security_policy->allow_constants + ) { + $compiler->trigger_template_error("(secure mode) constants not permitted"); + break; + } + if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) { + return "(defined('{$_index[1]}') ? constant('{$_index[1]}') : null)"; + } else { + return "(defined({$_index[1]}) ? constant({$_index[1]}) : null)"; + } + // no break + case 'config': + if (isset($_index[2])) { + return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)"; + } else { + return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])"; + } + // no break + case 'ldelim': + return "\$_smarty_tpl->smarty->left_delimiter"; + case 'rdelim': + return "\$_smarty_tpl->smarty->right_delimiter"; + default: + $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is not defined'); + break; + } + if (isset($_index[1])) { + array_shift($_index); + foreach ($_index as $_ind) { + $compiled_ref = $compiled_ref . "[$_ind]"; + } + } + return $compiled_ref; + } + } +} diff --git a/src/Compile/_make_nocache.php b/src/Compile/_make_nocache.php deleted file mode 100644 index e27bfb29..00000000 --- a/src/Compile/_make_nocache.php +++ /dev/null @@ -1,64 +0,0 @@ -getAttributes($compiler, $args); - if ($compiler->template->caching) { - $output = "smarty->ext->_make_nocache->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n"; - $compiler->template->compiled->has_nocache_code = true; - $compiler->suppressNocacheProcessing = true; - return $output; - } else { - return true; - } - } -} diff --git a/src/Compile/_private_block_plugin.php b/src/Compile/_private_block_plugin.php deleted file mode 100644 index 8b559f8a..00000000 --- a/src/Compile/_private_block_plugin.php +++ /dev/null @@ -1,125 +0,0 @@ -getAttributes($compiler, $args); - $this->nesting++; - unset($_attr[ 'nocache' ]); - [$callback, $_paramsArray, $callable] = $this->setup($compiler, $_attr, $tag, $function); - $_params = 'array(' . implode(',', $_paramsArray) . ')'; - // compile code - $output = "nesting} = isset({$callback[0]}) ? {$callback[0]} : null;\n"; - $callback = "\$_block_plugin{$this->nesting}{$callback[1]}"; - } - if (isset($callable)) { - $output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n"; - } - $output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();?>"; - $this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback)); - // maybe nocache because of nocache variables or nocache plugin - $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; - } else { - // must endblock be nocache? - if ($compiler->nocache) { - $compiler->tag_nocache = true; - } - // closing tag of block plugin, restore nocache - [$_params, $compiler->nocache, $callback] = $this->closeTag($compiler, substr($tag, 0, -5)); - // compile code - if (!isset($parameter[ 'modifier_list' ])) { - $mod_pre = $mod_post = $mod_content = ''; - $mod_content2 = 'ob_get_clean()'; - } else { - $mod_content2 = "\$_block_content{$this->nesting}"; - $mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n"; - $mod_pre = "ob_start();\n"; - $mod_post = 'echo ' . $compiler->compileTag( - 'private_modifier', - array(), - array( - 'modifierlist' => $parameter[ 'modifier_list' ], - 'value' => 'ob_get_clean()' - ) - ) . ";\n"; - } - $output = - "'; - } - return $output; - } - - /** - * Setup callback and parameter array - * - * @param \Smarty_Internal_TemplateCompilerBase $compiler - * @param array $_attr attributes - * @param string $tag - * @param string $function - * - * @return array - */ - public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) - { - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - return array($function, $_paramsArray, null); - } -} diff --git a/src/Compile/_private_foreachsection.php b/src/Compile/_private_foreachsection.php deleted file mode 100644 index 8bb1eb48..00000000 --- a/src/Compile/_private_foreachsection.php +++ /dev/null @@ -1,228 +0,0 @@ -propertyPreg = '~('; - $this->startOffset = 1; - $this->resultOffsets = array(); - $this->matchResults = array('named' => array(), 'item' => array()); - if (isset($attributes[ 'name' ])) { - $this->buildPropertyPreg(true, $attributes); - } - if (isset($this->itemProperties)) { - if ($this->isNamed) { - $this->propertyPreg .= '|'; - } - $this->buildPropertyPreg(false, $attributes); - } - $this->propertyPreg .= ')\W~i'; - // Template source - $this->matchTemplateSource($compiler); - // Parent template source - $this->matchParentTemplateSource($compiler); - // {block} source - $this->matchBlockSource($compiler); - } - - /** - * Build property preg string - * - * @param bool $named - * @param array $attributes - */ - public function buildPropertyPreg($named, $attributes) - { - if ($named) { - $this->resultOffsets[ 'named' ] = $this->startOffset = $this->startOffset + 3; - $this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . - ($this->tagName === 'section' ? "|[\[]\s*" : '') . - "){$attributes['name']}[.]("; - $properties = $this->nameProperties; - } else { - $this->resultOffsets[ 'item' ] = $this->startOffset = $this->startOffset + 2; - $this->propertyPreg .= "([\$]{$attributes['item']}[@]("; - $properties = $this->itemProperties; - } - $propName = reset($properties); - while ($propName) { - $this->propertyPreg .= "{$propName}"; - $propName = next($properties); - if ($propName) { - $this->propertyPreg .= '|'; - } - } - $this->propertyPreg .= '))'; - } - - /** - * Find matches in source string - * - * @param string $source - */ - public function matchProperty($source) - { - preg_match_all($this->propertyPreg, $source, $match); - foreach ($this->resultOffsets as $key => $offset) { - foreach ($match[ $offset ] as $m) { - if (!empty($m)) { - $this->matchResults[ $key ][ smarty_strtolower_ascii($m) ] = true; - } - } - } - } - - /** - * Find matches in template source - * - * @param \Smarty_Internal_TemplateCompilerBase $compiler - */ - public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) - { - $this->matchProperty($compiler->parser->lex->data); - } - - /** - * Find matches in all parent template source - * - * @param \Smarty_Internal_TemplateCompilerBase $compiler - * - * @throws \SmartyException - */ - public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) - { - // search parent compiler template source - $nextCompiler = $compiler; - while ($nextCompiler !== $nextCompiler->parent_compiler) { - $nextCompiler = $nextCompiler->parent_compiler; - if ($compiler !== $nextCompiler) { - // get template source - $_content = $nextCompiler->template->source->getContent(); - if ($_content !== '') { - // run pre filter if required - if (isset($nextCompiler->smarty->registered_filters[ 'pre' ])) { - $_content = $nextCompiler->smarty->ext->_filterHandler->runFilter( - 'pre', - $_content, - $nextCompiler->template - ); - } - $this->matchProperty($_content); - } - } - } - } - - /** - * Find matches in {block} tag source - * - * @param \Smarty_Internal_TemplateCompilerBase $compiler - */ - public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler) - { - } - - /** - * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * @param array $parameter array with compilation parameter - * - * @return string compiled code - * @throws \SmartyCompilerException - */ - public function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) - { - $tag = smarty_strtolower_ascii(trim($parameter[ 0 ], '"\'')); - $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false; - if (!$name) { - $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); - } - $property = isset($parameter[ 2 ]) ? smarty_strtolower_ascii($compiler->getId($parameter[ 2 ])) : false; - if (!$property || !in_array($property, $this->nameProperties)) { - $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); - } - $tagVar = "'__smarty_{$tag}_{$name}'"; - return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; - } -} diff --git a/src/Compile/_private_function_plugin.php b/src/Compile/_private_function_plugin.php deleted file mode 100644 index b334dbe1..00000000 --- a/src/Compile/_private_function_plugin.php +++ /dev/null @@ -1,80 +0,0 @@ -getAttributes($compiler, $args); - unset($_attr[ 'nocache' ]); - // convert attributes into parameter array string - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - $_params = 'array(' . implode(',', $_paramsArray) . ')'; - // compile code - $output = "{$function}({$_params},\$_smarty_tpl)"; - if (!empty($parameter[ 'modifierlist' ])) { - $output = $compiler->compileTag( - 'private_modifier', - array(), - array( - 'modifierlist' => $parameter[ 'modifierlist' ], - 'value' => $output - ) - ); - } - $output = "\n"; - return $output; - } -} diff --git a/src/Compile/_private_object_function.php b/src/Compile/_private_object_function.php deleted file mode 100644 index 05a2160b..00000000 --- a/src/Compile/_private_object_function.php +++ /dev/null @@ -1,87 +0,0 @@ -getAttributes($compiler, $args); - unset($_attr[ 'nocache' ]); - $_assign = null; - if (isset($_attr[ 'assign' ])) { - $_assign = $_attr[ 'assign' ]; - unset($_attr[ 'assign' ]); - } - // method or property ? - if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $function))) { - // convert attributes into parameter array string - if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) { - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - $_params = 'array(' . implode(',', $_paramsArray) . ')'; - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params},\$_smarty_tpl)"; - } else { - $_params = implode(',', $_attr); - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params})"; - } - } else { - // object property - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}"; - } - if (!empty($parameter[ 'modifierlist' ])) { - $output = $compiler->compileTag( - 'private_modifier', - array(), - array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output) - ); - } - if (empty($_assign)) { - return "\n"; - } else { - return "assign({$_assign},{$output});?>\n"; - } - } -} diff --git a/src/Compile/_private_print_expression.php b/src/Compile/_private_print_expression.php deleted file mode 100644 index 150a405c..00000000 --- a/src/Compile/_private_print_expression.php +++ /dev/null @@ -1,151 +0,0 @@ -getAttributes($compiler, $args); - $output = $parameter[ 'value' ]; - // tag modifier - if (!empty($parameter[ 'modifierlist' ])) { - $output = $compiler->compileTag( - 'private_modifier', - array(), - array( - 'modifierlist' => $parameter[ 'modifierlist' ], - 'value' => $output - ) - ); - } - if (isset($_attr[ 'assign' ])) { - // assign output to variable - return "assign({$_attr['assign']},{$output});?>"; - } else { - // display value - if (!$_attr[ 'nofilter' ]) { - // default modifier - if (!empty($compiler->smarty->default_modifiers)) { - if (empty($compiler->default_modifier_list)) { - $modifierlist = array(); - foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) { - preg_match_all( - '/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', - $single_default_modifier, - $mod_array - ); - for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i++) { - if ($mod_array[ 0 ][ $i ] !== ':') { - $modifierlist[ $key ][] = $mod_array[ 0 ][ $i ]; - } - } - } - $compiler->default_modifier_list = $modifierlist; - } - $output = $compiler->compileTag( - 'private_modifier', - array(), - array( - 'modifierlist' => $compiler->default_modifier_list, - 'value' => $output - ) - ); - } - // autoescape html - if ($compiler->template->smarty->escape_html) { - $output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(\Smarty\Smarty::$_CHARSET) . "')"; - } - // loop over registered filters - if (!empty($compiler->template->smarty->registered_filters[ \Smarty\Smarty::FILTER_VARIABLE ])) { - foreach ($compiler->template->smarty->registered_filters[ \Smarty\Smarty::FILTER_VARIABLE ] as $key => - $function) { - if (!is_array($function)) { - $output = "{$function}({$output},\$_smarty_tpl)"; - } elseif (is_object($function[ 0 ])) { - $output = - "\$_smarty_tpl->smarty->registered_filters[\Smarty\Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)"; - } else { - $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)"; - } - } - } - foreach ($compiler->variable_filters as $filter) { - if (count($filter) === 1 - && ($result = $this->compile_variable_filter($compiler, $filter[ 0 ], $output)) !== false - ) { - $output = $result; - } else { - $output = $compiler->compileTag( - 'private_modifier', - array(), - array('modifierlist' => array($filter), 'value' => $output) - ); - } - } - } - $output = "\n"; - } - return $output; - } - - /** - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * @param string $name name of variable filter - * @param string $output embedded output - * - * @return string - * @throws \SmartyException - */ - private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output) - { - $function = $compiler->getPlugin($name, 'variablefilter'); - if ($function) { - return "{$function}({$output},\$_smarty_tpl)"; - } else { - // not found - return false; - } - } -} diff --git a/src/Compile/_private_registered_function.php b/src/Compile/_private_registered_function.php deleted file mode 100644 index 5f80f943..00000000 --- a/src/Compile/_private_registered_function.php +++ /dev/null @@ -1,93 +0,0 @@ -getAttributes($compiler, $args); - unset($_attr[ 'nocache' ]); - if (isset($compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_FUNCTION ][ $tag ])) { - $tag_info = $compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_FUNCTION ][ $tag ]; - $is_registered = true; - } else { - $tag_info = $compiler->default_handler_plugins[ \Smarty\Smarty::PLUGIN_FUNCTION ][ $tag ]; - $is_registered = false; - } - // not cacheable? - $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[ 1 ]; - // convert attributes into parameter array string - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } elseif ($compiler->template->caching && in_array($_key, $tag_info[ 2 ])) { - $_value = str_replace('\'', "^#^", $_value); - $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - $_params = 'array(' . implode(',', $_paramsArray) . ')'; - // compile code - if ($is_registered) { - $output = - "call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[\\Smarty\\Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )"; - } else { - $function = $tag_info[ 0 ]; - if (!is_array($function)) { - $output = "{$function}({$_params},\$_smarty_tpl)"; - } else { - $output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)"; - } - } - if (!empty($parameter[ 'modifierlist' ])) { - $output = $compiler->compileTag( - 'private_modifier', - array(), - array( - 'modifierlist' => $parameter[ 'modifierlist' ], - 'value' => $output - ) - ); - } - $output = "\n"; - return $output; - } -} diff --git a/src/Compile/_private_special_variable.php b/src/Compile/_private_special_variable.php deleted file mode 100644 index a74a4e82..00000000 --- a/src/Compile/_private_special_variable.php +++ /dev/null @@ -1,132 +0,0 @@ -getId($_index[ 0 ])); - if ($variable === false) { - $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); - } - if (!isset($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) - ) { - switch ($variable) { - case 'foreach': - case 'section': - if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) { - $class = 'Smarty_Internal_Compile_' . smarty_ucfirst_ascii($variable); - Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class; - } - return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable( - array(), - $compiler, - $_index - ); - case 'capture': - if (class_exists('_Capture')) { - return _Capture::compileSpecialVariable(array(), $compiler, $_index); - } - return ''; - case 'now': - return 'time()'; - case 'cookies': - if (isset($compiler->smarty->security_policy) - && !$compiler->smarty->security_policy->allow_super_globals - ) { - $compiler->trigger_template_error("(secure mode) super globals not permitted"); - break; - } - $compiled_ref = '$_COOKIE'; - break; - case 'get': - case 'post': - case 'env': - case 'server': - case 'session': - case 'request': - if (isset($compiler->smarty->security_policy) - && !$compiler->smarty->security_policy->allow_super_globals - ) { - $compiler->trigger_template_error("(secure mode) super globals not permitted"); - break; - } - $compiled_ref = '$_' . smarty_strtoupper_ascii($variable); - break; - case 'template': - return 'basename($_smarty_tpl->source->filepath)'; - case 'template_object': - if (isset($compiler->smarty->security_policy)) { - $compiler->trigger_template_error("(secure mode) template_object not permitted"); - break; - } - return '$_smarty_tpl'; - case 'current_dir': - return 'dirname($_smarty_tpl->source->filepath)'; - case 'version': - return "\\Smarty\\Smarty::SMARTY_VERSION"; - case 'const': - if (isset($compiler->smarty->security_policy) - && !$compiler->smarty->security_policy->allow_constants - ) { - $compiler->trigger_template_error("(secure mode) constants not permitted"); - break; - } - if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) { - return "(defined('{$_index[1]}') ? constant('{$_index[1]}') : null)"; - } else { - return "(defined({$_index[1]}) ? constant({$_index[1]}) : null)"; - } - // no break - case 'config': - if (isset($_index[ 2 ])) { - return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)"; - } else { - return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])"; - } - // no break - case 'ldelim': - return "\$_smarty_tpl->smarty->left_delimiter"; - case 'rdelim': - return "\$_smarty_tpl->smarty->right_delimiter"; - default: - $compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined'); - break; - } - if (isset($_index[ 1 ])) { - array_shift($_index); - foreach ($_index as $_ind) { - $compiled_ref = $compiled_ref . "[$_ind]"; - } - } - return $compiled_ref; - } - } -} diff --git a/src/Compile/smarty_internal_compile_private_registered_block.php b/src/Compile/smarty_internal_compile__registered_Private_block.php similarity index 92% rename from src/Compile/smarty_internal_compile_private_registered_block.php rename to src/Compile/smarty_internal_compile__registered_Private_block.php index f78c81a0..1f2add11 100644 --- a/src/Compile/smarty_internal_compile_private_registered_block.php +++ b/src/Compile/smarty_internal_compile__registered_Private_block.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\PrivateBlockPlugin; + /** * Smarty Internal Plugin Compile Registered Block Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Registered_Block extends _Private_Block_Plugin +class Smarty_Internal_Compile__Registered_Private_Block extends PrivateBlockPlugin { /** * Setup callback, parameter array and nocache mode @@ -26,7 +28,7 @@ class Smarty_Internal_Compile_Private_Registered_Block extends _Private_Block_Pl * * @return array */ - public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) + protected function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) { if (isset($compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_BLOCK ][ $tag ])) { $tag_info = $compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_BLOCK ][ $tag ]; diff --git a/src/Compile/smarty_internal_compile_capture.php b/src/Compile/smarty_internal_compile_capture.php index b7c1b5cb..4c829205 100644 --- a/src/Compile/smarty_internal_compile_capture.php +++ b/src/Compile/smarty_internal_compile_capture.php @@ -37,14 +37,12 @@ class _Capture extends Base /** * Compiles code for the {$smarty.capture.xxx} * - * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code */ public static function compileSpecialVariable( - $args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null ) { diff --git a/src/Compile/smarty_internal_compile_foreach.php b/src/Compile/smarty_internal_compile_foreach.php index c60ba46f..3a4cdd9b 100644 --- a/src/Compile/smarty_internal_compile_foreach.php +++ b/src/Compile/smarty_internal_compile_foreach.php @@ -8,6 +8,7 @@ * @author Uwe Tews */ +use Smarty\Compile\ForeachSection; use Smarty\Compile\Base; /** @@ -16,7 +17,7 @@ use Smarty\Compile\Base; * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Foreach extends _Private_ForeachSection +class Smarty_Internal_Compile_Foreach extends ForeachSection { /** * Attribute definition: Overwrites base class. diff --git a/src/Compile/smarty_internal_compile_private_object_block_function.php b/src/Compile/smarty_internal_compile_private_object_block_function.php deleted file mode 100644 index 7868b716..00000000 --- a/src/Compile/smarty_internal_compile_private_object_block_function.php +++ /dev/null @@ -1,42 +0,0 @@ - $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - $callback = array("\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$method}"); - return array($callback, $_paramsArray, "array(\$_block_plugin{$this->nesting}, '{$method}')"); - } -} diff --git a/src/Compile/smarty_internal_compile_section.php b/src/Compile/smarty_internal_compile_section.php index 62a84ac5..e10b857a 100644 --- a/src/Compile/smarty_internal_compile_section.php +++ b/src/Compile/smarty_internal_compile_section.php @@ -8,6 +8,7 @@ * @author Uwe Tews */ +use Smarty\Compile\ForeachSection; use Smarty\Compile\Base; /** @@ -16,7 +17,7 @@ use Smarty\Compile\Base; * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Section extends _Private_ForeachSection +class Smarty_Internal_Compile_Section extends ForeachSection { /** * Attribute definition: Overwrites base class. diff --git a/src/Compiler/smarty_internal_templatecompilerbase.php b/src/Compiler/smarty_internal_templatecompilerbase.php index 64c52fcd..e46896aa 100644 --- a/src/Compiler/smarty_internal_templatecompilerbase.php +++ b/src/Compiler/smarty_internal_templatecompilerbase.php @@ -23,12 +23,6 @@ use Smarty\Compile\Base; */ abstract class Smarty_Internal_TemplateCompilerBase { - /** - * compile tag objects cache - * - * @var array - */ - public static $_tag_objects = array(); /** * counter for prefix variable number @@ -729,40 +723,44 @@ abstract class Smarty_Internal_TemplateCompilerBase * * @param string $tag tag name * - * @return bool|\Smarty\Compile\Base tag compiler object or false if not found + * @return bool|Base tag compiler object or false if not found or untrusted by security policy */ public function getTagCompiler($tag) { - static $map = [ - 'break' => \Smarty\Compile\BreakTag::class, - 'config_load' => \Smarty\Compile\ConfigLoad::class, - 'eval' => \Smarty\Compile\EvalTag::class, - 'include' => \Smarty\Compile\IncludeTag::class, - 'while' => \Smarty\Compile\WhileTag::class, - 'private_modifier' => \Smarty\Compile\PrivateModifier::class, - ]; + if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) { + return false; + } - // re-use object if already exists - if (!isset(self::$_tag_objects[ $tag ])) { + switch ($tag) { + case 'append': return new \Smarty\Compile\Append(); + case 'assign': return new \Smarty\Compile\Assign(); + case 'block': return new \Smarty\Compile\Block(); + case 'blockclose': return new \Smarty\Compile\Blockclose(); + case 'break': return new \Smarty\Compile\BreakTag(); + case 'call': return new \Smarty\Compile\Call(); + case 'child': return new \Smarty\Compile\Child(); + case 'config_load': return new \Smarty\Compile\ConfigLoad(); + case 'continue': return new \Smarty\Compile\ContinueTag(); + case 'debug': return new \Smarty\Compile\Debug(); + case 'eval': return new \Smarty\Compile\EvalTag(); + case 'include': return new \Smarty\Compile\IncludeTag(); + case 'insert': return new \Smarty\Compile\Inser(); + case 'ldelim': return new \Smarty\Compile\Ldelim(); + case 'make_nocache': return new \Smarty\Compile\MakeNocache(); + case 'private_block_plugin': return new \Smarty\Compile\PrivateBlockPlugin(); + case 'private_function_plugin': return new \Smarty\Compile\PrivateFunctionPlugin(); + case 'private_modifier': return new \Smarty\Compile\PrivateModifier(); + case 'private_object_function': return new \Smarty\Compile\PrivateObjectFunction(); + case 'private_object_block_function': return new \Smarty\Compile\PrivateObjectBlockFunction(); + case 'private_print_expression': return new \Smarty\Compile\PrivatePrintExpression(); + case 'private_registered_function': return new \Smarty\Compile\PrivateRegisteredFunction(); + case 'private_special_variable': return new \Smarty\Compile\PrivateSpecialVariable(); + case 'while': return new \Smarty\Compile\WhileTag(); + case 'whileclose': return new \Smarty\Compile\Whileclose(); + } - if (isset($map[$tag])) { - $class_name = $map[$tag]; - } else { - $_tag = explode('_', $tag); - $_tag = array_map('smarty_ucfirst_ascii', $_tag); - $class_name = '\\Smarty\\Compile\\' . implode('_', $_tag); - } - - if (class_exists($class_name) - && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) - ) { - self::$_tag_objects[ $tag ] = new $class_name; - } else { - self::$_tag_objects[ $tag ] = false; - } - } - return self::$_tag_objects[ $tag ]; + return false; } /** diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index f7769af3..b4abbc65 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -650,11 +650,6 @@ KEY `name` (`name`) */ protected function tearDown(): void { - if (class_exists('Smarty_Internal_TemplateCompilerBase') && - isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects) - ) { - Smarty_Internal_TemplateCompilerBase::$_tag_objects = array(); - } if (isset($this->smarty->smarty)) { $this->smarty->smarty = null; }