- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161

update of yesterdays fix
This commit is contained in:
uwetews
2016-01-26 21:25:29 +01:00
parent 8a0c783b71
commit 0b31052418
3 changed files with 158 additions and 159 deletions

View File

@@ -1,6 +1,8 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)  ===== 3.1.30-dev ===== (xx.xx.xx)
27.01.2016 27.01.2016
- revert bugfix compiling {section} did create warning - revert bugfix compiling {section} did create warning
- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
update of yesterdays fix
26.01.2016 26.01.2016
- improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169 - improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169

View File

@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.30-dev/20'; const SMARTY_VERSION = '3.1.30-dev/21';
/** /**
* define variable scopes * define variable scopes

View File

@@ -16,14 +16,6 @@
*/ */
class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection
{ {
/**
* Valid properties of $smarty.section.name.xxx variable
*
* @var array
*/
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev',
'index_next', 'loop');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -62,6 +54,14 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*/ */
public $tagName = 'section'; public $tagName = 'section';
/**
* Valid properties of $smarty.section.name.xxx variable
*
* @var array
*/
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum',
'index_prev', 'index_next', 'loop');
/** /**
* {section} tag has no item properties * {section} tag has no item properties
* *
@@ -79,20 +79,19 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
/** /**
* Compiles code for the {section} tag * Compiles code for the {section} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \SmartyCompilerException
*/ */
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting ++; $compiler->loopNesting++;
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$attributes = array('name' => $compiler->getId($_attr[ 'name' ])); $attributes = array('name' => $compiler->getId($_attr['name']));
unset($_attr[ 'name' ]); unset($_attr['name']);
foreach ($attributes as $a => $v) { foreach ($attributes as $a => $v) {
if ($v === false) { if ($v === false) {
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
@@ -104,8 +103,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal = $initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initNamedProperty = array(); $initNamedProperty = array();
$initFor = array(); $initFor = array();
$incFor = array(); $incFor = array();
@@ -117,12 +115,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,); $propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,);
// search for used tag attributes // search for used tag attributes
$this->scanForProperties($attributes, $compiler); $this->scanForProperties($attributes, $compiler);
if (!empty($this->matchResults[ 'named' ])) { if (!empty($this->matchResults['named'])) {
$namedAttr = $this->matchResults[ 'named' ]; $namedAttr = $this->matchResults['named'];
} }
$namedAttr[ 'index' ] = true; $namedAttr['index'] = true;
$v = $t = null; $output = "<?php\n";
$output = '';
foreach ($_attr as $attr_name => $attr_value) { foreach ($_attr as $attr_name => $attr_value) {
switch ($attr_name) { switch ($attr_name) {
case 'loop': case 'loop':
@@ -133,13 +130,13 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))"; $v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))";
$t = 1; $t = 1;
} }
if (isset($namedAttr[ 'loop' ])) { if (isset($namedAttr['loop'])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$v}"; $initNamedProperty['loop'] = "'loop' => {$v}";
if ($t == 1) { if ($t == 1) {
$v = "{$sectionVar}->value['loop']"; $v = "{$sectionVar}->value['loop']";
} }
} elseif ($t == 1) { } elseif ($t == 1) {
$initLocal[ 'loop' ] = $v; $initLocal['loop'] = $v;
$v = "{$local}loop"; $v = "{$local}loop";
} }
break; break;
@@ -159,7 +156,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$t = 0; $t = 0;
break; break;
} }
$initLocal[ 'step' ] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value"; $initLocal['step'] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value";
$v = "{$local}step"; $v = "{$local}step";
$t = 2; $t = 2;
break; break;
@@ -178,171 +175,169 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if ($t == 3 && $compiler->getId($attr_value)) { if ($t == 3 && $compiler->getId($attr_value)) {
$t = 1; $t = 1;
} }
$propValue[ $attr_name ] = $v; $propValue[$attr_name] = $v;
$propType[ $attr_name ] = $t; $propType[$attr_name] = $t;
} }
if (isset($namedAttr[ 'step' ])) { if (isset($namedAttr['step'])) {
$initNamedProperty[ 'step' ] = $propValue[ 'step' ]; $initNamedProperty['step'] = $propValue['step'];
} }
if (isset($namedAttr[ 'iteration' ])) { if (isset($namedAttr['iteration'])) {
$propValue[ 'iteration' ] = "{$sectionVar}->value['iteration']"; $propValue['iteration'] = "{$sectionVar}->value['iteration']";
} }
$incFor[ 'iteration' ] = "{$propValue['iteration']}++"; $incFor['iteration'] = "{$propValue['iteration']}++";
$initFor[ 'iteration' ] = "{$propValue['iteration']} = 1"; $initFor['iteration'] = "{$propValue['iteration']} = 1";
if ($propType[ 'step' ] == 0) { if ($propType['step'] == 0) {
if ($propValue[ 'step' ] == 1) { if ($propValue['step'] == 1) {
$incFor[ 'index' ] = "{$sectionVar}->value['index']++"; $incFor['index'] = "{$sectionVar}->value['index']++";
} elseif ($propValue[ 'step' ] > 1) { } elseif ($propValue['step'] > 1) {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}"; $incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} else { } else {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] -= " . - $propValue[ 'step' ]; $incFor['index'] = "{$sectionVar}->value['index'] -= " . - $propValue['step'];
} }
} else { } else {
$incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}"; $incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} }
if (!isset($propValue[ 'max' ])) { if (!isset($propValue['max'])) {
$propValue[ 'max' ] = $propValue[ 'loop' ]; $propValue['max'] = $propValue['loop'];
$propType[ 'max' ] = $propType[ 'loop' ]; $propType['max'] = $propType['loop'];
} elseif ($propType[ 'max' ] != 0) { } elseif ($propType['max'] != 0) {
$propValue[ 'max' ] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}"; $propValue['max'] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}";
$propType[ 'max' ] = 1; $propType['max'] = 1;
} else { } else {
if ($propValue[ 'max' ] < 0) { if ($propValue['max'] < 0) {
$propValue[ 'max' ] = $propValue[ 'loop' ]; $propValue['max'] = $propValue['loop'];
$propType[ 'max' ] = $propType[ 'loop' ]; $propType['max'] = $propType['loop'];
} }
} }
if (!isset($propValue[ 'start' ])) { if (!isset($propValue['start'])) {
$start_code = $start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'],
array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue[ 'loop' ], 5 => ' - 1'); 5 => ' - 1');
if ($propType[ 'loop' ] == 0) { if ($propType['loop'] == 0) {
$start_code[ 5 ] = ''; $start_code[5] = '';
$start_code[ 4 ] = $propValue[ 'loop' ] - 1; $start_code[4] = $propValue['loop'] - 1;
} }
if ($propType[ 'step' ] == 0) { if ($propType['step'] == 0) {
if ($propValue[ 'step' ] > 0) { if ($propValue['step'] > 0) {
$start_code = array(1 => '0'); $start_code = array(1 => '0');
$propType[ 'start' ] = 0; $propType['start'] = 0;
} else { } else {
$start_code[ 1 ] = $start_code[ 2 ] = $start_code[ 3 ] = ''; $start_code[1] = $start_code[2] = $start_code[3] = '';
$propType[ 'start' ] = $propType[ 'loop' ]; $propType['start'] = $propType['loop'];
} }
} else { } else {
$propType[ 'start' ] = 1; $propType['start'] = 1;
} }
$propValue[ 'start' ] = join('', $start_code); $propValue['start'] = join('', $start_code);
} else { } else {
$start_code = $start_code = array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ",
array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0', 4 => '0', 5 => ' : ', 6 => '-1', 7 => ', ',
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ',
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ', 12 => 'min(', 13 => $propValue['start'], 14 => ', ',
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ', 15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ',
18 => $propType[ 'loop' ] == 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1", 18 => $propType['loop'] == 0 ? $propValue['loop'] - 1 : "{$propValue['loop']} - 1",
19 => ')'); 19 => ')');
if ($propType[ 'step' ] == 0) { if ($propType['step'] == 0) {
$start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = ''; $start_code[3] = $start_code[5] = $start_code[15] = $start_code[17] = '';
if ($propValue[ 'step' ] > 0) { if ($propValue['step'] > 0) {
$start_code[ 6 ] = $start_code[ 18 ] = ''; $start_code[6] = $start_code[18] = '';
} else { } else {
$start_code[ 4 ] = $start_code[ 16 ] = ''; $start_code[4] = $start_code[16] = '';
} }
} }
if ($propType[ 'start' ] == 0) { if ($propType['start'] == 0) {
if ($propType[ 'loop' ] == 0) { if ($propType['loop'] == 0) {
$start_code[ 8 ] = $propValue[ 'start' ] + $propValue[ 'loop' ]; $start_code[8] = $propValue['start'] + $propValue['loop'];
} }
$propType[ 'start' ] = $propType[ 'step' ] + $propType[ 'loop' ]; $propType['start'] = $propType['step'] + $propType['loop'];
$start_code[ 1 ] = ''; $start_code[1] = '';
if ($propValue[ 'start' ] < 0) { if ($propValue['start'] < 0) {
for ($i = 11; $i <= 19; $i ++) { for ($i = 11; $i <= 19; $i ++) {
$start_code[ $i ] = ''; $start_code[$i] = '';
} }
if ($propType[ 'start' ] == 0) { if ($propType['start'] == 0) {
$start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1, $start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] +
$propValue[ 'start' ] + $propValue[ 'loop' ])); $propValue['loop']));
} }
} else { } else {
for ($i = 1; $i <= 11; $i ++) { for ($i = 1; $i <= 11; $i ++) {
$start_code[ $i ] = ''; $start_code[$i] = '';
} }
if ($propType[ 'start' ] == 0) { if ($propType['start'] == 0) {
$start_code = $start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] -
array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1, 1, $propValue['start']));
$propValue[ 'start' ]));
} }
} }
} }
$propValue[ 'start' ] = join('', $start_code); $propValue['start'] = join('', $start_code);
} }
if ($propType[ 'start' ] != 0) { if ($propType['start'] != 0) {
$initLocal[ 'start' ] = $propValue[ 'start' ]; $initLocal['start'] = $propValue['start'];
$propValue[ 'start' ] = "{$local}start"; $propValue['start'] = "{$local}start";
} }
$initFor[ 'index' ] = "{$sectionVar}->value['index'] = {$propValue['start']}"; $initFor['index'] = "{$sectionVar}->value['index'] = {$propValue['start']}";
if (!isset($_attr[ 'start' ]) && !isset($_attr[ 'step' ]) && !isset($_attr[ 'max' ])) { if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) {
$propValue[ 'total' ] = $propValue[ 'loop' ]; $propValue['total'] = $propValue['loop'];
$propType[ 'total' ] = $propType[ 'loop' ]; $propType['total'] = $propType['loop'];
} else { } else {
$propType[ 'total' ] = $propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max'];
$propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ]; if ($propType['total'] == 0) {
if ($propType[ 'total' ] == 0) { $propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] -
$propValue[ 'total' ] = $propValue['start'] : (int) $propValue['start'] + 1) /
min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] : abs($propValue['step'])), $propValue['max']);
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]);
} else { } else {
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ", $total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ', 5 => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ',
9 => $propValue[ 'start' ], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(', 9 => $propValue['start'], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
14 => $propValue[ 'step' ], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",); 14 => $propValue['step'], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",);
if (!isset($propValue[ 'max' ])) { if (!isset($propValue['max'])) {
$total_code[ 1 ] = $total_code[ 17 ] = ''; $total_code[1] = $total_code[17] = '';
} }
if ($propType[ 'loop' ] + $propType[ 'start' ] == 0) { if ($propType['loop'] + $propType['start'] == 0) {
$total_code[ 5 ] = $propValue[ 'loop' ] - $propValue[ 'start' ]; $total_code[5] = $propValue['loop'] - $propValue['start'];
$total_code[ 6 ] = $total_code[ 7 ] = ''; $total_code[6] = $total_code[7] = '';
} }
if ($propType[ 'start' ] == 0) { if ($propType['start'] == 0) {
$total_code[ 9 ] = (int) $propValue[ 'start' ] + 1; $total_code[9] = (int) $propValue['start'] + 1;
$total_code[ 10 ] = ''; $total_code[10] = '';
} }
if ($propType[ 'step' ] == 0) { if ($propType['step'] == 0) {
$total_code[ 13 ] = $total_code[ 15 ] = ''; $total_code[13] = $total_code[15] = '';
if ($propValue[ 'step' ] == 1 || $propValue[ 'step' ] == - 1) { if ($propValue['step'] == 1 || $propValue['step'] == - 1) {
$total_code[ 2 ] = $total_code[ 12 ] = $total_code[ 14 ] = $total_code[ 16 ] = ''; $total_code[2] = $total_code[12] = $total_code[14] = $total_code[16] = '';
} elseif ($propValue[ 'step' ] < 0) { } elseif ($propValue['step'] < 0) {
$total_code[ 14 ] = - $propValue[ 'step' ]; $total_code[14] = - $propValue['step'];
} }
$total_code[ 4 ] = ''; $total_code[4] = '';
if ($propValue[ 'step' ] > 0) { if ($propValue['step'] > 0) {
$total_code[ 8 ] = $total_code[ 9 ] = $total_code[ 10 ] = ''; $total_code[8] = $total_code[9] = $total_code[10] = '';
} else { } else {
$total_code[ 5 ] = $total_code[ 6 ] = $total_code[ 7 ] = $total_code[ 8 ] = ''; $total_code[5] = $total_code[6] = $total_code[7] = $total_code[8] = '';
} }
} }
$propValue[ 'total' ] = join('', $total_code); $propValue['total'] = join('', $total_code);
} }
} }
if (isset($namedAttr[ 'total' ])) { if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}"; $initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}";
} }
if (isset($namedAttr[ 'total' ])) { if (isset($namedAttr['total'])) {
$initNamedProperty[ 'total' ] = "'total' => {$propValue['total']}"; $initNamedProperty['total'] = "'total' => {$propValue['total']}";
if ($propType[ 'total' ] > 0) { if ($propType['total'] > 0) {
$propValue[ 'total' ] = "{$sectionVar}->value['total']"; $propValue['total'] = "{$sectionVar}->value['total']";
} }
} elseif ($propType[ 'total' ] > 0) { } elseif ($propType['total'] > 0) {
$initLocal[ 'total' ] = $propValue[ 'total' ]; $initLocal['total'] = $propValue['total'];
$propValue[ 'total' ] = "{$local}total"; $propValue['total'] = "{$local}total";
} }
$cmpFor[ 'iteration' ] = "{$propValue['iteration']} <= {$propValue['total']}"; $cmpFor['iteration'] = "{$propValue['iteration']} <= {$propValue['total']}";
foreach ($initLocal as $key => $code) { foreach ($initLocal as $key => $code) {
$output .= "{$local}{$key} = {$code};\n"; $output .= "{$local}{$key} = {$code};\n";
@@ -351,17 +346,17 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$_vars = 'array(' . join(', ', $initNamedProperty) . ')'; $_vars = 'array(' . join(', ', $initNamedProperty) . ')';
$output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n"; $output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n";
$cond_code = "{$propValue['total']} != 0"; $cond_code = "{$propValue['total']} != 0";
if ($propType[ 'total' ] == 0) { if ($propType['total'] == 0) {
if ($propValue[ 'total' ] == 0) { if ($propValue['total'] == 0) {
$cond_code = 'false'; $cond_code = 'false';
} else { } else {
$cond_code = 'true'; $cond_code = 'true';
} }
} }
if ($propType[ 'show' ] > 0) { if ($propType['show'] > 0) {
$output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n"; $output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n";
$output .= "if ({$local}show) {\n"; $output .= "if ({$local}show) {\n";
} elseif ($propValue[ 'show' ] == 'true') { } elseif ($propValue['show'] == 'true') {
$output .= "if ({$cond_code}) {\n"; $output .= "if ({$cond_code}) {\n";
} else { } else {
$output .= "if (false) {\n"; $output .= "if (false) {\n";
@@ -370,21 +365,23 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$jcmp = join(', ', $cmpFor); $jcmp = join(', ', $cmpFor);
$jinc = join(', ', $incFor); $jinc = join(', ', $incFor);
$output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n"; $output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n";
if (isset($namedAttr[ 'rownum' ])) { if (isset($namedAttr['rownum'])) {
$output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n"; $output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n";
} }
if (isset($namedAttr[ 'index_prev' ])) { if (isset($namedAttr['index_prev'])) {
$output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n"; $output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n";
} }
if (isset($namedAttr[ 'index_next' ])) { if (isset($namedAttr['index_next'])) {
$output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n"; $output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n";
} }
if (isset($namedAttr[ 'first' ])) { if (isset($namedAttr['first'])) {
$output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n"; $output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n";
} }
if (isset($namedAttr[ 'last' ])) { if (isset($namedAttr['last'])) {
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n"; $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
} }
$output .= "?>";
return $output; return $output;
} }
} }
@@ -400,13 +397,12 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {sectionelse} tag * Compiles code for the {sectionelse} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -414,7 +410,7 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section')); list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section'));
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar)); $this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar));
return "}\n} else {\n"; return "<?php }} else {\n ?>";
} }
} }
@@ -429,24 +425,23 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {/section} tag * Compiles code for the {/section} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting --; $compiler->loopNesting--;
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($openTag, $compiler->nocache, $local, $sectionVar) = list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section',
$this->closeTag($compiler, array('section', 'sectionelse')); 'sectionelse'));
$output = ''; $output = "<?php\n";
if ($openTag == 'sectionelse') { if ($openTag == 'sectionelse') {
$output .= "}\n"; $output .= "}\n";
} else { } else {
@@ -455,6 +450,8 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
$output .= "if ({$local}saved) {\n"; $output .= "if ({$local}saved) {\n";
$output .= "{$sectionVar} = {$local}saved;\n"; $output .= "{$sectionVar} = {$local}saved;\n";
$output .= "}\n"; $output .= "}\n";
$output .= "?>";
return $output; return $output;
} }
} }