From 2d2be8f57ffdb5bbf567feaaf35dc4e7d0a42938 Mon Sep 17 00:00:00 2001 From: uwetews Date: Thu, 27 Oct 2016 05:42:17 +0200 Subject: [PATCH] - bugfix template function definitions array has not been cached between Smarty::fetch() and Smarty::display() calls https://github.com/smarty-php/smarty/issues/301 --- change_log.txt | 6 ++- libs/Smarty.class.php | 2 +- .../smarty_internal_runtime_tplfunction.php | 37 +++++++++++-------- libs/sysplugins/smarty_internal_template.php | 7 ---- .../smarty_internal_templatebase.php | 7 ++++ 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/change_log.txt b/change_log.txt index ebebdb32..43802826 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,8 +1,12 @@ ===== 3.1.31-dev ===== (xx.xx.xx) + 27.10.2016 + - bugfix template function definitions array has not been cached between Smarty::fetch() and Smarty::display() calls + https://github.com/smarty-php/smarty/issues/301 + 23.10.2016 - improvement/bugfix when Smarty::fetch() is called on a template object the inheritance and tplFunctions property should be copied to the called template object - + 21.10.2016 - bugfix for compile locking touched timestamp of old compiled file was not restored on compilation error https://github.com/smarty-php/smarty/issues/308 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index dc68eb30..df0875e9 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.31-dev/39'; + const SMARTY_VERSION = '3.1.31-dev/40'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_runtime_tplfunction.php b/libs/sysplugins/smarty_internal_runtime_tplfunction.php index a8deaf28..f6b36f2a 100644 --- a/libs/sysplugins/smarty_internal_runtime_tplfunction.php +++ b/libs/sysplugins/smarty_internal_runtime_tplfunction.php @@ -22,14 +22,16 @@ class Smarty_Internal_Runtime_TplFunction */ public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache) { - if (isset($tpl->tplFunctions[ $name ])) { + $funcParam = isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] : + (isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplFunctions[ $name ] : null); + if (isset($funcParam)) { if (!$tpl->caching || ($tpl->caching && $nocache)) { - $function = $tpl->tplFunctions[ $name ][ 'call_name' ]; + $function = $funcParam[ 'call_name' ]; } else { - if (isset($tpl->tplFunctions[ $name ][ 'call_name_caching' ])) { - $function = $tpl->tplFunctions[ $name ][ 'call_name_caching' ]; + if (isset($funcParam[ 'call_name_caching' ])) { + $function = $funcParam[ 'call_name_caching' ]; } else { - $function = $tpl->tplFunctions[ $name ][ 'call_name' ]; + $function = $funcParam[ 'call_name' ]; } } if (function_exists($function)) { @@ -52,23 +54,27 @@ class Smarty_Internal_Runtime_TplFunction /** * Register template functions defined by template * - * @param \Smarty_Internal_Template $tpl - * @param array $tplFunctions source information array of template functions defined in template - * @param bool $override if true replace existing functions with same name + * @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $obj + * @param array $tplFunctions source information array of template functions defined in template + * @param bool $override if true replace existing functions with same name */ - public function registerTplFunctions(Smarty_Internal_Template $tpl, $tplFunctions, $override = true) + public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tplFunctions, $override = true) { - $tpl->tplFunctions = $override ? array_merge($tpl->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $tpl->tplFunctions); + $obj->tplFunctions = + $override ? array_merge($obj->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->tplFunctions); // make sure that the template functions are known in parent templates - if ($tpl->_isSubTpl()) { - $tpl->smarty->ext->_tplFunction->registerTplFunctions($tpl->parent,$tplFunctions, false); + if ($obj->_isSubTpl()) { + $obj->smarty->ext->_tplFunction->registerTplFunctions($obj->parent, $tplFunctions, false); + } else { + $obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->tplFunctions, $tplFunctions) : + array_merge($tplFunctions, $obj->smarty->tplFunctions); } } /** * Return source parameter array for single or all template functions * - * @param \Smarty_Internal_Template $tpl template object + * @param \Smarty_Internal_Template $tpl template object * @param null|string $name template function name * * @return array|bool|mixed @@ -76,9 +82,10 @@ class Smarty_Internal_Runtime_TplFunction public function getTplFunction(Smarty_Internal_Template $tpl, $name = null) { if (isset($name)) { - return isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] : false; + return isset($tpl->tplFunctions[ $name ]) ? $tpl->tplFunctions[ $name ] : + (isset($tpl->smarty->tplFunctions[ $name ]) ? $tpl->smarty->tplFunctions[ $name ] : false); } else { - return $tpl->tplFunctions; + return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl->tplFunctions; } } diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 0efcd698..5096eee3 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -81,13 +81,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public $scope = 0; - /** - * Array of source information for known template functions - * - * @var array - */ - public $tplFunctions = array(); - /** * Flag which is set while rending a cache file * diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 6a97bc4d..f44b1823 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -76,6 +76,13 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public $cache_lifetime = 3600; + /** + * Array of source information for known template functions + * + * @var array + */ + public $tplFunctions = array(); + /** * universal cache *