mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- bugfix string resource could inject code at {block} or inline subtemplates through PHP comments https://github.com/smarty-php/smarty/issues/157 (reverted from commit 2850cce19f
)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
- revert bugfix compiling {section} did create warning
|
||||
- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
|
||||
update of yesterdays fix
|
||||
- bugfix string resource could inject code at {block} or inline subtemplates through PHP comments https://github.com/smarty-php/smarty/issues/157
|
||||
|
||||
26.01.2016
|
||||
- improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/22';
|
||||
const SMARTY_VERSION = '3.1.30-dev/21';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -15,13 +15,6 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inheritance
|
||||
{
|
||||
/**
|
||||
* nesting level of block tags
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $blockTagNestingLevel = 0;
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -54,66 +47,30 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
*/
|
||||
public $optional_attributes = array('assign');
|
||||
|
||||
/**
|
||||
* nesting level of block tags
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $blockTagNestingLevel = 0;
|
||||
|
||||
/**
|
||||
* Saved compiler object
|
||||
*
|
||||
* @var Smarty_Internal_TemplateCompiler
|
||||
* @var Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $compiler = null;
|
||||
|
||||
/**
|
||||
* Compile saved child block source
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
*
|
||||
* @return string compiled code of child block
|
||||
*/
|
||||
static function compileChildBlock(Smarty_Internal_TemplateCompiler $compiler, $_name = null)
|
||||
{
|
||||
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
|
||||
$compiler->parser->lex->taglineno);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 1 ] = true;
|
||||
$output =
|
||||
"\$_smarty_tpl->_getExtension('_inheritance')->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile $smarty.block.parent
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
*
|
||||
* @return string compiled code of child block
|
||||
*/
|
||||
static function compileParentBlock(Smarty_Internal_TemplateCompiler $compiler, $_name = null)
|
||||
{
|
||||
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
|
||||
$compiler->parser->lex->taglineno);
|
||||
}
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$compiler->has_code = true;
|
||||
$output =
|
||||
"\$_smarty_tpl->_getExtension('_inheritance')->processBlock(\$_smarty_tpl, 4, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles code for the {block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||||
$compiler->_cache[ 'blockNesting' ] = 0;
|
||||
@@ -129,15 +86,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$compiler->_cache[ 'blockNesting' ] ++;
|
||||
$compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
|
||||
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 0 ] =
|
||||
'block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
|
||||
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 1 ] = false;
|
||||
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'name' ] = "{$_attr['name']}";
|
||||
$this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
|
||||
$compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching));
|
||||
// must whole block be nocache ?
|
||||
if ($compiler->tag_nocache) {
|
||||
// TODO rethink nocache handling
|
||||
$i = 0;
|
||||
}
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
// $compiler->suppressNocacheProcessing = true;
|
||||
@@ -148,6 +103,47 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
$compiler->template->compiled->has_nocache_code = false;
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile saved child block source
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase compiler object
|
||||
* @param string $_name optional name of child block
|
||||
*
|
||||
* @return string compiled code of child block
|
||||
*/
|
||||
static function compileChildBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
|
||||
{
|
||||
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
|
||||
$compiler->parser->lex->taglineno);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
|
||||
$output = "<?php \n\$this->callChild(\$_smarty_tpl);\n?>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile $smarty.block.parent
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
*
|
||||
* @return string compiled code of child block
|
||||
*/
|
||||
static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
|
||||
{
|
||||
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
|
||||
$compiler->parser->lex->taglineno);
|
||||
}
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$compiler->has_code = true;
|
||||
$output = "<?php \n\$this->callParent(\$_smarty_tpl);\n?>\n";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,91 +152,70 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
|
||||
*/
|
||||
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
|
||||
{
|
||||
/**
|
||||
* @var Smarty_Internal_TemplateCompiler
|
||||
*/
|
||||
public $compiler = null;
|
||||
|
||||
/**
|
||||
* Compiles code for the {/block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return bool true
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block'));
|
||||
// init block parameter
|
||||
$_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ];
|
||||
unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]);
|
||||
$_block[ 2 ] = $_block[ 3 ] = 0;
|
||||
$_name = trim($_attr[ 'name' ], "'\"");
|
||||
$_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
|
||||
unset($_attr[ 'assign' ], $_attr[ 'name' ]);
|
||||
foreach ($_attr as $name => $stat) {
|
||||
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat != 'false')) {
|
||||
$_block[ $name ] = is_string($stat) ? trim($stat, "'\"") : $stat;
|
||||
$_block[ $name ] = 'true';
|
||||
}
|
||||
}
|
||||
if ($compiler->template->source->type == 'file') {
|
||||
$sourceInfo = $compiler->template->source->filepath;
|
||||
} else {
|
||||
$basename = $compiler->template->source->handler->getBasename($compiler->template->source);
|
||||
$sourceInfo = $compiler->template->source->type .':' . ($basename ? $basename : $compiler->template->source->name);
|
||||
}
|
||||
$_funcName = $_block[ 0 ];
|
||||
$_className = 'Block_' . preg_replace('#[^\w\|]+#S', '_', $_name) . '_' .
|
||||
preg_replace('![^\w]+!', '_', uniqid(rand(), true));
|
||||
// get compiled block code
|
||||
$_functionCode = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "class {$_className} extends Smarty_Internal_Block\n";
|
||||
$output .= "{\n";
|
||||
foreach ($_block as $property => $value) {
|
||||
$output .= "public \${$property} = {$value};\n";
|
||||
}
|
||||
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||||
//$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
if ($compiler->template->compiled->has_nocache_code) {
|
||||
$_has_nocache_code = true;
|
||||
$_block[ 6 ] = $_funcNameCaching = $_funcName . '_nocache';
|
||||
$output =
|
||||
"/* {block '{$_name}'} {$sourceInfo} */\n";
|
||||
$output .= "function {$_funcNameCaching} (\$_smarty_tpl, \$_blockParentStack) {\n";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
|
||||
}
|
||||
if (isset($_assign)) {
|
||||
$output .= "ob_start();\n";
|
||||
}
|
||||
$output .= $_functionCode;
|
||||
if (isset($_assign)) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
|
||||
}
|
||||
$output .= "/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
|
||||
}
|
||||
//$output .= "/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "}\n";
|
||||
$output .= "}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
$this->compiler = $compiler;
|
||||
$_functionCode =
|
||||
preg_replace_callback("/(echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';)/",
|
||||
array($this, 'removeNocache'), $_functionCode);
|
||||
$this->compiler = null;
|
||||
}
|
||||
$output = "/* {block '{$_name}'} {$sourceInfo} */\n";
|
||||
$output .= "function {$_funcName}(\$_smarty_tpl, \$_blockParentStack) {\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "ob_start();\n";
|
||||
}
|
||||
$output .= $_functionCode;
|
||||
if (isset($_assign)) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
|
||||
}
|
||||
$output .= "}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
// nocache plugins must be copied
|
||||
if (!empty($compiler->template->compiled->required_plugins[ 'nocache' ])) {
|
||||
foreach ($compiler->template->compiled->required_plugins[ 'nocache' ] as $plugin => $tmp) {
|
||||
@@ -256,14 +231,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
|
||||
$compiler->tag_nocache = $compiler->nocache;
|
||||
$compiler->nocache = $_nocache;
|
||||
$compiler->parser->current_buffer = $_buffer;
|
||||
$output = '';
|
||||
$output = "<?php \n";
|
||||
if ($compiler->_cache[ 'blockNesting' ] == 1) {
|
||||
$output .= "\$_smarty_tpl->_getExtension('_inheritance')->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
|
||||
var_export($_block, true) . ");\n";
|
||||
$output .= "new {$_className}(\$_smarty_tpl);\n";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->_getExtension('_inheritance')->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
|
||||
var_export($_block, true) . ", \$_blockParentStack);\n";
|
||||
$output .= "new {$_className}(\$_smarty_tpl, \$this->tplIndex);\n";
|
||||
}
|
||||
$output .= "?>\n";
|
||||
$compiler->_cache[ 'blockNesting' ] --;
|
||||
if ($compiler->_cache[ 'blockNesting' ] == 0) {
|
||||
unset($compiler->_cache[ 'blockNesting' ]);
|
||||
@@ -272,18 +246,4 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $match
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function removeNocache($match)
|
||||
{
|
||||
$code =
|
||||
preg_replace("/(echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';)/",
|
||||
'', $match[ 0 ]);
|
||||
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
@@ -58,24 +58,23 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||
'smarty' => true, 'tpl_root' => true);
|
||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true,
|
||||
'tpl_root' => true);
|
||||
|
||||
/**
|
||||
* Compiles code for the {include} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param Smarty_Internal_TemplateCompiler $compiler compiler object
|
||||
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @throws SmartyCompilerException
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
|
||||
public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$compiler->requestExtension('_subTemplate', $compiler->nocache || $compiler->tag_nocache);
|
||||
|
||||
$hashResourceName = $fullResourceName = $source_resource = $_attr['file'];
|
||||
$variable_template = false;
|
||||
@@ -84,8 +83,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) {
|
||||
$type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type;
|
||||
$name = !empty($match[5]) ? $match[5] : $match[6];
|
||||
$handler = $compiler->smarty->_getExtension('_source')
|
||||
->getResourceHandler($compiler->smarty, $type);
|
||||
$handler = Smarty_Resource::load($compiler->smarty, $type);
|
||||
if ($handler->recompiled || $handler->uncompiled) {
|
||||
$variable_template = true;
|
||||
}
|
||||
@@ -119,31 +117,22 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if (!isset($this->valid_scopes[$_attr['scope']])) {
|
||||
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null,
|
||||
true);
|
||||
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
|
||||
}
|
||||
if ($_attr['scope'] != 'local') {
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr[ 'scope' ] == 'global') {
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} elseif ($_attr[ 'scope' ] == 'smarty') {
|
||||
$_scope = Smarty::SCOPE_SMARTY;
|
||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||
}
|
||||
if ($_attr[ 'bubble_up' ] === true) {
|
||||
$_scope = $_scope + Smarty::SCOPE_BUBBLE_UP;
|
||||
$_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
|
||||
Smarty::SCOPE_BUBBLE_UP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_scope) {
|
||||
$compiler->requestExtension('_updateScope', $compiler->nocache || $compiler->tag_nocache);
|
||||
}
|
||||
|
||||
// set flag to cache sub-template object when called within loop or template name is variable.
|
||||
// set flag to cache subtemplate object when called within loop or template name is variable.
|
||||
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
|
||||
$_cache_tpl = 'true';
|
||||
} else {
|
||||
@@ -178,9 +167,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
}
|
||||
// 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 ||
|
||||
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;
|
||||
@@ -194,7 +182,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
|
||||
/*
|
||||
* if the {include} tag provides individual parameter for caching or compile_id
|
||||
* the sub-template must not be included into the common cache file and is treated like
|
||||
* the subtemplate must not be included into the common cache file and is treated like
|
||||
* a call in nocache mode.
|
||||
*
|
||||
*/
|
||||
@@ -224,11 +212,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$_compile_id = '$_smarty_tpl->compile_id';
|
||||
}
|
||||
|
||||
// if sub-template will be called in nocache mode do not merge
|
||||
// if subtemplate will be called in nocache mode do not merge
|
||||
if ($compiler->template->caching && $call_nocache) {
|
||||
$merge_compiled_includes = false;
|
||||
}
|
||||
$t_hash = '';
|
||||
|
||||
$has_compiled_template = false;
|
||||
if ($merge_compiled_includes) {
|
||||
$c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id;
|
||||
@@ -246,7 +234,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline'], $_attr['bubble_up']);
|
||||
// remaining attributes must be assigned as smarty variable
|
||||
$_vars_nc = '';
|
||||
$_vars = 'array()';
|
||||
if (!empty($_attr)) {
|
||||
if ($_scope == Smarty::SCOPE_LOCAL) {
|
||||
$_pairs = array();
|
||||
@@ -259,17 +246,19 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$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';
|
||||
if ($has_compiled_template && !$call_nocache) {
|
||||
$_output = '';
|
||||
$_output = "<?php\n";
|
||||
if ($update_compile_id) {
|
||||
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
||||
}
|
||||
if (!empty($_vars_nc) && $_caching == 9999 && $compiler->template->caching) {
|
||||
//$compiler->suppressNocacheProcessing = false;
|
||||
$_output .= substr($compiler->processNocacheCode($_vars_nc, true), 6, - 3);
|
||||
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3);
|
||||
//$compiler->suppressNocacheProcessing = true;
|
||||
}
|
||||
if (isset($_assign)) {
|
||||
@@ -282,6 +271,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if ($update_compile_id) {
|
||||
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
|
||||
}
|
||||
$_output .= "?>\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
@@ -289,7 +279,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if ($call_nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
$_output = '';
|
||||
$_output = "<?php ";
|
||||
if ($update_compile_id) {
|
||||
$_output .= "\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n";
|
||||
}
|
||||
@@ -304,13 +294,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if ($update_compile_id) {
|
||||
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
|
||||
}
|
||||
$_output .= "?>\n";
|
||||
return $_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile inline sub template
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompiler $compiler
|
||||
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
|
||||
* @param $fullResourceName
|
||||
* @param $_caching
|
||||
* @param $hashResourceName
|
||||
@@ -319,49 +310,49 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compileInlineTemplate(Smarty_Internal_TemplateCompiler $compiler, $fullResourceName, $_caching,
|
||||
$hashResourceName, $t_hash, $c_id)
|
||||
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName,
|
||||
$_caching, $hashResourceName, $t_hash, $c_id)
|
||||
{
|
||||
$compiler->smarty->allow_ambiguous_resources = true;
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl = new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty,
|
||||
$compiler->template, $compiler->template->cache_id, $c_id,
|
||||
$_caching);
|
||||
$tpl =
|
||||
new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $compiler->template,
|
||||
$compiler->template->cache_id, $c_id, $_caching);
|
||||
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[ $hashResourceName ][ $t_hash ][ 'uid' ] =
|
||||
$tpl->source->uid;
|
||||
if (isset($compiler->template->_extensions[ '_inheritance' ])) {
|
||||
$tpl->_extensions[ '_inheritance' ] = clone $compiler->template->_extensions[ '_inheritance' ];
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid;
|
||||
if (isset($compiler->template->ext->_inheritance)) {
|
||||
$tpl->ext->_inheritance = clone $compiler->template->ext->_inheritance;
|
||||
}
|
||||
$tpl->loadCompiled();
|
||||
/* @var Smarty_Internal_TemplateCompiler $comp */
|
||||
$comp = $tpl->_getExtension('_compile')
|
||||
->loadCompiler($tpl);
|
||||
$tpl->compiled = new Smarty_Template_Compiled();
|
||||
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
||||
$tpl->loadCompiler();
|
||||
// save unique function name
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] =
|
||||
$tpl->compiled->renderCallback = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
$tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
// make sure whole chain gets compiled
|
||||
$tpl->mustCompile = true;
|
||||
if ($compiler->template->source->type == 'file') {
|
||||
$sourceInfo = $compiler->template->source->filepath;
|
||||
} else {
|
||||
$basename = $compiler->template->source->handler->getBasename($compiler->template->source);
|
||||
$sourceInfo = $compiler->template->source->type .':' . ($basename ? $basename : $compiler->template->source->name);
|
||||
}
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] =
|
||||
$tpl->compiled->nocache_hash;
|
||||
// get compiled code
|
||||
$compiled_code = "\n\n";
|
||||
$compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
|
||||
$compiled_code .= "function {$tpl->compiled->renderCallback} (\$_smarty_tpl) {\n";
|
||||
$compiled_code .= $comp->compileTemplateSource($tpl, null, $compiler->parent_compiler);
|
||||
$compiled_code .= "}\n";
|
||||
$compiled_code .= $comp->postFilter($comp->blockOrFunctionCode);
|
||||
$compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n";
|
||||
$compiled_code .= "\n\n";
|
||||
unset($comp);
|
||||
$compiled_code = "<?php\n\n";
|
||||
$compiled_code .= "/* Start inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
|
||||
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
|
||||
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
|
||||
$compiled_code .= "<?php\n";
|
||||
$compiled_code .= "}\n?>\n";
|
||||
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
|
||||
$compiled_code .= "<?php\n\n";
|
||||
$compiled_code .= "/* End inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
|
||||
$compiled_code .= "?>";
|
||||
unset($tpl->compiler);
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
// replace nocache_hash
|
||||
$compiled_code =
|
||||
str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
|
||||
$compiled_code);
|
||||
$compiler->template->compiled->has_nocache_code = true;
|
||||
}
|
||||
$compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->renderCallback ] = $compiled_code;
|
||||
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user