summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Wisselink <wisskid@users.noreply.github.com>2024-05-28 22:44:30 +0200
committerGitHub <noreply@github.com>2024-05-28 22:44:30 +0200
commit0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a (patch)
tree14d7933f7638a89e431fbde31dd4f64fee15cb91 /src
parent61db287b8fd58b2f0a714f1007bd71059b9e52a9 (diff)
downloadsmarty-0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a.tar.gz
smarty-0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a.tar.bz2
smarty-0be92bc8a6fb83e6e0d883946f7e7c09ba4e857a.zip
Merge pull request from GHSA-4rmg-292m-wg3w
Diffstat (limited to 'src')
-rw-r--r--src/Compile/Tag/ExtendsTag.php64
-rw-r--r--src/Compiler/Template.php38
-rw-r--r--src/Smarty.php9
3 files changed, 38 insertions, 73 deletions
diff --git a/src/Compile/Tag/ExtendsTag.php b/src/Compile/Tag/ExtendsTag.php
index dcdbbc97..0ec2cf2b 100644
--- a/src/Compile/Tag/ExtendsTag.php
+++ b/src/Compile/Tag/ExtendsTag.php
@@ -32,7 +32,7 @@ class ExtendsTag extends Inheritance {
*
* @var array
*/
- protected $optional_attributes = ['extends_resource'];
+ protected $optional_attributes = [];
/**
* Attribute definition: Overwrites base class.
@@ -64,29 +64,7 @@ class ExtendsTag extends Inheritance {
}
// add code to initialize inheritance
$this->registerInit($compiler, true);
- $file = trim($_attr['file'], '\'"');
- if (strlen($file) > 8 && substr($file, 0, 8) === 'extends:') {
- // generate code for each template
- $files = array_reverse(explode('|', substr($file, 8)));
- $i = 0;
- foreach ($files as $file) {
- if ($file[0] === '"') {
- $file = trim($file, '".');
- } else {
- $file = "'{$file}'";
- }
- $i++;
- if ($i === count($files) && isset($_attr['extends_resource'])) {
- $this->compileEndChild($compiler);
- }
- $this->compileInclude($compiler, $file);
- }
- if (!isset($_attr['extends_resource'])) {
- $this->compileEndChild($compiler);
- }
- } else {
- $this->compileEndChild($compiler, $_attr['file']);
- }
+ $this->compileEndChild($compiler, $_attr['file']);
return '';
}
@@ -106,42 +84,4 @@ class ExtendsTag extends Inheritance {
(isset($template) ? ", {$template}, \$_smarty_current_dir" : '') . ");\n?>"
);
}
-
- /**
- * Add code for including subtemplate to end of template
- *
- * @param \Smarty\Compiler\Template $compiler
- * @param string $template subtemplate name
- *
- * @throws \Smarty\CompilerException
- * @throws \Smarty\Exception
- */
- private function compileInclude(\Smarty\Compiler\Template $compiler, $template) {
- $compiler->getParser()->template_postfix[] = new \Smarty\ParseTree\Tag(
- $compiler->getParser(),
- $compiler->compileTag(
- 'include',
- [
- $template,
- ['scope' => 'parent'],
- ]
- )
- );
- }
-
- /**
- * Create source code for {extends} from source components array
- *
- * @param \Smarty\Template $template
- *
- * @return string
- */
- public static function extendsSourceArrayCode(\Smarty\Template $template) {
- $resources = [];
- foreach ($template->getSource()->components as $source) {
- $resources[] = $source->resource;
- }
- return $template->getLeftDelimiter() . 'extends file=\'extends:' . join('|', $resources) .
- '\' extends_resource=true' . $template->getRightDelimiter();
- }
}
diff --git a/src/Compiler/Template.php b/src/Compiler/Template.php
index b775abba..1d4aa244 100644
--- a/src/Compiler/Template.php
+++ b/src/Compiler/Template.php
@@ -403,21 +403,37 @@ class Template extends BaseCompiler {
}
// get template source
if (!empty($this->template->getSource()->components)) {
- // we have array of inheritance templates by extends: resource
- // generate corresponding source code sequence
- $_content =
- ExtendsTag::extendsSourceArrayCode($this->template);
+
+ $_compiled_code = '<?php $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?>';
+
+ $i = 0;
+ $reversed_components = array_reverse($this->template->getSource()->components);
+ foreach ($reversed_components as $source) {
+ $i++;
+ if ($i === count($reversed_components)) {
+ $_compiled_code .= '<?php $_smarty_tpl->getInheritance()->endChild($_smarty_tpl); ?>';
+ }
+ $_compiled_code .= $this->compileTag(
+ 'include',
+ [
+ var_export($source->resource, true),
+ ['scope' => 'parent'],
+ ]
+ );
+ }
+ $_compiled_code = $this->smarty->runPostFilters($_compiled_code, $this->template);
} else {
// get template source
$_content = $this->template->getSource()->getContent();
+ $_compiled_code = $this->smarty->runPostFilters(
+ $this->doCompile(
+ $this->smarty->runPreFilters($_content, $this->template),
+ true
+ ),
+ $this->template
+ );
}
- $_compiled_code = $this->smarty->runPostFilters(
- $this->doCompile(
- $this->smarty->runPreFilters($_content, $this->template),
- true
- ),
- $this->template
- );
+
} catch (\Exception $e) {
if ($this->smarty->debugging) {
$this->smarty->getDebug()->end_compile($this->template);
diff --git a/src/Smarty.php b/src/Smarty.php
index dbb91726..9c27d7a8 100644
--- a/src/Smarty.php
+++ b/src/Smarty.php
@@ -2211,5 +2211,14 @@ class Smarty extends \Smarty\TemplateBase {
return $template;
}
+ /**
+ * Sets if Smarty should check If-Modified-Since headers to determine cache validity.
+ * @param bool $cache_modified_check
+ * @return void
+ */
+ public function setCacheModifiedCheck($cache_modified_check): void {
+ $this->cache_modified_check = (bool) $cache_modified_check;
+ }
+
}