Adjusted header.tpl for Work plugin.
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_compile_if.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile If
4  * 
5  * Compiles the {if} {else} {elseif} {/if} tags
6  * 
7  * @package Smarty
8  * @subpackage Compiler
9  * @author Uwe Tews 
10  */
11
12 /**
13  * Smarty Internal Plugin Compile If Class
14  */
15 class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase {
16     /**
17      * Compiles code for the {if} tag
18      * 
19      * @param array $args array with attributes from parser
20      * @param object $compiler compiler object
21      * @param array $parameter array with compilation parameter
22      * @return string compiled code
23      */
24     public function compile($args, $compiler, $parameter)
25     {
26         $this->compiler = $compiler;
27         // check and get attributes
28         $_attr = $this->_get_attributes($args);
29         $this->_open_tag('if',array(1,$this->compiler->nocache));
30         // must whole block be nocache ?
31         $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; 
32         if (is_array($parameter['if condition'])) {
33                 if ($this->compiler->nocache) {
34                         $_nocache = ',true';
35                 // create nocache var to make it know for further compiling
36                 if (is_array($parameter['if condition']['var'])) {
37                         $this->compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
38                 } else {
39                         $this->compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
40                 }
41                 } else {
42                         $_nocache = '';
43                 }
44             if (is_array($parameter['if condition']['var'])) {
45                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
46                     $_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
47             } else {
48                     $_output = "<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";           
49                     $_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
50                 }
51             return $_output;
52         } else {
53             return "<?php if ({$parameter['if condition']}){?>";
54         } 
55     } 
56
57
58 /**
59  * Smarty Internal Plugin Compile Else Class
60  */
61 class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase {
62     /**
63      * Compiles code for the {else} tag
64      * 
65      * @param array $args array with attributes from parser
66      * @param object $compiler compiler object
67      * @param array $parameter array with compilation parameter
68      * @return string compiled code
69      */
70     public function compile($args, $compiler, $parameter)
71     {
72         $this->compiler = $compiler; 
73         list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
74         $this->_open_tag('else',array($nesting,$compiler->tag_nocache));
75
76         return "<?php }else{ ?>";
77     } 
78
79
80 /**
81  * Smarty Internal Plugin Compile ElseIf Class
82  */
83 class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase {
84     /**
85      * Compiles code for the {elseif} tag
86      * 
87      * @param array $args array with attributes from parser
88      * @param object $compiler compiler object
89      * @param array $parameter array with compilation parameter
90      * @return string compiled code
91      */
92     public function compile($args, $compiler, $parameter)
93     {
94         $this->compiler = $compiler;
95         // check and get attributes
96         $_attr = $this->_get_attributes($args);
97
98         list($nesting, $compiler->tag_nocache) = $this->_close_tag(array('if', 'elseif'));
99
100                 if (is_array($parameter['if condition'])) {
101                         $condition_by_assign = true;
102                         if ($this->compiler->nocache) {
103                         $_nocache = ',true';
104                                 // create nocache var to make it know for further compiling
105                                 if (is_array($parameter['if condition']['var'])) {
106                                         $this->compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
107                                 } else {
108                                         $this->compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
109                                 }
110                         } else {
111                                 $_nocache = '';
112                         }
113                 } else {
114                         $condition_by_assign = false;
115                 }
116
117         if (empty($this->compiler->prefix_code)) {
118                 if ($condition_by_assign) {
119                 $this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache));
120                 if (is_array($parameter['if condition']['var'])) {
121                         $_output = "<?php }else{ if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
122                         $_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
123                 } else {
124                         $_output = "<?php }else{ \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";          
125                         $_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
126                                 }
127                 return $_output;
128                 } else {
129                 $this->_open_tag('elseif', array($nesting, $compiler->tag_nocache));
130                 return "<?php }elseif({$parameter['if condition']}){?>";
131                 }
132         } else {
133             $tmp = '';
134             foreach ($this->compiler->prefix_code as $code) $tmp .= $code;
135             $this->compiler->prefix_code = array();
136             $this->_open_tag('elseif', array($nesting + 1, $compiler->tag_nocache));
137                 if ($condition_by_assign) {
138                 if (is_array($parameter['if condition']['var'])) {
139                         $_output = "<?php }else{?>{$tmp}<?php  if (!isset(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]) || !is_array(\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value)) \$_smarty_tpl->createLocalArrayVariable(".$parameter['if condition']['var']['var']."$_nocache);\n";
140                         $_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']['var']."]->value".$parameter['if condition']['var']['smarty_internal_index']." = ".$parameter['if condition']['value']."){?>";
141                 } else {
142                         $_output = "<?php }else{?>{$tmp}<?php \$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."] = new Smarty_Variable(\$_smarty_tpl->getVariable(".$parameter['if condition']['var'].",null,true,false)->value{$_nocache});";           
143                         $_output .= "if (\$_smarty_tpl->tpl_vars[".$parameter['if condition']['var']."]->value = ".$parameter['if condition']['value']."){?>";
144                                 }
145                 return $_output;
146                 } else {
147                 return "<?php }else{?>{$tmp}<?php if ({$parameter['if condition']}){?>";
148                 }
149         } 
150     } 
151
152
153 /**
154 * Smarty Internal Plugin Compile Ifclose Class
155 */
156 class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase {
157     /**
158     * Compiles code for the {/if} tag
159     * 
160     * @param array $args array with attributes from parser
161     * @param object $compiler compiler object
162      * @param array $parameter array with compilation parameter
163     * @return string compiled code
164     */
165     public function compile($args, $compiler, $parameter)
166     {
167         $this->compiler = $compiler; 
168             // must endblock be nocache?
169             if ($this->compiler->nocache) {
170                 $this->compiler->tag_nocache = true;
171             } 
172         list($nesting, $this->compiler->nocache) = $this->_close_tag(array('if', 'else', 'elseif'));
173         $tmp = '';
174         for ($i = 0; $i < $nesting ; $i++) $tmp .= '}';
175         return "<?php {$tmp}?>";
176     } 
177
178
179 ?>