|
1 <?php |
|
2 /** |
|
3 * Smarty Internal Plugin Compile Object Block Function |
|
4 * |
|
5 * Compiles code for registered objects as block function |
|
6 * |
|
7 * @package Smarty |
|
8 * @subpackage Compiler |
|
9 * @author Uwe Tews |
|
10 */ |
|
11 |
|
12 /** |
|
13 * Smarty Internal Plugin Compile Object Block Function Class |
|
14 * |
|
15 * @package Smarty |
|
16 * @subpackage Compiler |
|
17 */ |
|
18 class Smarty_Internal_Compile_Private_Object_Block_Function 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 block plugin |
|
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 object |
|
35 * @param string $method name of method to call |
|
36 * @return string compiled code |
|
37 */ |
|
38 public function compile($args, $compiler, $parameter, $tag, $method) |
|
39 { |
|
40 if (!isset($tag[5]) || substr($tag, -5) != 'close') { |
|
41 // opening tag of block plugin |
|
42 // check and get attributes |
|
43 $_attr = $this->getAttributes($compiler, $args); |
|
44 if ($_attr['nocache'] === true) { |
|
45 $compiler->tag_nocache = true; |
|
46 } |
|
47 unset($_attr['nocache']); |
|
48 // convert attributes into parameter array string |
|
49 $_paramsArray = array(); |
|
50 foreach ($_attr as $_key => $_value) { |
|
51 if (is_int($_key)) { |
|
52 $_paramsArray[] = "$_key=>$_value"; |
|
53 } else { |
|
54 $_paramsArray[] = "'$_key'=>$_value"; |
|
55 } |
|
56 } |
|
57 $_params = 'array(' . implode(",", $_paramsArray) . ')'; |
|
58 |
|
59 $this->openTag($compiler, $tag . '->' . $method, array($_params, $compiler->nocache)); |
|
60 // maybe nocache because of nocache variables or nocache plugin |
|
61 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |
|
62 // compile code |
|
63 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |
|
64 } else { |
|
65 $base_tag = substr($tag, 0, -5); |
|
66 // must endblock be nocache? |
|
67 if ($compiler->nocache) { |
|
68 $compiler->tag_nocache = true; |
|
69 } |
|
70 // closing tag of block plugin, restore nocache |
|
71 list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag . '->' . $method); |
|
72 // This tag does create output |
|
73 $compiler->has_output = true; |
|
74 // compile code |
|
75 if (!isset($parameter['modifier_list'])) { |
|
76 $mod_pre = $mod_post = ''; |
|
77 } else { |
|
78 $mod_pre = ' ob_start(); '; |
|
79 $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; |
|
80 } |
|
81 $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |
|
82 } |
|
83 return $output . "\n"; |
|
84 } |
|
85 |
|
86 } |
|
87 |
|
88 ?> |