mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- {strip} tag functionality rewritten
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
11/25/2009
|
11/25/2009
|
||||||
- allow the following writing for boolean: true, TRUE, True, false, FALSE, False
|
- allow the following writing for boolean: true, TRUE, True, false, FALSE, False
|
||||||
|
- {strip} tag functionality rewritten
|
||||||
|
|
||||||
11/24/2009
|
11/24/2009
|
||||||
- bugfix for $smarty->config_overwrite = false
|
- bugfix for $smarty->config_overwrite = false
|
||||||
|
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile Strip
|
|
||||||
*
|
|
||||||
* Compiles the {strip} {/strip} tags
|
|
||||||
*
|
|
||||||
* @package Smarty
|
|
||||||
* @subpackage Compiler
|
|
||||||
* @author Uwe Tews
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Smarty Internal Plugin Compile Strip Class
|
|
||||||
*/
|
|
||||||
class Smarty_Internal_Compile_Strip 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);
|
|
||||||
|
|
||||||
$this->_open_tag('strip');
|
|
||||||
|
|
||||||
$_output = "<?php ob_start(); ?>";
|
|
||||||
|
|
||||||
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 = "<?php echo preg_replace('![\t ]*[\r\n]+[\t ]*!', '', ob_get_clean()); ?>\n";
|
|
||||||
return $_output;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@@ -20,6 +20,7 @@ class Smarty_Internal_Templatelexer
|
|||||||
public $line;
|
public $line;
|
||||||
public $taglineno;
|
public $taglineno;
|
||||||
public $state = 1;
|
public $state = 1;
|
||||||
|
public $strip = false;
|
||||||
public $smarty_token_names = array ( // Text for parser error messages
|
public $smarty_token_names = array ( // Text for parser error messages
|
||||||
'IDENTITY' => '===',
|
'IDENTITY' => '===',
|
||||||
'NONEIDENTITY' => '!==',
|
'NONEIDENTITY' => '!==',
|
||||||
@@ -135,13 +136,16 @@ class Smarty_Internal_Templatelexer
|
|||||||
10 => 0,
|
10 => 0,
|
||||||
11 => 0,
|
11 => 0,
|
||||||
12 => 0,
|
12 => 0,
|
||||||
13 => 2,
|
13 => 0,
|
||||||
16 => 0,
|
14 => 0,
|
||||||
|
15 => 0,
|
||||||
|
16 => 2,
|
||||||
|
19 => 0,
|
||||||
);
|
);
|
||||||
if ($this->counter >= strlen($this->data)) {
|
if ($this->counter >= strlen($this->data)) {
|
||||||
return false; // end of input
|
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 {
|
do {
|
||||||
if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
|
if (preg_match($yy_global_pattern, substr($this->data, $this->counter), $yymatches)) {
|
||||||
@@ -181,19 +185,22 @@ class Smarty_Internal_Templatelexer
|
|||||||
// skip this token
|
// skip this token
|
||||||
continue;
|
continue;
|
||||||
} else { $yy_yymore_patterns = array(
|
} 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]+)"),
|
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)|^(<\\?=)|^(".$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)|^(<\\?=)|^([\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)|^(<\\?=)|^(".$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)|^(<\\?=)|^([\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, "^(<\\?=)|^(".$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, "^(<\\?=)|^([\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, "^(".$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, "^([\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."\/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."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."\\s{1,}\/)|^(".$this->ldel."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$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."\\s{1,})|^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$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."\/)|^(".$this->ldel.")|^(([\S\s]*?)(".$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\s]*?)(".$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, "^(([\S\s]*?)(".$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(3, "^([\S\s]+)"),
|
13 => array(1, "^(".$this->ldel."\/)|^(".$this->ldel.")|^(([\S\s]*?)([\t ]*[\r\n]+[\t ]*|".$this->ldel."|<\\?))|^([\S\s]+)"),
|
||||||
16 => array(3, ""),
|
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
|
// yymore is needed
|
||||||
@@ -281,17 +288,38 @@ class Smarty_Internal_Templatelexer
|
|||||||
function yy_r1_7($yy_subpatterns)
|
function yy_r1_7($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->yypushstate(self::LITERAL);
|
if ($this->strip) {
|
||||||
return true;
|
return false;
|
||||||
|
} else {
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function yy_r1_8($yy_subpatterns)
|
function yy_r1_8($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
return false; // unexspected here just ignore
|
$this->strip = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
function yy_r1_9($yy_subpatterns)
|
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) {
|
if ($this->smarty->auto_literal) {
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||||
} else {
|
} else {
|
||||||
@@ -300,7 +328,7 @@ class Smarty_Internal_Templatelexer
|
|||||||
$this->taglineno = $this->line;
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function yy_r1_10($yy_subpatterns)
|
function yy_r1_13($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->smarty->auto_literal) {
|
if ($this->smarty->auto_literal) {
|
||||||
@@ -311,34 +339,36 @@ class Smarty_Internal_Templatelexer
|
|||||||
$this->taglineno = $this->line;
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function yy_r1_11($yy_subpatterns)
|
function yy_r1_14($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
|
$this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
|
||||||
$this->yypushstate(self::SMARTY);
|
$this->yypushstate(self::SMARTY);
|
||||||
$this->taglineno = $this->line;
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
function yy_r1_12($yy_subpatterns)
|
function yy_r1_15($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_LDEL;
|
$this->token = Smarty_Internal_Templateparser::TP_LDEL;
|
||||||
$this->yypushstate(self::SMARTY);
|
$this->yypushstate(self::SMARTY);
|
||||||
$this->taglineno = $this->line;
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
function yy_r1_13($yy_subpatterns)
|
function yy_r1_16($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||||
if (substr($this->value,-2) == '<?') {
|
if (substr($this->value,-2) == '<?') {
|
||||||
$this->value = substr($this->value,0,-2);
|
$this->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));
|
$this->value = substr($this->value,0,-strlen($this->smarty->left_delimiter));
|
||||||
|
} else {
|
||||||
|
$this->value = rtrim($this->value);
|
||||||
}
|
}
|
||||||
if (strlen($this->value) == 0) {
|
if (strlen($this->value) == 0) {
|
||||||
return true; // rescan
|
return true; // rescan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function yy_r1_16($yy_subpatterns)
|
function yy_r1_19($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
$this->token = Smarty_Internal_Templateparser::TP_OTHER;
|
||||||
|
Reference in New Issue
Block a user