blob: bdfa4c48f58d3b58aff1688dae1ab045a48f182a (
plain) (
blame)
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
|
<?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->parser = $parser;
$this->subtrees[] = $subtree;
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
}
}
/**
* Append buffer to subtree
*
* @param Smarty_Internal_ParseTree $subtree parse tree buffer
*/
public function append_subtree(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 < $this->parser->block_nesting_level) {
if ($subtree instanceof Smarty_Internal_ParseTree_Code) {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>');
} elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>');
} else {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data);
}
} else {
$this->subtrees[] = $subtree;
}
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
}
}
/**
* Merge subtree buffer content together
*
* @return string compiled template code
*/
public function to_smarty_php()
{
$code = '';
foreach ($this->subtrees as $subtree) {
if ($code !== "") {
$code .= ".";
}
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$more_php = $subtree->assign_to_var();
} else {
$more_php = $subtree->to_smarty_php();
}
$code .= $more_php;
if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
$this->parser->compiler->has_variable_string = true;
}
}
return $code;
}
}
|