mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- avoid possible circular object referances caused by parser/lexer objects
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
===== 3.1.28-dev===== (xx.xx.2015)
|
||||
06.08.2015
|
||||
- avoid possible circular object referances caused by parser/lexer objects
|
||||
|
||||
03.08.2015
|
||||
- rework clear cache methods
|
||||
- bugfix compileAllConfig() was broken since 3.1.22 because of the changes in config file processing
|
||||
|
@@ -95,7 +95,7 @@ class Smarty_Internal_Configfilelexer
|
||||
/**
|
||||
* storage for assembled token patterns
|
||||
*
|
||||
* @var sring
|
||||
* @var string
|
||||
*/
|
||||
private $yy_global_pattern1 = null;
|
||||
private $yy_global_pattern2 = null;
|
||||
|
@@ -361,7 +361,7 @@ class Smarty_Internal_Templatelexer
|
||||
}
|
||||
text {
|
||||
$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])) {
|
||||
$to = $match[0][1];
|
||||
}
|
||||
|
@@ -79,7 +79,7 @@ class Smarty_Internal_Templateparser
|
||||
*
|
||||
* @var Smarty_Internal_Templatelexer
|
||||
*/
|
||||
private $lex;
|
||||
public $lex;
|
||||
/**
|
||||
* internal error flag
|
||||
*
|
||||
@@ -122,7 +122,7 @@ class Smarty_Internal_Templateparser
|
||||
*
|
||||
* @var Smarty_Security
|
||||
*/
|
||||
private $security = null;
|
||||
public $security = null;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
@@ -137,7 +137,7 @@ class Smarty_Internal_Templateparser
|
||||
$this->template = $this->compiler->template;
|
||||
$this->smarty = $this->template->smarty;
|
||||
$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)
|
||||
{
|
||||
$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
|
||||
//
|
||||
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
|
||||
template ::= template_element(e). {
|
||||
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). {
|
||||
if (e != null) {
|
||||
// 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
|
||||
template_element(res) ::= literal(l). {
|
||||
res = new Smarty_Internal_ParseTree_Text($this, l);
|
||||
res = new Smarty_Internal_ParseTree_Text(l);
|
||||
}
|
||||
// php tags
|
||||
template_element(res)::= PHP(o). {
|
||||
@@ -1286,12 +1286,12 @@ doublequoted_with_quotes(res) ::= QUOTE 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). {
|
||||
o1->append_subtree(o2);
|
||||
o1->append_subtree($this, o2);
|
||||
res = o1;
|
||||
}
|
||||
|
||||
@@ -1300,23 +1300,23 @@ doublequoted(res) ::= doublequotedcontent(o). {
|
||||
}
|
||||
|
||||
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. {
|
||||
res = new Smarty_Internal_ParseTree_Code($this, '(string)'.e);
|
||||
res = new Smarty_Internal_ParseTree_Code('(string)'.e);
|
||||
}
|
||||
|
||||
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. {
|
||||
res = new Smarty_Internal_ParseTree_Code($this, '(string)'.v);
|
||||
res = new Smarty_Internal_ParseTree_Code('(string)'.v);
|
||||
}
|
||||
|
||||
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). {
|
||||
@@ -1324,6 +1324,6 @@ doublequotedcontent(res) ::= smartytag(st). {
|
||||
}
|
||||
|
||||
doublequotedcontent(res) ::= TEXT(o). {
|
||||
res = new Smarty_Internal_ParseTree_DqContent($this, o);
|
||||
res = new Smarty_Internal_ParseTree_DqContent(o);
|
||||
}
|
||||
|
||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.28-dev/39';
|
||||
const SMARTY_VERSION = '3.1.28-dev/40';
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
// intentionally left blank
|
||||
$i =0;// intentionally left blank
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -19,13 +19,14 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {assign} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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
|
||||
$this->required_attributes = array('var', 'value');
|
||||
@@ -55,7 +56,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} 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
|
||||
|
@@ -73,7 +73,9 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
$_name = trim($_attr['name'], "\"'");
|
||||
|
||||
// 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['prepend'] = false;
|
||||
}
|
||||
@@ -82,7 +84,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
if ($compiler->inheritance_child) {
|
||||
array_unshift(self::$nested_block_names, $_name);
|
||||
// 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']) {
|
||||
self::$block_data[$_name]['source'] .= ' nocache';
|
||||
}
|
||||
@@ -94,7 +96,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
$this->openTag($compiler, 'block', $save);
|
||||
// set flag for {block} tag
|
||||
$compiler->inheritance = true;
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
}
|
||||
@@ -107,7 +109,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
$compiler->inheritance = true;
|
||||
$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;
|
||||
|
||||
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]['child'] = true;
|
||||
}
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
}
|
||||
@@ -146,7 +148,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
}
|
||||
}
|
||||
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?
|
||||
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
|
||||
$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) {
|
||||
Smarty_Internal_Debug::ignore($_tpl);
|
||||
}
|
||||
@@ -171,11 +174,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||
$nocache = $compiler->nocache || $compiler->tag_nocache;
|
||||
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') {
|
||||
$_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') {
|
||||
$_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])) {
|
||||
$_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) {
|
||||
$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)) {
|
||||
$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;
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
}
|
||||
@@ -282,29 +287,38 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
||||
if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
|
||||
$name2 = Smarty_Internal_Compile_Block::$nested_block_names[0];
|
||||
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'];
|
||||
} else {
|
||||
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') {
|
||||
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 {
|
||||
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
} else {
|
||||
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 (strpos($compiler->template->block_data[$name1]['source'], Smarty_Internal_Compile_Block::parent) !== false) {
|
||||
if (isset($compiler->template->block_data[$name1]) &&
|
||||
!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']);
|
||||
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
|
||||
$compiler->template->block_data[$name1]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
|
||||
} 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 {
|
||||
$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]);
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||
}
|
||||
$compiler->has_code = false;
|
||||
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);
|
||||
} else {
|
||||
if ($saved_data[0]['hide'] && !isset($compiler->template->block_data[$_name]['source'])) {
|
||||
$_output = '';
|
||||
} 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'])) {
|
||||
@@ -388,7 +404,8 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil
|
||||
$save = array($_attr, $compiler->nocache);
|
||||
|
||||
// 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);
|
||||
|
||||
|
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('levels');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -34,25 +35,26 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {break} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
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 (!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'];
|
||||
} else {
|
||||
@@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
$stack_count --;
|
||||
}
|
||||
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};?>";
|
||||
|
@@ -73,7 +73,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
$parameter = array_map('strtolower', $parameter);
|
||||
$tag = trim($parameter[0], '"\'');
|
||||
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";
|
||||
}
|
||||
|
@@ -41,19 +41,20 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {config_load} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @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);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
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
|
||||
@@ -70,7 +71,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
if (isset($_is_legal_scope[$_attr['scope']])) {
|
||||
$scope = $_attr['scope'];
|
||||
} 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
|
||||
|
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('levels');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -34,25 +35,26 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {continue} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
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 (!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'];
|
||||
} else {
|
||||
@@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
|
||||
$stack_count --;
|
||||
}
|
||||
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};?>";
|
||||
|
@@ -36,20 +36,22 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {extends} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @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
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
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) {
|
||||
$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'];
|
||||
@@ -60,7 +62,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
* used in evaluated code
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
eval("\$tpl_name = {$name};");
|
||||
eval("\$tpl_name = @{$name};");
|
||||
} else {
|
||||
$tpl_name = trim($name, '\'"');
|
||||
}
|
||||
@@ -69,7 +71,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
// check for recursion
|
||||
$uid = $_source->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);
|
||||
}
|
||||
$compiler->extends_uid[$uid] = true;
|
||||
@@ -80,14 +82,14 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
array_unshift($compiler->sources, $source);
|
||||
$uid = $source->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);
|
||||
}
|
||||
$compiler->extends_uid[$uid] = true;
|
||||
}
|
||||
}
|
||||
$compiler->inheritance_child = true;
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -110,14 +110,14 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
||||
}
|
||||
foreach ($attributes as $a => $v) {
|
||||
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']);
|
||||
if ($fromName) {
|
||||
foreach (array('item', 'key') as $a) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -44,19 +44,20 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {function} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @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
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
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']);
|
||||
$_name = trim($_attr['name'], "'\"");
|
||||
@@ -67,7 +68,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
$compiler->compiles_template_function = true;
|
||||
// Init temporary context
|
||||
$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->caching = true;
|
||||
return true;
|
||||
@@ -130,7 +131,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// 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']}";
|
||||
$_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 .= "\\\$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\";?>";
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($_functionCode);
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
$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";
|
||||
@@ -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 .= "/*/ {$_funcName}_nocache */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(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()));
|
||||
$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($compiler->parser)));
|
||||
}
|
||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName;
|
||||
$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 .= $_paramsCode;
|
||||
$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($_functionCode);
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$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 .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php();
|
||||
$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->parser);
|
||||
// restore old buffer
|
||||
$compiler->parser->current_buffer = $saved_data[1];
|
||||
// restore old status
|
||||
|
@@ -19,13 +19,14 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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
|
||||
$_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;
|
||||
|
||||
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'])) {
|
||||
@@ -45,7 +46,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
$var = trim($parameter['if condition']['var']['var'], "'");
|
||||
} else {
|
||||
$var = trim($parameter['if condition']['var'], "'");
|
||||
}
|
||||
}
|
||||
if (isset($compiler->template->tpl_vars[$var])) {
|
||||
$compiler->template->tpl_vars[$var]->nocache = true;
|
||||
} else {
|
||||
@@ -55,11 +56,19 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
$_nocache = '';
|
||||
}
|
||||
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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} 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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
@@ -80,13 +89,13 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {else} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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'));
|
||||
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
|
||||
@@ -106,13 +115,14 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {elseif} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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
|
||||
$_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'));
|
||||
|
||||
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'])) {
|
||||
@@ -149,11 +159,20 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
if ($condition_by_assign) {
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} 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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
@@ -166,17 +185,29 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
$tmp = '';
|
||||
foreach ($compiler->prefix_code as $code) {
|
||||
$tmp = $compiler->appendCode($tmp, $code);
|
||||
}
|
||||
}
|
||||
$compiler->prefix_code = array();
|
||||
$tmp = $compiler->appendCode("<?php } else {?>", $tmp);
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if ($condition_by_assign) {
|
||||
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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} 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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
@@ -198,13 +229,13 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
|
@@ -20,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* caching mode to create nocache code but no cache file
|
||||
*/
|
||||
const CACHING_NOCACHE_CODE = 9999;
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -27,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -34,6 +36,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -41,6 +44,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('nocache', 'inline', 'caching');
|
||||
|
||||
/**
|
||||
* 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
|
||||
$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) {
|
||||
// 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;
|
||||
if ($compiler->template->caching) {
|
||||
// must use individual cache file
|
||||
//$_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');
|
||||
}
|
||||
}
|
||||
// variable 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;
|
||||
if ($compiler->template->caching) {
|
||||
// must use individual cache file
|
||||
//$_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');
|
||||
}
|
||||
}
|
||||
@@ -167,7 +183,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
|
||||
$has_compiled_template = false;
|
||||
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;
|
||||
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) {
|
||||
$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
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
eval("\$tpl_name = $include_file;");
|
||||
eval("\$tpl_name = @$include_file;");
|
||||
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) {
|
||||
$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);
|
||||
// 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) {
|
||||
$tpl->compiler->inheritance = true;
|
||||
}
|
||||
@@ -195,7 +214,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$tpl->mustCompile = true;
|
||||
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
|
||||
$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
|
||||
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
|
||||
unset($tpl->compiler);
|
||||
@@ -243,12 +263,13 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
}
|
||||
$_vars = 'array(' . join(',', $_pairs) . ')';
|
||||
} 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 {
|
||||
$_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 && !$compiler->tag_nocache && !$compiler->nocache) {
|
||||
// never call inline templates in nocache mode
|
||||
|
@@ -43,13 +43,14 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {include_php} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return string compiled code
|
||||
* @return string
|
||||
* @throws \SmartyCompilerException
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
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;
|
||||
$_filepath = false;
|
||||
$_file = null;
|
||||
eval('$_file = ' . $_attr['file'] . ';');
|
||||
eval('$_file = @' . $_attr['file'] . ';');
|
||||
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
|
||||
$_filepath = $compiler->smarty->_realpath($_file, true);
|
||||
} else {
|
||||
@@ -83,7 +84,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
|
@@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -31,6 +32,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -42,12 +44,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {insert} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@@ -63,7 +66,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
|
||||
$_output = '<?php ';
|
||||
// save possible attributes
|
||||
eval('$_name = ' . $_attr['name'] . ';');
|
||||
eval('$_name = @' . $_attr['name'] . ';');
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
@@ -80,7 +83,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
$_function = "smarty_insert_{$_name}";
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
eval('$_script = ' . $_attr['script'] . ';');
|
||||
eval('$_script = @' . $_attr['script'] . ';');
|
||||
if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
|
||||
$_filepath = $_script;
|
||||
} else {
|
||||
@@ -100,13 +103,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
}
|
||||
}
|
||||
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
|
||||
$_output .= "require_once '{$_filepath}' ;";
|
||||
require_once $_filepath;
|
||||
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 {
|
||||
$_filepath = 'null';
|
||||
@@ -115,7 +118,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
if (!is_callable($_function)) {
|
||||
// try plugin
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +127,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
// convert attributes into parameter array string
|
||||
$_paramsArray = array();
|
||||
foreach ($_attr as $_key => $_value) {
|
||||
$_paramsArray[] = "'$_key' => $_value";
|
||||
$_paramsArray[] = "'$_key' => $_value";
|
||||
}
|
||||
$_params = 'array(' . implode(", ", $_paramsArray) . ')';
|
||||
// call insert
|
||||
|
@@ -20,16 +20,17 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {ldelim} tag
|
||||
* This tag does output the left delimiter
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
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
|
||||
$compiler->has_code = true;
|
||||
|
@@ -27,12 +27,12 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {nocache} tag
|
||||
* This tag does not generate compiled output. It only sets a compiler flag.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$this->openTag($compiler, 'nocache', array($compiler->nocache));
|
||||
@@ -57,12 +57,12 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {/nocache} tag
|
||||
* This tag does not generate compiled output. It only sets a compiler flag.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// leave nocache mode
|
||||
|
@@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block plugin
|
||||
* @param string $function PHP function name
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block plugin
|
||||
* @param string $function PHP function name
|
||||
*
|
||||
* @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') {
|
||||
// opening tag of block plugin
|
||||
@@ -75,9 +75,13 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
$mod_pre = $mod_post = '';
|
||||
} else {
|
||||
$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";
|
||||
|
@@ -155,7 +155,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
||||
*/
|
||||
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);
|
||||
$tag = trim($parameter[0], '"\'');
|
||||
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);
|
||||
if ((!isset($parameter[2]) || false === $property = $compiler->getId($parameter[2])) ||
|
||||
!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}'";
|
||||
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
|
||||
|
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array();
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -34,15 +35,15 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function plugin
|
||||
* @param string $function PHP function name
|
||||
* @param string $function PHP function name
|
||||
*
|
||||
* @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
|
||||
$compiler->has_output = true;
|
||||
|
@@ -20,13 +20,14 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
/**
|
||||
* Compiles code for modifier execution
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@@ -52,7 +53,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
$output = "{$function}({$params})";
|
||||
} else {
|
||||
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 {
|
||||
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
|
||||
}
|
||||
@@ -73,7 +75,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
// modifiercompiler plugin
|
||||
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
|
||||
// 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;
|
||||
$output = $plugin($single_modifier, $compiler);
|
||||
}
|
||||
@@ -85,7 +89,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
// modifier plugin
|
||||
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
|
||||
// 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})";
|
||||
}
|
||||
$compiler->known_modifier_type[$modifier] = $type;
|
||||
@@ -96,7 +102,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
// PHP function
|
||||
if (is_callable($modifier)) {
|
||||
// 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})";
|
||||
}
|
||||
$compiler->known_modifier_type[$modifier] = $type;
|
||||
@@ -105,21 +113,29 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
break;
|
||||
case 6:
|
||||
// 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];
|
||||
// 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)) {
|
||||
$output = "{$function}({$params})";
|
||||
} else {
|
||||
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 {
|
||||
$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
|
||||
$compiler->known_modifier_type[$modifier] = 4;
|
||||
} else {
|
||||
@@ -130,7 +146,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block object
|
||||
* @param string $method name of method to call
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block object
|
||||
* @param string $method name of method to call
|
||||
*
|
||||
* @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') {
|
||||
// opening tag of block plugin
|
||||
@@ -76,9 +76,13 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
$mod_pre = $mod_post = '';
|
||||
} else {
|
||||
$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";
|
||||
|
@@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param string $method name of method to call
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param string $method name of method to call
|
||||
*
|
||||
* @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
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
@@ -44,7 +44,9 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
$compiler->tag_nocache = true;
|
||||
$save = $compiler->template->has_nocache_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;
|
||||
return '';
|
||||
}
|
||||
@@ -53,29 +55,31 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
return '';
|
||||
} 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,
|
||||
'quote'), $_attr['code']);
|
||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output));
|
||||
'quote'), $_attr['code']);
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Text($output));
|
||||
return '';
|
||||
} elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') {
|
||||
$compiler->tag_nocache = true;
|
||||
$save = $compiler->template->has_nocache_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;
|
||||
return '';
|
||||
} elseif ($compiler->php_handling == Smarty::PHP_ALLOW) {
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', null, true);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
return $_attr['code'];
|
||||
} 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 {
|
||||
$compiler->has_code = true;
|
||||
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, '#');
|
||||
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
|
||||
@@ -84,11 +88,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
if ('nocache' == trim($match[2])) {
|
||||
$compiler->tag_nocache = true;
|
||||
} 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}#",
|
||||
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
|
||||
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +144,9 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
if ($lex->phpType == 'unmatched') {
|
||||
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;
|
||||
}
|
||||
$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) {
|
||||
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];
|
||||
$from = $close + strlen($match[0][0]);
|
||||
} else {
|
||||
@@ -190,6 +197,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
* Call back function for $php_handling = PHP_QUOTE
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param $match
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function quote($match)
|
||||
{
|
||||
return htmlspecialchars($match[0], ENT_QUOTES);
|
||||
|
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('assign');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -34,14 +35,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
/**
|
||||
* Compiles code for generating output from any expression
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return string compiled code
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@@ -57,7 +58,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
$output = $parameter['value'];
|
||||
// tag modifier
|
||||
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']) {
|
||||
// default modifier
|
||||
@@ -74,7 +76,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
$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
|
||||
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
|
||||
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)) {
|
||||
$output = "{$function}({$output},\$_smarty_tpl)";
|
||||
} 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)) {
|
||||
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;
|
||||
} 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 string $name name of variable filter
|
||||
* @param string $output embedded output
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param string $name name of variable filter
|
||||
* @param string $output embedded output
|
||||
*
|
||||
* @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}";
|
||||
$path = $compiler->smarty->loadPlugin($plugin_name, false);
|
||||
|
@@ -27,14 +27,14 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
/**
|
||||
* Compiles code for the execution of a block function
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block function
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block function
|
||||
*
|
||||
* @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') {
|
||||
// opening tag of block plugin
|
||||
@@ -95,14 +95,22 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
$mod_pre = $mod_post = '';
|
||||
} else {
|
||||
$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)) {
|
||||
$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])) {
|
||||
$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 {
|
||||
$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);?>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -27,14 +27,14 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
|
||||
/**
|
||||
* Compiles code for the execution of a registered function
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
*
|
||||
* @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
|
||||
$compiler->has_output = true;
|
||||
|
@@ -19,18 +19,19 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
/**
|
||||
* Compiles code for the special $smarty variables
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param $parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
|
||||
$variable = strtolower($compiler->getId($_index[0]));
|
||||
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) ||
|
||||
$compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
|
||||
@@ -53,7 +54,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
return '$_COOKIE';
|
||||
return '$_COOKIE';
|
||||
case 'get':
|
||||
case 'post':
|
||||
case 'env':
|
||||
|
@@ -25,11 +25,11 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
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
|
||||
$compiler->has_code = true;
|
||||
|
@@ -93,7 +93,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
||||
unset($_attr['name']);
|
||||
foreach ($attributes as $a => $v) {
|
||||
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 ++ . '_';
|
||||
|
@@ -25,7 +25,7 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @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->template->variable_filters = $parameter['modifier_list'];
|
||||
@@ -53,7 +53,7 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// reset variable filter to previous state
|
||||
|
@@ -19,20 +19,21 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {while} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @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
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$this->openTag($compiler, 'while', $compiler->nocache);
|
||||
|
||||
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
|
||||
@@ -55,11 +56,19 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
||||
$_nocache = '';
|
||||
}
|
||||
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 .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} 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 .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_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 .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
@@ -80,12 +89,12 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/while} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
|
@@ -21,6 +21,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
* @var array
|
||||
*/
|
||||
public $required_attributes = array();
|
||||
|
||||
/**
|
||||
* Array of names of optional attribute required by tag
|
||||
* use array('_any') if there is no restriction of attributes names
|
||||
@@ -28,12 +29,14 @@ abstract class Smarty_Internal_CompileBase
|
||||
* @var array
|
||||
*/
|
||||
public $optional_attributes = array();
|
||||
|
||||
/**
|
||||
* Shorttag attribute order defined by its names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $shorttag_order = array();
|
||||
|
||||
/**
|
||||
* Array of names of valid option flags
|
||||
*
|
||||
@@ -68,7 +71,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
$_indexed_attr[$this->shorttag_order[$key]] = $mixed;
|
||||
} else {
|
||||
// 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
|
||||
} else {
|
||||
@@ -90,7 +93,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
$_indexed_attr[$kv['key']] = false;
|
||||
}
|
||||
} 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
|
||||
} else {
|
||||
@@ -102,7 +105,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
// check if all required attributes present
|
||||
foreach ($this->required_attributes as $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
|
||||
@@ -110,7 +113,7 @@ abstract class Smarty_Internal_CompileBase
|
||||
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags);
|
||||
foreach ($_indexed_attr as $key => $dummy) {
|
||||
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
|
||||
$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;
|
||||
}
|
||||
// wrong nesting of tags
|
||||
$compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("unexpected closing tag", null, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -17,13 +17,6 @@
|
||||
abstract class Smarty_Internal_ParseTree
|
||||
{
|
||||
|
||||
/**
|
||||
* Parser object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $parser;
|
||||
|
||||
/**
|
||||
* Buffer content
|
||||
*
|
||||
@@ -41,9 +34,21 @@ abstract class Smarty_Internal_ParseTree
|
||||
/**
|
||||
* Return buffer
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_Code extends Smarty_Internal_ParseTree
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content in parentheses
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return sprintf("(%s)", $this->data);
|
||||
}
|
||||
|
@@ -25,43 +25,45 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
|
||||
*/
|
||||
public function __construct($parser, Smarty_Internal_ParseTree $subtree)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->subtrees[] = $subtree;
|
||||
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
|
||||
*
|
||||
* @param Smarty_Internal_ParseTree $subtree parse tree buffer
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
* @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;
|
||||
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) {
|
||||
$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) {
|
||||
$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 {
|
||||
$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 {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
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
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string compiled template code
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
$code = '';
|
||||
foreach ($this->subtrees as $subtree) {
|
||||
@@ -69,15 +71,15 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
|
||||
$code .= ".";
|
||||
}
|
||||
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$more_php = $subtree->assign_to_var();
|
||||
$more_php = $subtree->assign_to_var($parser);
|
||||
} else {
|
||||
$more_php = $subtree->to_smarty_php();
|
||||
$more_php = $subtree->to_smarty_php($parser);
|
||||
}
|
||||
|
||||
$code .= $more_php;
|
||||
|
||||
if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
|
||||
$this->parser->compiler->has_variable_string = true;
|
||||
$parser->compiler->has_variable_string = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_DqContent extends Smarty_Internal_ParseTree
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return content as double quoted string
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string doubled quoted string
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return '"' . $this->data . '"';
|
||||
}
|
||||
|
@@ -29,12 +29,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
|
||||
/**
|
||||
* Create parse tree buffer for Smarty tag
|
||||
*
|
||||
* @param object $parser parser object
|
||||
* @param string $data content
|
||||
* @param \Smarty_Internal_Templateparser $parser parser object
|
||||
* @param string $data content
|
||||
*/
|
||||
public function __construct($parser, $data)
|
||||
public function __construct(Smarty_Internal_Templateparser $parser, $data)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
$this->data = $data;
|
||||
$this->saved_block_nesting = $parser->block_nesting_level;
|
||||
}
|
||||
@@ -42,9 +41,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
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
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @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);
|
||||
$tmp = $this->parser->compiler->appendCode('<?php ob_start();?>', $this->data);
|
||||
$tmp = $this->parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
|
||||
$this->parser->compiler->prefix_code[] = sprintf("%s", $tmp);
|
||||
$tmp = $parser->compiler->appendCode('<?php ob_start();?>', $this->data);
|
||||
$tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
|
||||
$parser->compiler->prefix_code[] = sprintf("%s", $tmp);
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
@@ -29,19 +29,18 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param Smarty_Internal_ParseTree $subtree
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
* @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)) {
|
||||
$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
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string template code content
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
$code = '';
|
||||
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
|
||||
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text || $this->subtrees[$key + 1]->data == '')) {
|
||||
$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 == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[$key]->data == '') {
|
||||
continue;
|
||||
}
|
||||
$subtree .= $this->subtrees[$key]->to_smarty_php();
|
||||
$subtree .= $this->subtrees[$key]->to_smarty_php($parser);
|
||||
}
|
||||
if ($subtree == '') {
|
||||
continue;
|
||||
@@ -77,13 +79,14 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
||||
continue;
|
||||
}
|
||||
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
|
||||
$subtree = $this->subtrees[$key]->to_smarty_php();
|
||||
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag || $this->subtrees[$key + 1]->data == '')) {
|
||||
$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 == '')) {
|
||||
$key ++;
|
||||
if ($this->subtrees[$key]->data == '') {
|
||||
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 == '') {
|
||||
continue;
|
||||
@@ -91,7 +94,7 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
||||
$code .= $subtree;
|
||||
continue;
|
||||
}
|
||||
$code .= $this->subtrees[$key]->to_smarty_php();
|
||||
$code .= $this->subtrees[$key]->to_smarty_php($parser);
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
|
@@ -19,21 +19,21 @@ class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buffer content
|
||||
*
|
||||
* @param \Smarty_Internal_Templateparser $parser
|
||||
*
|
||||
* @return string text
|
||||
*/
|
||||
public function to_smarty_php()
|
||||
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class SmartyTemplateCompiler
|
||||
*
|
||||
@@ -69,14 +68,14 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
|
||||
tags in the templates are replaces with PHP code,
|
||||
then written to compiled files. */
|
||||
// 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($this->lex, $this);
|
||||
$this->parser = new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n",
|
||||
"\r"), "\n", $_content), $this), $this);
|
||||
if ($isTemplateSource) {
|
||||
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->properties['nocache_hash'] = '{$this->nocache_hash}';\n?>\n");
|
||||
}
|
||||
if ($this->inheritance_child) {
|
||||
// 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) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
@@ -87,15 +86,15 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
|
||||
|
||||
if ($this->smarty->_parserdebug) {
|
||||
$this->parser->PrintTrace();
|
||||
$this->lex->PrintTrace();
|
||||
$this->parser->lex->PrintTrace();
|
||||
}
|
||||
// get tokens from lexer and parse them
|
||||
while ($this->lex->yylex()) {
|
||||
while ($this->parser->lex->yylex()) {
|
||||
if ($this->smarty->_parserdebug) {
|
||||
echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
|
||||
htmlentities($this->lex->value) . "</pre>";
|
||||
echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " .
|
||||
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
|
||||
@@ -107,7 +106,8 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
|
||||
if (count($this->_tag_stack) > 0) {
|
||||
// get stacked info
|
||||
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 $this->parser->retvalue;
|
||||
|
@@ -25,13 +25,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $smarty = null;
|
||||
|
||||
/**
|
||||
* Lexer object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $lex;
|
||||
|
||||
/**
|
||||
* Parser object
|
||||
*
|
||||
@@ -311,6 +304,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
* @var array
|
||||
*/
|
||||
public $_capture_stack = array();
|
||||
|
||||
private $savedSource = null;
|
||||
|
||||
/**
|
||||
* Strip preg pattern
|
||||
*
|
||||
@@ -344,114 +340,131 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
* @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler
|
||||
*
|
||||
* @return bool true if compiling succeeded, false if it failed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null)
|
||||
{
|
||||
// save template object in compiler class
|
||||
$this->template = $template;
|
||||
if (isset($this->template->smarty->security_policy)) {
|
||||
$this->php_handling = $this->template->smarty->security_policy->php_handling;
|
||||
} else {
|
||||
$this->php_handling = $this->template->smarty->php_handling;
|
||||
}
|
||||
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
|
||||
$nocache = isset($nocache) ? $nocache : false;
|
||||
if (empty($template->properties['nocache_hash'])) {
|
||||
$template->properties['nocache_hash'] = $this->nocache_hash;
|
||||
} else {
|
||||
$this->nocache_hash = $template->properties['nocache_hash'];
|
||||
}
|
||||
$save_source = $this->template->source;
|
||||
// template header code
|
||||
$template_header = '';
|
||||
if (!$this->suppressHeader) {
|
||||
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " .
|
||||
strftime("%Y-%m-%d %H:%M:%S") . "\n";
|
||||
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
|
||||
}
|
||||
|
||||
if (empty($this->template->source->components)) {
|
||||
$this->sources = array($template->source);
|
||||
} else {
|
||||
// we have array of inheritance templates by extends: resource
|
||||
$this->sources = array_reverse($template->source->components);
|
||||
}
|
||||
$loop = 0;
|
||||
// the $this->sources array can get additional elements while compiling by the {extends} tag
|
||||
while ($this->template->source = array_shift($this->sources)) {
|
||||
$this->smarty->_current_file = $this->template->source->filepath;
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_compile($this->template);
|
||||
}
|
||||
$no_sources = count($this->sources);
|
||||
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath,
|
||||
$this->template->source->getTimeStamp(),
|
||||
$this->template->source->type);
|
||||
$loop ++;
|
||||
if ($no_sources) {
|
||||
$this->inheritance_child = true;
|
||||
$this->savedSource = $this->template->source;
|
||||
try {
|
||||
if (isset($this->template->smarty->security_policy)) {
|
||||
$this->php_handling = $this->template->smarty->security_policy->php_handling;
|
||||
} else {
|
||||
$this->inheritance_child = false;
|
||||
$this->php_handling = $this->template->smarty->php_handling;
|
||||
}
|
||||
// flag for nochache sections
|
||||
$this->nocache = $nocache;
|
||||
$this->tag_nocache = false;
|
||||
// reset has nocache code flag
|
||||
$this->template->has_nocache_code = false;
|
||||
$this->has_variable_string = false;
|
||||
$this->prefix_code = array();
|
||||
$_compiled_code = '';
|
||||
// get template source
|
||||
$_content = $this->template->source->getContent();
|
||||
if ($_content != '') {
|
||||
// run pre filter if required
|
||||
if ((isset($this->smarty->autoload_filters['pre']) ||
|
||||
isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter
|
||||
) {
|
||||
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
|
||||
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
|
||||
$nocache = isset($nocache) ? $nocache : false;
|
||||
if (empty($template->properties['nocache_hash'])) {
|
||||
$template->properties['nocache_hash'] = $this->nocache_hash;
|
||||
} else {
|
||||
$this->nocache_hash = $template->properties['nocache_hash'];
|
||||
}
|
||||
// template header code
|
||||
$template_header = '';
|
||||
if (!$this->suppressHeader) {
|
||||
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " .
|
||||
strftime("%Y-%m-%d %H:%M:%S") . "\n";
|
||||
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
|
||||
}
|
||||
|
||||
if (empty($this->template->source->components)) {
|
||||
$this->sources = array($template->source);
|
||||
} else {
|
||||
// we have array of inheritance templates by extends: resource
|
||||
$this->sources = array_reverse($template->source->components);
|
||||
}
|
||||
$loop = 0;
|
||||
// the $this->sources array can get additional elements while compiling by the {extends} tag
|
||||
while ($this->template->source = array_shift($this->sources)) {
|
||||
$this->smarty->_current_file = $this->template->source->filepath;
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_compile($this->template);
|
||||
}
|
||||
// call compiler
|
||||
$_compiled_code = $this->doCompile($_content, true);
|
||||
$no_sources = count($this->sources);
|
||||
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath,
|
||||
$this->template->source->getTimeStamp(),
|
||||
$this->template->source->type);
|
||||
$loop ++;
|
||||
if ($no_sources) {
|
||||
$this->inheritance_child = true;
|
||||
} else {
|
||||
$this->inheritance_child = false;
|
||||
}
|
||||
// flag for nochache sections
|
||||
$this->nocache = $nocache;
|
||||
$this->tag_nocache = false;
|
||||
// reset has nocache code flag
|
||||
$this->template->has_nocache_code = false;
|
||||
$this->has_variable_string = false;
|
||||
$this->prefix_code = array();
|
||||
$_compiled_code = '';
|
||||
// get template source
|
||||
$_content = $this->template->source->getContent();
|
||||
if ($_content != '') {
|
||||
// run pre filter if required
|
||||
if ((isset($this->smarty->autoload_filters['pre']) ||
|
||||
isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter
|
||||
) {
|
||||
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
|
||||
}
|
||||
// call compiler
|
||||
$_compiled_code = $this->doCompile($_content, true);
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_compile($this->template);
|
||||
}
|
||||
// free memory
|
||||
unset($this->parser->lex, $this->parser->root_buffer, $this->parser->current_buffer, $this->parser);
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_compile($this->template);
|
||||
// restore source
|
||||
$this->template->source = $this->savedSource;
|
||||
$this->savedSource = null;
|
||||
$this->smarty->_current_file = $this->template->source->filepath;
|
||||
// return compiled code to template object
|
||||
$merged_code = '';
|
||||
if (!empty($this->mergedSubTemplatesCode)) {
|
||||
foreach ($this->mergedSubTemplatesCode as $code) {
|
||||
$merged_code .= $code;
|
||||
}
|
||||
}
|
||||
}
|
||||
// restore source
|
||||
$this->template->source = $save_source;
|
||||
unset($save_source);
|
||||
$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
|
||||
$merged_code = '';
|
||||
if (!empty($this->mergedSubTemplatesCode)) {
|
||||
foreach ($this->mergedSubTemplatesCode as $code) {
|
||||
$merged_code .= $code;
|
||||
}
|
||||
}
|
||||
// run post filter if required on compiled template code
|
||||
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) &&
|
||||
!$this->suppressFilter && $_compiled_code != ''
|
||||
) {
|
||||
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
|
||||
}
|
||||
if ($this->suppressTemplatePropertyHeader) {
|
||||
$_compiled_code .= $merged_code;
|
||||
} else {
|
||||
$_compiled_code = $template_header .
|
||||
Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code;
|
||||
}
|
||||
if (!empty($this->templateFunctionCode)) {
|
||||
// run post filter if required on compiled template code
|
||||
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) &&
|
||||
!$this->suppressFilter
|
||||
!$this->suppressFilter && $_compiled_code != ''
|
||||
) {
|
||||
$_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template);
|
||||
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
|
||||
}
|
||||
if ($this->suppressTemplatePropertyHeader) {
|
||||
$_compiled_code .= $merged_code;
|
||||
} else {
|
||||
$_compiled_code .= $this->templateFunctionCode;
|
||||
$_compiled_code = $template_header .
|
||||
Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code;
|
||||
}
|
||||
if (!empty($this->templateFunctionCode)) {
|
||||
// run post filter if required on compiled template code
|
||||
if ((isset($this->smarty->autoload_filters['post']) ||
|
||||
isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter
|
||||
) {
|
||||
$_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template);
|
||||
} else {
|
||||
$_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->template = null;
|
||||
return $_compiled_code;
|
||||
@@ -557,7 +570,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
} else {
|
||||
// throw exception
|
||||
$this->trigger_template_error('not allowed method "' . $method . '" in registered object "' .
|
||||
$tag . '"', $this->lex->taglineno);
|
||||
$tag . '"', null, true);
|
||||
}
|
||||
}
|
||||
// check if tag is registered
|
||||
@@ -682,8 +695,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
} else {
|
||||
// throw exception
|
||||
$this->trigger_template_error('not allowed closing tag method "' . $method .
|
||||
'" in registered object "' . $base_tag .
|
||||
'"', $this->lex->taglineno);
|
||||
'" in registered object "' . $base_tag . '"', null, true);
|
||||
}
|
||||
}
|
||||
// registered block tag ?
|
||||
@@ -738,7 +750,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
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)
|
||||
{
|
||||
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 {
|
||||
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])) {
|
||||
// lazy load internal compiler plugin
|
||||
$_tag = explode('_', $tag);
|
||||
$_tag = array_map(function ($word) {
|
||||
return ucfirst($word);
|
||||
}, $_tag);
|
||||
$_tag = array_map('ucfirst', $_tag);
|
||||
$class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag);
|
||||
if (class_exists($class_name) &&
|
||||
(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
|
||||
@@ -1074,27 +1084,35 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
* In this case the parser is called to obtain information about expected tokens.
|
||||
* If parameter $args contains a string this is used as error message
|
||||
*
|
||||
* @param string $args individual error message or null
|
||||
* @param string $line line-number
|
||||
* @param string $args individual error message or null
|
||||
* @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)
|
||||
{
|
||||
// get template source line which has error
|
||||
if (!isset($line)) {
|
||||
$line = $this->lex->line;
|
||||
$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
|
||||
$line = $lex->line;
|
||||
} else {
|
||||
$line = (int) $line;
|
||||
}
|
||||
|
||||
if (in_array($this->template->source->type, array('eval', 'string'))) {
|
||||
$templateName = $this->template->source->type . ':' .
|
||||
trim(preg_replace('![\t\r\n]+!', ' ', strlen($this->lex->data) > 40 ? substr($this->lex->data, 0, 40) .
|
||||
'...' : $this->lex->data));
|
||||
trim(preg_replace('![\t\r\n]+!', ' ', strlen($lex->data) > 40 ? substr($lex->data, 0, 40) .
|
||||
'...' : $lex->data));
|
||||
} else {
|
||||
$templateName = $this->template->source->type . ':' . $this->template->source->filepath;
|
||||
}
|
||||
|
||||
// $line += $this->trace_line_offset;
|
||||
$match = preg_split("/\n/", $this->lex->data);
|
||||
$match = preg_split("/\n/", $lex->data);
|
||||
$error_text = 'Syntax error in template "' .
|
||||
(empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . '" on line ' .
|
||||
($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) .
|
||||
@@ -1105,13 +1123,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
} else {
|
||||
$expect = array();
|
||||
// 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) {
|
||||
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $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
|
||||
$expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
|
||||
$expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"';
|
||||
} else {
|
||||
// otherwise internal token name
|
||||
$expect[] = $this->parser->yyTokenName[$token];
|
||||
|
@@ -157,7 +157,7 @@ class Smarty_Internal_Templateparser
|
||||
*
|
||||
* @var Smarty_Internal_Templatelexer
|
||||
*/
|
||||
private $lex;
|
||||
public $lex;
|
||||
|
||||
/**
|
||||
* internal error flag
|
||||
@@ -206,7 +206,7 @@ class Smarty_Internal_Templateparser
|
||||
*
|
||||
* @var Smarty_Security
|
||||
*/
|
||||
private $security = null;
|
||||
public $security = null;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
@@ -221,7 +221,7 @@ class Smarty_Internal_Templateparser
|
||||
$this->template = $this->compiler->template;
|
||||
$this->smarty = $this->template->smarty;
|
||||
$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)
|
||||
{
|
||||
$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"
|
||||
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"
|
||||
function yy_r1()
|
||||
{
|
||||
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) {
|
||||
// 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"
|
||||
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"
|
||||
@@ -2527,13 +2527,13 @@ class Smarty_Internal_Templateparser
|
||||
#line 1288 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||
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"
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -2546,23 +2546,22 @@ class Smarty_Internal_Templateparser
|
||||
#line 1302 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||
function yy_r185()
|
||||
{
|
||||
$this->_retvalue = new Smarty_Internal_ParseTree_Code($this, '(string)' .
|
||||
$this->yystack[$this->yyidx + - 1]->minor);
|
||||
$this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)' . $this->yystack[$this->yyidx + - 1]->minor);
|
||||
}
|
||||
|
||||
#line 1310 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||
function yy_r187()
|
||||
{
|
||||
$this->_retvalue = new Smarty_Internal_ParseTree_Code($this, '(string)$_smarty_tpl->tpl_vars[\'' .
|
||||
substr($this->yystack[$this->yyidx + 0]->minor, 1) .
|
||||
'\']->value');
|
||||
$this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)$_smarty_tpl->tpl_vars[\'' .
|
||||
substr($this->yystack[$this->yyidx + 0]->minor, 1) .
|
||||
'\']->value');
|
||||
}
|
||||
|
||||
#line 1318 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||
function yy_r189()
|
||||
{
|
||||
$this->_retvalue = new Smarty_Internal_ParseTree_Code($this, '(string)(' .
|
||||
$this->yystack[$this->yyidx + - 1]->minor . ')');
|
||||
$this->_retvalue = new Smarty_Internal_ParseTree_Code('(string)(' . $this->yystack[$this->yyidx + - 1]->minor .
|
||||
')');
|
||||
}
|
||||
|
||||
#line 1322 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||
@@ -2574,7 +2573,7 @@ class Smarty_Internal_Templateparser
|
||||
#line 1326 "../smarty/lexer/smarty_internal_templateparser.y"
|
||||
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;
|
||||
|
@@ -389,12 +389,12 @@ class Smarty_Security
|
||||
if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
|
||||
return true;
|
||||
} 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)) {
|
||||
return true;
|
||||
} 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?
|
||||
@@ -414,7 +414,7 @@ class Smarty_Security
|
||||
if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
|
||||
return true;
|
||||
} 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?
|
||||
@@ -440,14 +440,14 @@ class Smarty_Security
|
||||
if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
|
||||
return true;
|
||||
} 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) &&
|
||||
!in_array($modifier_name, $this->disabled_modifiers)
|
||||
) {
|
||||
return true;
|
||||
} 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?
|
||||
@@ -639,9 +639,9 @@ class Smarty_Security
|
||||
/**
|
||||
* Exit template processing
|
||||
*
|
||||
* @param $template
|
||||
* @internal param $template
|
||||
*/
|
||||
public function exitTemplate($template)
|
||||
public function exitTemplate()
|
||||
{
|
||||
if ($this->max_template_nesting > 0) {
|
||||
$this->_current_template_nesting --;
|
||||
|
Reference in New Issue
Block a user