1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
18: {
19: 20: 21: 22: 23: 24: 25: 26: 27:
28: public function compile($args, $compiler, $parameter)
29: {
30:
31: $_attr = $this->getAttributes($compiler, $args);
32: $this->openTag($compiler, 'if', array(1, $compiler->nocache));
33:
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:
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: 69: 70: 71: 72:
73: class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
74: {
75: 76: 77: 78: 79: 80: 81: 82: 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: 95: 96: 97: 98:
99: class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
100: {
101: 102: 103: 104: 105: 106: 107: 108: 109:
110: public function compile($args, $compiler, $parameter)
111: {
112:
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:
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: 181: 182: 183: 184:
185: class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
186: {
187: 188: 189: 190: 191: 192: 193: 194: 195:
196: public function compile($args, $compiler, $parameter)
197: {
198:
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: }
211: