3 * Smarty Internal Plugin Compile Object Block Function
5 * Compiles code for registered objects as block function
13 * Smarty Internal Plugin Compile Object Block Function Class
15 class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $required_attributes = array();
18 public $optional_attributes = array('_any');
21 * Compiles code for the execution of block plugin
23 * @param array $args array with attributes from parser
24 * @param object $compiler compiler object
25 * @param array $parameter array with compilation parameter
26 * @param string $tag name of block object
27 * @param string $methode name of methode to call
28 * @return string compiled code
30 public function compile($args, $compiler, $parameter, $tag, $methode)
32 $this->compiler = $compiler;
33 if (strlen($tag) < 5 || substr($tag, -5) != 'close') {
34 // opening tag of block plugin
35 // check and get attributes
36 $_attr = $this->_get_attributes($args);
37 if ($_attr['nocache'] === true) {
38 $this->compiler->tag_nocache = true;
40 unset($_attr['nocache']);
41 // convert attributes into parameter array string
42 $_paramsArray = array();
43 foreach ($_attr as $_key => $_value) {
45 $_paramsArray[] = "$_key=>$_value";
47 $_paramsArray[] = "'$_key'=>$_value";
50 $_params = 'array(' . implode(",", $_paramsArray) . ')';
52 $this->_open_tag($tag . '->' . $methode, array($_params, $this->compiler->nocache));
53 // maybe nocache because of nocache variables or nocache plugin
54 $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
56 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$methode}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
58 $base_tag = substr($tag, 0, -5);
59 // must endblock be nocache?
60 if ($this->compiler->nocache) {
61 $this->compiler->tag_nocache = true;
63 // closing tag of block plugin, restore nocache
64 list($_params, $this->compiler->nocache) = $this->_close_tag($base_tag . '->' . $methode);
65 // This tag does create output
66 $this->compiler->has_output = true;
68 if (!isset($parameter['modifier_list'])) {
69 $mod_pre = $mod_post ='';
71 $mod_pre = ' ob_start(); ';
72 $mod_post = 'echo '.$this->compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
74 $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;".$mod_pre." echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$methode}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post." } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";