From bc2d519c38afe042cd50a0b34440bdab4197640f Mon Sep 17 00:00:00 2001 From: "uwe.tews@googlemail.com" Date: Wed, 28 Sep 2011 15:56:01 +0000 Subject: [PATCH] - bugfix on template functions called nocache calling other template functions --- change_log.txt | 3 +++ libs/sysplugins/smarty_internal_compile_call.php | 3 +++ libs/sysplugins/smarty_internal_compile_function.php | 6 ++++++ libs/sysplugins/smarty_internal_template.php | 9 ++++++++- .../smarty_internal_templatecompilerbase.php | 10 ++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/change_log.txt b/change_log.txt index f7180b2f..84b2ff78 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +28.09.2011 +- bugfix on template functions called nocache calling other template functions + 27.09.2011 - bugfix possible warning "attempt to modify property of non-object" in {section} (issue #34) - added chaining to Smarty_Internal_Data so $smarty->assign('a',1)->assign('b',2); is possible now diff --git a/libs/sysplugins/smarty_internal_compile_call.php b/libs/sysplugins/smarty_internal_compile_call.php index f1feba36..af12a048 100644 --- a/libs/sysplugins/smarty_internal_compile_call.php +++ b/libs/sysplugins/smarty_internal_compile_call.php @@ -57,6 +57,9 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase { $_assign = $_attr['assign']; } $_name = $_attr['name']; + if ($compiler->compiles_template_function) { + $compiler->called_functions[] = trim($_name, "'\""); + } unset($_attr['name'], $_attr['assign'], $_attr['nocache']); // set flag (compiled code of {function} must be included in cache file if ($compiler->nocache || $compiler->tag_nocache) { diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index 63ae5487..876b13de 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -61,6 +61,8 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { $this->openTag($compiler, 'function', $save); $_name = trim($_attr['name'], "'\""); unset($_attr['name']); + // set flag that we are compiling a template function + $compiler->compiles_template_function = true; $compiler->template->properties['function'][$_name]['parameter'] = array(); $_smarty_tpl = $compiler->template; foreach ($_attr as $_key => $_data) { @@ -141,12 +143,16 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase . $compiler->parser->current_buffer->to_smarty_php(); $compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash']; $compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code; + $compiler->template->properties['function'][$_name]['called_functions'] = $compiler->called_functions; + $compiler->called_functions = array(); $compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name]; $compiler->has_code = false; $output = true; } else { $output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() . "tpl_vars = \$saved_tpl_vars;}}?>\n"; } + // reset flag that we are compiling a template function + $compiler->compiles_template_function = false; // restore old compiler status $compiler->parser->current_buffer = $saved_data[1]; $compiler->template->has_nocache_code = $compiler->template->has_nocache_code | $saved_data[2]; diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 0336c7a6..0dde3928 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -360,7 +360,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { // copy code of {function} tags called in nocache mode foreach ($this->smarty->template_functions as $name => $function_data) { if (isset($function_data['called_nocache'])) { - unset($function_data['called_nocache'], $this->smarty->template_functions[$name]['called_nocache']); + foreach ($function_data['called_functions'] as $func_name) { + $this->smarty->template_functions[$func_name]['called_nocache'] = true; + } + } + } + foreach ($this->smarty->template_functions as $name => $function_data) { + if (isset($function_data['called_nocache'])) { + unset($function_data['called_nocache'], $function_data['called_functions'], $this->smarty->template_functions[$name]['called_nocache']); $this->properties['function'][$name] = $function_data; } } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 15df9090..ae3822cf 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -97,6 +97,16 @@ abstract class Smarty_Internal_TemplateCompilerBase { * @var bool */ public $write_compiled_code = true; + /** + * flag if currently a template function is compiled + * @var bool + */ + public $compiles_template_function = false; + /** + * called subfuntions from template function + * @var array + */ + public $called_functions = array(); /** * flags for used modifier plugins * @var array