Code

Updated smarty to recent 3.0.8
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_function_call_handler.php
index 0f5cfeba1900b11848c68af1257f215551a3fb83..928f04471107a9376fee69a74f34733fa418b8cf 100644 (file)
@@ -1,47 +1,40 @@
-<?php
-/**
-* Smarty Internal Plugin Function Call Handler
-* 
-* @package Smarty
-* @subpackage Security
-* @author Uwe Tews 
-*/
-/**
-* 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)
-    {
-        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']);
-        } else {
-            $this->compiled_template = $smarty->template_functions[$name]['compiled'];
-        } 
-        // 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};"));
-            } 
-        } 
-        // set flag if {function} contains nocache code
-        if ($smarty->template_functions[$name]['has_nocache_code']) {
-            $this->has_nocache_code = true;
-        } 
-    } 
-} 
-
-?>
+<?php\r
+/**\r
+ * Smarty Internal Plugin Function Call Handler\r
+ *\r
+ * @package Smarty\r
+ * @subpackage PluginsInternal\r
+ * @author Uwe Tews\r
+ */\r
+\r
+/**\r
+ * This class does call function defined with the {function} tag\r
+ */\r
+class Smarty_Internal_Function_Call_Handler extends Smarty_Internal_Template {\r
+    static function call ($_name, $_template, $_params, $_hash, $_nocache)\r
+    {\r
+        if ($_nocache) {\r
+            $_function = "smarty_template_function_{$_name}_nocache";\r
+            $_template->smarty->template_functions[$_name]['called_nocache'] = true;\r
+        } else {\r
+            $_function = "smarty_template_function_{$_hash}_{$_name}";\r
+        }\r
+        if (!is_callable($_function)) {\r
+            $_code = "function {$_function}(\$_smarty_tpl,\$params) {\r
+    \$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\r
+    foreach (\$_smarty_tpl->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};\r
+    foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";\r
+            if ($_nocache) {\r
+                $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!",\r
+                        "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']);\r
+            } else {\r
+                $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']);\r
+            }\r
+            $_code .= "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}";\r
+            eval($_code);\r
+        }\r
+        $_function($_template, $_params);\r
+    }\r
+}\r
+\r
+?>
\ No newline at end of file