[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 * Smarty Internal Plugin Compile Registered Block Class\r
13 */\r
14 class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase {\r
15 /**\r
16 * Compiles code for the execution of a block function\r
17 * \r
18 * @param array $args array with attributes from parser\r
19 * @param string $tag name of block function\r
20 * @param object $compiler compiler object\r
21 * @return string compiled code\r
22 */\r
23 public function compile($args, $compiler, $tag)\r
24 {\r
25 $this->compiler = $compiler;\r
26 if (strlen($tag) < 6 || substr_compare($tag, 'close', -5, 5) != 0) {\r
27 // opening tag of block plugin\r
28 $this->required_attributes = array();\r
29 $this->optional_attributes = array('_any'); \r
30 // check and get attributes\r
31 $_attr = $this->_get_attributes($args); \r
32 // convert attributes into parameter array string\r
33 $_paramsArray = array();\r
34 foreach ($_attr as $_key => $_value) {\r
35 if (is_int($_key)) {\r
36 $_paramsArray[] = "$_key=>$_value";\r
37 } else {\r
38 $_paramsArray[] = "'$_key'=>$_value";\r
39 } \r
40 } \r
41 $_params = 'array(' . implode(",", $_paramsArray) . ')';\r
42 \r
43 $this->_open_tag($tag, array($_params, $this->compiler->nocache)); \r
44 // maybe nocache because of nocache variables or nocache plugin\r
45 $this->compiler->nocache = !$compiler->smarty->registered_plugins['block'][$tag][1] | $this->compiler->nocache | $this->compiler->tag_nocache;\r
46 $function = $compiler->smarty->registered_plugins['block'][$tag][0]; \r
47 // compile code\r
48 if (!is_array($function)) {\r
49 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";\r
50 } else if (is_object($function[0])) {\r
51 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func(\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0],{$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";\r
52 } else {\r
53 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func(array('{$function[0]}','{$function[1]}'),{$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";\r
54 } \r
55 } else {\r
56 // must endblock be nocache?\r
57 if ($this->compiler->nocache) {\r
58 $this->compiler->tag_nocache = true;\r
59 } \r
60 $base_tag = substr($tag, 0, -5); \r
61 // closing tag of block plugin, restore nocache\r
62 list($_params, $this->compiler->nocache) = $this->_close_tag($base_tag); \r
63 // This tag does create output\r
64 $this->compiler->has_output = true;\r
65 $function = $compiler->smarty->registered_plugins['block'][$base_tag][0]; \r
66 // compile code\r
67 if (!is_array($function)) {\r
68 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";\r
69 } else if (is_object($function[0])) {\r
70 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo call_user_func(\$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0],{$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";\r
71 } else {\r
72 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo call_user_func(array('{$function[0]}','{$function[1]}'),{$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";\r
73 } \r
74 } \r
75 return $output."\n";\r
76 } \r
77 } \r
78 \r
79 ?>