Code

Updated smarty to recent 3.0.8
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_call.php
1 <?php
3 /**
4  * Smarty Internal Plugin Compile Function_Call
5  * 
6  * Compiles the calls of user defined tags defined by {function}
7  * 
8  * @package Smarty
9  * @subpackage Compiler
10  * @author Uwe Tews 
11  */
13 /**
14  * Smarty Internal Plugin Compile Function_Call Class
15  */
16 class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
17         // attribute definitions
18     public $required_attributes = array('name');
19     public $shorttag_order = array('name');
20     public $optional_attributes = array('_any'); 
22     /**
23      * Compiles the calls of user defined tags defined by {function}
24      * 
25      * @param array $args array with attributes from parser
26      * @param object $compiler compiler object
27      * @param array $parameter array with compilation parameter
28      * @return string compiled code
29      */
30     public function compile($args, $compiler)
31     {
32         $this->compiler = $compiler;
33         $this->smarty = $compiler->smarty;
34         // check and get attributes
35         $_attr = $this->_get_attributes($args); 
36         // save possible attributes
37         if (isset($_attr['assign'])) {
38             // output will be stored in a smarty variable instead of beind displayed
39             $_assign = $_attr['assign'];
40         } 
41         $_name = $_attr['name'];
42         unset($_attr['name'], $_attr['assign'], $_attr['nocache']); 
43         // set flag (compiled code of {function} must be included in cache file
44         if ($compiler->nocache || $compiler->tag_nocache) {
45             $_nocache = 'true';
46         } else {
47             $_nocache = 'false';
48         } 
49         $_paramsArray = array();
50         foreach ($_attr as $_key => $_value) {
51             if (is_int($_key)) {
52                 $_paramsArray[] = "$_key=>$_value";
53             } else {
54                 $_paramsArray[] = "'$_key'=>$_value";
55             } 
56         }
57         if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
58             foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
59                 if (!isset($_attr[$_key])) {
60                     if (is_int($_key)) {
61                         $_paramsArray[] = "$_key=>$_value";
62                     } else {
63                         $_paramsArray[] = "'$_key'=>$_value";
64                     } 
65                 } 
66             } 
67         } elseif (isset($this->smarty->template_functions[$_name]['parameter'])) {
68            foreach ($this->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
69                 if (!isset($_attr[$_key])) {
70                     if (is_int($_key)) {
71                         $_paramsArray[] = "$_key=>$_value";
72                     } else {
73                         $_paramsArray[] = "'$_key'=>$_value";
74                     } 
75                 } 
76             } 
77         }
78         //varibale name?
79         if (!(strpos($_name,'$')===false)) {
80                 $call_cache = $_name;
81                 $call_function = '$tmp = "smarty_template_function_".'.$_name.'; $tmp';
82         } else {
83                 $_name = trim($_name, "'\"");
84                 $call_cache = "'{$_name}'";
85                 $call_function = 'smarty_template_function_'.$_name;
86         }
87         
88         $_params = 'array(' . implode(",", $_paramsArray) . ')';
89         $_hash = str_replace('-','_',$compiler->template->properties['nocache_hash']);
90         // was there an assign attribute
91         if (isset($_assign)) {
92             if ($compiler->template->caching) {
93                 $_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
94             } else {
95                 $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
96             } 
97         } else {
98             if ($compiler->template->caching) {
99                 $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
100             } else {
101                 $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";
102             } 
103         } 
104         return $_output;
105     } 
106
108 ?>