diff options
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_internal_compile_foreach.php')
-rw-r--r-- | library/Smarty/libs/sysplugins/smarty_internal_compile_foreach.php | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_internal_compile_foreach.php b/library/Smarty/libs/sysplugins/smarty_internal_compile_foreach.php index 1354c89d5..fc77f5749 100644 --- a/library/Smarty/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/library/Smarty/libs/sysplugins/smarty_internal_compile_foreach.php @@ -1,21 +1,21 @@ <?php /** * Smarty Internal Plugin Compile Foreach - * * Compiles the {foreach} {foreachelse} {/foreach} tags * - * @package Smarty + * @package Smarty * @subpackage Compiler - * @author Uwe Tews + * @author Uwe Tews */ /** * Smarty Internal Plugin Compile Foreach Class * - * @package Smarty + * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { +class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase +{ /** * Attribute definition: Overwrites base class. * @@ -36,19 +36,19 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { * @var array * @see Smarty_Internal_CompileBase */ - public $shorttag_order = array('from','item','key','name'); + public $shorttag_order = array('from', 'item', 'key', 'name'); /** * Compiles code for the {foreach} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * * @return string compiled code */ public function compile($args, $compiler, $parameter) { - $tpl = $compiler->template; // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -79,12 +79,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { $ItemVarName = '$' . trim($item, '\'"') . '@'; // evaluates which Smarty variables and properties have to be computed if ($has_name) { - $usesSmartyFirst = strpos($tpl->source->content, $SmartyVarName . 'first') !== false; - $usesSmartyLast = strpos($tpl->source->content, $SmartyVarName . 'last') !== false; - $usesSmartyIndex = strpos($tpl->source->content, $SmartyVarName . 'index') !== false; - $usesSmartyIteration = strpos($tpl->source->content, $SmartyVarName . 'iteration') !== false; - $usesSmartyShow = strpos($tpl->source->content, $SmartyVarName . 'show') !== false; - $usesSmartyTotal = strpos($tpl->source->content, $SmartyVarName . 'total') !== false; + $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false; + $usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false; + $usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false; + $usesSmartyIteration = strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false; + $usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false; + $usesSmartyTotal = strpos($compiler->lex->data, $SmartyVarName . 'total') !== false; } else { $usesSmartyFirst = false; $usesSmartyLast = false; @@ -92,12 +92,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { $usesSmartyShow = false; } - $usesPropFirst = $usesSmartyFirst || strpos($tpl->source->content, $ItemVarName . 'first') !== false; - $usesPropLast = $usesSmartyLast || strpos($tpl->source->content, $ItemVarName . 'last') !== false; - $usesPropIndex = $usesPropFirst || strpos($tpl->source->content, $ItemVarName . 'index') !== false; - $usesPropIteration = $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'iteration') !== false; - $usesPropShow = strpos($tpl->source->content, $ItemVarName . 'show') !== false; - $usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'total') !== false; + $usesPropFirst = $usesSmartyFirst || strpos($compiler->lex->data, $ItemVarName . 'first') !== false; + $usesPropLast = $usesSmartyLast || strpos($compiler->lex->data, $ItemVarName . 'last') !== false; + $usesPropIndex = $usesPropFirst || strpos($compiler->lex->data, $ItemVarName . 'index') !== false; + $usesPropIteration = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false; + $usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false; + $usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false; // generate output code $output = "<?php "; $output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable; \$_smarty_tpl->tpl_vars[$item]->_loop = false;\n"; @@ -131,7 +131,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { $output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['show']=(\$_smarty_tpl->tpl_vars[$item]->total > 0);\n"; } } - $output .= "foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value){\n\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n"; + $output .= "foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value) {\n\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n"; if ($key != null) { $output .= " \$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n"; } @@ -170,17 +170,18 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { /** * Smarty Internal Plugin Compile Foreachelse Class * - * @package Smarty + * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase { - +class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase +{ /** * Compiles code for the {foreachelse} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * * @return string compiled code */ public function compile($args, $compiler, $parameter) @@ -193,23 +194,23 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase { return "<?php }\nif (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>"; } - } /** * Smarty Internal Plugin Compile Foreachclose Class * - * @package Smarty + * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase { - +class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase +{ /** * Compiles code for the {/foreach} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * * @return string compiled code */ public function compile($args, $compiler, $parameter) @@ -225,7 +226,4 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase { return "<?php } ?>"; } - } - -?>
\ No newline at end of file |