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