[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_private_block_plugin.php
1 <?php
2 /**
3 * Smarty Internal Plugin Compile Block Plugin
4 *
5 * Compiles code for the execution of block plugin
6 *
7 * @package Smarty
8 * @subpackage Compiler
9 * @author Uwe Tews
10 */
12 /**
13 * Smarty Internal Plugin Compile Block Plugin Class
14 */
15 class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $optional_attributes = array('_any');
19 /**
20 * Compiles code for the execution of block plugin
21 *
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
28 */
29 public function compile($args, $compiler, $parameter, $tag, $function)
30 {
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;
38 }
39 unset($_attr['nocache']);
40 // convert attributes into parameter array string
41 $_paramsArray = array();
42 foreach ($_attr as $_key => $_value) {
43 if (is_int($_key)) {
44 $_paramsArray[] = "$_key=>$_value";
45 } else {
46 $_paramsArray[] = "'$_key'=>$_value";
47 }
48 }
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;
54 // compile code
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();?>";
56 } else {
57 // must endblock be nocache?
58 if ($this->compiler->nocache) {
59 $this->compiler->tag_nocache = true;
60 }
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;
65 // compile code
66 if (!isset($parameter['modifier_list'])) {
67 $mod_pre = $mod_post ='';
68 } else {
69 $mod_pre = ' ob_start(); ';
70 $mod_post = 'echo '.$this->compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
71 }
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);?>";
73 }
74 return $output . "\n";
75 }
76 }
78 ?>