3 * Smarty Internal Plugin Compile Block Plugin
5 * Compiles code for the execution of block plugin
13 * Smarty Internal Plugin Compile Block Plugin Class
15 class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $optional_attributes = array('_any');
20 * Compiles code for the execution of block plugin
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 block plugin
26 * @param string $function PHP function name
27 * @return string compiled code
29 public function compile($args, $compiler, $parameter, $tag, $function)
31 $this->compiler = $compiler;
32 if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
33 // opening tag of block plugin
34 // check and get attributes
35 $_attr = $this->_get_attributes($args);
36 if ($_attr['nocache'] === true) {
37 $this->compiler->tag_nocache = true;
39 unset($_attr['nocache']);
40 // convert attributes into parameter array string
41 $_paramsArray = array();
42 foreach ($_attr as $_key => $_value) {
44 $_paramsArray[] = "$_key=>$_value";
46 $_paramsArray[] = "'$_key'=>$_value";
49 $_params = 'array(' . implode(",", $_paramsArray) . ')';
51 $this->_open_tag($tag, array($_params, $this->compiler->nocache));
52 // maybe nocache because of nocache variables or nocache plugin
53 $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
55 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
57 // must endblock be nocache?
58 if ($this->compiler->nocache) {
59 $this->compiler->tag_nocache = true;
61 // closing tag of block plugin, restore nocache
62 list($_params, $this->compiler->nocache) = $this->_close_tag(substr($tag, 0, -5));
63 // This tag does create output
64 $this->compiler->has_output = true;
66 if (!isset($parameter['modifier_list'])) {
67 $mod_pre = $mod_post ='';
69 $mod_pre = ' ob_start(); ';
70 $mod_post = 'echo '.$this->compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
72 $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);?>";
74 return $output . "\n";