| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: |
|
| 10: |
|
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: |
|
| 17: | class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
|
| 18: | {
|
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: |
|
| 35: | public function compile($args, $compiler, $parameter)
|
| 36: | {
|
| 37: | $compiler->loopNesting++;
|
| 38: | if ($parameter === 0) {
|
| 39: | $this->required_attributes = array('start', 'to');
|
| 40: | $this->optional_attributes = array('max', 'step');
|
| 41: | } else {
|
| 42: | $this->required_attributes = array('start', 'ifexp', 'var', 'step');
|
| 43: | $this->optional_attributes = array();
|
| 44: | }
|
| 45: | $this->mapCache = array();
|
| 46: |
|
| 47: | $_attr = $this->getAttributes($compiler, $args);
|
| 48: | $output = "<?php\n";
|
| 49: | if ($parameter === 1) {
|
| 50: | foreach ($_attr[ 'start' ] as $_statement) {
|
| 51: | if (is_array($_statement[ 'var' ])) {
|
| 52: | $var = $_statement[ 'var' ][ 'var' ];
|
| 53: | $index = $_statement[ 'var' ][ 'smarty_internal_index' ];
|
| 54: | } else {
|
| 55: | $var = $_statement[ 'var' ];
|
| 56: | $index = '';
|
| 57: | }
|
| 58: | $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable(null, \$_smarty_tpl->isRenderingCache);\n";
|
| 59: | $output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n";
|
| 60: | }
|
| 61: | if (is_array($_attr[ 'var' ])) {
|
| 62: | $var = $_attr[ 'var' ][ 'var' ];
|
| 63: | $index = $_attr[ 'var' ][ 'smarty_internal_index' ];
|
| 64: | } else {
|
| 65: | $var = $_attr[ 'var' ];
|
| 66: | $index = '';
|
| 67: | }
|
| 68: | $output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n";
|
| 69: | } else {
|
| 70: | $_statement = $_attr[ 'start' ];
|
| 71: | if (is_array($_statement[ 'var' ])) {
|
| 72: | $var = $_statement[ 'var' ][ 'var' ];
|
| 73: | $index = $_statement[ 'var' ][ 'smarty_internal_index' ];
|
| 74: | } else {
|
| 75: | $var = $_statement[ 'var' ];
|
| 76: | $index = '';
|
| 77: | }
|
| 78: | $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable(null, \$_smarty_tpl->isRenderingCache);";
|
| 79: | if (isset($_attr[ 'step' ])) {
|
| 80: | $output .= "\$_smarty_tpl->tpl_vars[$var]->step = $_attr[step];";
|
| 81: | } else {
|
| 82: | $output .= "\$_smarty_tpl->tpl_vars[$var]->step = 1;";
|
| 83: | }
|
| 84: | if (isset($_attr[ 'max' ])) {
|
| 85: | $output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) min(ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step)),$_attr[max]);\n";
|
| 86: | } else {
|
| 87: | $output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step));\n";
|
| 88: | }
|
| 89: | $output .= "if (\$_smarty_tpl->tpl_vars[$var]->total > 0) {\n";
|
| 90: | $output .= "for (\$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value], \$_smarty_tpl->tpl_vars[$var]->iteration = 1;\$_smarty_tpl->tpl_vars[$var]->iteration <= \$_smarty_tpl->tpl_vars[$var]->total;\$_smarty_tpl->tpl_vars[$var]->value{$index} += \$_smarty_tpl->tpl_vars[$var]->step, \$_smarty_tpl->tpl_vars[$var]->iteration++) {\n";
|
| 91: | $output .= "\$_smarty_tpl->tpl_vars[$var]->first = \$_smarty_tpl->tpl_vars[$var]->iteration === 1;";
|
| 92: | $output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;";
|
| 93: | }
|
| 94: | $output .= '?>';
|
| 95: | $this->openTag($compiler, 'for', array('for', $compiler->nocache));
|
| 96: |
|
| 97: | $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
| 98: |
|
| 99: | return $output;
|
| 100: | }
|
| 101: | }
|
| 102: |
|
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: |
|
| 109: | class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
|
| 110: | {
|
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: |
|
| 120: | public function compile($args, $compiler, $parameter)
|
| 121: | {
|
| 122: |
|
| 123: | $_attr = $this->getAttributes($compiler, $args);
|
| 124: | list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
|
| 125: | $this->openTag($compiler, 'forelse', array('forelse', $nocache));
|
| 126: | return "<?php }} else { ?>";
|
| 127: | }
|
| 128: | }
|
| 129: |
|
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: |
|
| 136: | class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
|
| 137: | {
|
| 138: | |
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: |
|
| 147: | public function compile($args, $compiler, $parameter)
|
| 148: | {
|
| 149: | $compiler->loopNesting--;
|
| 150: |
|
| 151: | $_attr = $this->getAttributes($compiler, $args);
|
| 152: |
|
| 153: | if ($compiler->nocache) {
|
| 154: | $compiler->tag_nocache = true;
|
| 155: | }
|
| 156: | list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
|
| 157: | $output = "<?php }\n";
|
| 158: | if ($openTag !== 'forelse') {
|
| 159: | $output .= "}\n";
|
| 160: | }
|
| 161: | $output .= "?>";
|
| 162: | return $output;
|
| 163: | }
|
| 164: | }
|
| 165: | |