summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2016-10-27 05:42:17 +0200
committeruwetews <uwe.tews@googlemail.com>2016-10-27 05:42:17 +0200
commit2d2be8f57ffdb5bbf567feaaf35dc4e7d0a42938 (patch)
tree9e21c9e8c4c2860d51253d8aa17a4411150d9528
parent98efe22e02bab7e363c1089ff2f3faffe6b30f21 (diff)
downloadsmarty-2d2be8f57ffdb5bbf567feaaf35dc4e7d0a42938.tar.gz
smarty-2d2be8f57ffdb5bbf567feaaf35dc4e7d0a42938.tar.bz2
smarty-2d2be8f57ffdb5bbf567feaaf35dc4e7d0a42938.zip
- bugfix template function definitions array has not been cached between Smarty::fetch() and Smarty::display() calls
https://github.com/smarty-php/smarty/issues/301
-rw-r--r--change_log.txt6
-rw-r--r--libs/Smarty.class.php2
-rw-r--r--libs/sysplugins/smarty_internal_runtime_tplfunction.php37
-rw-r--r--libs/sysplugins/smarty_internal_template.php7
-rw-r--r--libs/sysplugins/smarty_internal_templatebase.php7
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
@@ -82,13 +82,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
*
* @var bool
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
@@ -77,6 +77,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
*
* @var array()