3 * Smarty Internal Plugin Function Call Handler
6 * @subpackage PluginsInternal
11 * This class does handles template functions defined with the {function} tag missing in cache file.
12 * It can happen when the template function was called with the nocache option or within a nocache section.
13 * The template function will be loaded from it's compiled template file, executed and added to the cache file
17 * @subpackage PluginsInternal
19 class Smarty_Internal_Function_Call_Handler
22 * This function handles calls to template functions defined by {function}
23 * It does create a PHP function at the first call
25 * @param string $_name template function name
26 * @param Smarty_Internal_Template $_smarty_tpl
27 * @param string $_function PHP function name
28 * @param array $_params Smarty variables passed as call parameter
29 * @param bool $_nocache nocache flag
33 public static function call($_name, Smarty_Internal_Template
$_smarty_tpl, $_function, $_params, $_nocache)
35 $funcParam = $_smarty_tpl->properties
['tpl_function'][$_name];
36 if (is_file($funcParam['compiled_filepath'])) {
38 $code = file_get_contents($funcParam['compiled_filepath']);
39 // grab template function
40 if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) {
41 // grab source info from file dependency
42 preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1);
45 // make PHP function known
47 if (function_exists($_function)) {
48 // search cache file template
49 $tplPtr = $_smarty_tpl;
50 while (!isset($tplPtr->cached
) && isset($tplPtr->parent
)) {
51 $tplPtr = $tplPtr->parent
;
53 // add template function code to cache file
54 if (isset($tplPtr->cached
)) {
55 $cache = $tplPtr->cached
;
56 $content = $cache->read($tplPtr);
58 // check if we must update file dependency
59 if (!preg_match("/'{$funcParam['uid']}'([\S\s]*?)'nocache_hash'/", $content, $match2)) {
60 $content = preg_replace("/('file_dependency'([\S\s]*?)\()/", "\\1{$match1[0]}", $content);
62 $cache->write($tplPtr, $content . "<?php " . $match[0] . "?>\n");