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