]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_while.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_compile_while.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile While
4  * Compiles the {while} tag
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile While Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Compiles code for the {while} tag
21      *
22      * @param  array                                $args      array with attributes from parser
23      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object
24      * @param  array                                $parameter array with compilation parameter
25      *
26      * @return string compiled code
27      * @throws \SmartyCompilerException
28      */
29     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
30     {
31         $compiler->loopNesting ++;
32         // check and get attributes
33         $_attr = $this->getAttributes($compiler, $args);
34         $this->openTag($compiler, 'while', $compiler->nocache);
35
36         if (!array_key_exists("if condition", $parameter)) {
37             $compiler->trigger_template_error("missing while condition", null, true);
38         }
39
40         // maybe nocache because of nocache variables
41         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
42         if (is_array($parameter[ 'if condition' ])) {
43             if ($compiler->nocache) {
44                 // create nocache var to make it know for further compiling
45                 if (is_array($parameter[ 'if condition' ][ 'var' ])) {
46                     $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
47                 } else {
48                     $var = $parameter[ 'if condition' ][ 'var' ];
49                 }
50                 $compiler->setNocacheInVariable($var);
51             }
52             $prefixVar = $compiler->getNewPrefixVariable();
53             $assignCompiler = new Smarty_Internal_Compile_Assign();
54             $assignAttr = array();
55             $assignAttr[][ 'value' ] = "{$prefixVar}";
56             if (is_array($parameter[ 'if condition' ][ 'var' ])) {
57                 $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
58                 $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
59                 $_output .= $assignCompiler->compile($assignAttr, $compiler,
60                                                      array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
61             } else {
62                 $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
63                 $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
64                 $_output .= $assignCompiler->compile($assignAttr, $compiler, array());
65             }
66
67             return $_output;
68         } else {
69             return "<?php\n while ({$parameter['if condition']}) {?>";
70         }
71     }
72 }
73
74 /**
75  * Smarty Internal Plugin Compile Whileclose Class
76  *
77  * @package    Smarty
78  * @subpackage Compiler
79  */
80 class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
81 {
82     /**
83      * Compiles code for the {/while} tag
84      *
85      * @param  array                                $args     array with attributes from parser
86      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
87      *
88      * @return string compiled code
89      */
90     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
91     {
92         $compiler->loopNesting --;
93         // must endblock be nocache?
94         if ($compiler->nocache) {
95             $compiler->tag_nocache = true;
96         }
97         $compiler->nocache = $this->closeTag($compiler, array('while'));
98         return "<?php }?>\n";
99     }
100 }