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