3 * Smarty Internal Plugin Compile Function_Call
5 * Compiles the calls of user defined tags defined by {function}
13 * Smarty Internal Plugin Compile Function_Call Class
16 * @subpackage Compiler
18 class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
21 * Attribute definition: Overwrites base class.
24 * @see Smarty_Internal_CompileBase
26 public $required_attributes = array('name');
28 * Attribute definition: Overwrites base class.
31 * @see Smarty_Internal_CompileBase
33 public $shorttag_order = array('name');
35 * Attribute definition: Overwrites base class.
38 * @see Smarty_Internal_CompileBase
40 public $optional_attributes = array('_any');
43 * Compiles the calls of user defined tags defined by {function}
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
50 public function compile($args, $compiler)
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'];
59 $_name = $_attr['name'];
60 if ($compiler->compiles_template_function) {
61 $compiler->called_functions[] = trim($_name, "'\"");
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) {
70 $_paramsArray = array();
71 foreach ($_attr as $_key => $_value) {
73 $_paramsArray[] = "$_key=>$_value";
75 $_paramsArray[] = "'$_key'=>$_value";
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])) {
82 $_paramsArray[] = "$_key=>$_value";
84 $_paramsArray[] = "'$_key'=>$_value";
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])) {
92 $_paramsArray[] = "$_key=>$_value";
94 $_paramsArray[] = "'$_key'=>$_value";
100 if (!(strpos($_name, '$') === false)) {
101 $call_cache = $_name;
102 $call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
104 $_name = trim($_name, "'\"");
105 $call_cache = "'{$_name}'";
106 $call_function = 'smarty_template_function_' . $_name;
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";
116 $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
119 if ($compiler->template->caching) {
120 $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
122 $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";