Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_compile_private_registered_function.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Registered Function
4  * 
5  * Compiles code for the execution of a registered function
6  * 
7  * @package Smarty
8  * @subpackage Compiler
9  * @author Uwe Tews 
10  */
11  
12 /**
13  * Smarty Internal Plugin Compile Registered Function Class
14  */
15 class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
16         // attribute definitions
17     public $optional_attributes = array('_any'); 
18
19     /**
20      * Compiles code for the execution of a registered function
21      * 
22      * @param array $args array with attributes from parser
23      * @param object $compiler compiler object
24      * @param array $parameter array with compilation parameter
25      * @param string $tag name of function
26      * @return string compiled code
27      */
28     public function compile($args, $compiler, $parameter, $tag)
29     {
30         $this->compiler = $compiler; 
31         // This tag does create output
32         $this->compiler->has_output = true;
33         // check and get attributes
34         $_attr = $this->_get_attributes($args); 
35         if ($_attr['nocache']) {
36             $this->compiler->tag_nocache = true;
37         }
38         unset($_attr['nocache']);
39         // not cachable?
40         $this->compiler->tag_nocache =  $this->compiler->tag_nocache || !$compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag][1]; 
41         // convert attributes into parameter array string
42         $_paramsArray = array();
43         foreach ($_attr as $_key => $_value) {
44             if (is_int($_key)) {
45                 $_paramsArray[] = "$_key=>$_value";
46             } elseif ($this->compiler->template->caching && in_array($_key,$compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag][2])) {
47                                 $_value = str_replace("'","^#^",$_value);
48                 $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
49             } else {
50                 $_paramsArray[] = "'$_key'=>$_value";
51             } 
52         } 
53         $_params = 'array(' . implode(",", $_paramsArray) . ')'; 
54         $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag][0]; 
55         // compile code
56         if (!is_array($function)) {
57             $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
58         } else if (is_object($function[0])) {
59             $output = "<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
60         } else {
61             $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
62         } 
63         return $output;
64     } 
65
66
67 ?>