1 <?php |
|
2 |
|
3 /** |
|
4 * Double quoted string inside a tag. |
|
5 * |
|
6 * @package Smarty |
|
7 * @subpackage Compiler |
|
8 * @ignore |
|
9 */ |
|
10 |
|
11 /** |
|
12 * Double quoted string inside a tag. |
|
13 * |
|
14 * @package Smarty |
|
15 * @subpackage Compiler |
|
16 * @ignore |
|
17 */ |
|
18 class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree { |
|
19 /** |
|
20 * Create parse tree buffer for double quoted string subtrees |
|
21 * |
|
22 * @param object $parser parser object |
|
23 * @param Smarty_Internal_ParseTree $subtree parse tree buffer |
|
24 */ |
|
25 public function __construct($parser, Smarty_Internal_ParseTree $subtree) { |
|
26 $this->parser = $parser; |
|
27 $this->subtrees[] = $subtree; |
|
28 if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { |
|
29 $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); |
|
30 } |
|
31 } |
|
32 |
|
33 /** |
|
34 * Append buffer to subtree |
|
35 * |
|
36 * @param Smarty_Internal_ParseTree $subtree parse tree buffer |
|
37 */ |
|
38 public function append_subtree(Smarty_Internal_ParseTree $subtree) { |
|
39 $last_subtree = count($this->subtrees) - 1; |
|
40 if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) { |
|
41 if ($subtree instanceof Smarty_Internal_ParseTree_Code) { |
|
42 $this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>'); |
|
43 } elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) { |
|
44 $this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>'); |
|
45 } else { |
|
46 $this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data); |
|
47 } |
|
48 } else { |
|
49 $this->subtrees[] = $subtree; |
|
50 } |
|
51 if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { |
|
52 $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); |
|
53 } |
|
54 } |
|
55 |
|
56 /** |
|
57 * Merge subtree buffer content together |
|
58 * |
|
59 * @return string compiled template code |
|
60 */ |
|
61 public function to_smarty_php() { |
|
62 $code = ''; |
|
63 foreach ($this->subtrees as $subtree) { |
|
64 if ($code !== "") { |
|
65 $code .= "."; |
|
66 } |
|
67 if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { |
|
68 $more_php = $subtree->assign_to_var(); |
|
69 } else { |
|
70 $more_php = $subtree->to_smarty_php(); |
|
71 } |
|
72 |
|
73 $code .= $more_php; |
|
74 |
|
75 if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) { |
|
76 $this->parser->compiler->has_variable_string = true; |
|
77 } |
|
78 } |
|
79 |
|
80 return $code; |
|
81 } |
|
82 } |
|