mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	- rewrite of template function handling to improve speed
- bugfix on file dependency when merge_compiled_includes = true
This commit is contained in:
		@@ -1,47 +1,38 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
* Smarty Internal Plugin Function Call Handler
 | 
			
		||||
* 
 | 
			
		||||
* @package Smarty
 | 
			
		||||
* @subpackage PluginsInternal
 | 
			
		||||
* @author Uwe Tews 
 | 
			
		||||
*/
 | 
			
		||||
 * Smarty Internal Plugin Function Call Handler
 | 
			
		||||
 * 
 | 
			
		||||
 * @package Smarty
 | 
			
		||||
 * @subpackage PluginsInternal
 | 
			
		||||
 * @author Uwe Tews 
 | 
			
		||||
 */
 | 
			
		||||
/**
 | 
			
		||||
* This class does call function defined with the {function} tag
 | 
			
		||||
*/
 | 
			
		||||
 * This class does call function defined with the {function} tag
 | 
			
		||||
 */
 | 
			
		||||
class Smarty_Internal_Function_Call_Handler extends Smarty_Internal_Template {
 | 
			
		||||
    function __construct($name, $smarty, $parent, $nocache)
 | 
			
		||||
    static function call ($_name, $_template, $_params, $_hash, $_nocache)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct('string:', $smarty, $parent);
 | 
			
		||||
        if (!isset($this->smarty->template_functions[$name])) {
 | 
			
		||||
            throw new Exception("Call to undefined template function \"{$name}\" in template \"{$parent->template_resource}\"");
 | 
			
		||||
        } 
 | 
			
		||||
        $this->called_nocache = $nocache;
 | 
			
		||||
        $this->mustCompile = false;
 | 
			
		||||
        if ($nocache) {
 | 
			
		||||
            $smarty->template_functions[$name]['called_nocache'] = true;
 | 
			
		||||
            $this->properties['function'][$name]['called_nocache'] = true;
 | 
			
		||||
        } 
 | 
			
		||||
        $this->properties['nocache_hash'] = $smarty->template_functions[$name]['nocache_hash']; 
 | 
			
		||||
        // load compiled function
 | 
			
		||||
        if ($nocache) {
 | 
			
		||||
            // if called in nocache mode convert nocache code to real code
 | 
			
		||||
            $this->compiled_template = preg_replace(array("!(<\?php echo ')?/\*/?%%SmartyNocache:{$this->smarty->template_functions[$name]['nocache_hash']}%%\*/(';\?>)?!", "!\\\'!"), array('', "'"), $smarty->template_functions[$name]['compiled']);
 | 
			
		||||
        if ($_nocache) {
 | 
			
		||||
            $_function = "smarty_template_function_{$_name}_nocache";
 | 
			
		||||
            $_template->smarty->template_functions[$_name]['called_nocache'] = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            $this->compiled_template = $smarty->template_functions[$name]['compiled'];
 | 
			
		||||
            $_function = "smarty_template_function_{$_hash}_{$_name}";
 | 
			
		||||
        } 
 | 
			
		||||
        // assign default paramter
 | 
			
		||||
        if (isset($smarty->template_functions[$name]['parameter'])) {
 | 
			
		||||
            $_smarty_tpl = $this;
 | 
			
		||||
            foreach ($smarty->template_functions[$name]['parameter'] as $_key => $_value) {
 | 
			
		||||
                $this->assign($_key, eval("return {$_value};"));
 | 
			
		||||
        if (!is_callable($_function)) {
 | 
			
		||||
            $_code = "function {$_function}(\$_smarty_tpl,\$params) {
 | 
			
		||||
	\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
 | 
			
		||||
	foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
 | 
			
		||||
            if ($_nocache) {
 | 
			
		||||
                $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",
 | 
			
		||||
                        "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);
 | 
			
		||||
            } else {
 | 
			
		||||
                $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);
 | 
			
		||||
            } 
 | 
			
		||||
            $_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";
 | 
			
		||||
            eval($_code);
 | 
			
		||||
        } 
 | 
			
		||||
        // set flag if {function} contains nocache code
 | 
			
		||||
        if ($smarty->template_functions[$name]['has_nocache_code']) {
 | 
			
		||||
            $this->has_nocache_code = true;
 | 
			
		||||
        } 
 | 
			
		||||
        $_function($_template, $_params);
 | 
			
		||||
    } 
 | 
			
		||||
} 
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user