From 4afab27bd8477735b6524f85e23470c2b480625e Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Wed, 25 Nov 2009 20:56:51 +0000 Subject: [PATCH] - {strip} tag functionality rewritten --- change_log.txt | 1 + .../smarty_internal_compile_strip.php | 59 -------------- .../smarty_internal_templatelexer.php | 80 +++++++++++++------ 3 files changed, 56 insertions(+), 84 deletions(-) delete mode 100644 libs/sysplugins/smarty_internal_compile_strip.php diff --git a/change_log.txt b/change_log.txt index b57c9fb6..7cfa5255 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,6 @@ 11/25/2009 - allow the following writing for boolean: true, TRUE, True, false, FALSE, False +- {strip} tag functionality rewritten 11/24/2009 - bugfix for $smarty->config_overwrite = false diff --git a/libs/sysplugins/smarty_internal_compile_strip.php b/libs/sysplugins/smarty_internal_compile_strip.php deleted file mode 100644 index a6b2a6fe..00000000 --- a/libs/sysplugins/smarty_internal_compile_strip.php +++ /dev/null @@ -1,59 +0,0 @@ -compiler = $compiler; - // check and get attributes - $_attr = $this->_get_attributes($args); - - $this->_open_tag('strip'); - - $_output = ""; - - return $_output; - } -} - -/** -* Smarty Internal Plugin Compile Stripclose Class -*/ -class Smarty_Internal_Compile_Stripclose extends Smarty_Internal_CompileBase { - /** - * Compiles code for the {/strip} tag - * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @return string compiled code - */ - public function compile($args, $compiler) - { - $this->compiler = $compiler; - // check and get attributes - $_attr = $this->_get_attributes($args); - - $saved_attr = $this->_close_tag(array('strip')); - - $_output = "\n"; - return $_output; - } -} -?> diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index 1dbdb027..6954a873 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -20,6 +20,7 @@ class Smarty_Internal_Templatelexer public $line; public $taglineno; public $state = 1; + public $strip = false; public $smarty_token_names = array ( // Text for parser error messages 'IDENTITY' => '===', 'NONEIDENTITY' => '!==', @@ -135,13 +136,16 @@ class Smarty_Internal_Templatelexer 10 => 0, 11 => 0, 12 => 0, - 13 => 2, - 16 => 0, + 13 => 0, + 14 => 0, + 15 => 0, + 16 => 2, + 19 => 0, ); if ($this->counter >= strlen($this->data)) { return false; // end of input } - $yy_global_pattern = "/^(\\{\\})|^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|^(<\\?xml)|^(<\\?php)|^(<\\?=)|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)/"; + $yy_global_pattern = "/^(\\{\\})|^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|^(<\\?xml)|^(<\\?php)|^(<\\?=)|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)/"; do { if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) { @@ -181,19 +185,22 @@ class Smarty_Internal_Templatelexer // skip this token continue; } else { $yy_yymore_patterns = array( - 1 => array(0, "^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|^(<\\?xml)|^(<\\?php)|^(<\\?=)|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 2 => array(1, "^(<\\?xml)|^(<\\?php)|^(<\\?=)|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 4 => array(1, "^(<\\?php)|^(<\\?=)|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 5 => array(1, "^(<\\?=)|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 6 => array(1, "^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 7 => array(1, "^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 8 => array(1, "^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 9 => array(1, "^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 10 => array(1, "^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 11 => array(1, "^(".$this->ldel.")|^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 12 => array(1, "^(([\S\s]*?)(".$this->ldel."|<\\?))|^([\S\s]+)"), - 13 => array(3, "^([\S\s]+)"), - 16 => array(3, ""), + 1 => array(0, "^(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|^(<\\?xml)|^(<\\?php)|^(<\\?=)|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 2 => array(1, "^(<\\?xml)|^(<\\?php)|^(<\\?=)|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 4 => array(1, "^(<\\?php)|^(<\\?=)|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 5 => array(1, "^(<\\?=)|^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 6 => array(1, "^([\t ]*[\r\n]+[\t ]*)|^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 7 => array(1, "^(".$this->ldel."strip".$this->rdel.")|^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 8 => array(1, "^(".$this->ldel."\/strip".$this->rdel.")|^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 9 => array(1, "^(".$this->ldel."literal".$this->rdel.")|^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 10 => array(1, "^(".$this->ldel."\/literal".$this->rdel.")|^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 11 => array(1, "^(".$this->ldel."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 12 => array(1, "^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 13 => array(1, "^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 14 => array(1, "^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 15 => array(1, "^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"), + 16 => array(3, "^([\S\s]+)"), + 19 => array(3, ""), ); // yymore is needed @@ -281,17 +288,38 @@ class Smarty_Internal_Templatelexer function yy_r1_7($yy_subpatterns) { - $this->yypushstate(self::LITERAL); - return true; + if ($this->strip) { + return false; + } else { + $this->token = Smarty_Internal_Templateparser::TP_OTHER; + } } function yy_r1_8($yy_subpatterns) { - return false; // unexspected here just ignore + $this->strip = true; + return false; } function yy_r1_9($yy_subpatterns) { + $this->strip = false; + return false; + } + function yy_r1_10($yy_subpatterns) + { + + $this->yypushstate(self::LITERAL); + return true; + } + function yy_r1_11($yy_subpatterns) + { + + return false; // unexspected here just ignore + } + function yy_r1_12($yy_subpatterns) + { + if ($this->smarty->auto_literal) { $this->token = Smarty_Internal_Templateparser::TP_OTHER; } else { @@ -300,7 +328,7 @@ class Smarty_Internal_Templatelexer $this->taglineno = $this->line; } } - function yy_r1_10($yy_subpatterns) + function yy_r1_13($yy_subpatterns) { if ($this->smarty->auto_literal) { @@ -311,34 +339,36 @@ class Smarty_Internal_Templatelexer $this->taglineno = $this->line; } } - function yy_r1_11($yy_subpatterns) + function yy_r1_14($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->yypushstate(self::SMARTY); $this->taglineno = $this->line; } - function yy_r1_12($yy_subpatterns) + function yy_r1_15($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->yypushstate(self::SMARTY); $this->taglineno = $this->line; } - function yy_r1_13($yy_subpatterns) + function yy_r1_16($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_OTHER; if (substr($this->value,-2) == 'value = substr($this->value,0,-2); - } else { + } elseif (substr($this->value,-strlen($this->smarty->left_delimiter)) == $this->smarty->left_delimiter){ $this->value = substr($this->value,0,-strlen($this->smarty->left_delimiter)); + } else { + $this->value = rtrim($this->value); } if (strlen($this->value) == 0) { return true; // rescan } } - function yy_r1_16($yy_subpatterns) + function yy_r1_19($yy_subpatterns) { $this->token = Smarty_Internal_Templateparser::TP_OTHER;