Code

Readded smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_while.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile While
4  *
5  * Compiles the {while} tag
6  *
7  * @package Smarty
8  * @subpackage Compiler
9  * @author Uwe Tews
10  */
12 /**
13  * Smarty Internal Plugin Compile While Class
14  *
15  * @package Smarty
16  * @subpackage Compiler
17  */
18 class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase {
20     /**
21      * Compiles code for the {while} tag
22      *
23      * @param array  $args      array with attributes from parser
24      * @param object $compiler  compiler object
25      * @param array  $parameter array with compilation parameter
26      * @return string compiled code
27      */
28     public function compile($args, $compiler, $parameter)
29     {
30         // check and get attributes
31         $_attr = $this->getAttributes($compiler, $args);
32         $this->openTag($compiler, 'while', $compiler->nocache);
34         // maybe nocache because of nocache variables
35         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
36         if (is_array($parameter['if condition'])) {
37             if ($compiler->nocache) {
38                 $_nocache = ',true';
39                 // create nocache var to make it know for further compiling
40                 if (is_array($parameter['if condition']['var'])) {
41                     $compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
42                 } else {
43                     $compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
44                 }
45             } else {
46                 $_nocache = '';
47             }
48             if (is_array($parameter['if condition']['var'])) {
49                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
50                 $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . "){?>";
51             } else {
52                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
53                 $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . "){?>";
54             }
55             return $_output;
56         } else {
57             return "<?php while ({$parameter['if condition']}){?>";
58         }
59     }
61 }
63 /**
64  * Smarty Internal Plugin Compile Whileclose Class
65  *
66  * @package Smarty
67  * @subpackage Compiler
68  */
69 class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase {
71     /**
72      * Compiles code for the {/while} tag
73      *
74      * @param array  $args     array with attributes from parser
75      * @param object $compiler compiler object
76      * @return string compiled code
77      */
78     public function compile($args, $compiler)
79     {
80         // must endblock be nocache?
81         if ($compiler->nocache) {
82             $compiler->tag_nocache = true;
83         }
84         $compiler->nocache = $this->closeTag($compiler, array('while'));
85         return "<?php }?>";
86     }
88 }
90 ?>