3 * Smarty Internal Plugin Compile Function_Call
4 * Compiles the calls of user defined tags defined by {function}
12 * Smarty Internal Plugin Compile Function_Call Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
20 * Attribute definition: Overwrites base class.
23 * @see Smarty_Internal_CompileBase
25 public $required_attributes = array('name');
27 * Attribute definition: Overwrites base class.
30 * @see Smarty_Internal_CompileBase
32 public $shorttag_order = array('name');
34 * Attribute definition: Overwrites base class.
37 * @see Smarty_Internal_CompileBase
39 public $optional_attributes = array('_any');
42 * Compiles the calls of user defined tags defined by {function}
44 * @param array $args array with attributes from parser
45 * @param object $compiler compiler object
47 * @return string compiled code
49 public function compile($args, $compiler)
51 // check and get attributes
52 $_attr = $this->getAttributes($compiler, $args);
53 // save possible attributes
54 if (isset($_attr['assign'])) {
55 // output will be stored in a smarty variable instead of being displayed
56 $_assign = $_attr['assign'];
58 $_name = $_attr['name'];
59 if ($compiler->compiles_template_function) {
60 $compiler->called_functions[] = trim($_name, "'\"");
62 unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
63 // set flag (compiled code of {function} must be included in cache file
64 if ($compiler->nocache || $compiler->tag_nocache) {
69 $_paramsArray = array();
70 foreach ($_attr as $_key => $_value) {
72 $_paramsArray[] = "$_key=>$_value";
74 $_paramsArray[] = "'$_key'=>$_value";
77 if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
78 foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
79 if (!isset($_attr[$_key])) {
81 $_paramsArray[] = "$_key=>$_value";
83 $_paramsArray[] = "'$_key'=>$_value";
87 } elseif (isset($compiler->smarty->template_functions[$_name]['parameter'])) {
88 foreach ($compiler->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
89 if (!isset($_attr[$_key])) {
91 $_paramsArray[] = "$_key=>$_value";
93 $_paramsArray[] = "'$_key'=>$_value";
99 if (!(strpos($_name, '$') === false)) {
100 $call_cache = $_name;
101 $call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
103 $_name = trim($_name, "'\"");
104 $call_cache = "'{$_name}'";
105 $call_function = 'smarty_template_function_' . $_name;
108 $_params = 'array(' . implode(",", $_paramsArray) . ')';
109 $_hash = str_replace('-', '_', $compiler->template->properties['nocache_hash']);
110 // was there an assign attribute
111 if (isset($_assign)) {
112 if ($compiler->template->caching) {
113 $_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 $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
118 if ($compiler->template->caching) {
119 $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
121 $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";