- avoid possible circular object referances caused by parser/lexer objects

This commit is contained in:
Uwe Tews
2015-08-06 01:19:11 +02:00
parent ca969fe663
commit e1cc514a68
47 changed files with 674 additions and 492 deletions

View File

@@ -1,4 +1,7 @@
 ===== 3.1.28-dev===== (xx.xx.2015)  ===== 3.1.28-dev===== (xx.xx.2015)
06.08.2015
- avoid possible circular object referances caused by parser/lexer objects
03.08.2015 03.08.2015
- rework clear cache methods - rework clear cache methods
- bugfix compileAllConfig() was broken since 3.1.22 because of the changes in config file processing - bugfix compileAllConfig() was broken since 3.1.22 because of the changes in config file processing

View File

@@ -95,7 +95,7 @@ class Smarty_Internal_Configfilelexer
/** /**
* storage for assembled token patterns * storage for assembled token patterns
* *
* @var sring * @var string
*/ */
private $yy_global_pattern1 = null; private $yy_global_pattern1 = null;
private $yy_global_pattern2 = null; private $yy_global_pattern2 = null;

View File

@@ -361,7 +361,7 @@ class Smarty_Internal_Templatelexer
} }
text { text {
$to = strlen($this->data); $to = strlen($this->data);
preg_match("~($this->ldel)|([<]script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*[>])|([<][?])|([<][%])|([?][>])|([%][>])~i",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); preg_match("~($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*[\"']?\s*php\s*[\"']?\s*>)|([?][>])|([%][>])~i",$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];
} }

View File

@@ -79,7 +79,7 @@ class Smarty_Internal_Templateparser
* *
* @var Smarty_Internal_Templatelexer * @var Smarty_Internal_Templatelexer
*/ */
private $lex; public $lex;
/** /**
* internal error flag * internal error flag
* *
@@ -122,7 +122,7 @@ class Smarty_Internal_Templateparser
* *
* @var Smarty_Security * @var Smarty_Security
*/ */
private $security = null; public $security = null;
/** /**
* constructor * constructor
@@ -137,7 +137,7 @@ class Smarty_Internal_Templateparser
$this->template = $this->compiler->template; $this->template = $this->compiler->template;
$this->smarty = $this->template->smarty; $this->smarty = $this->template->smarty;
$this->security = isset($this->smarty->security_policy) ? $this->smarty->security_policy : false; $this->security = isset($this->smarty->security_policy) ? $this->smarty->security_policy : false;
$this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template($this); $this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template();
} }
/** /**
@@ -147,7 +147,7 @@ class Smarty_Internal_Templateparser
*/ */
public function insertPhpCode($code) public function insertPhpCode($code)
{ {
$this->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($this, $code)); $this->current_buffer->append_subtree($this, new Smarty_Internal_ParseTree_Tag($this, $code));
} }
/** /**
@@ -199,7 +199,7 @@ class Smarty_Internal_Templateparser
// complete template // complete template
// //
start(res) ::= template. { start(res) ::= template. {
res = $this->root_buffer->to_smarty_php(); res = $this->root_buffer->to_smarty_php($this);
} }
// //
@@ -208,7 +208,7 @@ start(res) ::= template. {
// single template element // single template element
template ::= template_element(e). { template ::= template_element(e). {
if (e != null) { if (e != null) {
$this->current_buffer->append_subtree(e); $this->current_buffer->append_subtree($this, e);
} }
} }
@@ -216,7 +216,7 @@ template ::= template_element(e). {
template ::= template template_element(e). { template ::= template template_element(e). {
if (e != null) { if (e != null) {
// because of possible code injection // because of possible code injection
$this->current_buffer->append_subtree(e); $this->current_buffer->append_subtree($this, e);
} }
} }
@@ -239,7 +239,7 @@ template_element(res)::= smartytag(st). {
// Literal // Literal
template_element(res) ::= literal(l). { template_element(res) ::= literal(l). {
res = new Smarty_Internal_ParseTree_Text($this, l); res = new Smarty_Internal_ParseTree_Text(l);
} }
// php tags // php tags
template_element(res)::= PHP(o). { template_element(res)::= PHP(o). {
@@ -1286,12 +1286,12 @@ doublequoted_with_quotes(res) ::= QUOTE QUOTE. {
} }
doublequoted_with_quotes(res) ::= QUOTE doublequoted(s) QUOTE. { doublequoted_with_quotes(res) ::= QUOTE doublequoted(s) QUOTE. {
res = s->to_smarty_php(); res = s->to_smarty_php($this);
} }
doublequoted(res) ::= doublequoted(o1) doublequotedcontent(o2). { doublequoted(res) ::= doublequoted(o1) doublequotedcontent(o2). {
o1->append_subtree(o2); o1->append_subtree($this, o2);
res = o1; res = o1;
} }
@@ -1300,23 +1300,23 @@ doublequoted(res) ::= doublequotedcontent(o). {
} }
doublequotedcontent(res) ::= BACKTICK variable(v) BACKTICK. { doublequotedcontent(res) ::= BACKTICK variable(v) BACKTICK. {
res = new Smarty_Internal_ParseTree_Code($this, '(string)'.v); res = new Smarty_Internal_ParseTree_Code('(string)'.v);
} }
doublequotedcontent(res) ::= BACKTICK expr(e) BACKTICK. { doublequotedcontent(res) ::= BACKTICK expr(e) BACKTICK. {
res = new Smarty_Internal_ParseTree_Code($this, '(string)'.e); res = new Smarty_Internal_ParseTree_Code('(string)'.e);
} }
doublequotedcontent(res) ::= DOLLARID(i). { doublequotedcontent(res) ::= DOLLARID(i). {
res = new Smarty_Internal_ParseTree_Code($this, '(string)$_smarty_tpl->tpl_vars[\''. substr(i,1) .'\']->value'); res = new Smarty_Internal_ParseTree_Code('(string)$_smarty_tpl->tpl_vars[\''. substr(i,1) .'\']->value');
} }
doublequotedcontent(res) ::= LDEL variable(v) RDEL. { doublequotedcontent(res) ::= LDEL variable(v) RDEL. {
res = new Smarty_Internal_ParseTree_Code($this, '(string)'.v); res = new Smarty_Internal_ParseTree_Code('(string)'.v);
} }
doublequotedcontent(res) ::= LDEL expr(e) RDEL. { doublequotedcontent(res) ::= LDEL expr(e) RDEL. {
res = new Smarty_Internal_ParseTree_Code($this, '(string)('.e.')'); res = new Smarty_Internal_ParseTree_Code('(string)('.e.')');
} }
doublequotedcontent(res) ::= smartytag(st). { doublequotedcontent(res) ::= smartytag(st). {
@@ -1324,6 +1324,6 @@ doublequotedcontent(res) ::= smartytag(st). {
} }
doublequotedcontent(res) ::= TEXT(o). { doublequotedcontent(res) ::= TEXT(o). {
res = new Smarty_Internal_ParseTree_DqContent($this, o); res = new Smarty_Internal_ParseTree_DqContent(o);
} }

View File

@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.28-dev/39'; const SMARTY_VERSION = '3.1.28-dev/40';
/** /**
* define variable scopes * define variable scopes
@@ -1405,7 +1405,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) public function compileAllTemplates($extension = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{ {
return Smarty_Internal_Utility::compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, $this); return Smarty_Internal_Extension_CompileAll::compileAll($extension, $force_compile, $time_limit, $max_errors, $this);
} }
/** /**
@@ -1420,7 +1420,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null) public function compileAllConfig($extension = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
{ {
return Smarty_Internal_Utility::compileAllConfig($extension, $force_compile, $time_limit, $max_errors, $this); return Smarty_Internal_Extension_CompileAll::compileAll($extension, $force_compile, $time_limit, $max_errors, $this, true);
} }
/** /**
@@ -1610,7 +1610,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public function __destruct() public function __destruct()
{ {
// intentionally left blank $i =0;// intentionally left blank
} }
/** /**

View File

@@ -20,12 +20,13 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
* Compiles code for the {assign} tag * Compiles code for the {assign} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
$this->required_attributes = array('var', 'value'); $this->required_attributes = array('var', 'value');
@@ -55,7 +56,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
} elseif ($_attr['scope'] == 'global') { } elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL; $_scope = Smarty::SCOPE_GLOBAL;
} else { } else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno); $compiler->trigger_template_error('illegal value for "scope" attribute', null, true);
} }
} }
// compiled output // compiled output

View File

@@ -73,7 +73,9 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$_name = trim($_attr['name'], "\"'"); $_name = trim($_attr['name'], "\"'");
// existing child must override parent settings // existing child must override parent settings
if (isset($compiler->template->block_data[$_name]) && $compiler->template->block_data[$_name]['mode'] == 'replace') { if (isset($compiler->template->block_data[$_name]) &&
$compiler->template->block_data[$_name]['mode'] == 'replace'
) {
$_attr['append'] = false; $_attr['append'] = false;
$_attr['prepend'] = false; $_attr['prepend'] = false;
} }
@@ -82,7 +84,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
if ($compiler->inheritance_child) { if ($compiler->inheritance_child) {
array_unshift(self::$nested_block_names, $_name); array_unshift(self::$nested_block_names, $_name);
// build {block} for child block // build {block} for child block
self::$block_data[$_name]['source'] = "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} uid='{$compiler->template->source->uid}' line={$compiler->lex->line}"; self::$block_data[$_name]['source'] = "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} uid='{$compiler->template->source->uid}' line={$compiler->parser->lex->line}";
if ($_attr['nocache']) { if ($_attr['nocache']) {
self::$block_data[$_name]['source'] .= ' nocache'; self::$block_data[$_name]['source'] .= ' nocache';
} }
@@ -94,7 +96,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$this->openTag($compiler, 'block', $save); $this->openTag($compiler, 'block', $save);
// set flag for {block} tag // set flag for {block} tag
$compiler->inheritance = true; $compiler->inheritance = true;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
$compiler->has_code = false; $compiler->has_code = false;
return; return;
} }
@@ -107,7 +109,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$compiler->inheritance = true; $compiler->inheritance = true;
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->has_code = false; $compiler->has_code = false;
return true; return true;
@@ -131,7 +133,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= $compiler->template->block_data[$name1]['source']; Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= $compiler->template->block_data[$name1]['source'];
Smarty_Internal_Compile_Block::$block_data[$name1]['child'] = true; Smarty_Internal_Compile_Block::$block_data[$name1]['child'] = true;
} }
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
$compiler->has_code = false; $compiler->has_code = false;
return; return;
} }
@@ -146,7 +148,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
} }
} }
if ($_name == null) { if ($_name == null) {
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', $compiler->lex->taglineno); $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', null, true);
} }
// undefined child? // undefined child?
if (!isset($compiler->template->block_data[$_name]['source'])) { if (!isset($compiler->template->block_data[$_name]['source'])) {
@@ -155,7 +157,8 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
} }
// flag that child is already compile by {$smarty.block.child} inclusion // flag that child is already compile by {$smarty.block.child} inclusion
$compiler->template->block_data[$_name]['compiled'] = true; $compiler->template->block_data[$_name]['compiled'] = true;
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime); $_tpl = new Smarty_Internal_template('string:' .
$compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
if ($compiler->smarty->debugging) { if ($compiler->smarty->debugging) {
Smarty_Internal_Debug::ignore($_tpl); Smarty_Internal_Debug::ignore($_tpl);
} }
@@ -171,11 +174,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
$_tpl->compiler->suppressTemplatePropertyHeader = true; $_tpl->compiler->suppressTemplatePropertyHeader = true;
$nocache = $compiler->nocache || $compiler->tag_nocache; $nocache = $compiler->nocache || $compiler->tag_nocache;
if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) { if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) {
$_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler)); $_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php($compiler->parser), $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler));
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') { } elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler) . $compiler->parser->current_buffer->to_smarty_php(); $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler) .
$compiler->parser->current_buffer->to_smarty_php($compiler->parser);
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') { } elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler); $_output = $compiler->parser->current_buffer->to_smarty_php($compiler->parser) .
$_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
} elseif (!empty($compiler->template->block_data[$_name])) { } elseif (!empty($compiler->template->block_data[$_name])) {
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler); $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
} }
@@ -226,13 +231,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
} }
} }
if ($_name == null) { if ($_name == null) {
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno); $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', null, true);
} }
if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) { if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
$compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno); $compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', null, true);
} }
Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent; Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
$compiler->has_code = false; $compiler->has_code = false;
return; return;
} }
@@ -282,29 +287,38 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) { if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
$name2 = Smarty_Internal_Compile_Block::$nested_block_names[0]; $name2 = Smarty_Internal_Compile_Block::$nested_block_names[0];
if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) { if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) {
if (isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child']) || !isset($compiler->template->block_data[$name1])) { if (isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child']) ||
!isset($compiler->template->block_data[$name1])
) {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source']; Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
} else { } else {
if ($compiler->template->block_data[$name1]['mode'] == 'append') { if ($compiler->template->block_data[$name1]['mode'] == 'append') {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source']; Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .
$compiler->template->block_data[$name1]['source'];
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') { } elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'] . Smarty_Internal_Compile_Block::$block_data[$name1]['source']; Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'] .
Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
} else { } else {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source']; Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'];
} }
} }
} }
unset(Smarty_Internal_Compile_Block::$block_data[$name1]); unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
} else { } else {
if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) { if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) {
if (isset($compiler->template->block_data[$name1]) && !isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child'])) { if (isset($compiler->template->block_data[$name1]) &&
if (strpos($compiler->template->block_data[$name1]['source'], Smarty_Internal_Compile_Block::parent) !== false) { !isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child'])
) {
if (strpos($compiler->template->block_data[$name1]['source'], Smarty_Internal_Compile_Block::parent) !==
false
) {
$compiler->template->block_data[$name1]['source'] = str_replace(Smarty_Internal_Compile_Block::parent, Smarty_Internal_Compile_Block::$block_data[$name1]['source'], $compiler->template->block_data[$name1]['source']); $compiler->template->block_data[$name1]['source'] = str_replace(Smarty_Internal_Compile_Block::parent, Smarty_Internal_Compile_Block::$block_data[$name1]['source'], $compiler->template->block_data[$name1]['source']);
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') { } elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
$compiler->template->block_data[$name1]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source']; $compiler->template->block_data[$name1]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
} elseif ($compiler->template->block_data[$name1]['mode'] == 'append') { } elseif ($compiler->template->block_data[$name1]['mode'] == 'append') {
$compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source']; $compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .
$compiler->template->block_data[$name1]['source'];
} }
} else { } else {
$compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source']; $compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
@@ -318,18 +332,20 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
} }
} }
unset(Smarty_Internal_Compile_Block::$block_data[$name1]); unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); $compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
} }
$compiler->has_code = false; $compiler->has_code = false;
return; return;
} }
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) { if (isset($compiler->template->block_data[$_name]) &&
!isset($compiler->template->block_data[$_name]['compiled'])
) {
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name); $_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
} else { } else {
if ($saved_data[0]['hide'] && !isset($compiler->template->block_data[$_name]['source'])) { if ($saved_data[0]['hide'] && !isset($compiler->template->block_data[$_name]['source'])) {
$_output = ''; $_output = '';
} else { } else {
$_output = $compiler->parser->current_buffer->to_smarty_php(); $_output = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
} }
} }
if (isset($compiler->template->block_data[$_name]['compiled'])) { if (isset($compiler->template->block_data[$_name]['compiled'])) {
@@ -388,7 +404,8 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
$save = array($_attr, $compiler->nocache); $save = array($_attr, $compiler->nocache);
// set trace back to child block // set trace back to child block
$compiler->pushTrace($compiler->template->source->filepath, $uid, $_attr['line'] - $compiler->lex->line); $compiler->pushTrace($compiler->template->source->filepath, $uid, $_attr['line'] -
$compiler->parser->lex->line);
$this->openTag($compiler, 'private_child_block', $save); $this->openTag($compiler, 'private_child_block', $save);

View File

@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('levels'); public $optional_attributes = array('levels');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -35,24 +36,25 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
* Compiles code for the {break} tag * Compiles code for the {break} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
if (isset($_attr['levels'])) { if (isset($_attr['levels'])) {
if (!is_numeric($_attr['levels'])) { if (!is_numeric($_attr['levels'])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
} }
$_levels = $_attr['levels']; $_levels = $_attr['levels'];
} else { } else {
@@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
$stack_count --; $stack_count --;
} }
if ($level_count != 0) { if ($level_count != 0) {
$compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno); $compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true);
} }
return "<?php break {$_levels};?>"; return "<?php break {$_levels};?>";

View File

@@ -73,7 +73,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
$parameter = array_map('strtolower', $parameter); $parameter = array_map('strtolower', $parameter);
$tag = trim($parameter[0], '"\''); $tag = trim($parameter[0], '"\'');
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) { if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", $compiler->lex->taglineno); $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
} }
return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null"; return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null";
} }

View File

@@ -42,18 +42,19 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* Compiles code for the {config_load} tag * Compiles code for the {config_load} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true); static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// save possible attributes // save possible attributes
@@ -70,7 +71,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
if (isset($_is_legal_scope[$_attr['scope']])) { if (isset($_is_legal_scope[$_attr['scope']])) {
$scope = $_attr['scope']; $scope = $_attr['scope'];
} else { } else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno); $compiler->trigger_template_error('illegal value for "scope" attribute', null, true);
} }
} }
// create config object // create config object

View File

@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('levels'); public $optional_attributes = array('levels');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -35,24 +36,25 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
* Compiles code for the {continue} tag * Compiles code for the {continue} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
if (isset($_attr['levels'])) { if (isset($_attr['levels'])) {
if (!is_numeric($_attr['levels'])) { if (!is_numeric($_attr['levels'])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
} }
$_levels = $_attr['levels']; $_levels = $_attr['levels'];
} else { } else {
@@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
$stack_count --; $stack_count --;
} }
if ($level_count != 0) { if ($level_count != 0) {
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno); $compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true);
} }
return "<?php continue {$_levels};?>"; return "<?php continue {$_levels};?>";

View File

@@ -37,19 +37,21 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
* Compiles code for the {extends} tag * Compiles code for the {extends} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
if (strpos($_attr['file'], '$_tmp') !== false) { if (strpos($_attr['file'], '$_tmp') !== false) {
$compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno); $compiler->trigger_template_error('illegal value for file attribute', null, true);
} }
$name = $_attr['file']; $name = $_attr['file'];
@@ -60,7 +62,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
* used in evaluated code * used in evaluated code
*/ */
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
eval("\$tpl_name = {$name};"); eval("\$tpl_name = @{$name};");
} else { } else {
$tpl_name = trim($name, '\'"'); $tpl_name = trim($name, '\'"');
} }
@@ -69,7 +71,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
// check for recursion // check for recursion
$uid = $_source->uid; $uid = $_source->uid;
if (isset($compiler->extends_uid[$uid])) { if (isset($compiler->extends_uid[$uid])) {
$compiler->trigger_template_error("illegal recursive call of \"{$_source->filepath}\"", $compiler->lex->line - $compiler->trigger_template_error("illegal recursive call of \"{$_source->filepath}\"", $compiler->parser->lex->line -
1); 1);
} }
$compiler->extends_uid[$uid] = true; $compiler->extends_uid[$uid] = true;
@@ -80,14 +82,14 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
array_unshift($compiler->sources, $source); array_unshift($compiler->sources, $source);
$uid = $source->uid; $uid = $source->uid;
if (isset($compiler->extends_uid[$uid])) { if (isset($compiler->extends_uid[$uid])) {
$compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->parser->lex->line -
1); 1);
} }
$compiler->extends_uid[$uid] = true; $compiler->extends_uid[$uid] = true;
} }
} }
$compiler->inheritance_child = true; $compiler->inheritance_child = true;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); $compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
return ''; return '';
} }
} }

