| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * Smarty Internal Plugin Compile While | 
					
						
							|  |  |  |  * Compiles the {while} tag | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * Smarty Internal Plugin Compile While Class | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Compiles code for the {while} tag | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |      * @param  array                                $args      array with attributes from parser | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |      * @param  array                                $parameter array with compilation parameter | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |      * @throws \SmartyCompilerException | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         $compiler->loopNesting ++; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  |         $this->openTag($compiler, 'while', $compiler->nocache); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         if (!array_key_exists("if condition", $parameter)) { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |             $compiler->trigger_template_error("missing while condition", null, true); | 
					
						
							| 
									
										
										
										
											2011-11-01 20:27:53 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         // maybe nocache because of nocache variables
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if (is_array($parameter[ 'if condition' ])) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             if ($compiler->nocache) { | 
					
						
							|  |  |  |                 // create nocache var to make it know for further compiling
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 if (is_array($parameter[ 'if condition' ][ 'var' ])) { | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                     $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                     $var = $parameter[ 'if condition' ][ 'var' ]; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                 $compiler->setNocacheInVariable($var); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-09-15 02:56:34 +02:00
										 |  |  |             $prefixVar = $compiler->getNewPrefixVariable(); | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |             $assignCompiler = new Smarty_Internal_Compile_Assign(); | 
					
						
							|  |  |  |             $assignAttr = array(); | 
					
						
							| 
									
										
										
										
											2016-09-15 02:56:34 +02:00
										 |  |  |             $assignAttr[][ 'value' ] = "{$prefixVar}"; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (is_array($parameter[ 'if condition' ][ 'var' ])) { | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                 $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; | 
					
						
							| 
									
										
										
										
											2016-09-15 02:56:34 +02:00
										 |  |  |                 $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>"; | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                 $_output .= $assignCompiler->compile($assignAttr, $compiler, | 
					
						
							|  |  |  |                                                      array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ])); | 
					
						
							| 
									
										
										
										
											2010-11-24 19:38:45 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                 $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ]; | 
					
						
							| 
									
										
										
										
											2016-09-15 02:56:34 +02:00
										 |  |  |                 $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>"; | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |                 $_output .= $assignCompiler->compile($assignAttr, $compiler, array()); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return $_output; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |             return "<?php\n while ({$parameter['if condition']}) {?>"; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Whileclose Class | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * Compiles code for the {/while} tag | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |      * @param  array                                $args     array with attributes from parser | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         $compiler->loopNesting --; | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +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
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $compiler->nocache = $this->closeTag($compiler, array('while')); | 
					
						
							| 
									
										
										
										
											2015-08-10 21:57:06 +02:00
										 |  |  |         return "<?php }?>\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |