Code

8be744c94ba33d6e70ee2a5b5a846d0beeb044e1
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_function_call_handler.php
1 <?php\r
2 /**\r
3  * Smarty Internal Plugin Function Call Handler\r
4  *\r
5  * @package Smarty\r
6  * @subpackage PluginsInternal\r
7  * @author Uwe Tews\r
8  */\r
9 \r
10 /**\r
11  * This class does call function defined with the {function} tag\r
12  *\r
13  * @package Smarty\r
14  * @subpackage PluginsInternal\r
15  */\r
16 class Smarty_Internal_Function_Call_Handler {\r
17 \r
18     /**\r
19      * This function handles calls to template functions defined by {function}\r
20      * It does create a PHP function at the first call\r
21      *\r
22      * @param string                   $_name       template function name\r
23      * @param Smarty_Internal_Template $_template   template object\r
24      * @param array                    $_params     Smarty variables passed as call paramter\r
25      * @param string                   $_hash       nocache hash value\r
26      * @param bool                     $_nocache    nocache flag\r
27      */\r
28     public static function call($_name, Smarty_Internal_Template $_template, $_params, $_hash, $_nocache)\r
29     {\r
30         if ($_nocache) {\r
31             $_function = "smarty_template_function_{$_name}_nocache";\r
32         } else {\r
33             $_function = "smarty_template_function_{$_hash}_{$_name}";\r
34         }\r
35         if (!is_callable($_function)) {\r
36             $_code = "function {$_function}(\$_smarty_tpl,\$params) {\r
37     \$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\r
38     foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};\r
39     foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";\r
40             if ($_nocache) {\r
41                 $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",\r
42                         "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);\r
43                 $_template->smarty->template_functions[$_name]['called_nocache'] = true;\r
44             } else {\r
45                 $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);\r
46             }\r
47             $_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";\r
48             eval($_code);\r
49         }\r
50         $_function($_template, $_params);\r
51     }\r
52 \r
53 }\r
54 \r
55 ?>