Adjusted time.php to honor note on separate row option.
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_parsetree.php
1 <?php
2 /**
3  * Smarty Internal Plugin Templateparser Parsetrees
4  * 
5  * These are classes to build parsetrees in the template parser
6  * 
7  * @package Smarty
8  * @subpackage Compiler
9  * @author Thue Kristensen 
10  * @author Uwe Tews 
11  */
12  
13 abstract class _smarty_parsetree {
14   abstract public function to_smarty_php();
15 }
16
17 /**
18  * A complete smarty tag.
19  */
20 class _smarty_tag extends _smarty_parsetree
21 {
22     public $parser;
23     public $data;
24     public $saved_block_nesting;
25     function __construct($parser, $data)
26     {
27         $this->parser = $parser;
28         $this->data = $data;
29         $this->saved_block_nesting = $parser->block_nesting_level;
30     } 
31
32     public function to_smarty_php()
33     {
34         return $this->data;
35     } 
36
37     public function assign_to_var()
38     {
39         $var = sprintf('$_tmp%d', ++$this->parser->prefix_number);
40         $this->parser->compiler->prefix_code[] = sprintf('<?php ob_start();?>%s<?php %s=ob_get_clean();?>',
41             $this->data, $var);
42         return $var;
43     } 
44
45
46 /**
47  * Code fragment inside a tag.
48  */
49 class _smarty_code extends _smarty_parsetree {
50     public $parser;
51     public $data;
52     function __construct($parser, $data)
53     {
54         $this->parser = $parser;
55         $this->data = $data;
56     } 
57
58     public function to_smarty_php()
59     {
60         return sprintf("(%s)", $this->data);
61     } 
62
63
64 /**
65  * Double quoted string inside a tag.
66  */
67 class _smarty_doublequoted extends _smarty_parsetree {
68     public $parser;
69     public $subtrees = Array();
70     function __construct($parser, _smarty_parsetree $subtree)
71     {
72         $this->parser = $parser;
73         $this->subtrees[] = $subtree;
74         if ($subtree instanceof _smarty_tag) {
75             $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
76         } 
77     } 
78
79     function append_subtree(_smarty_parsetree $subtree)
80     {
81         $last_subtree = count($this->subtrees)-1;
82         if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
83             if ($subtree instanceof _smarty_code) {
84                 $this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';
85             } elseif ($subtree instanceof _smarty_dq_content) {
86                 $this->subtrees[$last_subtree]->data .= '<?php echo "' . $subtree->data . '";?>';
87             } else {
88                 $this->subtrees[$last_subtree]->data .= $subtree->data;
89             } 
90         } else {
91             $this->subtrees[] = $subtree;
92         } 
93         if ($subtree instanceof _smarty_tag) {
94             $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
95         } 
96     } 
97
98     public function to_smarty_php()
99     {
100         $code = '';
101         foreach ($this->subtrees as $subtree) {
102             if ($code !== "") {
103                 $code .= ".";
104             } 
105             if ($subtree instanceof _smarty_tag) {
106                 $more_php = $subtree->assign_to_var();
107             } else {
108                 $more_php = $subtree->to_smarty_php();
109             } 
110
111             $code .= $more_php;
112
113             if (!$subtree instanceof _smarty_dq_content) {
114                 $this->parser->compiler->has_variable_string = true;
115             } 
116         } 
117         return $code;
118     } 
119
120
121 /**
122  * Raw chars as part of a double quoted string.
123  */
124 class _smarty_dq_content extends _smarty_parsetree {
125     public $data;
126     function __construct($parser, $data)
127     {
128         $this->parser = $parser;
129         $this->data = $data;
130     } 
131
132     public function to_smarty_php()
133     {
134         return '"' . $this->data . '"';
135     } 
136
137
138 /**
139  * Template element
140  */
141 class _smarty_template_buffer extends _smarty_parsetree {
142     public $subtrees = Array();
143     function __construct($parser)
144     {
145         $this->parser = $parser;
146     } 
147
148     function append_subtree(_smarty_parsetree $subtree)
149     {
150         $this->subtrees[] = $subtree;
151     } 
152
153     public function to_smarty_php()
154     {
155         $code = '';
156         for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
157             if ($key + 2 < $cnt) {
158                 if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) {
159                     $key = $key + 1;
160                     continue;
161                 } 
162                 if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') {
163                     $key = $key + 2;
164                     continue;
165                 } 
166             } 
167             if (substr($code, -1) == '<') {
168                 $subtree = $this->subtrees[$key]->to_smarty_php();
169                 if (substr($subtree, 0, 1) == '?') {
170                     $code = substr($code, 0, strlen($code)-1) . '<<?php ?>?' . substr($subtree, 1);
171                 } elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') {
172                     $code = substr($code, 0, strlen($code)-1) . '<<?php ?>%' . substr($subtree, 1);
173            } else {
174                     $code .= $subtree;
175                 } 
176                 continue;
177             } 
178             if ($this->parser->asp_tags && substr($code, -1) == '%') {
179                 $subtree = $this->subtrees[$key]->to_smarty_php();
180                 if (substr($subtree, 0, 1) == '>') {
181                     $code = substr($code, 0, strlen($code)-1) . '%<?php ?>>' . substr($subtree, 1);
182            } else {
183                     $code .= $subtree;
184                 } 
185                 continue;
186             } 
187             if (substr($code, -1) == '?') {
188                 $subtree = $this->subtrees[$key]->to_smarty_php();
189                 if (substr($subtree, 0, 1) == '>') {
190                     $code = substr($code, 0, strlen($code)-1) . '?<?php ?>>' . substr($subtree, 1);
191            } else {
192                     $code .= $subtree;
193                 } 
194                 continue;
195             } 
196             $code .= $this->subtrees[$key]->to_smarty_php();
197         } 
198         return $code;
199     } 
200 }
201
202 /**
203  * template text
204  */
205 class _smarty_text extends _smarty_parsetree {
206     public $data;
207     function __construct($parser, $data)
208     {
209         $this->parser = $parser;
210         $this->data = $data;
211     } 
212
213     public function to_smarty_php()
214     {
215         return $this->data;
216     } 
217
218
219 /**
220  * template linebreaks
221  */
222 class _smarty_linebreak extends _smarty_parsetree {
223     public $data;
224     function __construct($parser, $data)
225     {
226         $this->parser = $parser;
227         $this->data = $data;
228     } 
229
230     public function to_smarty_php()
231     {
232         return $this->data;
233     } 
234
235
236 ?>