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