View File

@@ -110,14 +110,14 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
} }
foreach ($attributes as $a => $v) { foreach ($attributes as $a => $v) {
if ($v === false) { if ($v === false) {
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", $compiler->lex->taglineno); $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
} }
} }
$fromName = $compiler->getVariableName($_attr['from']); $fromName = $compiler->getVariableName($_attr['from']);
if ($fromName) { if ($fromName) {
foreach (array('item', 'key') as $a) { foreach (array('item', 'key') as $a) {
if (isset($attributes[$a]) && $attributes[$a] == $fromName) { if (isset($attributes[$a]) && $attributes[$a] == $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", $compiler->lex->taglineno); $compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", null, true);
} }
} }
} }

View File

@@ -45,18 +45,19 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
* Compiles code for the {function} tag * Compiles code for the {function} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return boolean true * @return bool true
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
unset($_attr['nocache']); unset($_attr['nocache']);
$_name = trim($_attr['name'], "'\""); $_name = trim($_attr['name'], "'\"");
@@ -67,7 +68,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
$compiler->compiles_template_function = true; $compiler->compiles_template_function = true;
// Init temporary context // Init temporary context
$compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array()); $compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->has_nocache_code = false; $compiler->template->has_nocache_code = false;
$compiler->template->caching = true; $compiler->template->caching = true;
return true; return true;
@@ -130,7 +131,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
} }
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code // setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}"; $_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}";
$_funcNameCaching = $_funcName . '_nocache'; $_funcNameCaching = $_funcName . '_nocache';
@@ -165,8 +166,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; $output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>"; $output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>"; $output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parser->current_buffer->append_subtree($_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n"; $output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n";
$output .= "if (\\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n"; $output .= "if (\\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n";
@@ -176,8 +177,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->properties['saved_tpl_vars']);\n}\n}\n"; $output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->properties['saved_tpl_vars']);\n}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n"; $output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php())); $_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php($compiler->parser)));
} }
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName; $compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName;
$output = "<?php\n"; $output = "<?php\n";
@@ -198,15 +199,15 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; $output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>"; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parser->current_buffer->append_subtree($_functionCode); $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n"; $output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n";
$output .= "if (\$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n"; $output .= "if (\$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n";
$output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n"; $output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n";
$output .= "/*/ {$_funcName} */\n\n"; $output .= "/*/ {$_funcName} */\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php(); $compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// restore old buffer // restore old buffer
$compiler->parser->current_buffer = $saved_data[1]; $compiler->parser->current_buffer = $saved_data[1];
// restore old status // restore old status

View File

@@ -20,12 +20,13 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
* Compiles code for the {if} tag * Compiles code for the {if} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -34,7 +35,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (!array_key_exists("if condition", $parameter)) { if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno); $compiler->trigger_template_error("missing if condition", null, true);
} }
if (is_array($parameter['if condition'])) { if (is_array($parameter['if condition'])) {
@@ -55,11 +56,19 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$_nocache = ''; $_nocache = '';
} }
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter['if condition']['var'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"; $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] .
"$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else { } else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
} }
return $_output; return $_output;
@@ -81,12 +90,12 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
* Compiles code for the {else} tag * Compiles code for the {else} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache)); $this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
@@ -107,12 +116,13 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
* Compiles code for the {elseif} tag * Compiles code for the {elseif} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -120,7 +130,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
if (!array_key_exists("if condition", $parameter)) { if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno); $compiler->trigger_template_error("missing elseif condition", null, true);
} }
if (is_array($parameter['if condition'])) { if (is_array($parameter['if condition'])) {
@@ -149,11 +159,20 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
if ($condition_by_assign) { if ($condition_by_assign) {
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter['if condition']['var'])) {
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"; $_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" .
$parameter['if condition']['var']['var'] . "$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else { } else {
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; $_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
} }
return $_output; return $_output;
@@ -172,11 +191,23 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if ($condition_by_assign) { if ($condition_by_assign) {
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter['if condition']['var'])) {
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"); $_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; $parameter['if condition']['var']['var'] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" .
$parameter['if condition']['var']['var'] . "$_nocache);\n");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else { } else {
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"); $_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; $parameter['if condition']['var'] .
"])) \$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
} }
return $_output; return $_output;
@@ -199,12 +230,12 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
* Compiles code for the {/if} tag * Compiles code for the {/if} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {

View File

@@ -20,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* caching mode to create nocache code but no cache file * caching mode to create nocache code but no cache file
*/ */
const CACHING_NOCACHE_CODE = 9999; const CACHING_NOCACHE_CODE = 9999;
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -27,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('file'); public $required_attributes = array('file');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -34,6 +36,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('file'); public $shorttag_order = array('file');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -41,6 +44,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $option_flags = array('nocache', 'inline', 'caching'); public $option_flags = array('nocache', 'inline', 'caching');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -99,29 +103,41 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
// flag if included template code should be merged into caller // flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled; $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes ||
($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) ||
$_attr['inline'] === true) && !$compiler->template->source->recompiled;
if ($merge_compiled_includes && $_attr['inline'] !== true) { if ($merge_compiled_includes && $_attr['inline'] !== true) {
// variable template name ? // variable template name ?
if ($compiler->has_variable_string || !((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2)) || substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0) { if ($compiler->has_variable_string ||
!((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2)) ||
substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0
) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
if ($compiler->template->caching) { if ($compiler->template->caching) {
// must use individual cache file // must use individual cache file
//$_attr['caching'] = 1; //$_attr['caching'] = 1;
} }
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) { if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes &&
$_attr['inline'] !== true
) {
$compiler->trigger_template_error(' variable template file names not allow within {block} tags'); $compiler->trigger_template_error(' variable template file names not allow within {block} tags');
} }
} }
// variable compile_id? // variable compile_id?
if (isset($_attr['compile_id'])) { if (isset($_attr['compile_id'])) {
if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 || is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0) { if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 ||
is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 ||
substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0
) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
if ($compiler->template->caching) { if ($compiler->template->caching) {
// must use individual cache file // must use individual cache file
//$_attr['caching'] = 1; //$_attr['caching'] = 1;
} }
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) { if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes &&
$_attr['inline'] !== true
) {
$compiler->trigger_template_error(' variable compile_id not allow within {block} tags'); $compiler->trigger_template_error(' variable compile_id not allow within {block} tags');
} }
} }
@@ -167,7 +183,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$has_compiled_template = false; $has_compiled_template = false;
if ($merge_compiled_includes) { if ($merge_compiled_includes) {
if ($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache) && $_caching != self::CACHING_NOCACHE_CODE) { if ($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache) &&
$_caching != self::CACHING_NOCACHE_CODE
) {
// $merge_compiled_includes = false; // $merge_compiled_includes = false;
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) { if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) {
$compiler->trigger_template_error(' invalid caching mode of subtemplate within {block} tags'); $compiler->trigger_template_error(' invalid caching mode of subtemplate within {block} tags');
@@ -182,12 +200,13 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* used in evaluated code * used in evaluated code
*/ */
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
eval("\$tpl_name = $include_file;"); eval("\$tpl_name = @$include_file;");
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) { if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) {
$compiler->smarty->allow_ambiguous_resources = true; $compiler->smarty->allow_ambiguous_resources = true;
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching); $tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
// save unique function name // save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' .
str_replace(array('.', ','), '_', uniqid('', true));
if ($compiler->inheritance) { if ($compiler->inheritance) {
$tpl->compiler->inheritance = true; $tpl->compiler->inheritance = true;
} }
@@ -195,7 +214,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$tpl->mustCompile = true; $tpl->mustCompile = true;
if (!($tpl->source->uncompiled) && $tpl->source->exists) { if (!($tpl->source->uncompiled) && $tpl->source->exists) {
$tpl->compiler->suppressTemplatePropertyHeader = true; $tpl->compiler->suppressTemplatePropertyHeader = true;
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = str_replace(array('.', ','), '_', uniqid(rand(), true)); $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = str_replace(array('.',
','), '_', uniqid(rand(), true));
// get compiled code // get compiled code
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler)); $compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
unset($tpl->compiler); unset($tpl->compiler);
@@ -243,12 +263,13 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
$_vars = 'array(' . join(',', $_pairs) . ')'; $_vars = 'array(' . join(',', $_pairs) . ')';
} else { } else {
$compiler->trigger_template_error('variable passing not allowed in parent/global scope', $compiler->lex->taglineno); $compiler->trigger_template_error('variable passing not allowed in parent/global scope', null, true);
} }
} else { } else {
$_vars = 'array()'; $_vars = 'array()';
} }
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && $_compile_id != '$_smarty_tpl->compile_id'; $update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
$_compile_id != '$_smarty_tpl->compile_id';
if ($has_compiled_template && !$call_nocache) { if ($has_compiled_template && !$call_nocache) {
// if ($has_compiled_template && !$compiler->tag_nocache && !$compiler->nocache) { // if ($has_compiled_template && !$compiler->tag_nocache && !$compiler->nocache) {
// never call inline templates in nocache mode // never call inline templates in nocache mode

View File

@@ -44,12 +44,13 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
* Compiles code for the {include_php} tag * Compiles code for the {include_php} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @throws SmartyException * @return string
* @return string compiled code * @throws \SmartyCompilerException
* @throws \SmartyException
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
if (!($compiler->smarty instanceof SmartyBC)) { if (!($compiler->smarty instanceof SmartyBC)) {
throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable"); throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable");
@@ -63,7 +64,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
$_filepath = false; $_filepath = false;
$_file = null; $_file = null;
eval('$_file = ' . $_attr['file'] . ';'); eval('$_file = @' . $_attr['file'] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) { if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
$_filepath = $compiler->smarty->_realpath($_file, true); $_filepath = $compiler->smarty->_realpath($_file, true);
} else { } else {
@@ -83,7 +84,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
} }
} }
if ($_filepath == false) { if ($_filepath == false) {
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $compiler->lex->taglineno); $compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true);
} }
if (isset($compiler->smarty->security_policy)) { if (isset($compiler->smarty->security_policy)) {

View File

@@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name'); public $required_attributes = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -31,6 +32,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('name'); public $shorttag_order = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -43,11 +45,12 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* Compiles code for the {insert} tag * Compiles code for the {insert} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -63,7 +66,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output = '<?php '; $_output = '<?php ';
// save possible attributes // save possible attributes
eval('$_name = ' . $_attr['name'] . ';'); eval('$_name = @' . $_attr['name'] . ';');
if (isset($_attr['assign'])) { if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of being displayed // output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign']; $_assign = $_attr['assign'];
@@ -80,7 +83,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_function = "smarty_insert_{$_name}"; $_function = "smarty_insert_{$_name}";
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
$_filepath = false; $_filepath = false;
eval('$_script = ' . $_attr['script'] . ';'); eval('$_script = @' . $_attr['script'] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
$_filepath = $_script; $_filepath = $_script;
} else { } else {
@@ -100,13 +103,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
} }
} }
if ($_filepath == false) { if ($_filepath == false) {
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno); $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true);
} }
// code for script file loading // code for script file loading
$_output .= "require_once '{$_filepath}' ;"; $_output .= "require_once '{$_filepath}' ;";
require_once $_filepath; require_once $_filepath;
if (!is_callable($_function)) { if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->lex->taglineno); $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true);
} }
} else { } else {
$_filepath = 'null'; $_filepath = 'null';
@@ -115,7 +118,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) { if (!is_callable($_function)) {
// try plugin // try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) { if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->lex->taglineno); $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true);
} }
} }
} }

View File

@@ -21,15 +21,16 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
* This tag does output the left delimiter * This tag does output the left delimiter
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = true; $compiler->has_code = true;

View File

@@ -28,11 +28,11 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
* This tag does not generate compiled output. It only sets a compiler flag. * This tag does not generate compiled output. It only sets a compiler flag.
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return bool * @return bool
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'nocache', array($compiler->nocache)); $this->openTag($compiler, 'nocache', array($compiler->nocache));
@@ -58,11 +58,11 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
* This tag does not generate compiled output. It only sets a compiler flag. * This tag does not generate compiled output. It only sets a compiler flag.
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return bool * @return bool
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// leave nocache mode // leave nocache mode

View File

@@ -28,14 +28,14 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
* Compiles code for the execution of block plugin * Compiles code for the execution of block plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of block plugin * @param string $tag name of block plugin
* @param string $function PHP function name * @param string $function PHP function name
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag, $function) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{ {
if (!isset($tag[5]) || substr($tag, - 5) != 'close') { if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin // opening tag of block plugin
@@ -75,9 +75,13 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$mod_pre = $mod_post = ''; $mod_pre = $mod_post = '';
} else { } else {
$mod_pre = ' ob_start(); '; $mod_pre = ' ob_start(); ';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; $mod_post = 'echo ' .
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
'value' => 'ob_get_clean()')) . ';';
} }
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post .
" } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} }
return $output . "\n"; return $output . "\n";

View File

@@ -155,7 +155,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/ */
public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$this->matchProperty($compiler->lex->data); $this->matchProperty($compiler->parser->lex->data);
} }
/** /**
@@ -205,7 +205,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
} }
} }
$this->matchProperty($compiler->lex->data); $this->matchProperty($compiler->parser->lex->data);
} }
/** /**
@@ -224,13 +224,13 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$parameter = array_map('strtolower', $parameter); $parameter = array_map('strtolower', $parameter);
$tag = trim($parameter[0], '"\''); $tag = trim($parameter[0], '"\'');
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) { if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", $compiler->lex->taglineno); $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
} }
$className = 'Smarty_Internal_Compile_' . ucfirst($tag); $className = 'Smarty_Internal_Compile_' . ucfirst($tag);
if ((!isset($parameter[2]) || false === $property = $compiler->getId($parameter[2])) || if ((!isset($parameter[2]) || false === $property = $compiler->getId($parameter[2])) ||
!in_array($property, $className::$nameProperties) !in_array($property, $className::$nameProperties)
) { ) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", $compiler->lex->taglineno); $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true);
} }
$tagVar = "'__smarty_{$tag}_{$name}'"; $tagVar = "'__smarty_{$tag}_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";

View File

@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array(); public $required_attributes = array();
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -35,14 +36,14 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
* Compiles code for the execution of function plugin * Compiles code for the execution of function plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function plugin * @param string $tag name of function plugin
* @param string $function PHP function name * @param string $function PHP function name
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag, $function) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{ {
// This tag does create output // This tag does create output
$compiler->has_output = true; $compiler->has_output = true;

View File

@@ -21,12 +21,13 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
* Compiles code for modifier execution * Compiles code for modifier execution
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -52,7 +53,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { } else {
if (is_object($function[0])) { if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else { } else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')'; $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
} }
@@ -73,7 +75,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifiercompiler plugin // modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$plugin = 'smarty_modifiercompiler_' . $modifier; $plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler); $output = $plugin($single_modifier, $compiler);
} }
@@ -85,7 +89,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifier plugin // modifier plugin
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
@@ -96,7 +102,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// PHP function // PHP function
if (is_callable($modifier)) { if (is_callable($modifier)) {
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
$output = "{$modifier}({$params})"; $output = "{$modifier}({$params})";
} }
$compiler->known_modifier_type[$modifier] = $type; $compiler->known_modifier_type[$modifier] = $type;
@@ -105,21 +113,29 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
break; break;
case 6: case 6:
// default plugin handler // default plugin handler
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) { if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) ||
(is_callable($compiler->smarty->default_plugin_handler_func) &&
$compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
// check if modifier allowed // check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$params})"; $output = "{$function}({$params})";
} else { } else {
if (is_object($function[0])) { if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else { } else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')'; $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
} }
} }
} }
if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) { if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ||
isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])
) {
// was a plugin // was a plugin
$compiler->known_modifier_type[$modifier] = 4; $compiler->known_modifier_type[$modifier] = 4;
} else { } else {
@@ -130,7 +146,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
} }
} }
if (!isset($compiler->known_modifier_type[$modifier])) { if (!isset($compiler->known_modifier_type[$modifier])) {
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno); $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
} }
} }

View File

@@ -28,14 +28,14 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
* Compiles code for the execution of block plugin * Compiles code for the execution of block plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of block object * @param string $tag name of block object
* @param string $method name of method to call * @param string $method name of method to call
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag, $method) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
{ {
if (!isset($tag[5]) || substr($tag, - 5) != 'close') { if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin // opening tag of block plugin
@@ -76,9 +76,13 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
$mod_pre = $mod_post = ''; $mod_pre = $mod_post = '';
} else { } else {
$mod_pre = ' ob_start(); '; $mod_pre = ' ob_start(); ';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; $mod_post = 'echo ' .
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
'value' => 'ob_get_clean()')) . ';';
} }
$output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre .
" echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
$mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} }
return $output . "\n"; return $output . "\n";

View File

@@ -28,14 +28,14 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
* Compiles code for the execution of function plugin * Compiles code for the execution of function plugin
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function * @param string $tag name of function
* @param string $method name of method to call * @param string $method name of method to call
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag, $method) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);

View File

@@ -44,7 +44,9 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
$save = $compiler->template->has_nocache_code; $save = $compiler->template->has_nocache_code;
$output = addcslashes($_attr['code'], "'\\"); $output = addcslashes($_attr['code'], "'\\");
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $output . "';?>", $compiler, true))); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" .
$output .
"';?>", $compiler, true)));
$compiler->template->has_nocache_code = $save; $compiler->template->has_nocache_code = $save;
return ''; return '';
} }
@@ -54,28 +56,30 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
} elseif ($compiler->php_handling == Smarty::PHP_QUOTE) { } elseif ($compiler->php_handling == Smarty::PHP_QUOTE) {
$output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this, $output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this,
'quote'), $_attr['code']); 'quote'), $_attr['code']);
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Text($output));
return ''; return '';
} elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') { } elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
$save = $compiler->template->has_nocache_code; $save = $compiler->template->has_nocache_code;
$output = addcslashes($_attr['code'], "'\\"); $output = addcslashes($_attr['code'], "'\\");
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $output . "';?>", $compiler, true))); $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" .
$output .
"';?>", $compiler, true)));
$compiler->template->has_nocache_code = $save; $compiler->template->has_nocache_code = $save;
return ''; return '';
} elseif ($compiler->php_handling == Smarty::PHP_ALLOW) { } elseif ($compiler->php_handling == Smarty::PHP_ALLOW) {
if (!($compiler->smarty instanceof SmartyBC)) { 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->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', null, true);
} }
$compiler->has_code = true; $compiler->has_code = true;
return $_attr['code']; return $_attr['code'];
} else { } else {
$compiler->trigger_template_error('Illegal $smarty->php_handling value', $compiler->lex->taglineno); $compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true);
} }
} else { } else {
$compiler->has_code = true; $compiler->has_code = true;
if (!($compiler->smarty instanceof SmartyBC)) { if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', $compiler->lex->taglineno); $compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', null, true);
} }
$ldel = preg_quote($compiler->smarty->left_delimiter, '#'); $ldel = preg_quote($compiler->smarty->left_delimiter, '#');
$rdel = preg_quote($compiler->smarty->right_delimiter, '#'); $rdel = preg_quote($compiler->smarty->right_delimiter, '#');
@@ -84,7 +88,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ('nocache' == trim($match[2])) { if ('nocache' == trim($match[2])) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} else { } else {
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", $compiler->lex->taglineno); $compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", null, true);
} }
} }
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#",
@@ -140,7 +144,9 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($lex->phpType == 'unmatched') { if ($lex->phpType == 'unmatched') {
return; return;
} }
if (($lex->phpType == 'php' || $lex->phpType == 'asp') && ($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)) { if (($lex->phpType == 'php' || $lex->phpType == 'asp') &&
($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)
) {
return; return;
} }
$start = $lex->counter + strlen($lex->value); $start = $lex->counter + strlen($lex->value);
@@ -167,7 +173,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
} }
} }
while ($close > $pos && $close < $start) { while ($close > $pos && $close < $start) {
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) { if (preg_match('~' . preg_quote($closeTag, '~') .
'~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) {
$close = $match[0][1]; $close = $match[0][1];
$from = $close + strlen($match[0][0]); $from = $close + strlen($match[0][0]);
} else { } else {
@@ -190,6 +197,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
* Call back function for $php_handling = PHP_QUOTE * Call back function for $php_handling = PHP_QUOTE
* *
*/ */
/**
* @param $match
*
* @return string
*/
private function quote($match) private function quote($match)
{ {
return htmlspecialchars($match[0], ENT_QUOTES); return htmlspecialchars($match[0], ENT_QUOTES);

View File

@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $optional_attributes = array('assign'); public $optional_attributes = array('assign');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -35,13 +36,13 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
* Compiles code for generating output from any expression * Compiles code for generating output from any expression
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @throws SmartyException * @return string
* @return string compiled code * @throws \SmartyException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -57,7 +58,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$output = $parameter['value']; $output = $parameter['value'];
// tag modifier // tag modifier
if (!empty($parameter['modifierlist'])) { if (!empty($parameter['modifierlist'])) {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output)); $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'],
'value' => $output));
} }
if (!$_attr['nofilter']) { if (!$_attr['nofilter']) {
// default modifier // default modifier
@@ -74,7 +76,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
$compiler->default_modifier_list = $modifierlist; $compiler->default_modifier_list = $modifierlist;
} }
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output)); $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list,
'value' => $output));
} }
// autoescape html // autoescape html
if ($compiler->template->smarty->escape_html) { if ($compiler->template->smarty->escape_html) {
@@ -82,7 +85,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
// loop over registered filters // loop over registered filters
if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) { if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) { foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key =>
$function) {
if (!is_array($function)) { if (!is_array($function)) {
$output = "{$function}({$output},\$_smarty_tpl)"; $output = "{$function}({$output},\$_smarty_tpl)";
} elseif (is_object($function[0])) { } elseif (is_object($function[0])) {
@@ -106,10 +110,13 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
if (isset($compiler->template->variable_filters)) { if (isset($compiler->template->variable_filters)) {
foreach ($compiler->template->variable_filters as $filter) { foreach ($compiler->template->variable_filters as $filter) {
if (count($filter) == 1 && ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false) { if (count($filter) == 1 &&
($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false
) {
$output = $result; $output = $result;
} else { } else {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), 'value' => $output)); $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter),
'value' => $output));
} }
} }
} }
@@ -123,13 +130,13 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
} }
/** /**
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param string $name name of variable filter * @param string $name name of variable filter
* @param string $output embedded output * @param string $output embedded output
* *
* @return string * @return string
*/ */
private function compile_output_filter($compiler, $name, $output) private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
{ {
$plugin_name = "smarty_variablefilter_{$name}"; $plugin_name = "smarty_variablefilter_{$name}";
$path = $compiler->smarty->loadPlugin($plugin_name, false); $path = $compiler->smarty->loadPlugin($plugin_name, false);

View File

@@ -28,13 +28,13 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
* Compiles code for the execution of a block function * Compiles code for the execution of a block function
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of block function * @param string $tag name of block function
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
{ {
if (!isset($tag[5]) || substr($tag, - 5) != 'close') { if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin // opening tag of block plugin
@@ -95,14 +95,22 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
$mod_pre = $mod_post = ''; $mod_pre = $mod_post = '';
} else { } else {
$mod_pre = ' ob_start(); '; $mod_pre = ' ob_start(); ';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; $mod_post = 'echo ' .
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
'value' => 'ob_get_clean()')) . ';';
} }
if (!is_array($function)) { if (!is_array($function)) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post .
" } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} elseif (is_object($function[0])) { } elseif (is_object($function[0])) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
$mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} else { } else {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
$mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
} }
} }

View File

@@ -28,13 +28,13 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
* Compiles code for the execution of a registered function * Compiles code for the execution of a registered function
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @param string $tag name of function * @param string $tag name of function
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter, $tag) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
{ {
// This tag does create output // This tag does create output
$compiler->has_output = true; $compiler->has_output = true;

View File

@@ -20,17 +20,18 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
* Compiles code for the special $smarty variables * Compiles code for the special $smarty variables
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param $parameter * @param $parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$variable = strtolower($compiler->getId($_index[0])); $variable = strtolower($compiler->getId($_index[0]));
if ($variable === false) { if ($variable === false) {
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", $compiler->lex->taglineno); $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
} }
if (!isset($compiler->smarty->security_policy) || if (!isset($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)

View File

@@ -25,11 +25,11 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
// this tag does not return compiled code // this tag does not return compiled code
$compiler->has_code = true; $compiler->has_code = true;

View File

@@ -93,7 +93,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
unset($_attr['name']); unset($_attr['name']);
foreach ($attributes as $a => $v) { foreach ($attributes as $a => $v) {
if ($v === false) { if ($v === false) {
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", $compiler->lex->taglineno); $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
} }
} }
$local = "\$__section_{$attributes['name']}_" . $this->counter ++ . '_'; $local = "\$__section_{$attributes['name']}_" . $this->counter ++ . '_';

View File

@@ -25,7 +25,7 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
$compiler->variable_filter_stack[] = $compiler->template->variable_filters; $compiler->variable_filter_stack[] = $compiler->template->variable_filters;
$compiler->template->variable_filters = $parameter['modifier_list']; $compiler->template->variable_filters = $parameter['modifier_list'];
@@ -53,7 +53,7 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
// reset variable filter to previous state // reset variable filter to previous state

View File

@@ -20,19 +20,20 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
* Compiles code for the {while} tag * Compiles code for the {while} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache); $this->openTag($compiler, 'while', $compiler->nocache);
if (!array_key_exists("if condition", $parameter)) { if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno); $compiler->trigger_template_error("missing while condition", null, true);
} }
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
@@ -55,11 +56,19 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$_nocache = ''; $_nocache = '';
} }
if (is_array($parameter['if condition']['var'])) { if (is_array($parameter['if condition']['var'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"; $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] .
"$_nocache);\n";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else { } else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
} }
return $_output; return $_output;
@@ -81,11 +90,11 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
* Compiles code for the {/while} tag * Compiles code for the {/while} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {

View File

@@ -21,6 +21,7 @@ abstract class Smarty_Internal_CompileBase
* @var array * @var array
*/ */
public $required_attributes = array(); public $required_attributes = array();
/** /**
* Array of names of optional attribute required by tag * Array of names of optional attribute required by tag
* use array('_any') if there is no restriction of attributes names * use array('_any') if there is no restriction of attributes names
@@ -28,12 +29,14 @@ abstract class Smarty_Internal_CompileBase
* @var array * @var array
*/ */
public $optional_attributes = array(); public $optional_attributes = array();
/** /**
* Shorttag attribute order defined by its names * Shorttag attribute order defined by its names
* *
* @var array * @var array
*/ */
public $shorttag_order = array(); public $shorttag_order = array();
/** /**
* Array of names of valid option flags * Array of names of valid option flags
* *
@@ -68,7 +71,7 @@ abstract class Smarty_Internal_CompileBase
$_indexed_attr[$this->shorttag_order[$key]] = $mixed; $_indexed_attr[$this->shorttag_order[$key]] = $mixed;
} else { } else {
// too many shorthands // too many shorthands
$compiler->trigger_template_error('too many shorthand attributes', $compiler->lex->taglineno); $compiler->trigger_template_error('too many shorthand attributes', null, true);
} }
// named attribute // named attribute
} else { } else {
@@ -90,7 +93,7 @@ abstract class Smarty_Internal_CompileBase
$_indexed_attr[$kv['key']] = false; $_indexed_attr[$kv['key']] = false;
} }
} else { } else {
$compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", $compiler->lex->taglineno); $compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", null, true);
} }
// must be named attribute // must be named attribute
} else { } else {
@@ -102,7 +105,7 @@ abstract class Smarty_Internal_CompileBase
// check if all required attributes present // check if all required attributes present
foreach ($this->required_attributes as $attr) { foreach ($this->required_attributes as $attr) {
if (!array_key_exists($attr, $_indexed_attr)) { if (!array_key_exists($attr, $_indexed_attr)) {
$compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $compiler->lex->taglineno); $compiler->trigger_template_error("missing \"" . $attr . "\" attribute", null, true);
} }
} }
// check for not allowed attributes // check for not allowed attributes
@@ -110,7 +113,7 @@ abstract class Smarty_Internal_CompileBase
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags); $tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags);
foreach ($_indexed_attr as $key => $dummy) { foreach ($_indexed_attr as $key => $dummy) {
if (!in_array($key, $tmp_array) && $key !== 0) { if (!in_array($key, $tmp_array) && $key !== 0) {
$compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", $compiler->lex->taglineno); $compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", null, true);
} }
} }
} }
@@ -162,12 +165,13 @@ abstract class Smarty_Internal_CompileBase
} }
} }
// wrong nesting of tags // wrong nesting of tags
$compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . "{$compiler->smarty->right_delimiter} tag"); $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag .
"{$compiler->smarty->right_delimiter} tag");
return; return;
} }
// wrong nesting of tags // wrong nesting of tags
$compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno); $compiler->trigger_template_error("unexpected closing tag", null, true);
return; return;
} }

View File

@@ -17,13 +17,6 @@
abstract class Smarty_Internal_ParseTree abstract class Smarty_Internal_ParseTree
{ {
/**
* Parser object
*
* @var object
*/
public $parser;
/** /**
* Buffer content * Buffer content
* *
@@ -41,9 +34,21 @@ abstract class Smarty_Internal_ParseTree
/** /**
* Return buffer * Return buffer
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string buffer content * @return string buffer content
*/ */
abstract public function to_smarty_php(); abstract public function to_smarty_php(Smarty_Internal_Templateparser $parser);
/**
* Template data object destructor
*/
public function __destruct()
{
$this->data = null;
$this->subtrees = null;
}
} }

View File

@@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_Code extends Smarty_Internal_ParseTree
/** /**
* Create parse tree buffer for code fragment * Create parse tree buffer for code fragment
* *
* @param object $parser parser object
* @param string $data content * @param string $data content
*/ */
public function __construct($parser, $data) public function __construct($data)
{ {
$this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return buffer content in parentheses * Return buffer content in parentheses
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string content * @return string content
*/ */
public function to_smarty_php() public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
return sprintf("(%s)", $this->data); return sprintf("(%s)", $this->data);
} }

View File

@@ -25,43 +25,45 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
*/ */
public function __construct($parser, Smarty_Internal_ParseTree $subtree) public function __construct($parser, Smarty_Internal_ParseTree $subtree)
{ {
$this->parser = $parser;
$this->subtrees[] = $subtree; $this->subtrees[] = $subtree;
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); $parser->block_nesting_level = count($parser->compiler->_tag_stack);
} }
} }
/** /**
* Append buffer to subtree * Append buffer to subtree
* *
* @param \Smarty_Internal_Templateparser $parser
* @param Smarty_Internal_ParseTree $subtree parse tree buffer * @param Smarty_Internal_ParseTree $subtree parse tree buffer
*/ */
public function append_subtree(Smarty_Internal_ParseTree $subtree) public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
{ {
$last_subtree = count($this->subtrees) - 1; $last_subtree = count($this->subtrees) - 1;
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) { if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $parser->block_nesting_level) {
if ($subtree instanceof Smarty_Internal_ParseTree_Code) { if ($subtree instanceof Smarty_Internal_ParseTree_Code) {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>'); $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>');
} elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) { } elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>'); $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>');
} else { } else {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data); $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data);
} }
} else { } else {
$this->subtrees[] = $subtree; $this->subtrees[] = $subtree;
} }
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); $parser->block_nesting_level = count($parser->compiler->_tag_stack);
} }
} }
/** /**
* Merge subtree buffer content together * Merge subtree buffer content together
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string compiled template code * @return string compiled template code
*/ */
public function to_smarty_php() public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
$code = ''; $code = '';
foreach ($this->subtrees as $subtree) { foreach ($this->subtrees as $subtree) {
@@ -69,15 +71,15 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
$code .= "."; $code .= ".";
} }
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$more_php = $subtree->assign_to_var(); $more_php = $subtree->assign_to_var($parser);
} else { } else {
$more_php = $subtree->to_smarty_php(); $more_php = $subtree->to_smarty_php($parser);
} }
$code .= $more_php; $code .= $more_php;
if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) { if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
$this->parser->compiler->has_variable_string = true; $parser->compiler->has_variable_string = true;
} }
} }

View File

@@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_DqContent extends Smarty_Internal_ParseTree
/** /**
* Create parse tree buffer with string content * Create parse tree buffer with string content
* *
* @param object $parser parser object
* @param string $data string section * @param string $data string section
*/ */
public function __construct($parser, $data) public function __construct($data)
{ {
$this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return content as double quoted string * Return content as double quoted string
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string doubled quoted string * @return string doubled quoted string
*/ */
public function to_smarty_php() public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
return '"' . $this->data . '"'; return '"' . $this->data . '"';
} }

View File

@@ -29,12 +29,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
/** /**
* Create parse tree buffer for Smarty tag * Create parse tree buffer for Smarty tag
* *
* @param object $parser parser object * @param \Smarty_Internal_Templateparser $parser parser object
* @param string $data content * @param string $data content
*/ */
public function __construct($parser, $data) public function __construct(Smarty_Internal_Templateparser $parser, $data)
{ {
$this->parser = $parser;
$this->data = $data; $this->data = $data;
$this->saved_block_nesting = $parser->block_nesting_level; $this->saved_block_nesting = $parser->block_nesting_level;
} }
@@ -42,9 +41,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
/** /**
* Return buffer content * Return buffer content
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string content * @return string content
*/ */
public function to_smarty_php() public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
return $this->data; return $this->data;
} }
@@ -52,14 +53,16 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
/** /**
* Return complied code that loads the evaluated output of buffer content into a temporary variable * Return complied code that loads the evaluated output of buffer content into a temporary variable
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string template code * @return string template code
*/ */
public function assign_to_var() public function assign_to_var(Smarty_Internal_Templateparser $parser)
{ {
$var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number); $var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number);
$tmp = $this->parser->compiler->appendCode('<?php ob_start();?>', $this->data); $tmp = $parser->compiler->appendCode('<?php ob_start();?>', $this->data);
$tmp = $this->parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>"); $tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
$this->parser->compiler->prefix_code[] = sprintf("%s", $tmp); $parser->compiler->prefix_code[] = sprintf("%s", $tmp);
return $var; return $var;
} }

View File

@@ -29,19 +29,18 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
/** /**
* Create root of parse tree for template elements * Create root of parse tree for template elements
* *
* @param object $parser parse object
*/ */
public function __construct($parser) public function __construct()
{ {
$this->parser = $parser;
} }
/** /**
* Append buffer to subtree * Append buffer to subtree
* *
* @param \Smarty_Internal_Templateparser $parser
* @param Smarty_Internal_ParseTree $subtree * @param Smarty_Internal_ParseTree $subtree
*/ */
public function append_subtree(Smarty_Internal_ParseTree $subtree) public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
{ {
if (!empty($subtree->subtrees)) { if (!empty($subtree->subtrees)) {
$this->subtrees = array_merge($this->subtrees, $subtree->subtrees); $this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
@@ -55,20 +54,23 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
/** /**
* Sanitize and merge subtree buffers together * Sanitize and merge subtree buffers together
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string template code content * @return string template code content
*/ */
public function to_smarty_php() public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
$code = ''; $code = '';
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) { for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) { if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) {
$subtree = $this->subtrees[$key]->to_smarty_php(); $subtree = $this->subtrees[$key]->to_smarty_php($parser);
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text || $this->subtrees[$key + 1]->data == '')) { while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text ||
$this->subtrees[$key + 1]->data == '')) {
$key ++; $key ++;
if ($this->subtrees[$key]->data == '') { if ($this->subtrees[$key]->data == '') {
continue; continue;
} }
$subtree .= $this->subtrees[$key]->to_smarty_php(); $subtree .= $this->subtrees[$key]->to_smarty_php($parser);
} }
if ($subtree == '') { if ($subtree == '') {
continue; continue;
@@ -77,13 +79,14 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
continue; continue;
} }
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) { if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
$subtree = $this->subtrees[$key]->to_smarty_php(); $subtree = $this->subtrees[$key]->to_smarty_php($parser);
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag || $this->subtrees[$key + 1]->data == '')) { while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag ||
$this->subtrees[$key + 1]->data == '')) {
$key ++; $key ++;
if ($this->subtrees[$key]->data == '') { if ($this->subtrees[$key]->data == '') {
continue; continue;
} }
$subtree = $this->parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php()); $subtree = $parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php($parser));
} }
if ($subtree == '') { if ($subtree == '') {
continue; continue;
@@ -91,7 +94,7 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
$code .= $subtree; $code .= $subtree;
continue; continue;
} }
$code .= $this->subtrees[$key]->to_smarty_php(); $code .= $this->subtrees[$key]->to_smarty_php($parser);
} }
return $code; return $code;
} }

View File

@@ -19,21 +19,21 @@ class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
/** /**
* Create template text buffer * Create template text buffer
* *
* @param object $parser parser object
* @param string $data text * @param string $data text
*/ */
public function __construct($parser, $data) public function __construct($data)
{ {
$this->parser = $parser;
$this->data = $data; $this->data = $data;
} }
/** /**
* Return buffer content * Return buffer content
* *
* @param \Smarty_Internal_Templateparser $parser
*
* @return string text * @return string text
*/ */
public function to_smarty_php() public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{ {
return $this->data; return $this->data;
} }

View File

@@ -8,7 +8,6 @@
* @author Uwe Tews * @author Uwe Tews
*/ */
/** /**
* Class SmartyTemplateCompiler * Class SmartyTemplateCompiler
* *
@@ -69,14 +68,14 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
tags in the templates are replaces with PHP code, tags in the templates are replaces with PHP code,
then written to compiled files. */ then written to compiled files. */
// init the lexer/parser to compile the template // init the lexer/parser to compile the template
$this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this); $this->parser = new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n",
$this->parser = new $this->parser_class($this->lex, $this); "\r"), "\n", $_content), $this), $this);
if ($isTemplateSource) { if ($isTemplateSource) {
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->properties['nocache_hash'] = '{$this->nocache_hash}';\n?>\n"); $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->properties['nocache_hash'] = '{$this->nocache_hash}';\n?>\n");
} }
if ($this->inheritance_child) { if ($this->inheritance_child) {
// start state on child templates // start state on child templates
$this->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); $this->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
} }
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding(); $mbEncoding = mb_internal_encoding();
@@ -87,15 +86,15 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
if ($this->smarty->_parserdebug) { if ($this->smarty->_parserdebug) {
$this->parser->PrintTrace(); $this->parser->PrintTrace();
$this->lex->PrintTrace(); $this->parser->lex->PrintTrace();
} }
// get tokens from lexer and parse them // get tokens from lexer and parse them
while ($this->lex->yylex()) { while ($this->parser->lex->yylex()) {
if ($this->smarty->_parserdebug) { if ($this->smarty->_parserdebug) {
echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " . echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " .
htmlentities($this->lex->value) . "</pre>"; htmlentities($this->parser->lex->value) . "</pre>";
} }
$this->parser->doParse($this->lex->token, $this->lex->value); $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value);
} }
// finish parsing process // finish parsing process
@@ -107,7 +106,8 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
if (count($this->_tag_stack) > 0) { if (count($this->_tag_stack) > 0) {
// get stacked info // get stacked info
list($openTag, $_data) = array_pop($this->_tag_stack); list($openTag, $_data) = array_pop($this->_tag_stack);
$this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . "{$this->smarty->right_delimiter} tag"); $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag .
"{$this->smarty->right_delimiter} tag");
} }
// return compiled code // return compiled code
return $this->parser->retvalue; return $this->parser->retvalue;

View File

@@ -25,13 +25,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public $smarty = null; public $smarty = null;
/**
* Lexer object
*
* @var object
*/
public $lex;
/** /**
* Parser object * Parser object
* *
@@ -311,6 +304,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var array * @var array
*/ */
public $_capture_stack = array(); public $_capture_stack = array();
private $savedSource = null;
/** /**
* Strip preg pattern * Strip preg pattern
* *
@@ -344,11 +340,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @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
* @throws \Exception
*/ */
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null) public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null)
{ {
// save template object in compiler class // save template object in compiler class
$this->template = $template; $this->template = $template;
$this->savedSource = $this->template->source;
try {
if (isset($this->template->smarty->security_policy)) { if (isset($this->template->smarty->security_policy)) {
$this->php_handling = $this->template->smarty->security_policy->php_handling; $this->php_handling = $this->template->smarty->security_policy->php_handling;
} else { } else {
@@ -361,7 +360,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
} else { } else {
$this->nocache_hash = $template->properties['nocache_hash']; $this->nocache_hash = $template->properties['nocache_hash'];
} }
$save_source = $this->template->source;
// template header code // template header code
$template_header = ''; $template_header = '';
if (!$this->suppressHeader) { if (!$this->suppressHeader) {
@@ -416,13 +414,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this->template); Smarty_Internal_Debug::end_compile($this->template);
} }
// free memory
unset($this->parser->lex, $this->parser->root_buffer, $this->parser->current_buffer, $this->parser);
} }
// restore source // restore source
$this->template->source = $save_source; $this->template->source = $this->savedSource;
unset($save_source); $this->savedSource = null;
$this->smarty->_current_file = $this->template->source->filepath; $this->smarty->_current_file = $this->template->source->filepath;
// free memory
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex);
// return compiled code to template object // return compiled code to template object
$merged_code = ''; $merged_code = '';
if (!empty($this->mergedSubTemplatesCode)) { if (!empty($this->mergedSubTemplatesCode)) {
@@ -444,14 +442,29 @@ abstract class Smarty_Internal_TemplateCompilerBase
} }
if (!empty($this->templateFunctionCode)) { if (!empty($this->templateFunctionCode)) {
// run post filter if required on compiled template code // run post filter if required on compiled template code
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && if ((isset($this->smarty->autoload_filters['post']) ||
!$this->suppressFilter isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter
) { ) {
$_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template); $_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template);
} else { } else {
$_compiled_code .= $this->templateFunctionCode; $_compiled_code .= $this->templateFunctionCode;
} }
} }
}
catch (Exception $e) {
// restore source
$this->template->source = $this->savedSource;
$this->savedSource = null;
$this->smarty->_current_file = $this->template->source->filepath;
// free memory
$this->parent_compiler = null;
$this->template = null;
$this->_tag_stack = array();
$this->_tag_objects = array();
$this->parser = null;
throw $e;
}
$this->parent_compiler = null; $this->parent_compiler = null;
$this->template = null; $this->template = null;
return $_compiled_code; return $_compiled_code;
@@ -557,7 +570,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
} else { } else {
// throw exception // throw exception
$this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' .
$tag . '"', $this->lex->taglineno); $tag . '"', null, true);
} }
} }
// check if tag is registered // check if tag is registered
@@ -682,8 +695,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
} else { } else {
// throw exception // throw exception
$this->trigger_template_error('not allowed closing tag method "' . $method . $this->trigger_template_error('not allowed closing tag method "' . $method .
'" in registered object "' . $base_tag . '" in registered object "' . $base_tag . '"', null, true);
'"', $this->lex->taglineno);
} }
} }
// registered block tag ? // registered block tag ?
@@ -738,7 +750,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
throw new SmartyException("Plugin \"{$tag}\" not callable"); throw new SmartyException("Plugin \"{$tag}\" not callable");
} }
} }
$this->trigger_template_error("unknown tag \"" . $tag . "\"", $this->lex->taglineno); $this->trigger_template_error("unknown tag \"" . $tag . "\"", null, true);
} }
} }
@@ -772,9 +784,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function processText($text) public function processText($text)
{ {
if ($this->parser->strip) { if ($this->parser->strip) {
return new Smarty_Internal_ParseTree_Text($this->parser, preg_replace($this->stripRegEx, '', $text)); return new Smarty_Internal_ParseTree_Text(preg_replace($this->stripRegEx, '', $text));
} else { } else {
return new Smarty_Internal_ParseTree_Text($this->parser, $text); return new Smarty_Internal_ParseTree_Text($text);
} }
} }
@@ -798,9 +810,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (!isset($this->_tag_objects[$tag])) { if (!isset($this->_tag_objects[$tag])) {
// lazy load internal compiler plugin // lazy load internal compiler plugin
$_tag = explode('_', $tag); $_tag = explode('_', $tag);
$_tag = array_map(function ($word) { $_tag = array_map('ucfirst', $_tag);
return ucfirst($word);
}, $_tag);
$class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag); $class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag);
if (class_exists($class_name) && if (class_exists($class_name) &&
(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
@@ -1076,25 +1086,33 @@ abstract class Smarty_Internal_TemplateCompilerBase
* *
* @param string $args individual error message or null * @param string $args individual error message or null
* @param string $line line-number * @param string $line line-number
* @param null|bool $tagline if true the line number of last tag
* *
* @throws SmartyCompilerException when an unexpected token is found * @throws \SmartyCompilerException when an unexpected token is found
*/ */
public function trigger_template_error($args = null, $line = null) public function trigger_template_error($args = null, $line = null, $tagline = null)
{ {
$lex = $this->parser->lex;
if ($tagline === true) {
// get line number of Tag
$line = $lex->taglineno;
} elseif (!isset($line)) {
// get template source line which has error // get template source line which has error
if (!isset($line)) { $line = $lex->line;
$line = $this->lex->line; } else {
$line = (int) $line;
} }
if (in_array($this->template->source->type, array('eval', 'string'))) { if (in_array($this->template->source->type, array('eval', 'string'))) {
$templateName = $this->template->source->type . ':' . $templateName = $this->template->source->type . ':' .
trim(preg_replace('![\t\r\n]+!', ' ', strlen($this->lex->data) > 40 ? substr($this->lex->data, 0, 40) . trim(preg_replace('![\t\r\n]+!', ' ', strlen($lex->data) > 40 ? substr($lex->data, 0, 40) .
'...' : $this->lex->data)); '...' : $lex->data));
} else { } else {
$templateName = $this->template->source->type . ':' . $this->template->source->filepath; $templateName = $this->template->source->type . ':' . $this->template->source->filepath;
} }
// $line += $this->trace_line_offset; // $line += $this->trace_line_offset;
$match = preg_split("/\n/", $this->lex->data); $match = preg_split("/\n/", $lex->data);
$error_text = 'Syntax error in template "' . $error_text = 'Syntax error in template "' .
(empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . '" on line ' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . '" on line ' .
($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) .
@@ -1105,13 +1123,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
} else { } else {
$expect = array(); $expect = array();
// expected token from parser // expected token from parser
$error_text .= ' - Unexpected "' . $this->lex->value . '"'; $error_text .= ' - Unexpected "' . $lex->value . '"';
if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) {
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
$exp_token = $this->parser->yyTokenName[$token]; $exp_token = $this->parser->yyTokenName[$token];
if (isset($this->lex->smarty_token_names[$exp_token])) { if (isset($lex->smarty_token_names[$exp_token])) {
// token type from lexer // token type from lexer
$expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"'; $expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"';
} else { } else {
// otherwise internal token name // otherwise internal token name
$expect[] = $this->parser->yyTokenName[$token]; $expect[] = $this->parser->yyTokenName[$token];

View File

@@ -157,7 +157,7 @@ class Smarty_Internal_Templateparser
* *
* @var Smarty_Internal_Templatelexer * @var Smarty_Internal_Templatelexer
*/ */
private $lex; public $lex;
/** /**
* internal error flag * internal error flag
@@ -206,7 +206,7 @@ class Smarty_Internal_Templateparser
* *
* @var Smarty_Security * @var Smarty_Security
*/ */
private $security = null; public $security = null;
/** /**
* constructor * constructor
@@ -221,7 +221,7 @@ class Smarty_Internal_Templateparser
$this->template = $this->compiler->template; $this->template = $this->compiler->template;
$this->smarty = $this->template->smarty; $this->smarty = $this->template->smarty;
$this->security = isset($this->smarty->security_policy) ? $this->smarty->security_policy : false; $this->security = isset($this->smarty->security_policy) ? $this->smarty->security_policy : false;
$this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template($this); $this->current_buffer = $this->root_buffer = new Smarty_Internal_ParseTree_Template();
} }
/** /**
@@ -231,7 +231,7 @@ class Smarty_Internal_Templateparser
*/ */
public function insertPhpCode($code) public function insertPhpCode($code)
{ {
$this->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($this, $code)); $this->current_buffer->append_subtree($this, new Smarty_Internal_ParseTree_Tag($this, $code));
} }
/** /**
@@ -1391,14 +1391,14 @@ class Smarty_Internal_Templateparser
#line 201 "../smarty/lexer/smarty_internal_templateparser.y" #line 201 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r0() function yy_r0()
{ {
$this->_retvalue = $this->root_buffer->to_smarty_php(); $this->_retvalue = $this->root_buffer->to_smarty_php($this);
} }
#line 209 "../smarty/lexer/smarty_internal_templateparser.y" #line 209 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r1() function yy_r1()
{ {
if ($this->yystack[$this->yyidx + 0]->minor != null) { if ($this->yystack[$this->yyidx + 0]->minor != null) {
$this->current_buffer->append_subtree($this->yystack[$this->yyidx + 0]->minor); $this->current_buffer->append_subtree($this, $this->yystack[$this->yyidx + 0]->minor);
} }
} }
@@ -1407,7 +1407,7 @@ class Smarty_Internal_Templateparser
{ {
if ($this->yystack[$this->yyidx + 0]->minor != null) { if ($this->yystack[$this->yyidx + 0]->minor != null) {
// because of possible code injection // because of possible code injection
$this->current_buffer->append_subtree($this->yystack[$this->yyidx + 0]->minor); $this->current_buffer->append_subtree($this, $this->yystack[$this->yyidx + 0]->minor);
} }
} }
@@ -1426,7 +1426,7 @@ class Smarty_Internal_Templateparser
#line 241 "../smarty/lexer/smarty_internal_templateparser.y" #line 241 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r5() function yy_r5()
{ {
$this->_retvalue = new Smarty_Internal_ParseTree_Text($this, $this->yystack[$this->yyidx + 0]->minor); $this->_retvalue = new Smarty_Internal_ParseTree_Text($this->yystack[$this->yyidx + 0]->minor);
} }
#line 245 "../smarty/lexer/smarty_internal_templateparser.y" #line 245 "../smarty/lexer/smarty_internal_templateparser.y"
@@ -2527,13 +2527,13 @@ class Smarty_Internal_Templateparser
#line 1288 "../smarty/lexer/smarty_internal_templateparser.y" #line 1288 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r182() function yy_r182()
{ {
$this->_retvalue = $this->yystack[$this->yyidx + - 1]->minor->to_smarty_php(); $this->_retvalue = $this->yystack[$this->yyidx + - 1]->minor->to_smarty_php($this);
} }
#line 1293 "../smarty/lexer/smarty_internal_templateparser.y" #line 1293 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r183() function yy_r183()
{ {
$this->yystack[$this->yyidx + - 1]->minor->append_subtree($this->yystack[$this->yyidx + 0]->minor); $this->yystack[$this->yyidx + - 1]->minor->append_subtree($this, $this->yystack[$this->yyidx + 0]->minor);
$this->_retvalue = $this->yystack[$this->yyidx + - 1]->minor; $this->_retvalue = $this->yystack[$this->yyidx + - 1]->minor;
} }
@@ -2546,14 +2546,13 @@ class Smarty_Internal_Templateparser
#line 1302 "../smarty/lexer/smarty_internal_templateparser.y" #line 1302 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r185() function yy_r185()
{ {
$this->_retvalue = new Smarty_Internal_ParseTree_Code($this, '(string)' . $this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)' . $this->yystack[$this->yyidx + - 1]->minor);
$this->yystack[$this->yyidx + - 1]->minor);
} }
#line 1310 "../smarty/lexer/smarty_internal_templateparser.y" #line 1310 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r187() function yy_r187()
{ {
$this->_retvalue = new Smarty_Internal_ParseTree_Code($this, '(string)$_smarty_tpl->tpl_vars[\'' . $this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)$_smarty_tpl->tpl_vars[\'' .
substr($this->yystack[$this->yyidx + 0]->minor, 1) . substr($this->yystack[$this->yyidx + 0]->minor, 1) .
'\']->value'); '\']->value');
} }
@@ -2561,8 +2560,8 @@ class Smarty_Internal_Templateparser
#line 1318 "../smarty/lexer/smarty_internal_templateparser.y" #line 1318 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r189() function yy_r189()
{ {
$this->_retvalue = new Smarty_Internal_ParseTree_Code($this, '(string)(' . $this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)(' . $this->yystack[$this->yyidx + - 1]->minor .
$this->yystack[$this->yyidx + - 1]->minor . ')'); ')');
} }
#line 1322 "../smarty/lexer/smarty_internal_templateparser.y" #line 1322 "../smarty/lexer/smarty_internal_templateparser.y"
@@ -2574,7 +2573,7 @@ class Smarty_Internal_Templateparser
#line 1326 "../smarty/lexer/smarty_internal_templateparser.y" #line 1326 "../smarty/lexer/smarty_internal_templateparser.y"
function yy_r191() function yy_r191()
{ {
$this->_retvalue = new Smarty_Internal_ParseTree_DqContent($this, $this->yystack[$this->yyidx + 0]->minor); $this->_retvalue = new Smarty_Internal_ParseTree_DqContent($this->yystack[$this->yyidx + 0]->minor);
} }
private $_retvalue; private $_retvalue;

View File

@@ -389,12 +389,12 @@ class Smarty_Security
if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) { if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
return true; return true;
} else { } else {
$compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", $compiler->lex->taglineno); $compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true);
} }
} elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) { } elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) {
return true; return true;
} else { } else {
$compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", $compiler->lex->taglineno); $compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true);
} }
return false; // should not, but who knows what happens to the compiler in the future? return false; // should not, but who knows what happens to the compiler in the future?
@@ -414,7 +414,7 @@ class Smarty_Security
if (!in_array($var_name, $this->disabled_special_smarty_vars)) { if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
return true; return true;
} else { } else {
$compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", $compiler->lex->taglineno); $compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", null, true);
} }
return false; // should not, but who knows what happens to the compiler in the future? return false; // should not, but who knows what happens to the compiler in the future?
@@ -440,14 +440,14 @@ class Smarty_Security
if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) { if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
return true; return true;
} else { } else {
$compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", $compiler->lex->taglineno); $compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", null, true);
} }
} elseif (in_array($modifier_name, $this->allowed_modifiers) && } elseif (in_array($modifier_name, $this->allowed_modifiers) &&
!in_array($modifier_name, $this->disabled_modifiers) !in_array($modifier_name, $this->disabled_modifiers)
) { ) {
return true; return true;
} else { } else {
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", $compiler->lex->taglineno); $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", null, true);
} }
return false; // should not, but who knows what happens to the compiler in the future? return false; // should not, but who knows what happens to the compiler in the future?
@@ -639,9 +639,9 @@ class Smarty_Security
/** /**
* Exit template processing * Exit template processing
* *
* @param $template * @internal param $template
*/ */
public function exitTemplate($template) public function exitTemplate()
{ {
if ($this->max_template_nesting > 0) { if ($this->max_template_nesting > 0) {
$this->_current_template_nesting --; $this->_current_template_nesting --;