mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
26.01.2016
|
||||
- improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169
|
||||
- bugfix compiling {section} did create warning
|
||||
- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
|
||||
|
||||
02.01.2016
|
||||
- update scope handling
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/18';
|
||||
const SMARTY_VERSION = '3.1.30-dev/19';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -16,6 +16,14 @@
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -54,14 +62,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
*/
|
||||
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');
|
||||
|
||||
/**
|
||||
* {section} tag has no item properties
|
||||
*
|
||||
@@ -80,12 +80,13 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
* Compiles code for the {section} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param null $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
|
||||
{
|
||||
$compiler->loopNesting ++;
|
||||
// check and get attributes
|
||||
@@ -103,7 +104,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
$initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
|
||||
$initLocal =
|
||||
array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
|
||||
$initNamedProperty = array();
|
||||
$initFor = array();
|
||||
$incFor = array();
|
||||
@@ -119,7 +121,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$namedAttr = $this->matchResults[ 'named' ];
|
||||
}
|
||||
$namedAttr[ 'index' ] = true;
|
||||
$output = "<?php\n";
|
||||
$v = $t = null;
|
||||
$output = '';
|
||||
foreach ($_attr as $attr_name => $attr_value) {
|
||||
switch ($attr_name) {
|
||||
case 'loop':
|
||||
@@ -214,8 +217,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
}
|
||||
|
||||
if (!isset($propValue[ 'start' ])) {
|
||||
$start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'],
|
||||
5 => ' - 1');
|
||||
$start_code =
|
||||
array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue[ 'loop' ], 5 => ' - 1');
|
||||
if ($propType[ 'loop' ] == 0) {
|
||||
$start_code[ 5 ] = '';
|
||||
$start_code[ 4 ] = $propValue[ 'loop' ] - 1;
|
||||
@@ -233,10 +236,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
}
|
||||
$propValue[ 'start' ] = join('', $start_code);
|
||||
} else {
|
||||
$start_code = array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ",
|
||||
4 => '0', 5 => ' : ', 6 => '-1', 7 => ', ',
|
||||
8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ',
|
||||
12 => 'min(', 13 => $propValue['start'], 14 => ', ',
|
||||
$start_code =
|
||||
array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0',
|
||||
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')',
|
||||
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ',
|
||||
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue[ 'loop' ], 17 => ' : ',
|
||||
18 => $propType[ 'loop' ] == 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1",
|
||||
19 => ')');
|
||||
@@ -259,16 +262,17 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$start_code[ $i ] = '';
|
||||
}
|
||||
if ($propType[ 'start' ] == 0) {
|
||||
$start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] +
|
||||
$propValue['loop']));
|
||||
$start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1,
|
||||
$propValue[ 'start' ] + $propValue[ 'loop' ]));
|
||||
}
|
||||
} else {
|
||||
for ($i = 1; $i <= 11; $i ++) {
|
||||
$start_code[ $i ] = '';
|
||||
}
|
||||
if ($propType[ 'start' ] == 0) {
|
||||
$start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] -
|
||||
1, $propValue['start']));
|
||||
$start_code =
|
||||
array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1,
|
||||
$propValue[ 'start' ]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,11 +289,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
$propValue[ 'total' ] = $propValue[ 'loop' ];
|
||||
$propType[ 'total' ] = $propType[ 'loop' ];
|
||||
} else {
|
||||
$propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max'];
|
||||
$propType[ 'total' ] =
|
||||
$propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ];
|
||||
if ($propType[ 'total' ] == 0) {
|
||||
$propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] -
|
||||
$propValue['start'] : (int) $propValue['start'] + 1) /
|
||||
abs($propValue['step'])), $propValue['max']);
|
||||
$propValue[ 'total' ] =
|
||||
min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] :
|
||||
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]);
|
||||
} else {
|
||||
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
|
||||
5 => $propValue[ 'loop' ], 6 => ' - ', 7 => $propValue[ 'start' ], 8 => ' : ',
|
||||
@@ -324,6 +329,9 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($namedAttr[ 'total' ])) {
|
||||
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}";
|
||||
}
|
||||
if (isset($namedAttr[ 'total' ])) {
|
||||
$initNamedProperty[ 'total' ] = "'total' => {$propValue['total']}";
|
||||
if ($propType[ 'total' ] > 0) {
|
||||
@@ -377,8 +385,6 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
if (isset($namedAttr[ 'last' ])) {
|
||||
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
|
||||
}
|
||||
$output .= "?>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -395,11 +401,12 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {sectionelse} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param null $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@@ -407,7 +414,7 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
|
||||
list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section'));
|
||||
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar));
|
||||
|
||||
return "<?php }} else {\n ?>";
|
||||
return "}\n} else {\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,11 +430,12 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {/section} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param null $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
|
||||
{
|
||||
$compiler->loopNesting --;
|
||||
// must endblock be nocache?
|
||||
@@ -435,10 +443,10 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section',
|
||||
'sectionelse'));
|
||||
list($openTag, $compiler->nocache, $local, $sectionVar) =
|
||||
$this->closeTag($compiler, array('section', 'sectionelse'));
|
||||
|
||||
$output = "<?php\n";
|
||||
$output = '';
|
||||
if ($openTag == 'sectionelse') {
|
||||
$output .= "}\n";
|
||||
} else {
|
||||
@@ -447,8 +455,6 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
|
||||
$output .= "if ({$local}saved) {\n";
|
||||
$output .= "{$sectionVar} = {$local}saved;\n";
|
||||
$output .= "}\n";
|
||||
$output .= "?>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user