[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_private_object_block_function.php
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 */
12 /**
13 * Smarty Internal Plugin Compile Object Block Function Class
14 */
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');
20 /**
21 * Compiles code for the execution of block plugin
22 *
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
29 */
30 public function compile($args, $compiler, $parameter, $tag, $methode)
31 {
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;
39 }
40 unset($_attr['nocache']);
41 // convert attributes into parameter array string
42 $_paramsArray = array();
43 foreach ($_attr as $_key => $_value) {
44 if (is_int($_key)) {
45 $_paramsArray[] = "$_key=>$_value";
46 } else {
47 $_paramsArray[] = "'$_key'=>$_value";
48 }
49 }
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;
55 // compile code
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();?>";
57 } else {
58 $base_tag = substr($tag, 0, -5);
59 // must endblock be nocache?
60 if ($this->compiler->nocache) {
61 $this->compiler->tag_nocache = true;
62 }
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;
67 // compile code
68 if (!isset($parameter['modifier_list'])) {
69 $mod_pre = $mod_post ='';
70 } else {
71 $mod_pre = ' ob_start(); ';
72 $mod_post = 'echo '.$this->compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
73 }
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);?>";
75 }
76 return $output."\n";
77 }
78 }
80 ?>