mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
parser: add support for template prefix and postfix code
This commit is contained in:
@@ -31,58 +31,68 @@ class Smarty_Internal_Templateparser
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $successful = true;
|
public $successful = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return value
|
* return value
|
||||||
*
|
*
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
public $retvalue = 0;
|
public $retvalue = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* counter for prefix code
|
* counter for prefix code
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public static $prefix_number = 0;
|
public static $prefix_number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var
|
* @var
|
||||||
*/
|
*/
|
||||||
public $yymajor;
|
public $yymajor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* last index of array variable
|
* last index of array variable
|
||||||
*
|
*
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
public $last_index;
|
public $last_index;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* last variable name
|
* last variable name
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $last_variable;
|
public $last_variable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* root parse tree buffer
|
* root parse tree buffer
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_ParseTree
|
* @var Smarty_Internal_ParseTree
|
||||||
*/
|
*/
|
||||||
public $root_buffer;
|
public $root_buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* current parse tree object
|
* current parse tree object
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_ParseTree
|
* @var Smarty_Internal_ParseTree
|
||||||
*/
|
*/
|
||||||
public $current_buffer;
|
public $current_buffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lexer object
|
* lexer object
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_Templatelexer
|
* @var Smarty_Internal_Templatelexer
|
||||||
*/
|
*/
|
||||||
public $lex;
|
public $lex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* internal error flag
|
* internal error flag
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $internalError = false;
|
private $internalError = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {strip} status
|
* {strip} status
|
||||||
*
|
*
|
||||||
@@ -95,18 +105,21 @@ class Smarty_Internal_Templateparser
|
|||||||
* @var Smarty_Internal_TemplateCompilerBase
|
* @var Smarty_Internal_TemplateCompilerBase
|
||||||
*/
|
*/
|
||||||
public $compiler = null;
|
public $compiler = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* smarty object
|
* smarty object
|
||||||
*
|
*
|
||||||
* @var Smarty
|
* @var Smarty
|
||||||
*/
|
*/
|
||||||
public $smarty = null;
|
public $smarty = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* template object
|
* template object
|
||||||
*
|
*
|
||||||
* @var Smarty_Internal_Template
|
* @var Smarty_Internal_Template
|
||||||
*/
|
*/
|
||||||
public $template = null;
|
public $template = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* block nesting level
|
* block nesting level
|
||||||
*
|
*
|
||||||
@@ -121,6 +134,20 @@ class Smarty_Internal_Templateparser
|
|||||||
*/
|
*/
|
||||||
public $security = null;
|
public $security = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* template prefix array
|
||||||
|
*
|
||||||
|
* @var \Smarty_Internal_ParseTree[]
|
||||||
|
*/
|
||||||
|
public $template_prefix = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* security object
|
||||||
|
*
|
||||||
|
* @var \Smarty_Internal_ParseTree[]
|
||||||
|
*/
|
||||||
|
public $template_postfix = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*
|
*
|
||||||
@@ -196,7 +223,8 @@ class Smarty_Internal_Templateparser
|
|||||||
// complete template
|
// complete template
|
||||||
//
|
//
|
||||||
start(res) ::= template. {
|
start(res) ::= template. {
|
||||||
$this->compiler->processInheritance($this);
|
$this->root_buffer->prepend_array($this, $this->template_prefix);
|
||||||
|
$this->root_buffer->append_array($this, $this->template_postfix);
|
||||||
res = $this->root_buffer->to_smarty_php($this);
|
res = $this->root_buffer->to_smarty_php($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -794,7 +822,7 @@ value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
|
|||||||
self::$prefix_number++;
|
self::$prefix_number++;
|
||||||
if (vi['var'] == '\'smarty\'') {
|
if (vi['var'] == '\'smarty\'') {
|
||||||
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.' = '. $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>';
|
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.' = '. $this->compiler->compileTag('private_special_variable',array(),vi['smarty_internal_index']).';?>';
|
||||||
} else {
|
} else {
|
||||||
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.' = '. $this->compiler->compileVariable(vi['var']).vi['smarty_internal_index'].';?>';
|
$this->compiler->prefix_code[] = '<?php $_tmp'.self::$prefix_number.' = '. $this->compiler->compileVariable(vi['var']).vi['smarty_internal_index'].';?>';
|
||||||
}
|
}
|
||||||
res = '$_tmp'.self::$prefix_number.'::'.r[0].r[1];
|
res = '$_tmp'.self::$prefix_number.'::'.r[0].r[1];
|
||||||
@@ -802,7 +830,7 @@ value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
|
|||||||
|
|
||||||
// Smarty tag
|
// Smarty tag
|
||||||
value(res) ::= smartytag(st). {
|
value(res) ::= smartytag(st). {
|
||||||
self::$prefix_number++;
|
self::$prefix_number++;
|
||||||
$tmp = $this->compiler->appendCode('<?php ob_start();?>', st);
|
$tmp = $this->compiler->appendCode('<?php ob_start();?>', st);
|
||||||
$this->compiler->prefix_code[] = $this->compiler->appendCode($tmp, '<?php $_tmp'.self::$prefix_number.'=ob_get_clean();?>');
|
$this->compiler->prefix_code[] = $this->compiler->appendCode($tmp, '<?php $_tmp'.self::$prefix_number.'=ob_get_clean();?>');
|
||||||
res = '$_tmp'.self::$prefix_number;
|
res = '$_tmp'.self::$prefix_number;
|
||||||
@@ -839,11 +867,7 @@ ns1(res) ::= ID(i). {
|
|||||||
|
|
||||||
ns1(res) ::= NAMESPACE(i). {
|
ns1(res) ::= NAMESPACE(i). {
|
||||||
res = i;
|
res = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ns1(res) ::= variable(v). {
|
|
||||||
// res = v;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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
|
* Sanitize and merge subtree buffers together
|
||||||
*
|
*
|
||||||
@@ -75,7 +101,8 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
|||||||
if ($subtree == '') {
|
if ($subtree == '') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n", $subtree);
|
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n",
|
||||||
|
$subtree);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
|
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user