From 2a2a73cabc315f16a742715d7b076d052028b1dd Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Wed, 10 Dec 2014 00:51:09 +0100 Subject: [PATCH] - bugfix call of template function by a variable name did not work after latest changes (forum 25342) --- change_log.txt | 1 + libs/sysplugins/smarty_internal_compile_call.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/change_log.txt b/change_log.txt index 24010cc3..f82c0ac4 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@ ===== 3.1.22-dev ===== (xx.xx.2014) 09.12.2014 - bugfix variables $null, $true and $false did not work after the change of 12.11.2014 (forum 25342) + - bugfix call of template function by a variable name did not work after latest changes (forum 25342) 23.11.2014 - bugfix a plugin with attached modifier could fail if the tag was immediately followed by another Smarty tag (since 3.1.21) (forum 25326) diff --git a/libs/sysplugins/smarty_internal_compile_call.php b/libs/sysplugins/smarty_internal_compile_call.php index 025ee3d7..0c517fb7 100644 --- a/libs/sysplugins/smarty_internal_compile_call.php +++ b/libs/sysplugins/smarty_internal_compile_call.php @@ -55,11 +55,18 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase // output will be stored in a smarty variable instead of being displayed $_assign = $_attr['assign']; } - $_name = trim($_attr['name'], "'\""); + //$_name = trim($_attr['name'], "'\""); + $_name = $_attr['name']; unset($_attr['name'], $_attr['assign'], $_attr['nocache']); // set flag (compiled code of {function} must be included in cache file if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) { - $compiler->parent_compiler->templateProperties['tpl_function']['to_cache'][$_name] = true; + // variable template name ? + if (!($compiler->has_variable_string || !((substr_count($_name, '"') == 2 || substr_count($_name, "'") == 2)) + || substr_count($_name, '(') != 0 || substr_count($_name, '$_smarty_tpl->') != 0 + )) { + $n = trim($_name, "'\""); + $compiler->parent_compiler->templateProperties['tpl_function']['to_cache'][$n] = true; + } $_nocache = 'true'; } else { $_nocache = 'false'; @@ -76,9 +83,9 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase //$compiler->suppressNocacheProcessing = true; // was there an assign attribute if (isset($_assign)) { - $_output = "callTemplateFunction ('{$_name}', \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; + $_output = "callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; } else { - $_output = "callTemplateFunction ('{$_name}', \$_smarty_tpl, {$_params}, {$_nocache});?>\n"; + $_output = "callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n"; } return $_output; }