Code

Readded smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_function_call_handler.php
diff --git a/gosa-core/include/smarty/sysplugins/smarty_internal_function_call_handler.php b/gosa-core/include/smarty/sysplugins/smarty_internal_function_call_handler.php
new file mode 100644 (file)
index 0000000..8be744c
--- /dev/null
@@ -0,0 +1,55 @@
+<?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
+ * @package Smarty\r
+ * @subpackage PluginsInternal\r
+ */\r
+class Smarty_Internal_Function_Call_Handler {\r
+\r
+    /**\r
+     * This function handles calls to template functions defined by {function}\r
+     * It does create a PHP function at the first call\r
+     *\r
+     * @param string                   $_name       template function name\r
+     * @param Smarty_Internal_Template $_template   template object\r
+     * @param array                    $_params     Smarty variables passed as call paramter\r
+     * @param string                   $_hash       nocache hash value\r
+     * @param bool                     $_nocache    nocache flag\r
+     */\r
+    public static function call($_name, Smarty_Internal_Template $_template, $_params, $_hash, $_nocache)\r
+    {\r
+        if ($_nocache) {\r
+            $_function = "smarty_template_function_{$_name}_nocache";\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->smarty->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
+                $_template->smarty->template_functions[$_name]['called_nocache'] = true;\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
+\r
+?>
\ No newline at end of file