mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
template function call handling
This commit is contained in:
@@ -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 . "<?php " . $match[0] . "?>\n");
|
||||
|
@@ -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}'");
|
||||
}
|
||||
|
Reference in New Issue
Block a user