3 * Smarty Internal Plugin Templateparser Parse Tree
4 * These are classes to build parse tree in the template parser
8 * @author Thue Kristensen
16 * @subpackage Compiler
19 class Smarty_Internal_ParseTree_Template
extends Smarty_Internal_ParseTree
23 * Array of template elements
27 public $subtrees = Array();
30 * Create root of parse tree for template elements
32 * @param object $parser parse object
34 public function __construct($parser)
36 $this->parser
= $parser;
40 * Append buffer to subtree
42 * @param Smarty_Internal_ParseTree $subtree
44 public function append_subtree(Smarty_Internal_ParseTree
$subtree)
46 if (!empty($subtree->subtrees
)) {
47 $this->subtrees
= array_merge($this->subtrees
, $subtree->subtrees
);
49 if ($subtree->data
!== '') {
50 $this->subtrees
[] = $subtree;
56 * Sanitize and merge subtree buffers together
58 * @return string template code content
60 public function to_smarty_php()
63 for ($key = 0, $cnt = count($this->subtrees
); $key < $cnt; $key ++
) {
64 if ($this->subtrees
[$key] instanceof Smarty_Internal_ParseTree_Text
) {
65 $subtree = $this->subtrees
[$key]->to_smarty_php();
66 while ($key +
1 < $cnt && ($this->subtrees
[$key +
1] instanceof Smarty_Internal_ParseTree_Text ||
$this->subtrees
[$key +
1]->data
== '')) {
68 if ($this->subtrees
[$key]->data
== '') {
71 $subtree .= $this->subtrees
[$key]->to_smarty_php();
76 $code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n", $subtree);
79 if ($this->subtrees
[$key] instanceof Smarty_Internal_ParseTree_Tag
) {
80 $subtree = $this->subtrees
[$key]->to_smarty_php();
81 while ($key +
1 < $cnt && ($this->subtrees
[$key +
1] instanceof Smarty_Internal_ParseTree_Tag ||
$this->subtrees
[$key +
1]->data
== '')) {
83 if ($this->subtrees
[$key]->data
== '') {
86 $subtree = $this->parser
->compiler
->appendCode($subtree, $this->subtrees
[$key]->to_smarty_php());
94 $code .= $this->subtrees
[$key]->to_smarty_php();