| 
									
										
										
										
											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
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  | class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_ForeachSection | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											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'); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-20 21:45:21 +01:00
										 |  |  |     public $optional_attributes = array('name', 'key', 'properties'); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  |      * counter | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  |     public $counter = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Name of this tag | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $tagName = 'foreach'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Valid properties of $smarty.foreach.name.xxx variable | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-12-19 21:55:32 +01:00
										 |  |  |     public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total'); | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Valid properties of $item@xxx variable | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |     public $itemProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'key'); | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Flag if tag had name attribute | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $isNamed = false; | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02: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
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                                 $args     array with attributes from parser | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |      * @throws \SmartyCompilerException | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @throws \SmartyException | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         $compiler->loopNesting++; | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  |         // init
 | 
					
						
							|  |  |  |         $this->isNamed = false; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         $from = $_attr[ 'from' ]; | 
					
						
							|  |  |  |         $item = $compiler->getId($_attr[ 'item' ]); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         if ($item === false) { | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             $item = $compiler->getVariableName($_attr[ 'item' ]); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         $key = $name = null; | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         $attributes = array('item' => $item); | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($_attr[ 'key' ])) { | 
					
						
							|  |  |  |             $key = $compiler->getId($_attr[ 'key' ]); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |             if ($key === false) { | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |                 $key = $compiler->getVariableName($_attr[ 'key' ]); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             $attributes[ 'key' ] = $key; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($_attr[ 'name' ])) { | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  |             $this->isNamed = true; | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             $name = $attributes[ 'name' ] = $compiler->getId($_attr[ 'name' ]); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         foreach ($attributes as $a => $v) { | 
					
						
							|  |  |  |             if ($v === false) { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |                 $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         $fromName = $compiler->getVariableName($_attr[ 'from' ]); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         if ($fromName) { | 
					
						
							|  |  |  |             foreach (array('item', 'key') as $a) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                 if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) { | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                     $compiler->trigger_template_error( | 
					
						
							|  |  |  |                         "'{$a}' and 'from' may not have same variable name '{$fromName}'", | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                         null, | 
					
						
							|  |  |  |                         true | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         $itemVar = "\$_smarty_tpl->tpl_vars['{$item}']"; | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         $local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter++ . '_'; | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  |         // search for used tag attributes
 | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         $itemAttr = array(); | 
					
						
							| 
									
										
										
										
											2015-07-31 01:03:29 +02:00
										 |  |  |         $namedAttr = array(); | 
					
						
							|  |  |  |         $this->scanForProperties($attributes, $compiler); | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (!empty($this->matchResults[ 'item' ])) { | 
					
						
							|  |  |  |             $itemAttr = $this->matchResults[ 'item' ]; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (!empty($this->matchResults[ 'named' ])) { | 
					
						
							|  |  |  |             $namedAttr = $this->matchResults[ 'named' ]; | 
					
						
							| 
									
										
										
										
											2015-07-01 13:01:16 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if (isset($_attr[ 'properties' ]) && preg_match_all('/[\'](.*?)[\']/', $_attr[ 'properties' ], $match)) { | 
					
						
							| 
									
										
										
										
											2016-02-20 21:45:21 +01:00
										 |  |  |             foreach ($match[ 1 ] as $prop) { | 
					
						
							|  |  |  |                 if (in_array($prop, $this->itemProperties)) { | 
					
						
							|  |  |  |                     $itemAttr[ $prop ] = true; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($this->isNamed) { | 
					
						
							|  |  |  |                 foreach ($match[ 1 ] as $prop) { | 
					
						
							|  |  |  |                     if (in_array($prop, $this->nameProperties)) { | 
					
						
							|  |  |  |                         $nameAttr[ $prop ] = true; | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         $compiler->trigger_template_error("Invalid property '{$prop}'", null, true); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'first' ])) { | 
					
						
							|  |  |  |             $itemAttr[ 'index' ] = true; | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($namedAttr[ 'first' ])) { | 
					
						
							|  |  |  |             $namedAttr[ 'index' ] = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (isset($namedAttr[ 'last' ])) { | 
					
						
							|  |  |  |             $namedAttr[ 'iteration' ] = true; | 
					
						
							|  |  |  |             $namedAttr[ 'total' ] = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (isset($itemAttr[ 'last' ])) { | 
					
						
							|  |  |  |             $itemAttr[ 'iteration' ] = true; | 
					
						
							|  |  |  |             $itemAttr[ 'total' ] = true; | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |         if (isset($namedAttr[ 'show' ])) { | 
					
						
							|  |  |  |             $namedAttr[ 'total' ] = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (isset($itemAttr[ 'show' ])) { | 
					
						
							|  |  |  |             $itemAttr[ 'total' ] = true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $keyTerm = ''; | 
					
						
							| 
									
										
										
										
											2016-07-18 05:27:46 +02:00
										 |  |  |         if (isset($attributes[ 'key' ])) { | 
					
						
							|  |  |  |             $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'key' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |             $keyTerm = "{$itemVar}->key => "; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         if ($this->isNamed) { | 
					
						
							|  |  |  |             $foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']"; | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |         $needTotal = isset($itemAttr[ 'total' ]); | 
					
						
							|  |  |  |         // Register tag
 | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |         $this->openTag( | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |             $compiler, | 
					
						
							|  |  |  |             'foreach', | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |             array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2) | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         // maybe nocache because of nocache variables
 | 
					
						
							|  |  |  |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | 
					
						
							|  |  |  |         // generate output code
 | 
					
						
							|  |  |  |         $output = "<?php\n"; | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         $output .= "\$_from = \$_smarty_tpl->smarty->ext->_foreach->init(\$_smarty_tpl, $from, " . | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                    var_export($item, true); | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if ($name || $needTotal || $key) { | 
					
						
							|  |  |  |             $output .= ', ' . var_export($needTotal, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if ($name || $key) { | 
					
						
							|  |  |  |             $output .= ', ' . var_export($key, true); | 
					
						
							| 
									
										
										
										
											2015-12-16 03:25:33 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if ($name) { | 
					
						
							|  |  |  |             $output .= ', ' . var_export($name, true) . ', ' . var_export($namedAttr, true); | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         $output .= ");\n"; | 
					
						
							|  |  |  |         if (isset($itemAttr[ 'show' ])) { | 
					
						
							|  |  |  |             $output .= "{$itemVar}->show = ({$itemVar}->total > 0);\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'iteration' ])) { | 
					
						
							|  |  |  |             $output .= "{$itemVar}->iteration = 0;\n"; | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'index' ])) { | 
					
						
							|  |  |  |             $output .= "{$itemVar}->index = -1;\n"; | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |         $output .= "if (\$_from !== null) {\n"; | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |         $output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |             $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'iteration' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |             $output .= "{$itemVar}->iteration++;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'index' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |             $output .= "{$itemVar}->index++;\n"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'first' ])) { | 
					
						
							|  |  |  |             $output .= "{$itemVar}->first = !{$itemVar}->index;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |         if (isset($itemAttr[ 'last' ])) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             $output .= "{$itemVar}->last = {$itemVar}->iteration === {$itemVar}->total;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |         if (isset($foreachVar)) { | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             if (isset($namedAttr[ 'iteration' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |                 $output .= "{$foreachVar}->value['iteration']++;\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             if (isset($namedAttr[ 'index' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |                 $output .= "{$foreachVar}->value['index']++;\n"; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             if (isset($namedAttr[ 'first' ])) { | 
					
						
							|  |  |  |                 $output .= "{$foreachVar}->value['first'] = !{$foreachVar}->value['index'];\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             if (isset($namedAttr[ 'last' ])) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                 $output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] === {$foreachVar}->value['total'];\n"; | 
					
						
							| 
									
										
										
										
											2015-08-02 19:43:21 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-09-17 21:01:48 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |         if (!empty($itemAttr)) { | 
					
						
							|  |  |  |             $output .= "{$local}saved = {$itemVar};\n"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         $output .= '?>'; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Compiles code for to restore saved template variables | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param int $levels number of levels to restore | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string compiled code | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function compileRestore($levels) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-20 04:07:51 +01:00
										 |  |  |         return "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl, {$levels});"; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											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
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                                 $args     array with attributes from parser | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |         list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach')); | 
					
						
							|  |  |  |         $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0)); | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output = "<?php\n"; | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($restore === 2) { | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |             $output .= "{$itemVar} = {$local}saved;\n"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-20 04:07:51 +01:00
										 |  |  |         $output .= "}\n} else {\n?>"; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         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
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                                 $args     array with attributes from parser | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-04-28 20:30:27 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @throws \SmartyCompilerException | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         $compiler->loopNesting--; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-09-03 01:18:26 +02:00
										 |  |  |         list( | 
					
						
							|  |  |  |             $openTag, $compiler->nocache, $local, $itemVar, $restore | 
					
						
							|  |  |  |             ) = $this->closeTag($compiler, array('foreach', 'foreachelse')); | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         $output = "<?php\n"; | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($restore === 2) { | 
					
						
							| 
									
										
										
										
											2015-12-28 00:58:22 +01:00
										 |  |  |             $output .= "{$itemVar} = {$local}saved;\n"; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-16 17:57:06 +02:00
										 |  |  |         if ($restore > 0) { | 
					
						
							|  |  |  |             $output .= "}\n"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-01 03:30:08 +02:00
										 |  |  |         $output .= "}\n"; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |         /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */ | 
					
						
							|  |  |  |         $foreachCompiler = $compiler->getTagCompiler('foreach'); | 
					
						
							|  |  |  |         $output .= $foreachCompiler->compileRestore(1); | 
					
						
							| 
									
										
										
										
											2017-11-20 04:07:51 +01:00
										 |  |  |         $output .= "?>"; | 
					
						
							| 
									
										
										
										
											2015-02-15 16:58:42 +01:00
										 |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |