parser: add support for template prefix and postfix code

This commit is contained in:
uwetews
2015-10-08 21:14:16 +02:00
parent 5cde3a8799
commit 757d66a731
3 changed files with 238 additions and 166 deletions

View File

@@ -51,6 +51,32 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
}
}
/**
* Append array to subtree
*
* @param \Smarty_Internal_Templateparser $parser
* @param \Smarty_Internal_ParseTree[] $array
*/
public function append_array(Smarty_Internal_Templateparser $parser, $array = array())
{
if (!empty($array)) {
$this->subtrees = array_merge($this->subtrees, (array) $array);
}
}
/**
* Prepend array to subtree
*
* @param \Smarty_Internal_Templateparser $parser
* @param \Smarty_Internal_ParseTree[] $array
*/
public function prepend_array(Smarty_Internal_Templateparser $parser, $array = array())
{
if (!empty($array)) {
$this->subtrees = array_merge((array) $array, $this->subtrees);
}
}
/**
* Sanitize and merge subtree buffers together
*
@@ -75,7 +101,8 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
if ($subtree == '') {
continue;
}
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n", $subtree);
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n",
$subtree);
continue;
}
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {