Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

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