mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- optimization move <?php ?> handling from parser to new compiler module
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
===== 3.1.22-dev ===== (xx.xx.2015)
|
===== 3.1.22-dev ===== (xx.xx.2015)
|
||||||
05.05.2015
|
05.05.2015
|
||||||
- optimization on cache update when main template is modified
|
- optimization on cache update when main template is modified
|
||||||
|
- optimization move <?php ?> handling from parser to new compiler module
|
||||||
|
|
||||||
05.05.2015
|
05.05.2015
|
||||||
- bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23
|
- bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23
|
||||||
|
@@ -61,6 +61,12 @@ class Smarty_Internal_Templatelexer
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $is_phpScript = false;
|
public $is_phpScript = false;
|
||||||
|
/**
|
||||||
|
* php code type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $phpType = '';
|
||||||
/**
|
/**
|
||||||
* escaped left delimiter
|
* escaped left delimiter
|
||||||
*
|
*
|
||||||
@@ -227,11 +233,12 @@ class Smarty_Internal_Templatelexer
|
|||||||
namespace = /([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+/
|
namespace = /([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+/
|
||||||
all = /[\S\s]+/
|
all = /[\S\s]+/
|
||||||
emptyjava = /\{\}/
|
emptyjava = /\{\}/
|
||||||
phpstarttag = /(<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)|(<\?(?:php\w+|=|[a-zA-Z]+)?)/
|
xmltag = /<\?xml\s+([\S\s]*?)\?>/
|
||||||
phpendtag = /\?>/
|
php = /(<\?(?:php\s+|=)?)((('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*")|(\/\*(.)*?\*\/)|.)*?)\?>/
|
||||||
phpendscript = /<\/script>/
|
phpscript = /<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>((('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*")|(\/\*(.)*?\*\/)|.)*?)<\/script>/
|
||||||
aspstarttag = /<%/
|
phptag = /(SMARTYldel\s*php\s*(.)*?SMARTYrdel((.)*?)SMARTYldel\s*\/php\s*SMARTYrdel)|(SMARTYldel\s*[\/]?php\s*(.)*?SMARTYrdel)/
|
||||||
aspendtag = /%>/
|
asp = /<%((('[^'\\]*(?:\\.[^'\\]*)*')|("[^"\\]*(?:\\.[^"\\]*)*")|(\/\*(.)*?\*\/)|.)*?)%>/
|
||||||
|
unmatched = /(<(\?(?:php\s+|=)?|(script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)|%))|\?>|%>/
|
||||||
slash = /\//
|
slash = /\//
|
||||||
ldel = /SMARTYldel\s*/
|
ldel = /SMARTYldel\s*/
|
||||||
rdel = /\s*SMARTYrdel/
|
rdel = /\s*SMARTYrdel/
|
||||||
@@ -372,6 +379,15 @@ class Smarty_Internal_Templatelexer
|
|||||||
$this->taglineno = $this->line;
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
phptag {
|
||||||
|
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||||
|
} else {
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
$this->phpType = 'tag';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
}
|
||||||
|
}
|
||||||
ldel slash {
|
ldel slash {
|
||||||
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||||
@@ -390,38 +406,36 @@ class Smarty_Internal_Templatelexer
|
|||||||
$this->taglineno = $this->line;
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
phpstarttag {
|
|
||||||
if (($script = strpos($this->value, '<s') === 0) || in_array($this->value, Array('<?', '<?=', '<?php'))) {
|
|
||||||
if ($script) {
|
|
||||||
$this->is_phpScript = true;
|
|
||||||
}
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
|
|
||||||
} elseif ($this->value == '<?xml') {
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
|
|
||||||
} else {
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
|
||||||
//$this->value = substr($this->value, 0, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
phpendtag {
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
|
|
||||||
}
|
|
||||||
phpendscript {
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
|
|
||||||
}
|
|
||||||
rdel {
|
rdel {
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||||
}
|
}
|
||||||
aspstarttag {
|
xmltag {
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
|
$this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
|
||||||
|
$this->taglineno = $this->line;
|
||||||
}
|
}
|
||||||
aspendtag {
|
asp {
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
|
$this->phpType = 'asp';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
php {
|
||||||
|
$this->phpType = 'php';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
phpscript {
|
||||||
|
$this->phpType = 'script';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
unmatched {
|
||||||
|
$this->phpType = 'unmatched';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
}
|
}
|
||||||
text {
|
text {
|
||||||
$phpEndScript = $this->is_phpScript ? '|<\\/script>' : '';
|
|
||||||
$to = strlen($this->data);
|
$to = strlen($this->data);
|
||||||
preg_match("/{$this->ldel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>{$phpEndScript}/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
|
preg_match("/{$this->ldel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
|
||||||
if (isset($match[0][1])) {
|
if (isset($match[0][1])) {
|
||||||
$to = $match[0][1];
|
$to = $match[0][1];
|
||||||
}
|
}
|
||||||
|
@@ -116,25 +116,15 @@ class Smarty_Internal_Templateparser
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $block_nesting_level = 0;
|
public $block_nesting_level = 0;
|
||||||
/**
|
|
||||||
* xml tag flag
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $is_xml = false;
|
|
||||||
/**
|
/**
|
||||||
* security object
|
* security object
|
||||||
*
|
*
|
||||||
* @var Smarty_Security
|
* @var Smarty_Security
|
||||||
*/
|
*/
|
||||||
private $security = null;
|
private $security = null;
|
||||||
/**
|
|
||||||
* asp enabled
|
/**
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $asp_tags = false;
|
|
||||||
/**
|
|
||||||
* PHP tag handling mode
|
* PHP tag handling mode
|
||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
@@ -160,7 +150,6 @@ class Smarty_Internal_Templateparser
|
|||||||
} else {
|
} else {
|
||||||
$this->php_handling = $this->smarty->php_handling;
|
$this->php_handling = $this->smarty->php_handling;
|
||||||
}
|
}
|
||||||
$this->asp_tags = (ini_get('asp_tags') != '0');
|
|
||||||
$this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template($this);
|
$this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,119 +241,25 @@ template_element(res)::= COMMENT(c). {
|
|||||||
template_element(res) ::= literal(l). {
|
template_element(res) ::= literal(l). {
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, l);
|
res = new Smarty_Internal_ParseTree_Text($this, l);
|
||||||
}
|
}
|
||||||
|
// php tags
|
||||||
// '<?php' | '<script language=php>' tag
|
template_element(res)::= PHP(o). {
|
||||||
template_element(res)::= PHPSTARTTAG(st). {
|
$code = $this->compiler->compileTag('private_php',array(array('code' => o), array('type' => $this->lex->phpType )),array());
|
||||||
if (strpos(st, '<s') === 0) {
|
if ($this->compiler->has_code && !empty($code)) {
|
||||||
$this->lex->is_phpScript = true;
|
$tmp =''; foreach ($this->compiler->prefix_code as $code) {$tmp.=$code;} $this->compiler->prefix_code=array();
|
||||||
}
|
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode($tmp.$code,true));
|
||||||
if ($this->php_handling == Smarty::PHP_PASSTHRU) {
|
|
||||||
if ($this->lex->is_phpScript) {
|
|
||||||
$s = addcslashes(st, "'");
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, $s);
|
|
||||||
} else {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
}
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars(st, ENT_QUOTES));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_ALLOW) {
|
|
||||||
if (!($this->smarty instanceof SmartyBC)) {
|
|
||||||
$this->compiler->trigger_template_error (self::Err3);
|
|
||||||
}
|
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('<?php ', true));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_REMOVE) {
|
|
||||||
res = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// '?>' tag
|
|
||||||
template_element(res)::= PHPENDTAG(st). {
|
|
||||||
if ($this->is_xml) {
|
|
||||||
$this->compiler->tag_nocache = true;
|
|
||||||
$this->is_xml = false;
|
|
||||||
$save = $this->template->has_nocache_code;
|
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode("<?php echo '?>';?>\n", $this->compiler, true));
|
|
||||||
$this->template->has_nocache_code = $save;
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_PASSTHRU) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars('?>', ENT_QUOTES));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_ALLOW) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('?>', true));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_REMOVE) {
|
|
||||||
res = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// '</script>' tag (only for PHP)
|
|
||||||
template_element(res)::= PHPENDSCRIPT(st). {
|
|
||||||
if (!$this->lex->is_phpScript) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
} else {
|
} else {
|
||||||
$this->lex->is_phpScript = false;
|
res = null;
|
||||||
if ($this->php_handling == Smarty::PHP_PASSTHRU) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars(st, ENT_QUOTES));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_ALLOW) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('?>', true));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_REMOVE) {
|
|
||||||
res = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// '<%' tag
|
|
||||||
template_element(res)::= ASPSTARTTAG(st). {
|
|
||||||
if ($this->php_handling == Smarty::PHP_PASSTHRU) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars(st, ENT_QUOTES));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_ALLOW) {
|
|
||||||
if ($this->asp_tags) {
|
|
||||||
if (!($this->smarty instanceof SmartyBC)) {
|
|
||||||
$this->compiler->trigger_template_error (self::Err3);
|
|
||||||
}
|
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('<%', true));
|
|
||||||
} else {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
}
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_REMOVE) {
|
|
||||||
if ($this->asp_tags) {
|
|
||||||
res = null;
|
|
||||||
} else {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// '%>' tag
|
|
||||||
template_element(res)::= ASPENDTAG(st). {
|
|
||||||
if ($this->php_handling == Smarty::PHP_PASSTHRU) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, htmlspecialchars('%>', ENT_QUOTES));
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_ALLOW) {
|
|
||||||
if ($this->asp_tags) {
|
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode('%>', true));
|
|
||||||
} else {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
}
|
|
||||||
} elseif ($this->php_handling == Smarty::PHP_REMOVE) {
|
|
||||||
if ($this->asp_tags) {
|
|
||||||
res = null;
|
|
||||||
} else {
|
|
||||||
res = new Smarty_Internal_ParseTree_Text($this, st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// XML tag
|
// XML tag
|
||||||
template_element(res)::= XMLTAG. {
|
template_element(res)::= XMLTAG(x). {
|
||||||
$this->compiler->tag_nocache = true;
|
$this->compiler->tag_nocache = true;
|
||||||
$this->is_xml = true;
|
$xml = x;
|
||||||
$save = $this->template->has_nocache_code;
|
$save = $this->template->has_nocache_code;
|
||||||
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode("<?php echo '<?xml';?>", $this->compiler, true));
|
res = new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode("<?php echo '{$xml}';?>", $this->compiler, true));
|
||||||
$this->template->has_nocache_code = $save;
|
$this->template->has_nocache_code = $save;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.22-dev/25';
|
const SMARTY_VERSION = '3.1.22-dev/26';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -52,8 +52,6 @@ class SmartyBC extends Smarty
|
|||||||
public function __construct(array $options = array())
|
public function __construct(array $options = array())
|
||||||
{
|
{
|
||||||
parent::__construct($options);
|
parent::__construct($options);
|
||||||
// register {php} tag
|
|
||||||
$this->registerPlugin('block', 'php', 'smarty_php_tag');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,10 +113,10 @@ class SmartyBC extends Smarty
|
|||||||
/**
|
/**
|
||||||
* Registers object to be used in templates
|
* Registers object to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $object name of template object
|
* @param string $object name of template object
|
||||||
* @param object $object_impl the referenced PHP object to register
|
* @param object $object_impl the referenced PHP object to register
|
||||||
* @param array $allowed list of allowed methods (empty = all)
|
* @param array $allowed list of allowed methods (empty = all)
|
||||||
* @param boolean $smarty_args smarty argument format, else traditional
|
* @param boolean $smarty_args smarty argument format, else traditional
|
||||||
* @param array $block_methods list of methods that are block format
|
* @param array $block_methods list of methods that are block format
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
@@ -448,20 +446,3 @@ class SmartyBC extends Smarty
|
|||||||
trigger_error("Smarty error: $error_msg", $error_type);
|
trigger_error("Smarty error: $error_msg", $error_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Smarty {php}{/php} block function
|
|
||||||
*
|
|
||||||
* @param array $params parameter list
|
|
||||||
* @param string $content contents of the block
|
|
||||||
* @param object $template template object
|
|
||||||
* @param boolean &$repeat repeat flag
|
|
||||||
*
|
|
||||||
* @return string content re-formatted
|
|
||||||
*/
|
|
||||||
function smarty_php_tag($params, $content, $template, &$repeat)
|
|
||||||
{
|
|
||||||
eval($content);
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
92
libs/sysplugins/smarty_internal_compile_private_php.php
Normal file
92
libs/sysplugins/smarty_internal_compile_private_php.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Smarty Internal Plugin Compile Print Expression
|
||||||
|
* Compiles any tag which will output an expression or variable
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage Compiler
|
||||||
|
* @author Uwe Tews
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Internal Plugin Compile Print Expression Class
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage Compiler
|
||||||
|
*/
|
||||||
|
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Attribute definition: Overwrites base class.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @see Smarty_Internal_CompileBase
|
||||||
|
*/
|
||||||
|
public $required_attributes = array('code', 'type');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles code for generating output from any expression
|
||||||
|
*
|
||||||
|
* @param array $args array with attributes from parser
|
||||||
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||||
|
* @param array $parameter array with compilation parameter
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws \SmartyException
|
||||||
|
*/
|
||||||
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||||
|
{
|
||||||
|
// check and get attributes
|
||||||
|
$_attr = $this->getAttributes($compiler, $args);
|
||||||
|
$compiler->has_code = false;
|
||||||
|
$this->asp_tags = (ini_get('asp_tags') != '0');
|
||||||
|
if ($_attr['type'] == 'tag' && !($compiler->smarty instanceof SmartyBC)) {
|
||||||
|
$compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
if ($_attr['type'] != 'tag') {
|
||||||
|
if (isset($compiler->smarty->security_policy)) {
|
||||||
|
$this->php_handling = $compiler->smarty->security_policy->php_handling;
|
||||||
|
} else {
|
||||||
|
$this->php_handling = $compiler->smarty->php_handling;
|
||||||
|
}
|
||||||
|
if ($this->php_handling == Smarty::PHP_REMOVE) {
|
||||||
|
$output = preg_replace(array('#^(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)#', '#(\?>)|(%>)|(<\/script>)$#'), '', $_attr['code']);
|
||||||
|
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output));
|
||||||
|
return '';
|
||||||
|
} elseif ($this->php_handling == Smarty::PHP_QUOTE) {
|
||||||
|
$output = preg_replace_callback(array('#^(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)#', '#(\?>)|(%>)|(<\/script>)$#'), function ($match) {return htmlspecialchars($match[0], ENT_QUOTES);}, $_attr['code']);
|
||||||
|
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output));
|
||||||
|
return '';
|
||||||
|
} elseif ($this->php_handling == Smarty::PHP_PASSTHRU || ($_attr['type'] == 'asp' && !$this->asp_tags) || $_attr['type'] == 'unmatched') {
|
||||||
|
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $_attr['code']));
|
||||||
|
return '';
|
||||||
|
} elseif ($this->php_handling == Smarty::PHP_ALLOW) {
|
||||||
|
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||||
|
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
$compiler->has_code = true;
|
||||||
|
return $_attr['code'];
|
||||||
|
} else {
|
||||||
|
$compiler->trigger_template_error('Illegal $smarty->php_handling value', $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$compiler->has_code = true;
|
||||||
|
$ldel = preg_quote($compiler->smarty->left_delimiter, '#');
|
||||||
|
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
|
||||||
|
if (!preg_match("#{$ldel}\\s*/\\s*php\\s*{$rdel}$#", $_attr['code'], $match)) {
|
||||||
|
$compiler->trigger_template_error('Missing {/php} closing tag', $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
if (!preg_match("#^({$ldel}\\s*php\\s*)((.)*?)({$rdel})#", $_attr['code'], $match)) {
|
||||||
|
$compiler->trigger_template_error('Missing {php} open tag', $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
if (!empty($match[2])) {
|
||||||
|
if ('nocache' == trim($match[2])) {
|
||||||
|
$compiler->tag_nocache = true;
|
||||||
|
} else {
|
||||||
|
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", $compiler->lex->taglineno);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -19,6 +19,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Smarty object
|
* Smarty object
|
||||||
|
*
|
||||||
* @var Smarty
|
* @var Smarty
|
||||||
*/
|
*/
|
||||||
public $smarty = null;
|
public $smarty = null;
|
||||||
@@ -234,12 +235,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag true when tag is compiled as nocache
|
* Flag true when tag is compiled as nocache
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $tag_nocache = false;
|
public $tag_nocache = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag to restart parsing
|
* Flag to restart parsing
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $abort_and_recompile = false;
|
public $abort_and_recompile = false;
|
||||||
@@ -253,18 +256,28 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Prefix code stack
|
* Prefix code stack
|
||||||
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $prefixCodeStack = array();
|
public $prefixCodeStack = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag has compiled code
|
* Tag has compiled code
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $has_code = false;
|
public $has_code = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A variable string was compiled
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $has_variable_string = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag creates output
|
* Tag creates output
|
||||||
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $has_output = false;
|
public $has_output = false;
|
||||||
@@ -296,9 +309,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
/**
|
/**
|
||||||
* Method to compile a Smarty template
|
* Method to compile a Smarty template
|
||||||
*
|
*
|
||||||
* @param Smarty_Internal_Template $template template object to compile
|
* @param Smarty_Internal_Template $template template object to compile
|
||||||
* @param bool $nocache true is shall be compiled in nocache mode
|
* @param bool $nocache true is shall be compiled in nocache mode
|
||||||
* @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler
|
* @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler
|
||||||
*
|
*
|
||||||
* @return bool true if compiling succeeded, false if it failed
|
* @return bool true if compiling succeeded, false if it failed
|
||||||
*/
|
*/
|
||||||
|
@@ -61,6 +61,12 @@ class Smarty_Internal_Templatelexer
|
|||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $is_phpScript = false;
|
public $is_phpScript = false;
|
||||||
|
/**
|
||||||
|
* php code type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $phpType = '';
|
||||||
/**
|
/**
|
||||||
* escaped left delimiter
|
* escaped left delimiter
|
||||||
*
|
*
|
||||||
@@ -265,20 +271,21 @@ class Smarty_Internal_Templatelexer
|
|||||||
9 => 0,
|
9 => 0,
|
||||||
10 => 0,
|
10 => 0,
|
||||||
11 => 0,
|
11 => 0,
|
||||||
12 => 0,
|
12 => 6,
|
||||||
13 => 0,
|
|
||||||
14 => 2,
|
|
||||||
17 => 0,
|
|
||||||
18 => 0,
|
|
||||||
19 => 0,
|
19 => 0,
|
||||||
20 => 0,
|
20 => 0,
|
||||||
21 => 0,
|
21 => 0,
|
||||||
22 => 0,
|
22 => 1,
|
||||||
|
24 => 6,
|
||||||
|
31 => 7,
|
||||||
|
39 => 6,
|
||||||
|
46 => 3,
|
||||||
|
50 => 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 = "/\G(\\{\\})|\G(" . $this->ldel . "\\*([\S\s]*?)\\*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G((<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|(<\\?(?:php\\w+|=|[a-zA-Z]+)?))|\G(\\?>)|\G(<\/script>)|\G(\\s*" . $this->rdel . ")|\G(<%)|\G(%>)|\G([\S\s])/iS";
|
$yy_global_pattern = "/\G(\\{\\})|\G(" . $this->ldel . "\\*([\S\s]*?)\\*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G((" . $this->ldel . "\\s*php\\s*(.)*?" . $this->rdel . "((.)*?)" . $this->ldel . "\\s*\/php\\s*" . $this->rdel . ")|(" . $this->ldel . "\\s*[\/]?php\\s*(.)*?" . $this->rdel . "))|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel . ")|\G(<\\?xml\\s+([\S\s]*?)\\?>)|\G(<%((('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")|(\/\\*(.)*?\\*\/)|.)*?)%>)|\G((<\\?(?:php\\s+|=)?)((('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")|(\/\\*(.)*?\\*\/)|.)*?)\\?>)|\G(<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>((('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")|(\/\\*(.)*?\\*\/)|.)*?)<\/script>)|\G((<(\\?(?:php\\s+|=)?|(script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|%))|\\?>|%>)|\G([\S\s])/iS";
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
|
if (preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) {
|
||||||
@@ -420,6 +427,18 @@ class Smarty_Internal_Templatelexer
|
|||||||
}
|
}
|
||||||
|
|
||||||
function yy_r1_12($yy_subpatterns)
|
function yy_r1_12($yy_subpatterns)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||||
|
} else {
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
$this->phpType = 'tag';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function yy_r1_19($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
||||||
@@ -431,7 +450,7 @@ class Smarty_Internal_Templatelexer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function yy_r1_13($yy_subpatterns)
|
function yy_r1_20($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) {
|
||||||
@@ -443,58 +462,56 @@ class Smarty_Internal_Templatelexer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function yy_r1_14($yy_subpatterns)
|
function yy_r1_21($yy_subpatterns)
|
||||||
{
|
|
||||||
|
|
||||||
if (($script = strpos($this->value, '<s') === 0) || in_array($this->value, Array('<?', '<?=', '<?php'))) {
|
|
||||||
if ($script) {
|
|
||||||
$this->is_phpScript = true;
|
|
||||||
}
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG;
|
|
||||||
} elseif ($this->value == '<?xml') {
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
|
|
||||||
} else {
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
|
||||||
//$this->value = substr($this->value, 0, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function yy_r1_17($yy_subpatterns)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
function yy_r1_18($yy_subpatterns)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_PHPENDSCRIPT;
|
|
||||||
}
|
|
||||||
|
|
||||||
function yy_r1_19($yy_subpatterns)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
function yy_r1_20($yy_subpatterns)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
function yy_r1_21($yy_subpatterns)
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
function yy_r1_22($yy_subpatterns)
|
function yy_r1_22($yy_subpatterns)
|
||||||
{
|
{
|
||||||
|
|
||||||
$phpEndScript = $this->is_phpScript ? '|<\\/script>' : '';
|
$this->token = Smarty_Internal_Templateparser::TP_XMLTAG;
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
}
|
||||||
|
|
||||||
|
function yy_r1_24($yy_subpatterns)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->phpType = 'asp';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
function yy_r1_31($yy_subpatterns)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->phpType = 'php';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
function yy_r1_39($yy_subpatterns)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->phpType = 'script';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
function yy_r1_46($yy_subpatterns)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->phpType = 'unmatched';
|
||||||
|
$this->taglineno = $this->line;
|
||||||
|
$this->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||||
|
}
|
||||||
|
|
||||||
|
function yy_r1_50($yy_subpatterns)
|
||||||
|
{
|
||||||
|
|
||||||
$to = strlen($this->data);
|
$to = strlen($this->data);
|
||||||
preg_match("/{$this->ldel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>{$phpEndScript}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
|
preg_match("/{$this->ldel}|<\?|<%|\?>|%>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter);
|
||||||
if (isset($match[0][1])) {
|
if (isset($match[0][1])) {
|
||||||
$to = $match[0][1];
|
$to = $match[0][1];
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user