| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Foreach | 
					
						
							|  |  |  |  * Compiles the {foreach} {foreachelse} {/foreach} tags | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Foreach Class | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $required_attributes = array('from', 'item'); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $optional_attributes = array('name', 'key'); | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     public $shorttag_order = array('from', 'item', 'key', 'name'); | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * Compiles code for the {foreach} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  array  $args      array with attributes from parser | 
					
						
							|  |  |  |      * @param  object $compiler  compiler object | 
					
						
							|  |  |  |      * @param  array  $parameter array with compilation parameter | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public function compile($args, $compiler, $parameter) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $from = $_attr['from']; | 
					
						
							|  |  |  |         $item = $_attr['item']; | 
					
						
							| 
									
										
										
										
											2011-10-01 18:47:56 +00:00
										 |  |  |         if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             $compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-06 20:00:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if (isset($_attr['key'])) { | 
					
						
							|  |  |  |             $key = $_attr['key']; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $key = null; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $this->openTag($compiler, 'foreach', array('foreach', $compiler->nocache, $item, $key, true)); | 
					
						
							| 
									
										
										
										
											2010-05-10 20:08:24 +00:00
										 |  |  |         // maybe nocache because of nocache variables
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | 
					
						
							| 
									
										
										
										
											2010-05-10 20:08:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if (isset($_attr['name'])) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $name = trim($_attr['name'], '\'"'); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             $has_name = true; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $SmartyVarName = "\$smarty.foreach.{$name}."; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $has_name = false; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         $ItemVarName = '$' . trim($item, '\'"') . '@'; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         // evaluates which Smarty variables and properties have to be computed
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($has_name) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $useSmartyForeach = $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false; | 
					
						
							|  |  |  |             $useSmartyForeach = ($usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false) || $useSmartyForeach; | 
					
						
							|  |  |  |             $useSmartyForeach = ($usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false) || $useSmartyForeach; | 
					
						
							|  |  |  |             $useSmartyForeach = ($usesSmartyIteration = (!$usesSmartyIndex && ($usesSmartyFirst || $usesSmartyLast)) || strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false) || $useSmartyForeach; | 
					
						
							|  |  |  |             $useSmartyForeach = ($usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false) || $useSmartyForeach; | 
					
						
							|  |  |  |             $useSmartyForeach = ($usesSmartyTotal = $usesSmartyLast ||strpos($compiler->lex->data, $SmartyVarName . 'total') !== false) || $useSmartyForeach; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $usesSmartyFirst = false; | 
					
						
							|  |  |  |             $usesSmartyLast = false; | 
					
						
							|  |  |  |             $usesSmartyTotal = false; | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             $usesSmartyShow = false; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $useSmartyForeach = false; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $usesPropKey = strpos($compiler->lex->data, $ItemVarName . 'key') !== false; | 
					
						
							|  |  |  |         $usesPropFirst = strpos($compiler->lex->data, $ItemVarName . 'first') !== false; | 
					
						
							|  |  |  |         $usesPropLast =  strpos($compiler->lex->data, $ItemVarName . 'last') !== false; | 
					
						
							|  |  |  |         $usesPropIndex =  strpos($compiler->lex->data, $ItemVarName . 'index') !== false; | 
					
						
							|  |  |  |         $usesPropIteration = (!$usesPropIndex && ($usesPropFirst || $usesPropLast)) || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false; | 
					
						
							| 
									
										
										
										
											2014-03-24 18:52:29 +00:00
										 |  |  |         $usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $usesPropTotal = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $keyTerm = ''; | 
					
						
							|  |  |  |         if ($usesPropKey) { | 
					
						
							|  |  |  |             $keyTerm = "\$_smarty_tpl->tpl_vars[$item]->key => "; | 
					
						
							|  |  |  |         } elseif ($key != null) { | 
					
						
							|  |  |  |             $keyTerm = "\$_smarty_tpl->tpl_vars[$key]->value => "; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         // generate output code
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output = "<?php\n"; | 
					
						
							|  |  |  |         $output .= "\$_from = $from;\n"; | 
					
						
							|  |  |  |         $output .= "if (!is_array(\$_from) && !is_object(\$_from)) {\n"; | 
					
						
							|  |  |  |         $output .= "settype(\$_from, 'array');\n"; | 
					
						
							|  |  |  |         $output .= "}\n"; | 
					
						
							|  |  |  |         $output .= "\$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n"; | 
					
						
							|  |  |  |         $output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = false;\n"; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($key != null) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropTotal) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$item]->total= \$_smarty_tpl->_count(\$_from);\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropIteration) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$item]->iteration=0;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropIndex) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$item]->index=-1;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |         if ($usesPropShow) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             if ($usesPropTotal) { | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->tpl_vars[$item]->total > 0);\n"; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->_count(\$_from) > 0);\n"; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($has_name) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $prop = array(); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             if ($usesSmartyTotal) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 $prop['total'] = "'total' => "; | 
					
						
							|  |  |  |                 $prop['total'] .= $usesSmartyShow ? '$total = ' : ''; | 
					
						
							|  |  |  |                 $prop['total'] .= '$_smarty_tpl->_count($_from)'; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             if ($usesSmartyIteration) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 $prop['iteration'] = "'iteration' => 0"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             if ($usesSmartyIndex) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 $prop['index'] = "'index' => -1"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             if ($usesSmartyShow) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 $prop['show'] = "'show' => "; | 
					
						
							|  |  |  |                 if ($usesSmartyTotal) { | 
					
						
							|  |  |  |                     $prop['show'] .= "(\$total > 0)"; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $prop['show'] .= "(\$_smarty_tpl->_count(\$_from) > 0)"; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($useSmartyForeach) { | 
					
						
							|  |  |  |                 $_vars = 'array(' . join(', ', $prop) . ')'; | 
					
						
							|  |  |  |                 $foreachVar = "'__foreach_{$name}'"; | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar] = new Smarty_Variable({$_vars});\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output .= "foreach (\$_from as {$keyTerm}\$_smarty_tpl->tpl_vars[$item]->value) {\n"; | 
					
						
							|  |  |  |         $output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n"; | 
					
						
							|  |  |  |         if ($key != null && $usesPropKey) { | 
					
						
							|  |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropIteration) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$item]->iteration++;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropIndex) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$item]->index++;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropFirst) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             if ($usesPropIndex) { | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index == 0;\n"; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->iteration == 1;\n"; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($usesPropLast) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             if ($usesPropIndex) { | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->index + 1 == \$_smarty_tpl->tpl_vars[$item]->total;\n"; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration == \$_smarty_tpl->tpl_vars[$item]->total;\n"; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         if ($has_name) { | 
					
						
							|  |  |  |             if ($usesSmartyIteration) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration']++;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             if ($usesSmartyIndex) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['index']++;\n"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($usesSmartyFirst) { | 
					
						
							|  |  |  |                 if ($usesSmartyIndex) { | 
					
						
							|  |  |  |                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index'] == 0;\n"; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration'] == 1;\n"; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |             if ($usesSmartyLast) { | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |                 if ($usesSmartyIndex) { | 
					
						
							|  |  |  |                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index'] + 1 == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total'];\n"; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration'] == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total'];\n"; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-13 00:33:23 +02:00
										 |  |  |         $itemName = trim($item,"'\""); | 
					
						
							|  |  |  |         $output .= "\$foreach_{$itemName}_Sav = \$_smarty_tpl->tpl_vars[$item];\n"; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         $output .= "?>"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Foreachelse Class | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * Compiles code for the {foreachelse} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  array  $args      array with attributes from parser | 
					
						
							|  |  |  |      * @param  object $compiler  compiler object | 
					
						
							|  |  |  |      * @param  array  $parameter array with compilation parameter | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public function compile($args, $compiler, $parameter) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         list($openTag, $nocache, $item, $key, $foo) = $this->closeTag($compiler, array('foreach')); | 
					
						
							|  |  |  |         $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $item, $key, false)); | 
					
						
							| 
									
										
										
										
											2015-05-13 00:33:23 +02:00
										 |  |  |         $itemName = trim($item,"'\""); | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output = "<?php\n"; | 
					
						
							| 
									
										
										
										
											2015-05-13 00:33:23 +02:00
										 |  |  |         $output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n"; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output .= "}\n"; | 
					
						
							|  |  |  |         $output .= "if (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>"; | 
					
						
							|  |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Foreachclose Class | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * Compiles code for the {/foreach} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @param  array  $args      array with attributes from parser | 
					
						
							|  |  |  |      * @param  object $compiler  compiler object | 
					
						
							|  |  |  |      * @param  array  $parameter array with compilation parameter | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public function compile($args, $compiler, $parameter) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |         // must endblock be nocache?
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         if ($compiler->nocache) { | 
					
						
							|  |  |  |             $compiler->tag_nocache = true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         list($openTag, $compiler->nocache, $item, $key, $restore) = $this->closeTag($compiler, array('foreach', 'foreachelse')); | 
					
						
							| 
									
										
										
										
											2015-05-13 00:33:23 +02:00
										 |  |  |         $itemName = trim($item,"'\""); | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output = "<?php\n"; | 
					
						
							|  |  |  |         if ($restore) { | 
					
						
							| 
									
										
										
										
											2015-05-13 00:33:23 +02:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n"; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         $output .= "}\n?>"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |