smarty_internal_function_call_handler.php (3047B)
1 <?php 2 /** 3 * Smarty Internal Plugin Function Call Handler 4 * 5 * @package Smarty 6 * @subpackage PluginsInternal 7 * @author Uwe Tews 8 */ 9 10 /** 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 14 * for later use. 15 * 16 * @package Smarty 17 * @subpackage PluginsInternal 18 */ 19 class Smarty_Internal_Function_Call_Handler 20 { 21 /** 22 * This function handles calls to template functions defined by {function} 23 * It does create a PHP function at the first call 24 * 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 30 * 31 * @return bool 32 */ 33 public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache) 34 { 35 $funcParam = $_smarty_tpl->properties['tpl_function'][$_name]; 36 if (is_file($funcParam['compiled_filepath'])) { 37 // read compiled file 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); 43 unset($code); 44 $output = ''; 45 // make PHP function known 46 eval($match[0]); 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; 52 } 53 // add template function code to cache file 54 if (isset($tplPtr->cached)) { 55 $cache = $tplPtr->cached; 56 $content = $cache->read($tplPtr); 57 if ($content) { 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); 61 } 62 $cache->write($tplPtr, $content . "<?php " . $match[0] . "?>\n"); 63 } 64 } 65 return true; 66 } 67 } 68 } 69 return false; 70 } 71 }