| 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: |
|
| 29: | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
| 30: | {
|
| 31: |
|
| 32: | $_attr = $this->getAttributes($compiler, $args);
|
| 33: | $this->openTag($compiler, 'if', array(1, $compiler->nocache));
|
| 34: |
|
| 35: | $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
| 36: | if (!isset($parameter[ 'if condition' ])) {
|
| 37: | $compiler->trigger_template_error('missing if condition', null, true);
|
| 38: | }
|
| 39: | if (is_array($parameter[ 'if condition' ])) {
|
| 40: | if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
| 41: | $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
| 42: | } else {
|
| 43: | $var = $parameter[ 'if condition' ][ 'var' ];
|
| 44: | }
|
| 45: | if ($compiler->nocache) {
|
| 46: |
|
| 47: | $compiler->setNocacheInVariable($var);
|
| 48: | }
|
| 49: | $prefixVar = $compiler->getNewPrefixVariable();
|
| 50: | $_output = "<?php {$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]};?>\n";
|
| 51: | $assignAttr = array();
|
| 52: | $assignAttr[][ 'value' ] = $prefixVar;
|
| 53: | $assignCompiler = new Smarty_Internal_Compile_Assign();
|
| 54: | if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
| 55: | $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
| 56: | $_output .= $assignCompiler->compile(
|
| 57: | $assignAttr,
|
| 58: | $compiler,
|
| 59: | array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
| 60: | );
|
| 61: | } else {
|
| 62: | $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
| 63: | $_output .= $assignCompiler->compile($assignAttr, $compiler, array());
|
| 64: | }
|
| 65: | $_output .= "<?php if ({$prefixVar}) {?>";
|
| 66: | return $_output;
|
| 67: | } else {
|
| 68: | return "<?php if ({$parameter['if condition']}) {?>";
|
| 69: | }
|
| 70: | }
|
| 71: | }
|
| 72: |
|
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: |
|
| 79: | class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
|
| 80: | {
|
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: |
|
| 89: | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
| 90: | {
|
| 91: | list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
| 92: | $this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
|
| 93: | return '<?php } else { ?>';
|
| 94: | }
|
| 95: | }
|
| 96: |
|
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: |
|
| 103: | class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
| 104: | {
|
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: |
|
| 115: | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
| 116: | {
|
| 117: |
|
| 118: | $_attr = $this->getAttributes($compiler, $args);
|
| 119: | list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
| 120: | if (!isset($parameter[ 'if condition' ])) {
|
| 121: | $compiler->trigger_template_error('missing elseif condition', null, true);
|
| 122: | }
|
| 123: | $assignCode = '';
|
| 124: | $var = '';
|
| 125: | if (is_array($parameter[ 'if condition' ])) {
|
| 126: | $condition_by_assign = true;
|
| 127: | if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
| 128: | $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
| 129: | } else {
|
| 130: | $var = $parameter[ 'if condition' ][ 'var' ];
|
| 131: | }
|
| 132: | if ($compiler->nocache) {
|
| 133: |
|
| 134: | $compiler->setNocacheInVariable($var);
|
| 135: | }
|
| 136: | $prefixVar = $compiler->getNewPrefixVariable();
|
| 137: | $assignCode = "<?php {$prefixVar} = {$parameter[ 'if condition' ][ 'value' ]};?>\n";
|
| 138: | $assignCompiler = new Smarty_Internal_Compile_Assign();
|
| 139: | $assignAttr = array();
|
| 140: | $assignAttr[][ 'value' ] = $prefixVar;
|
| 141: | if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
| 142: | $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
| 143: | $assignCode .= $assignCompiler->compile(
|
| 144: | $assignAttr,
|
| 145: | $compiler,
|
| 146: | array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])
|
| 147: | );
|
| 148: | } else {
|
| 149: | $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
| 150: | $assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());
|
| 151: | }
|
| 152: | } else {
|
| 153: | $condition_by_assign = false;
|
| 154: | }
|
| 155: | $prefixCode = $compiler->getPrefixCode();
|
| 156: | if (empty($prefixCode)) {
|
| 157: | if ($condition_by_assign) {
|
| 158: | $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
| 159: | $_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
|
| 160: | return $compiler->appendCode($_output, "<?php if ({$prefixVar}) {?>");
|
| 161: | } else {
|
| 162: | $this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
| 163: | return "<?php } elseif ({$parameter['if condition']}) {?>";
|
| 164: | }
|
| 165: | } else {
|
| 166: | $_output = $compiler->appendCode("<?php } else {\n?>", $prefixCode);
|
| 167: | $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
| 168: | if ($condition_by_assign) {
|
| 169: | $_output = $compiler->appendCode($_output, $assignCode);
|
| 170: | return $compiler->appendCode($_output, "<?php if ({$prefixVar}) {?>");
|
| 171: | } else {
|
| 172: | return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
|
| 173: | }
|
| 174: | }
|
| 175: | }
|
| 176: | }
|
| 177: |
|
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: | |
| 183: |
|
| 184: | class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
|
| 185: | {
|
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: | |
| 193: |
|
| 194: | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
| 195: | {
|
| 196: |
|
| 197: | if ($compiler->nocache) {
|
| 198: | $compiler->tag_nocache = true;
|
| 199: | }
|
| 200: | list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
|
| 201: | $tmp = '';
|
| 202: | for ($i = 0; $i < $nesting; $i++) {
|
| 203: | $tmp .= '}';
|
| 204: | }
|
| 205: | return "<?php {$tmp}?>";
|
| 206: | }
|
| 207: | }
|
| 208: | |