3 * Smarty Internal Plugin Compile Registered Function
5 * Compiles code for the execution of a registered function
13 * Smarty Internal Plugin Compile Registered Function Class
15 class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $optional_attributes = array('_any');
20 * Compiles code for the execution of a registered function
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
28 public function compile($args, $compiler, $parameter, $tag)
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;
38 unset($_attr['nocache']);
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) {
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).^#^";
50 $_paramsArray[] = "'$_key'=>$_value";
53 $_params = 'array(' . implode(",", $_paramsArray) . ')';
54 $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag][0];
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";
61 $output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";