From 2db464a6e547c4e27b8c81051a72eaa21341f2d4 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Thu, 14 May 2015 15:11:38 +0200 Subject: [PATCH] - bugfix template functions failed when calling the function recursively with function name as tag name https://github.com/smarty-php/smarty/issues/28 --- change_log.txt | 1 + .../smarty_internal_compile_function.php | 17 +++++++++------- .../smarty_internal_templatecompilerbase.php | 20 +++++++++---------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/change_log.txt b/change_log.txt index 9783613e..4bda5da5 100644 --- a/change_log.txt +++ b/change_log.txt @@ -7,6 +7,7 @@ - display Smarty version number - Truncate lenght of Origin display and extend strin value display to 80 character - bugfix in Smarty_Security 'nl2br' should be a trusted modifier, not PHP function (code.google issue 223) + - bugfix template functions failed when calling the function recursively with function name as tag name https://github.com/smarty-php/smarty/issues/28 12.05.2015 - bugfix {$smarty.constant.TEST} did fail on undefined constant https://github.com/smarty-php/smarty/issues/28 diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index 57054851..35408bcb 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -16,6 +16,7 @@ */ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { + /** * Attribute definition: Overwrites base class. * @@ -23,6 +24,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase */ public $required_attributes = array('name'); + /** * Attribute definition: Overwrites base class. * @@ -30,6 +32,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase */ public $shorttag_order = array('name'); + /** * Attribute definition: Overwrites base class. * @@ -57,9 +60,8 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase } unset($_attr['nocache']); $_name = trim($_attr['name'], "'\""); - - $save = array($_attr, $compiler->parser->current_buffer, - $compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching); + $compiler->parent_compiler->templateProperties['tpl_function'][$_name] = array(); + $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching); $this->openTag($compiler, 'function', $save); // set flag that we are compiling a template function $compiler->compiles_template_function = true; @@ -80,6 +82,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase */ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase { + /** * Compiler object * @@ -90,11 +93,11 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase /** * Compiles code for the {/function} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $args array with attributes from parser + * @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter * - * @return boolean true + * @return bool true */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index c38c21b1..f5895a29 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -17,6 +17,7 @@ */ abstract class Smarty_Internal_TemplateCompilerBase { + /** * Smarty object * @@ -128,6 +129,7 @@ abstract class Smarty_Internal_TemplateCompilerBase * @var string */ public $trace_filepath = ''; + /** * stack for tracing file and line of nested {block} tags * @@ -466,8 +468,7 @@ abstract class Smarty_Internal_TemplateCompilerBase $this->template->used_tags[] = array($tag, $args); } // check nocache option flag - if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) - || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args) + if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args) ) { $this->tag_nocache = true; } @@ -507,8 +508,7 @@ abstract class Smarty_Internal_TemplateCompilerBase // check if tag is a registered object if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) { $method = $parameter['object_method']; - if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && - (empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1])) + if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && (empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1])) ) { return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); } elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) { @@ -820,9 +820,7 @@ abstract class Smarty_Internal_TemplateCompilerBase $callback = null; $script = null; $cacheable = true; - $result = call_user_func_array( - $this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable) - ); + $result = call_user_func_array($this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)); if ($result) { $this->tag_nocache = $this->tag_nocache || !$cacheable; if ($script !== null) { @@ -862,8 +860,9 @@ abstract class Smarty_Internal_TemplateCompilerBase * * @return string */ - public function appendCode($left, $right) { - if ( preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) { + public function appendCode($left, $right) + { + if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) { $left = preg_replace('/\s*\?>\s*$/', "\n", $left); $left .= preg_replace('/^\s*<\?php\s+/', '', $right); } else { @@ -888,8 +887,7 @@ abstract class Smarty_Internal_TemplateCompilerBase // If the template is not evaluated and we have a nocache section and or a nocache tag if ($is_code && !empty($content)) { // generate replacement code - if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && - ($this->nocache || $this->tag_nocache) + if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) ) { $this->template->has_nocache_code = true; $_output = addcslashes($content, '\'\\');