Code

Updated smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_parsetree.php
1 <?php\r
2 \r
3 abstract class _smarty_parsetree {\r
4   abstract public function to_smarty_php();\r
5 }\r
6 \r
7 /* A complete smarty tag. */\r
8 \r
9 class _smarty_tag extends _smarty_parsetree {\r
10     public $parser;\r
11     public $data;\r
12     public $saved_block_nesting;\r
13     function __construct($parser, $data)\r
14     {\r
15         $this->parser = $parser;\r
16         $this->data = $data;\r
17         $this->saved_block_nesting = $parser->block_nesting_level;\r
18     } \r
19 \r
20     public function to_smarty_php()\r
21     {\r
22         return $this->data;\r
23     } \r
24 \r
25     public function assign_to_var()\r
26     {\r
27         $var = sprintf('$_tmp%d', ++$this->parser->prefix_number);\r
28         $this->parser->compiler->prefix_code[] = sprintf('<?php ob_start();?>%s<?php %s=ob_get_clean();?>',\r
29             $this->data, $var);\r
30         return $var;\r
31     } \r
32\r
33 \r
34 /* Code fragment inside a tag. */\r
35 class _smarty_code extends _smarty_parsetree {\r
36     public $parser;\r
37     public $data;\r
38     function __construct($parser, $data)\r
39     {\r
40         $this->parser = $parser;\r
41         $this->data = $data;\r
42     } \r
43 \r
44     public function to_smarty_php()\r
45     {\r
46         return sprintf("(%s)", $this->data);\r
47     } \r
48\r
49 \r
50 /* Double quoted string inside a tag. */\r
51 class _smarty_doublequoted extends _smarty_parsetree {\r
52     public $parser;\r
53     public $subtrees = Array();\r
54     function __construct($parser, _smarty_parsetree $subtree)\r
55     {\r
56         $this->parser = $parser;\r
57         $this->subtrees[] = $subtree;\r
58         if ($subtree instanceof _smarty_tag) {\r
59             $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);\r
60         } \r
61     } \r
62 \r
63     function append_subtree(_smarty_parsetree $subtree)\r
64     {\r
65         $last_subtree = count($this->subtrees)-1;\r
66         if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {\r
67             if ($subtree instanceof _smarty_code) {\r
68                 $this->subtrees[$last_subtree]->data .= '<?php echo ' . $subtree->data . ';?>';\r
69             } else {\r
70                 $this->subtrees[$last_subtree]->data .= $subtree->data;\r
71             } \r
72         } else {\r
73             $this->subtrees[] = $subtree;\r
74         } \r
75         if ($subtree instanceof _smarty_tag) {\r
76             $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);\r
77         } \r
78     } \r
79 \r
80     public function to_smarty_php()\r
81     {\r
82         $code = '';\r
83         foreach ($this->subtrees as $subtree) {\r
84             if ($code !== "") {\r
85                 $code .= ".";\r
86             } \r
87             if ($subtree instanceof _smarty_tag) {\r
88                 $more_php = $subtree->assign_to_var();\r
89             } else {\r
90                 $more_php = $subtree->to_smarty_php();\r
91             } \r
92 \r
93             $code .= $more_php;\r
94 \r
95             if (!$subtree instanceof _smarty_dq_content) {\r
96                 $this->parser->compiler->has_variable_string = true;\r
97             } \r
98         } \r
99 \r
100 //        $code = sprintf("(%s)", $code);\r
101         return $code;\r
102     } \r
103\r
104 \r
105 /* Raw chars as part of a double quoted string. */\r
106 class _smarty_dq_content extends _smarty_parsetree {\r
107     public $data;\r
108     function __construct($parser, $data)\r
109     {\r
110         $this->parser = $parser;\r
111         $this->data = $data;\r
112     } \r
113 \r
114     public function to_smarty_php()\r
115     {\r
116         return '"' . $this->data . '"';\r
117     } \r
118\r
119 \r
120 \r
121 ?>