From d3e26fb679081bc5f4427d86cb8d4275e835e094 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Tue, 30 Dec 2014 16:43:42 +0100 Subject: [PATCH] template function call handling --- .../smarty_internal_function_call_handler.php | 16 +++++++--------- libs/sysplugins/smarty_internal_template.php | 16 ++++++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libs/sysplugins/smarty_internal_function_call_handler.php b/libs/sysplugins/smarty_internal_function_call_handler.php index be769903..eb637239 100644 --- a/libs/sysplugins/smarty_internal_function_call_handler.php +++ b/libs/sysplugins/smarty_internal_function_call_handler.php @@ -22,11 +22,11 @@ class Smarty_Internal_Function_Call_Handler * This function handles calls to template functions defined by {function} * It does create a PHP function at the first call * - * @param string $_name template function name + * @param string $_name template function name * @param Smarty_Internal_Template $_smarty_tpl * @param string $_function PHP function name - * @param array $_params Smarty variables passed as call parameter - * @param bool $_nocache nocache flag + * @param array $_params Smarty variables passed as call parameter + * @param bool $_nocache nocache flag * * @return bool */ @@ -39,14 +39,12 @@ class Smarty_Internal_Function_Call_Handler // grab template function if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) { // grab source info from file dependency - preg_match("/\s*'{$funcParam['source_uid']}'([\S\s]*?)\),/", $code, $match1); - unset($code); + preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1); + unset($code); $output = ''; // make PHP function known eval($match[0]); if (function_exists($_function)) { - // call template function - $_function ($_smarty_tpl, $_params); // search cache file template $tplPtr = $_smarty_tpl; while (!isset($tplPtr->cached) && isset($tplPtr->parent)) { @@ -57,8 +55,8 @@ class Smarty_Internal_Function_Call_Handler $cache = $tplPtr->cached; $content = $cache->read($tplPtr); if ($content) { -// check if we must update file dependency - if (!preg_match("/'{$funcParam['source_uid']}'([\S\s]*?)'nocache_hash'/", $content, $match2)) { + // check if we must update file dependency + if (!preg_match("/'{$funcParam['uid']}'([\S\s]*?)'nc_h'/", $content, $match2)) { $content = preg_replace("/('file_dependency'([\S\s]*?)\()/", "\\1{$match1[0]}", $content); } $cache->write($tplPtr, $content . "\n"); diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index ef014721..0c85ed84 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -383,12 +383,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase * @param object $_smarty_tpl template object * @param array $params parameter array * @param bool $nocache true if called nocache + * + * @throws SmartyException */ public function callTemplateFunction($name, $_smarty_tpl, $params, $nocache) { if (isset($_smarty_tpl->properties['tpl_function']['param'][$name])) { - if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache) || $_smarty_tpl->properties['type'] !== 'cache') { - //$_smarty_tpl->properties['tpl_function']['to_cache'][$name] = true; + if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) { $function = $_smarty_tpl->properties['tpl_function']['param'][$name]['call_name']; } else { if (isset($_smarty_tpl->properties['tpl_function']['param'][$name]['call_name_caching'])) { @@ -399,12 +400,15 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } if (function_exists($function)) { $function ($_smarty_tpl, $params); - return; - } - // try to load template function dynamically - if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function, $params, $nocache)) { return; } + if ($_smarty_tpl->caching) { + // try to load template function dynamically + if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function, $params, $nocache)) { + $function ($_smarty_tpl, $params); + return; + } + } } throw new SmartyException("Unable to find template function '{$name}'"); }