1 | <?php |
---|
2 | /** |
---|
3 | * Smarty Internal Plugin Compile Registered Block |
---|
4 | * |
---|
5 | * Compiles code for the execution of a registered block function |
---|
6 | * |
---|
7 | * @package Smarty |
---|
8 | * @subpackage Compiler |
---|
9 | * @author Uwe Tews |
---|
10 | */ |
---|
11 | |
---|
12 | /** |
---|
13 | * Smarty Internal Plugin Compile Registered Block Class |
---|
14 | * |
---|
15 | * @package Smarty |
---|
16 | * @subpackage Compiler |
---|
17 | */ |
---|
18 | class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase { |
---|
19 | |
---|
20 | /** |
---|
21 | * Attribute definition: Overwrites base class. |
---|
22 | * |
---|
23 | * @var array |
---|
24 | * @see Smarty_Internal_CompileBase |
---|
25 | */ |
---|
26 | public $optional_attributes = array('_any'); |
---|
27 | |
---|
28 | /** |
---|
29 | * Compiles code for the execution of a block function |
---|
30 | * |
---|
31 | * @param array $args array with attributes from parser |
---|
32 | * @param object $compiler compiler object |
---|
33 | * @param array $parameter array with compilation parameter |
---|
34 | * @param string $tag name of block function |
---|
35 | * @return string compiled code |
---|
36 | */ |
---|
37 | public function compile($args, $compiler, $parameter, $tag) |
---|
38 | { |
---|
39 | if (!isset($tag[5]) || substr($tag,-5) != 'close') { |
---|
40 | // opening tag of block plugin |
---|
41 | // check and get attributes |
---|
42 | $_attr = $this->getAttributes($compiler, $args); |
---|
43 | if ($_attr['nocache']) { |
---|
44 | $compiler->tag_nocache = true; |
---|
45 | } |
---|
46 | unset($_attr['nocache']); |
---|
47 | if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) { |
---|
48 | $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag]; |
---|
49 | } else { |
---|
50 | $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag]; |
---|
51 | } |
---|
52 | // convert attributes into parameter array string |
---|
53 | $_paramsArray = array(); |
---|
54 | foreach ($_attr as $_key => $_value) { |
---|
55 | if (is_int($_key)) { |
---|
56 | $_paramsArray[] = "$_key=>$_value"; |
---|
57 | } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { |
---|
58 | $_value = str_replace("'","^#^",$_value); |
---|
59 | $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; |
---|
60 | } else { |
---|
61 | $_paramsArray[] = "'$_key'=>$_value"; |
---|
62 | } |
---|
63 | } |
---|
64 | $_params = 'array(' . implode(",", $_paramsArray) . ')'; |
---|
65 | |
---|
66 | $this->openTag($compiler, $tag, array($_params, $compiler->nocache)); |
---|
67 | // maybe nocache because of nocache variables or nocache plugin |
---|
68 | $compiler->nocache = !$tag_info[1] | $compiler->nocache | $compiler->tag_nocache; |
---|
69 | $function = $tag_info[0]; |
---|
70 | // compile code |
---|
71 | if (!is_array($function)) { |
---|
72 | $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |
---|
73 | } else if (is_object($function[0])) { |
---|
74 | $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |
---|
75 | } else { |
---|
76 | $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |
---|
77 | } |
---|
78 | } else { |
---|
79 | // must endblock be nocache? |
---|
80 | if ($compiler->nocache) { |
---|
81 | $compiler->tag_nocache = true; |
---|
82 | } |
---|
83 | $base_tag = substr($tag, 0, -5); |
---|
84 | // closing tag of block plugin, restore nocache |
---|
85 | list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag); |
---|
86 | // This tag does create output |
---|
87 | $compiler->has_output = true; |
---|
88 | if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { |
---|
89 | $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; |
---|
90 | } else { |
---|
91 | $function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; |
---|
92 | } |
---|
93 | // compile code |
---|
94 | if (!isset($parameter['modifier_list'])) { |
---|
95 | $mod_pre = $mod_post =''; |
---|
96 | } else { |
---|
97 | $mod_pre = ' ob_start(); '; |
---|
98 | $mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';'; |
---|
99 | } |
---|
100 | if (!is_array($function)) { |
---|
101 | $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);".$mod_post." } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |
---|
102 | } else if (is_object($function[0])) { |
---|
103 | $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |
---|
104 | } else { |
---|
105 | $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;".$mod_pre." echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |
---|
106 | } |
---|
107 | } |
---|
108 | return $output . "\n"; |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | ?> |
---|