PageRenderTime 27ms CodeModel.GetById 8ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_private_registered_block.php

http://zoop.googlecode.com/
PHP | 79 lines | 48 code | 2 blank | 29 comment | 15 complexity | e6e2ac5a03abba42826ee3499e81e3cc MD5 | raw file
 1<?php
 2/**
 3* Smarty Internal Plugin Compile Registered Block
 4* 
 5* Compiles code for the execution of a registered block function
 6* 
 7* @package Smarty
 8* @subpackage Compiler
 9* @author Uwe Tews 
10*/
11/**
12* Smarty Internal Plugin Compile Registered Block Class
13*/
14class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase {
15    /**
16    * Compiles code for the execution of a block function
17    * 
18    * @param array $args array with attributes from parser
19    * @param string $tag name of block function
20    * @param object $compiler compiler object
21    * @return string compiled code
22    */
23    public function compile($args, $compiler, $tag)
24    {
25        $this->compiler = $compiler;
26        if (strlen($tag) < 6 || substr_compare($tag, 'close', -5, 5) != 0) {
27            // opening tag of block plugin
28            $this->required_attributes = array();
29            $this->optional_attributes = array('_any'); 
30            // check and get attributes
31            $_attr = $this->_get_attributes($args); 
32            // convert attributes into parameter array string
33            $_paramsArray = array();
34            foreach ($_attr as $_key => $_value) {
35                if (is_int($_key)) {
36                    $_paramsArray[] = "$_key=>$_value";
37                } else {
38                    $_paramsArray[] = "'$_key'=>$_value";
39                } 
40            } 
41            $_params = 'array(' . implode(",", $_paramsArray) . ')';
42
43            $this->_open_tag($tag, array($_params, $this->compiler->nocache)); 
44            // maybe nocache because of nocache variables or nocache plugin
45            $this->compiler->nocache = !$compiler->smarty->registered_plugins['block'][$tag][1] | $this->compiler->nocache | $this->compiler->tag_nocache;
46            $function = $compiler->smarty->registered_plugins['block'][$tag][0]; 
47            // compile code
48            if (!is_array($function)) {
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();?>";
50            } else if (is_object($function[0])) {
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();?>";
52            } else {
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();?>";
54            } 
55        } else {
56            // must endblock be nocache?
57            if ($this->compiler->nocache) {
58                $this->compiler->tag_nocache = true;
59            } 
60            $base_tag = substr($tag, 0, -5); 
61            // closing tag of block plugin, restore nocache
62            list($_params, $this->compiler->nocache) = $this->_close_tag($base_tag); 
63            // This tag does create output
64            $this->compiler->has_output = true;
65            $function = $compiler->smarty->registered_plugins['block'][$base_tag][0]; 
66            // compile code
67            if (!is_array($function)) {
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);?>";
69            } else if (is_object($function[0])) {
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);?>";
71            } else {
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);?>";
73            } 
74        } 
75        return $output."\n";
76    } 
77} 
78
79?>