Skip to content

Commit

Permalink
- bugfix template function definitions array has not been cached betw…
Browse files Browse the repository at this point in the history
…een Smarty::fetch() and Smarty::display() calls

    #301
  • Loading branch information
uwetews committed Oct 27, 2016
1 parent 98efe22 commit 2d2be8f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
6 changes: 5 additions & 1 deletion change_log.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 22 additions & 15 deletions libs/sysplugins/smarty_internal_runtime_tplfunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -52,33 +54,38 @@ public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $para
/**
* 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
*/
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;
}
}

Expand Down
7 changes: 0 additions & 7 deletions libs/sysplugins/smarty_internal_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions libs/sysplugins/smarty_internal_templatebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 2d2be8f

Please sign in to comment.