diff options
Diffstat (limited to 'vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_section.php')
-rw-r--r-- | vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_section.php | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_section.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_section.php index c3701fc63..6e80e0fde 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_section.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_section.php @@ -84,6 +84,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo * * @return string compiled code * @throws \SmartyCompilerException + * @throws \SmartyException */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) { @@ -103,8 +104,7 @@ 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(); $initNamedProperty = array(); $initFor = array(); $incFor = array(); @@ -140,12 +140,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))"; $t = 1; } - if (isset($namedAttr[ 'loop' ])) { - $initNamedProperty[ 'loop' ] = "'loop' => {$v}"; - if ($t == 1) { - $v = "{$sectionVar}->value['loop']"; - } - } elseif ($t == 1) { + if ($t === 1) { $initLocal[ 'loop' ] = $v; $v = "{$local}loop"; } @@ -162,11 +157,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo case 'step': if (is_numeric($attr_value)) { $v = (int) $attr_value; - $v = ($v == 0) ? 1 : $v; + $v = ($v === 0) ? 1 : $v; $t = 0; break; } - $initLocal[ 'step' ] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value"; + $initLocal[ 'step' ] = "((int)@$attr_value) === 0 ? 1 : (int)@$attr_value"; $v = "{$local}step"; $t = 2; break; @@ -182,7 +177,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $t = 3; break; } - if ($t == 3 && $compiler->getId($attr_value)) { + if ($t === 3 && $compiler->getId($attr_value)) { $t = 1; } $propValue[ $attr_name ] = $v; @@ -198,8 +193,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $incFor[ 'iteration' ] = "{$propValue['iteration']}++"; $initFor[ 'iteration' ] = "{$propValue['iteration']} = 1"; - if ($propType[ 'step' ] == 0) { - if ($propValue[ 'step' ] == 1) { + if ($propType[ 'step' ] === 0) { + if ($propValue[ 'step' ] === 1) { $incFor[ 'index' ] = "{$sectionVar}->value['index']++"; } elseif ($propValue[ 'step' ] > 1) { $incFor[ 'index' ] = "{$sectionVar}->value['index'] += {$propValue['step']}"; @@ -213,7 +208,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo if (!isset($propValue[ 'max' ])) { $propValue[ 'max' ] = $propValue[ 'loop' ]; $propType[ 'max' ] = $propType[ 'loop' ]; - } elseif ($propType[ 'max' ] != 0) { + } elseif ($propType[ 'max' ] !== 0) { $propValue[ 'max' ] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}"; $propType[ 'max' ] = 1; } else { @@ -226,11 +221,11 @@ 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'); - if ($propType[ 'loop' ] == 0) { + if ($propType[ 'loop' ] === 0) { $start_code[ 5 ] = ''; $start_code[ 4 ] = $propValue[ 'loop' ] - 1; } - if ($propType[ 'step' ] == 0) { + if ($propType[ 'step' ] === 0) { if ($propValue[ 'step' ] > 0) { $start_code = array(1 => '0'); $propType[ 'start' ] = 0; @@ -248,9 +243,9 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo 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", + 18 => $propType[ 'loop' ] === 0 ? $propValue[ 'loop' ] - 1 : "{$propValue['loop']} - 1", 19 => ')'); - if ($propType[ 'step' ] == 0) { + if ($propType[ 'step' ] === 0) { $start_code[ 3 ] = $start_code[ 5 ] = $start_code[ 15 ] = $start_code[ 17 ] = ''; if ($propValue[ 'step' ] > 0) { $start_code[ 6 ] = $start_code[ 18 ] = ''; @@ -258,8 +253,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $start_code[ 4 ] = $start_code[ 16 ] = ''; } } - if ($propType[ 'start' ] == 0) { - if ($propType[ 'loop' ] == 0) { + if ($propType[ 'start' ] === 0) { + if ($propType[ 'loop' ] === 0) { $start_code[ 8 ] = $propValue[ 'start' ] + $propValue[ 'loop' ]; } $propType[ 'start' ] = $propType[ 'step' ] + $propType[ 'loop' ]; @@ -268,7 +263,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo for ($i = 11; $i <= 19; $i ++) { $start_code[ $i ] = ''; } - if ($propType[ 'start' ] == 0) { + if ($propType[ 'start' ] === 0) { $start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1, $propValue[ 'start' ] + $propValue[ 'loop' ])); } @@ -276,7 +271,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo for ($i = 1; $i <= 11; $i ++) { $start_code[ $i ] = ''; } - if ($propType[ 'start' ] == 0) { + if ($propType[ 'start' ] === 0) { $start_code = array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1, $propValue[ 'start' ])); @@ -285,7 +280,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo } $propValue[ 'start' ] = join('', $start_code); } - if ($propType[ 'start' ] != 0) { + if ($propType[ 'start' ] !== 0) { $initLocal[ 'start' ] = $propValue[ 'start' ]; $propValue[ 'start' ] = "{$local}start"; } @@ -298,7 +293,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo } else { $propType[ 'total' ] = $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[ 'start' ] : (int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]); @@ -310,17 +305,17 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo if (!isset($propValue[ 'max' ])) { $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[ 6 ] = $total_code[ 7 ] = ''; } - if ($propType[ 'start' ] == 0) { + if ($propType[ 'start' ] === 0) { $total_code[ 9 ] = (int) $propValue[ 'start' ] + 1; $total_code[ 10 ] = ''; } - if ($propType[ 'step' ] == 0) { + if ($propType[ 'step' ] === 0) { $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 ] = ''; } elseif ($propValue[ 'step' ] < 0) { $total_code[ 14 ] = - $propValue[ 'step' ]; @@ -337,7 +332,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo } if (isset($namedAttr[ 'loop' ])) { - $initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}"; + $initNamedProperty[ 'loop' ] = "'loop' => {$propValue['loop']}"; } if (isset($namedAttr[ 'total' ])) { $initNamedProperty[ 'total' ] = "'total' => {$propValue['total']}"; @@ -357,9 +352,9 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $_vars = 'array(' . join(', ', $initNamedProperty) . ')'; $output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n"; - $cond_code = "{$propValue['total']} != 0"; - if ($propType[ 'total' ] == 0) { - if ($propValue[ 'total' ] == 0) { + $cond_code = "{$propValue['total']} !== 0"; + if ($propType[ 'total' ] === 0) { + if ($propValue[ 'total' ] === 0) { $cond_code = 'false'; } else { $cond_code = 'true'; @@ -368,7 +363,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo if ($propType[ 'show' ] > 0) { $output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n"; $output .= "if ({$local}show) {\n"; - } elseif ($propValue[ 'show' ] == 'true') { + } elseif ($propValue[ 'show' ] === 'true') { $output .= "if ({$cond_code}) {\n"; } else { $output .= "if (false) {\n"; @@ -387,12 +382,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo $output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n"; } if (isset($namedAttr[ 'first' ])) { - $output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n"; + $output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} === 1);\n"; } if (isset($namedAttr[ 'last' ])) { - $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n"; + $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} === {$propValue['total']});\n"; } - $output .= "?>"; + $output .= '?>'; return $output; } @@ -454,15 +449,12 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase $this->closeTag($compiler, array('section', 'sectionelse')); $output = "<?php\n"; - if ($openTag == 'sectionelse') { + if ($openTag === 'sectionelse') { $output .= "}\n"; } else { $output .= "}\n}\n"; } - $output .= "if ({$local}saved) {\n"; - $output .= "{$sectionVar} = {$local}saved;\n"; - $output .= "}\n"; - $output .= "?>"; + $output .= '?>'; return $output; } |