1 <?php |
|
2 /** |
|
3 * Smarty Internal Plugin Compile Block Plugin |
|
4 * Compiles code for the execution of block plugin |
|
5 * |
|
6 * @package Smarty |
|
7 * @subpackage Compiler |
|
8 * @author Uwe Tews |
|
9 */ |
|
10 |
|
11 /** |
|
12 * Smarty Internal Plugin Compile Block Plugin Class |
|
13 * |
|
14 * @package Smarty |
|
15 * @subpackage Compiler |
|
16 */ |
|
17 class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase { |
|
18 /** |
|
19 * Attribute definition: Overwrites base class. |
|
20 * |
|
21 * @var array |
|
22 * @see Smarty_Internal_CompileBase |
|
23 */ |
|
24 public $optional_attributes = array('_any'); |
|
25 |
|
26 /** |
|
27 * Compiles code for the execution of block plugin |
|
28 * |
|
29 * @param array $args array with attributes from parser |
|
30 * @param object $compiler compiler object |
|
31 * @param array $parameter array with compilation parameter |
|
32 * @param string $tag name of block plugin |
|
33 * @param string $function PHP function name |
|
34 * |
|
35 * @return string compiled code |
|
36 */ |
|
37 public function compile($args, $compiler, $parameter, $tag, $function) { |
|
38 if (!isset($tag[5]) || substr($tag, -5) != 'close') { |
|
39 // opening tag of block plugin |
|
40 // check and get attributes |
|
41 $_attr = $this->getAttributes($compiler, $args); |
|
42 if ($_attr['nocache'] === true) { |
|
43 $compiler->tag_nocache = true; |
|
44 } |
|
45 unset($_attr['nocache']); |
|
46 // convert attributes into parameter array string |
|
47 $_paramsArray = array(); |
|
48 foreach ($_attr as $_key => $_value) { |
|
49 if (is_int($_key)) { |
|
50 $_paramsArray[] = "$_key=>$_value"; |
|
51 } else { |
|
52 $_paramsArray[] = "'$_key'=>$_value"; |
|
53 } |
|
54 } |
|
55 $_params = 'array(' . implode(",", $_paramsArray) . ')'; |
|
56 |
|
57 $this->openTag($compiler, $tag, array($_params, $compiler->nocache)); |
|
58 // maybe nocache because of nocache variables or nocache plugin |
|
59 $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |
|
60 // compile code |
|
61 $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();?>"; |
|
62 } else { |
|
63 // must endblock be nocache? |
|
64 if ($compiler->nocache) { |
|
65 $compiler->tag_nocache = true; |
|
66 } |
|
67 // closing tag of block plugin, restore nocache |
|
68 list($_params, $compiler->nocache) = $this->closeTag($compiler, substr($tag, 0, -5)); |
|
69 // This tag does create output |
|
70 $compiler->has_output = true; |
|
71 // compile code |
|
72 if (!isset($parameter['modifier_list'])) { |
|
73 $mod_pre = $mod_post = ''; |
|
74 } else { |
|
75 $mod_pre = ' ob_start(); '; |
|
76 $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; |
|
77 } |
|
78 $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);?>"; |
|
79 } |
|
80 |
|
81 return $output . "\n"; |
|
82 } |
|
83 } |
|