1: <?php
2: /**
3: * Smarty Internal Plugin Compile Registered Function
4: * Compiles code for the execution of a registered function
5: *
6: * @package Smarty
7: * @subpackage Compiler
8: * @author Uwe Tews
9: */
10:
11: /**
12: * Smarty Internal Plugin Compile Registered Function Class
13: *
14: * @package Smarty
15: * @subpackage Compiler
16: */
17: class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase
18: {
19: /**
20: * Attribute definition: Overwrites base class.
21: *
22: * @var array
23: * @see Smarty_Internal_CompileBase
24: */
25: public $optional_attributes = array('_any');
26:
27: /**
28: * Compiles code for the execution of a registered function
29: *
30: * @param array $args array with attributes from parser
31: * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
32: * @param array $parameter array with compilation parameter
33: * @param string $tag name of function
34: *
35: * @return string compiled code
36: * @throws \SmartyCompilerException
37: * @throws \SmartyException
38: */
39: public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
40: {
41: // check and get attributes
42: $_attr = $this->getAttributes($compiler, $args);
43: unset($_attr[ 'nocache' ]);
44: if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
45: $tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
46: $is_registered = true;
47: } else {
48: $tag_info = $compiler->default_handler_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
49: $is_registered = false;
50: }
51: // not cacheable?
52: $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[ 1 ];
53: // convert attributes into parameter array string
54: $_paramsArray = array();
55: foreach ($_attr as $_key => $_value) {
56: if (is_int($_key)) {
57: $_paramsArray[] = "$_key=>$_value";
58: } elseif ($compiler->template->caching && in_array($_key, $tag_info[ 2 ])) {
59: $_value = str_replace('\'', "^#^", $_value);
60: $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
61: } else {
62: $_paramsArray[] = "'$_key'=>$_value";
63: }
64: }
65: $_params = 'array(' . implode(',', $_paramsArray) . ')';
66: // compile code
67: if ($is_registered) {
68: $output =
69: "call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )";
70: } else {
71: $function = $tag_info[ 0 ];
72: if (!is_array($function)) {
73: $output = "{$function}({$_params},\$_smarty_tpl)";
74: } else {
75: $output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)";
76: }
77: }
78: if (!empty($parameter[ 'modifierlist' ])) {
79: $output = $compiler->compileTag(
80: 'private_modifier',
81: array(),
82: array(
83: 'modifierlist' => $parameter[ 'modifierlist' ],
84: 'value' => $output
85: )
86: );
87: }
88: $output = "<?php echo {$output};?>\n";
89: return $output;
90: }
91: }
92: