aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php')
-rw-r--r--vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php116
1 files changed, 78 insertions, 38 deletions
diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php
index 8e716bd5d..477232ef8 100644
--- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php
+++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php
@@ -85,45 +85,85 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
$code = '';
- for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
- if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
- $subtree = $this->subtrees[ $key ]->to_smarty_php($parser);
- while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Text ||
- $this->subtrees[ $key + 1 ]->data === '')) {
- $key++;
- if ($this->subtrees[ $key ]->data === '') {
- continue;
- }
- $subtree .= $this->subtrees[ $key ]->to_smarty_php($parser);
- }
- if ($subtree === '') {
- continue;
- }
- $code .= preg_replace(
- '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
- "<?php echo '\$1'; ?>\n",
- $subtree
- );
- continue;
- }
- if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
- $subtree = $this->subtrees[ $key ]->to_smarty_php($parser);
- while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Tag ||
- $this->subtrees[ $key + 1 ]->data === '')) {
- $key++;
- if ($this->subtrees[ $key ]->data === '') {
- continue;
- }
- $subtree = $parser->compiler->appendCode($subtree, $this->subtrees[ $key ]->to_smarty_php($parser));
- }
- if ($subtree === '') {
- continue;
- }
- $code .= $subtree;
- continue;
- }
- $code .= $this->subtrees[ $key ]->to_smarty_php($parser);
+
+ foreach ($this->getChunkedSubtrees() as $chunk) {
+ $text = '';
+ switch ($chunk['mode']) {
+ case 'textstripped':
+ foreach ($chunk['subtrees'] as $subtree) {
+ $text .= $subtree->to_smarty_php($parser);
+ }
+ $code .= preg_replace(
+ '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
+ "<?php echo '\$1'; ?>\n",
+ $parser->compiler->processText($text)
+ );
+ break;
+ case 'text':
+ foreach ($chunk['subtrees'] as $subtree) {
+ $text .= $subtree->to_smarty_php($parser);
+ }
+ $code .= preg_replace(
+ '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
+ "<?php echo '\$1'; ?>\n",
+ $text
+ );
+ break;
+ case 'tag':
+ foreach ($chunk['subtrees'] as $subtree) {
+ $text = $parser->compiler->appendCode($text, $subtree->to_smarty_php($parser));
+ }
+ $code .= $text;
+ break;
+ default:
+ foreach ($chunk['subtrees'] as $subtree) {
+ $text = $subtree->to_smarty_php($parser);
+ }
+ $code .= $text;
+
+ }
}
return $code;
}
+
+ private function getChunkedSubtrees() {
+ $chunks = [];
+ $currentMode = null;
+ $currentChunk = [];
+ for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
+
+ if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, ['textstripped', 'text', 'tag'])) {
+ continue;
+ }
+
+ if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text
+ && $this->subtrees[ $key ]->isToBeStripped()) {
+ $newMode = 'textstripped';
+ } elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
+ $newMode = 'text';
+ } elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
+ $newMode = 'tag';
+ } else {
+ $newMode = 'other';
+ }
+
+ if ($newMode == $currentMode) {
+ $currentChunk[] = $this->subtrees[ $key ];
+ } else {
+ $chunks[] = [
+ 'mode' => $currentMode,
+ 'subtrees' => $currentChunk
+ ];
+ $currentMode = $newMode;
+ $currentChunk = [$this->subtrees[ $key ]];
+ }
+ }
+ if ($currentMode && $currentChunk) {
+ $chunks[] = [
+ 'mode' => $currentMode,
+ 'subtrees' => $currentChunk
+ ];
+ }
+ return $chunks;
+ }
}