| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Internal Plugin Compile Break | 
					
						
							|  |  |  |  * Compiles the {break} tag | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Smarty Internal Plugin Compile Break Class | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $optional_attributes = array('levels'); | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $shorttag_order = array('levels'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * Tag name may be overloaded by Smarty_Internal_Compile_Continue | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |     public $tag = 'break'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Compiles code for the {break} tag | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											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
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @throws \SmartyCompilerException | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         list($levels, $foreachLevels) = $this->checkLevels($args, $compiler); | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |         $output = "<?php "; | 
					
						
							|  |  |  |         if ($foreachLevels > 0 && $this->tag === 'continue') { | 
					
						
							|  |  |  |             $foreachLevels--; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if ($foreachLevels > 0) { | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |             /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */ | 
					
						
							|  |  |  |             $foreachCompiler = $compiler->getTagCompiler('foreach'); | 
					
						
							|  |  |  |             $output .= $foreachCompiler->compileRestore($foreachLevels); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |         $output .= "{$this->tag} {$levels};?>"; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |         return $output; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * check attributes and return array of break and foreach levels | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                                 $args     array with attributes from parser | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws \SmartyCompilerException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |     public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							|  |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if ($_attr[ 'nocache' ] === true) { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |             $compiler->trigger_template_error('nocache option not allowed', null, true); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if (isset($_attr[ 'levels' ])) { | 
					
						
							|  |  |  |             if (!is_numeric($_attr[ 'levels' ])) { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |                 $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |             $levels = $_attr[ 'levels' ]; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |             $levels = 1; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |         $level_count = $levels; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         $stack_count = count($compiler->_tag_stack) - 1; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |         $foreachLevels = 0; | 
					
						
							|  |  |  |         $lastTag = ''; | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |         while ($level_count > 0 && $stack_count >= 0) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) { | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |                 $lastTag = $compiler->_tag_stack[ $stack_count ][ 0 ]; | 
					
						
							|  |  |  |                 if ($level_count === 0) { | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                 $level_count--; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |                 if ($compiler->_tag_stack[ $stack_count ][ 0 ] === 'foreach') { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                     $foreachLevels++; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |             $stack_count--; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if ($level_count !== 0) { | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |             $compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-22 01:21:09 +01:00
										 |  |  |         if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |             $foreachLevels--; | 
					
						
							| 
									
										
										
										
											2016-09-09 22:54:42 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         return array($levels, $foreachLevels); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |