summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2016-01-26 21:49:56 +0100
committeruwetews <uwe.tews@googlemail.com>2016-01-26 21:49:56 +0100
commit867a2f316549fa3466df531701bb0a630ae318f3 (patch)
treea4993fa0e9ee62760d85f43fd42a4d1e2d09b34d
parent2850cce19f6c9dcb0e8daf4ec11ad34e7bcd3d55 (diff)
downloadsmarty-867a2f316549fa3466df531701bb0a630ae318f3.tar.gz
smarty-867a2f316549fa3466df531701bb0a630ae318f3.tar.bz2
smarty-867a2f316549fa3466df531701bb0a630ae318f3.zip
- 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 2850cce19f6c9dcb0e8daf4ec11ad34e7bcd3d55)
-rw-r--r--change_log.txt1
-rw-r--r--libs/Smarty.class.php2
-rw-r--r--libs/sysplugins/smarty_internal_compile_block.php210
-rw-r--r--libs/sysplugins/smarty_internal_compile_include.php183
4 files changed, 173 insertions, 223 deletions
diff --git a/change_log.txt b/change_log.txt
index aaab7dbc..d5103bff 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -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
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index d6a802aa..8eec85d3 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -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
diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php
index 0c926798..0d897b5f 100644
--- a/libs/sysplugins/smarty_internal_compile_block.php
+++ b/libs/sysplugins/smarty_internal_compile_block.php
@@ -16,13 +16,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.
*
* @var array
@@ -55,65 +48,29 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
public $optional_attributes = array('assign');
/**
- * Saved compiler object
- *
- * @var Smarty_Internal_TemplateCompiler
- */
- public $compiler = null;
-
- /**
- * Compile saved child block source
- *
- * @param \Smarty_Internal_TemplateCompiler compiler object
- * @param string $_name optional name of child block
+ * nesting level of block tags
*
- * @return string compiled code of child block
+ * @var int
*/
- 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;
- }
+ public static $blockTagNestingLevel = 0;
/**
- * Compile $smarty.block.parent
- *
- * @param \Smarty_Internal_TemplateCompiler $compiler compiler object
- * @param string $_name optional name of child block
+ * Saved compiler object
*
- * @return string compiled code of child block
+ * @var Smarty_Internal_TemplateCompilerBase
*/
- 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;
- }
+ 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 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 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;
+ }
}
/**
@@ -157,90 +153,69 @@ 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 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 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";
- $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 = 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;
+ $output .= "?>\n";
+ $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\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 .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
+ $compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
+ $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// 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;
- }
}
diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php
index 1775ca81..a87fbed8 100644
--- a/libs/sysplugins/smarty_internal_compile_include.php
+++ b/libs/sysplugins/smarty_internal_compile_include.php
@@ -58,34 +58,32 @@ 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 array $parameter array with compilation parameter
+ * @param array $args array with attributes from parser
+ * @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' ];
+ $hashResourceName = $fullResourceName = $source_resource = $_attr['file'];
$variable_template = false;
$cache_tpl = false;
// parse resource_name
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);
+ $type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type;
+ $name = !empty($match[5]) ? $match[5] : $match[6];
+ $handler = Smarty_Resource::load($compiler->smarty, $type);
if ($handler->recompiled || $handler->uncompiled) {
$variable_template = true;
}
@@ -93,57 +91,48 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($type != 'string') {
$fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->compiled;
- if (isset($compiled->includes[ $fullResourceName ])) {
- $compiled->includes[ $fullResourceName ] ++;
+ if (isset($compiled->includes[$fullResourceName])) {
+ $compiled->includes[$fullResourceName] ++;
$cache_tpl = true;
} else {
- $compiled->includes[ $fullResourceName ] = 1;
+ $compiled->includes[$fullResourceName] = 1;
}
$fullResourceName = '"' . $fullResourceName . '"';
}
}
- if (empty($match[ 5 ])) {
+ if (empty($match[5])) {
$variable_template = true;
}
} else {
$variable_template = true;
}
- if (isset($_attr[ 'assign' ])) {
+ if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of being displayed
- $_assign = $_attr[ 'assign' ];
+ $_assign = $_attr['assign'];
}
// scope setup
$_scope = Smarty::SCOPE_LOCAL;
- 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);
+ 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);
}
- if ($_attr[ 'scope' ] != 'local') {
- if ($_attr[ 'scope' ] == 'parent') {
+ if ($_attr['scope'] != 'local') {
+ if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
- } elseif ($_attr[ 'scope' ] == 'root') {
+ } 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') {
+ } 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 {
@@ -152,7 +141,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// assume caching is off
$_caching = Smarty::CACHING_OFF;
- if ($_attr[ 'nocache' ] === true) {
+ if ($_attr['nocache'] === true) {
$compiler->tag_nocache = true;
}
@@ -164,10 +153,10 @@ 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 || $_attr[ 'inline' ] === true) &&
+ $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) &&
!$compiler->template->source->handler->recompiled;
- if ($merge_compiled_includes && $_attr[ 'inline' ] !== true) {
+ if ($merge_compiled_includes && $_attr['inline'] !== true) {
// variable template name ?
if ($variable_template) {
$merge_compiled_includes = false;
@@ -177,11 +166,10 @@ 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 ||
- substr_count($_attr[ 'compile_id' ], '$_smarty_tpl->') != 0
+ 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
) {
$merge_compiled_includes = false;
if ($compiler->template->caching) {
@@ -194,47 +182,47 @@ 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.
*
*/
- if ($_attr[ 'nocache' ] !== true && $_attr[ 'caching' ]) {
- $_caching = $_new_caching = (int) $_attr[ 'caching' ];
+ if ($_attr['nocache'] !== true && $_attr['caching']) {
+ $_caching = $_new_caching = (int) $_attr['caching'];
$call_nocache = true;
} else {
$_new_caching = Smarty::CACHING_LIFETIME_CURRENT;
}
- if (isset($_attr[ 'cache_lifetime' ])) {
- $_cache_lifetime = $_attr[ 'cache_lifetime' ];
+ if (isset($_attr['cache_lifetime'])) {
+ $_cache_lifetime = $_attr['cache_lifetime'];
$call_nocache = true;
$_caching = $_new_caching;
} else {
$_cache_lifetime = '$_smarty_tpl->cache_lifetime';
}
- if (isset($_attr[ 'cache_id' ])) {
- $_cache_id = $_attr[ 'cache_id' ];
+ if (isset($_attr['cache_id'])) {
+ $_cache_id = $_attr['cache_id'];
$call_nocache = true;
$_caching = $_new_caching;
} else {
$_cache_id = '$_smarty_tpl->cache_id';
}
- if (isset($_attr[ 'compile_id' ])) {
- $_compile_id = $_attr[ 'compile_id' ];
+ if (isset($_attr['compile_id'])) {
+ $_compile_id = $_attr['compile_id'];
} else {
$_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;
+ $c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id;
// we must observe different compile_id and caching
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
- if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $hashResourceName ][ $t_hash ])) {
+ if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) {
$has_compiled_template =
$this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash,
$c_id);
@@ -243,10 +231,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
}
}
// delete {include} standard attributes
- 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' ]);
+ 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));
+ $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] =
+ $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;