diff options
Diffstat (limited to 'vendor/smarty/smarty/src/ParseTree')
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/Base.php | 45 | ||||
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/Code.php | 45 | ||||
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/Dq.php | 97 | ||||
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/DqContent.php | 44 | ||||
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/Tag.php | 70 | ||||
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/Template.php | 172 | ||||
-rw-r--r-- | vendor/smarty/smarty/src/ParseTree/Text.php | 59 |
7 files changed, 532 insertions, 0 deletions
diff --git a/vendor/smarty/smarty/src/ParseTree/Base.php b/vendor/smarty/smarty/src/ParseTree/Base.php new file mode 100644 index 000000000..e1140c15e --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/Base.php @@ -0,0 +1,45 @@ +<?php + +namespace Smarty\ParseTree; + +/** + * Smarty Internal Plugin Templateparser ParseTree + * These are classes to build parsetree in the template parser + * + + + * @author Thue Kristensen + * @author Uwe Tews + */ + +/** + + + * @ignore + */ +abstract class Base +{ + /** + * Buffer content + * + * @var mixed + */ + public $data; + + /** + * Subtree array + * + * @var array + */ + public $subtrees = array(); + + /** + * Return buffer + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string buffer content + */ + abstract public function to_smarty_php(\Smarty\Parser\TemplateParser $parser); + +} diff --git a/vendor/smarty/smarty/src/ParseTree/Code.php b/vendor/smarty/smarty/src/ParseTree/Code.php new file mode 100644 index 000000000..b39f22c8b --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/Code.php @@ -0,0 +1,45 @@ +<?php + +namespace Smarty\ParseTree; + +/** + * Smarty Internal Plugin Templateparser Parse Tree + * These are classes to build parse trees in the template parser + * + + + * @author Thue Kristensen + * @author Uwe Tews + */ + +/** + * Code fragment inside a tag . + * + + + * @ignore + */ +class Code extends Base +{ + /** + * Create parse tree buffer for code fragment + * + * @param string $data content + */ + public function __construct($data) + { + $this->data = $data; + } + + /** + * Return buffer content in parentheses + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string content + */ + public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) + { + return sprintf('(%s)', $this->data); + } +} diff --git a/vendor/smarty/smarty/src/ParseTree/Dq.php b/vendor/smarty/smarty/src/ParseTree/Dq.php new file mode 100644 index 000000000..b5fca3b40 --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/Dq.php @@ -0,0 +1,97 @@ +<?php + +namespace Smarty\ParseTree; +/** + * Double-quoted string inside a tag. + * + + + * @ignore + */ + +/** + * Double quoted string inside a tag. + * + + + * @ignore + */ +class Dq extends Base +{ + /** + * Create parse tree buffer for double-quoted string subtrees + * + * @param object $parser parser object + * @param Base $subtree parse tree buffer + */ + public function __construct($parser, Base $subtree) + { + $this->subtrees[] = $subtree; + if ($subtree instanceof Tag) { + $parser->block_nesting_level = $parser->compiler->getTagStackCount(); + } + } + + /** + * Append buffer to subtree + * + * @param \Smarty\Parser\TemplateParser $parser + * @param Base $subtree parse tree buffer + */ + public function append_subtree(\Smarty\Parser\TemplateParser $parser, Base $subtree) + { + $last_subtree = count($this->subtrees) - 1; + if ($last_subtree >= 0 && $this->subtrees[ $last_subtree ] instanceof Tag + && $this->subtrees[ $last_subtree ]->saved_block_nesting < $parser->block_nesting_level + ) { + if ($subtree instanceof Code) { + $this->subtrees[ $last_subtree ]->data = + $parser->compiler->appendCode( + (string) $this->subtrees[ $last_subtree ]->data, + '<?php echo ' . $subtree->data . ';?>' + ); + } elseif ($subtree instanceof DqContent) { + $this->subtrees[ $last_subtree ]->data = + $parser->compiler->appendCode( + (string) $this->subtrees[ $last_subtree ]->data, + '<?php echo "' . $subtree->data . '";?>' + ); + } else { + $this->subtrees[ $last_subtree ]->data = + $parser->compiler->appendCode((string) $this->subtrees[ $last_subtree ]->data, (string) $subtree->data); + } + } else { + $this->subtrees[] = $subtree; + } + if ($subtree instanceof Tag) { + $parser->block_nesting_level = $parser->compiler->getTagStackCount(); + } + } + + /** + * Merge subtree buffer content together + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string compiled template code + */ + public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) + { + $code = ''; + foreach ($this->subtrees as $subtree) { + if ($code !== '') { + $code .= '.'; + } + if ($subtree instanceof Tag) { + $more_php = $subtree->assign_to_var($parser); + } else { + $more_php = $subtree->to_smarty_php($parser); + } + $code .= $more_php; + if (!$subtree instanceof DqContent) { + $parser->compiler->has_variable_string = true; + } + } + return $code; + } +} diff --git a/vendor/smarty/smarty/src/ParseTree/DqContent.php b/vendor/smarty/smarty/src/ParseTree/DqContent.php new file mode 100644 index 000000000..f0a4b0697 --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/DqContent.php @@ -0,0 +1,44 @@ +<?php + +namespace Smarty\ParseTree; +/** + * Smarty Internal Plugin Templateparser Parse Tree + * These are classes to build parse tree in the template parser + * + + + * @author Thue Kristensen + * @author Uwe Tews + */ + +/** + * Raw chars as part of a double-quoted string. + * + + + * @ignore + */ +class DqContent extends Base +{ + /** + * Create parse tree buffer with string content + * + * @param string $data string section + */ + public function __construct($data) + { + $this->data = $data; + } + + /** + * Return content as double-quoted string + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string doubled quoted string + */ + public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) + { + return '"' . $this->data . '"'; + } +} diff --git a/vendor/smarty/smarty/src/ParseTree/Tag.php b/vendor/smarty/smarty/src/ParseTree/Tag.php new file mode 100644 index 000000000..05237f2de --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/Tag.php @@ -0,0 +1,70 @@ +<?php + +namespace Smarty\ParseTree; + +/** + * Smarty Internal Plugin Templateparser Parse Tree + * These are classes to build parse tree in the template parser + * + + + * @author Thue Kristensen + * @author Uwe Tews + */ + +/** + * A complete smarty tag. + * + + + * @ignore + */ +class Tag extends Base +{ + /** + * Saved block nesting level + * + * @var int + */ + public $saved_block_nesting; + + /** + * Create parse tree buffer for Smarty tag + * + * @param \Smarty\Parser\TemplateParser $parser parser object + * @param string $data content + */ + public function __construct(\Smarty\Parser\TemplateParser $parser, $data) + { + $this->data = $data; + $this->saved_block_nesting = $parser->block_nesting_level; + } + + /** + * Return buffer content + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string content + */ + public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) + { + return $this->data; + } + + /** + * Return complied code that loads the evaluated output of buffer content into a temporary variable + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string template code + */ + public function assign_to_var(\Smarty\Parser\TemplateParser $parser) + { + $var = $parser->compiler->getNewPrefixVariable(); + $tmp = $parser->compiler->appendCode('<?php ob_start();?>', (string) $this->data); + $tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>"); + $parser->compiler->appendPrefixCode($tmp); + return $var; + } +} diff --git a/vendor/smarty/smarty/src/ParseTree/Template.php b/vendor/smarty/smarty/src/ParseTree/Template.php new file mode 100644 index 000000000..ce802a0f4 --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/Template.php @@ -0,0 +1,172 @@ +<?php + +namespace Smarty\ParseTree; + +/** + * Smarty Internal Plugin Templateparser Parse Tree + * These are classes to build parse tree in the template parser + * + + + * @author Thue Kristensen + * @author Uwe Tews + */ + +/** + * Template element + * + + + * @ignore + */ +class Template extends Base +{ + /** + * Array of template elements + * + * @var array + */ + public $subtrees = array(); + + /** + * Create root of parse tree for template elements + */ + public function __construct() + { + } + + /** + * Append buffer to subtree + * + * @param \Smarty\Parser\TemplateParser $parser + * @param Base $subtree + */ + public function append_subtree(\Smarty\Parser\TemplateParser $parser, Base $subtree) + { + if (!empty($subtree->subtrees)) { + $this->subtrees = array_merge($this->subtrees, $subtree->subtrees); + } else { + if ($subtree->data !== '') { + $this->subtrees[] = $subtree; + } + } + } + + /** + * Append array to subtree + * + * @param \Smarty\Parser\TemplateParser $parser + * @param Base[] $array + */ + public function append_array(\Smarty\Parser\TemplateParser $parser, $array = array()) + { + if (!empty($array)) { + $this->subtrees = array_merge($this->subtrees, (array)$array); + } + } + + /** + * Prepend array to subtree + * + * @param \Smarty\Parser\TemplateParser $parser + * @param Base[] $array + */ + public function prepend_array(\Smarty\Parser\TemplateParser $parser, $array = array()) + { + if (!empty($array)) { + $this->subtrees = array_merge((array)$array, $this->subtrees); + } + } + + /** + * Sanitize and merge subtree buffers together + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string template code content + */ + public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) + { + $code = ''; + + 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, (string) $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 = array(); + $currentMode = null; + $currentChunk = array(); + for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) { + + if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, array('textstripped', 'text', 'tag'))) { + continue; + } + + if ($this->subtrees[ $key ] instanceof Text + && $this->subtrees[ $key ]->isToBeStripped()) { + $newMode = 'textstripped'; + } elseif ($this->subtrees[ $key ] instanceof Text) { + $newMode = 'text'; + } elseif ($this->subtrees[ $key ] instanceof Tag) { + $newMode = 'tag'; + } else { + $newMode = 'other'; + } + + if ($newMode == $currentMode) { + $currentChunk[] = $this->subtrees[ $key ]; + } else { + $chunks[] = array( + 'mode' => $currentMode, + 'subtrees' => $currentChunk + ); + $currentMode = $newMode; + $currentChunk = array($this->subtrees[ $key ]); + } + } + if ($currentMode && $currentChunk) { + $chunks[] = array( + 'mode' => $currentMode, + 'subtrees' => $currentChunk + ); + } + return $chunks; + } +} diff --git a/vendor/smarty/smarty/src/ParseTree/Text.php b/vendor/smarty/smarty/src/ParseTree/Text.php new file mode 100644 index 000000000..e6131407c --- /dev/null +++ b/vendor/smarty/smarty/src/ParseTree/Text.php @@ -0,0 +1,59 @@ +<?php + +namespace Smarty\ParseTree; + +/** + * Smarty Internal Plugin Templateparser Parse Tree + * These are classes to build parse tree in the template parser + * + + + * @author Thue Kristensen + * @author Uwe Tews + * * + * template text + + + * @ignore + */ +class Text extends Base +{ + + /** + * Wether this section should be stripped on output to smarty php + * @var bool + */ + private $toBeStripped = false; + + /** + * Create template text buffer + * + * @param string $data text + * @param bool $toBeStripped wether this section should be stripped on output to smarty php + */ + public function __construct($data, $toBeStripped = false) + { + $this->data = $data; + $this->toBeStripped = $toBeStripped; + } + + /** + * Wether this section should be stripped on output to smarty php + * @return bool + */ + public function isToBeStripped() { + return $this->toBeStripped; + } + + /** + * Return buffer content + * + * @param \Smarty\Parser\TemplateParser $parser + * + * @return string text + */ + public function to_smarty_php(\Smarty\Parser\TemplateParser $parser) + { + return $this->data; + } +} |