Merge branch 'master' into 979_setErrorUnassigned

This commit is contained in:
Simon Wisselink
2024-05-29 21:21:36 +02:00
committed by GitHub
68 changed files with 791 additions and 762 deletions

View File

@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [5.2.0] - 2024-05-28
- Fixed a code injection vulnerability in extends-tag. This addresses CVE-2024-35226.
- Added `$smarty->setCacheModifiedCheck()` setter for cache_modified_check
- Added a PSR-4 loading script to allow Smarty to be used without Composer [#1017](https://github.com/smarty-php/smarty/pull/1017)
## [5.1.0] - 2024-04-22
- Prevent deprecation notices during compilation in PHP8.3 [#996](https://github.com/smarty-php/smarty/issues/996)
- Fix that getTemplateVars would return an array of objects instead of the assigned variables values [#994](https://github.com/smarty-php/smarty/issues/994)
- Fix Smarty::assign() not returning $this when called with an array as first parameter [#972](https://github.com/smarty-php/smarty/pull/972)
- Documented support for `{if $element is in $array}` syntax [#937](https://github.com/smarty-php/smarty/issues/937)
- Added support for `{if $element is not in $array}` syntax [#937](https://github.com/smarty-php/smarty/issues/937)
- Using stream variables in templates now throws a deprecation notice [#933](https://github.com/smarty-php/smarty/pull/933)
- Internal compiler classes always return a string (the internal has_code flag has been removed for simplicity) [#918](https://github.com/smarty-php/smarty/pull/918)
- Fix invalid classnames in Runtime code for foreach [#1000](https://github.com/smarty-php/smarty/issues/1000)
## [5.0.1] - 2024-03-27 ## [5.0.1] - 2024-03-27
- Fix error in Smarty\Smarty::compileAllTemplates() by including missing FilesystemIterator class [#966](https://github.com/smarty-php/smarty/issues/966) - Fix error in Smarty\Smarty::compileAllTemplates() by including missing FilesystemIterator class [#966](https://github.com/smarty-php/smarty/issues/966)

1
changelog/1022.md Normal file
View File

@@ -0,0 +1 @@
- Added `$smarty->prependTemplateDir()` method [#1022](https://github.com/smarty-php/smarty/issues/1022)

View File

@@ -1 +0,0 @@
- Internal compiler classes always return a string (the internal has_code flag has been removed for simplicity) [#918](https://github.com/smarty-php/smarty/pull/918)

View File

@@ -1 +0,0 @@
- Using stream variables in templates now throws a deprecation notice [#933](https://github.com/smarty-php/smarty/pull/933)

View File

@@ -1,2 +0,0 @@
- Documented support for `{if $element is in $array}` syntax [#937](https://github.com/smarty-php/smarty/issues/937)
- Added support for `{if $element is not in $array}` syntax [#937](https://github.com/smarty-php/smarty/issues/937)

View File

@@ -12,24 +12,27 @@ Use `getTemplateDir()` to retrieve the configured paths.
<?php <?php
// set a single directory where the config files are stored // set a single directory where the config files are stored
$smarty->setTemplateDir('./config'); $smarty->setTemplateDir('./templates');
// set multiple directories where config files are stored // set multiple directories where templates are stored
$smarty->setTemplateDir(['./config', './config_2', './config_3']); $smarty->setTemplateDir(['./templates', './templates_2', './templates_3']);
// add directory where config files are stored to the current list of dirs // add directory where templates files are stored to the current list of dirs
$smarty->addTemplateDir('./config_1'); $smarty->addTemplateDir('./templates_1');
// add multiple directories to the current list of dirs // add multiple directories to the current list of dirs
$smarty->addTemplateDir([ $smarty->addTemplateDir([
'./config_2', './templates_2',
'./config_3', './templates_3',
]); ]);
// chaining of method calls // chaining of method calls
$smarty->setTemplateDir('./config') $smarty->setTemplateDir('./templates')
->addTemplateDir('./config_1') ->addTemplateDir('./templates_1')
->addTemplateDir('./config_2'); ->addTemplateDir('./templates_2');
// insert a template dir before exising template dirs
$smarty->prependTemplateDir('./more_important_templates')
// get all directories where config files are stored // get all directories where config files are stored
$template_dirs = $smarty->getTemplateDir(); $template_dirs = $smarty->getTemplateDir();

View File

@@ -9,7 +9,6 @@
|----------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |----------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| file | Yes | The name of the config file to include | | file | Yes | The name of the config file to include |
| section | No | The name of the section to load | | section | No | The name of the section to load |
| scope | no | How the scope of the loaded variables are treated, which must be one of local, parent or global. local means variables are loaded into the local template context. parent means variables are loaded into both the local context and the parent template that called it. global means variables are available to all templates. |
## Examples ## Examples

View File

@@ -0,0 +1,9 @@
# is_array
Return true if the variable passed to it is an array.
## Basic usage
```smarty
{if $myVar|is_array}it's an array{/if}
```

View File

@@ -25,9 +25,17 @@ Here's how you create an instance of Smarty in your PHP scripts:
```php ```php
<?php <?php
// Instantiated via composer
require 'vendor/autoload.php'; require 'vendor/autoload.php';
use Smarty\Smarty; use Smarty\Smarty;
$smarty = new Smarty(); $smarty = new Smarty();
// or ...
// Instantiated directly
require("/path/to/smarty/libs/Smarty.class.php");
use Smarty\Smarty;
$smarty = new Smarty();
``` ```
Now that the library files are in place, it's time to set up the Smarty Now that the library files are in place, it's time to set up the Smarty

42
libs/Smarty.class.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
/////////////////////////////////////////////////////////////////////
// This is a stub PSR-4 loading script that gets all the pieces of //
// Smarty 5.x loaded without requiring the use of composer. It's //
// not really a 'class' file, but the name is used so we're //
// backwards compatible with previous versions of Smarty. //
// //
// Example: //
// require_once("/path/to/smarty/libs/Smarty.class.php"); //
// //
// $smarty = new Smarty\Smarty; //
// $smarty->testInstall(); //
/////////////////////////////////////////////////////////////////////
define('__SMARTY_DIR', __DIR__ . '/../src/');
// Global function declarations
require_once(__SMARTY_DIR . "/functions.php");
spl_autoload_register(function ($class) {
// Class prefix
$prefix = 'Smarty\\';
// Does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// If not, move to the next registered autoloader
return;
}
// Hack off the prefix part
$relative_class = substr($class, $len);
// Build a path to the include file
$file = __SMARTY_DIR . str_replace('\\', '/', $relative_class) . '.php';
// If the file exists, require it
if (file_exists($file)) {
require_once($file);
}
});

View File

@@ -60,6 +60,7 @@ nav:
- 'escape': 'designers/language-modifiers/language-modifier-escape.md' - 'escape': 'designers/language-modifiers/language-modifier-escape.md'
- 'from_charset': 'designers/language-modifiers/language-modifier-from-charset.md' - 'from_charset': 'designers/language-modifiers/language-modifier-from-charset.md'
- 'indent': 'designers/language-modifiers/language-modifier-indent.md' - 'indent': 'designers/language-modifiers/language-modifier-indent.md'
- 'is_array': 'designers/language-modifiers/language-modifier-is_array.md'
- 'isset': 'designers/language-modifiers/language-modifier-isset.md' - 'isset': 'designers/language-modifiers/language-modifier-isset.md'
- 'join': 'designers/language-modifiers/language-modifier-join.md' - 'join': 'designers/language-modifiers/language-modifier-join.md'
- 'json_encode': 'designers/language-modifiers/language-modifier-json-encode.md' - 'json_encode': 'designers/language-modifiers/language-modifier-json-encode.md'

View File

@@ -20,9 +20,6 @@ use Smarty\Template;
* - indent_char - string (" ") * - indent_char - string (" ")
* - wrap_boundary - boolean (true) * - wrap_boundary - boolean (true)
* *
* @link https://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual)
*
* @param array $params parameters * @param array $params parameters
* @param string $content contents of the block * @param string $content contents of the block
* @param Template $template template object * @param Template $template template object

View File

@@ -11,8 +11,6 @@ namespace Smarty\Compile\Modifier;
* Input: string to catenate * Input: string to catenate
* Example: {$var|cat:"foo"} * Example: {$var|cat:"foo"}
* *
* @link https://www.smarty.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,8 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: count_characters * Name: count_characters
* Purpose: count the number of characters in a text * Purpose: count the number of characters in a text
* *
* @link https://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
* manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,8 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: count_paragraphs * Name: count_paragraphs
* Purpose: count the number of paragraphs in a text * Purpose: count the number of paragraphs in a text
* *
* @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,8 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: count_sentences * Name: count_sentences
* Purpose: count the number of sentences in a text * Purpose: count the number of sentences in a text
* *
* @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: count_words * Name: count_words
* Purpose: count the number of words in a text * Purpose: count the number of words in a text
* *
* @link https://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: default * Name: default
* Purpose: designate default value for empty variables * Purpose: designate default value for empty variables
* *
* @link https://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -9,7 +9,6 @@ use Smarty\Exception;
* Name: escape * Name: escape
* Purpose: escape string for output * Purpose: escape string for output
* *
* @link https://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm * @author Rodney Rehm
*/ */

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: indent * Name: indent
* Purpose: indent lines of text * Purpose: indent lines of text
* *
* @link https://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: lower * Name: lower
* Purpose: convert string to lowercase * Purpose: convert string to lowercase
* *
* @link https://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -7,7 +7,6 @@ namespace Smarty\Compile\Modifier;
* Name: nl2br * Name: nl2br
* Purpose: insert HTML line breaks before all newlines in a string * Purpose: insert HTML line breaks before all newlines in a string
* *
* @link https://www.smarty.net/docs/en/language.modifier.nl2br.tpl nl2br (Smarty online manual)
*/ */
class Nl2brModifierCompiler extends Base { class Nl2brModifierCompiler extends Base {

View File

@@ -7,7 +7,6 @@ namespace Smarty\Compile\Modifier;
* Name: round * Name: round
* Purpose: Returns the rounded value of num to specified precision (number of digits after the decimal point) * Purpose: Returns the rounded value of num to specified precision (number of digits after the decimal point)
* *
* @link https://www.smarty.net/docs/en/language.modifier.round.tpl round (Smarty online manual)
*/ */
class RoundModifierCompiler extends Base { class RoundModifierCompiler extends Base {

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: str_repeat * Name: str_repeat
* Purpose: returns string repeated times times * Purpose: returns string repeated times times
* *
* @link https://www.smarty.net/docs/en/language.modifier.str_repeat.tpl str_repeat (Smarty online manual)
*/ */
class StrRepeatModifierCompiler extends Base { class StrRepeatModifierCompiler extends Base {

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: string_format * Name: string_format
* Purpose: format strings via sprintf * Purpose: format strings via sprintf
* *
* @link https://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -9,7 +9,6 @@ namespace Smarty\Compile\Modifier;
* Example: {$var|strip} {$var|strip:"&nbsp;"} * Example: {$var|strip} {$var|strip:"&nbsp;"}
* Date: September 25th, 2002 * Date: September 25th, 2002
* *
* @link https://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: strip_tags * Name: strip_tags
* Purpose: strip html tags from text * Purpose: strip html tags from text
* *
* @link https://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -7,7 +7,6 @@ namespace Smarty\Compile\Modifier;
* Name: strlen * Name: strlen
* Purpose: return the length of the given string * Purpose: return the length of the given string
* *
* @link https://www.smarty.net/docs/en/language.modifier.strlen.tpl strlen (Smarty online manual)
*/ */
class StrlenModifierCompiler extends Base { class StrlenModifierCompiler extends Base {

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: lower * Name: lower
* Purpose: convert string to uppercase * Purpose: convert string to uppercase
* *
* @link https://www.smarty.net/manual/en/language.modifier.upper.php lower (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -6,7 +6,6 @@ namespace Smarty\Compile\Modifier;
* Name: wordwrap * Name: wordwrap
* Purpose: wrap a string of text at a given length * Purpose: wrap a string of text at a given length
* *
* @link https://www.smarty.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews * @author Uwe Tews
*/ */

View File

@@ -43,7 +43,7 @@ class ConfigLoad extends Base {
* @var array * @var array
* @see BasePlugin * @see BasePlugin
*/ */
protected $optional_attributes = ['section', 'scope']; protected $optional_attributes = ['section'];
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
@@ -51,7 +51,7 @@ class ConfigLoad extends Base {
* @var array * @var array
* @see BasePlugin * @see BasePlugin
*/ */
protected $option_flags = ['nocache', 'noscope']; protected $option_flags = [];
/** /**
* Compiles code for the {config_load} tag * Compiles code for the {config_load} tag
@@ -66,9 +66,7 @@ class ConfigLoad extends Base {
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// save possible attributes // save possible attributes
$conf_file = $_attr['file']; $conf_file = $_attr['file'];
$section = $_attr['section'] ?? 'null'; $section = $_attr['section'] ?? 'null';

View File

@@ -32,7 +32,7 @@ class ExtendsTag extends Inheritance {
* *
* @var array * @var array
*/ */
protected $optional_attributes = ['extends_resource']; protected $optional_attributes = [];
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
@@ -64,29 +64,7 @@ class ExtendsTag extends Inheritance {
} }
// add code to initialize inheritance // add code to initialize inheritance
$this->registerInit($compiler, true); $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 ''; return '';
} }
@@ -106,42 +84,4 @@ class ExtendsTag extends Inheritance {
(isset($template) ? ", {$template}, \$_smarty_current_dir" : '') . ");\n?>" (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();
}
} }

View File

@@ -403,14 +403,28 @@ class Template extends BaseCompiler {
} }
// get template source // get template source
if (!empty($this->template->getSource()->components)) { if (!empty($this->template->getSource()->components)) {
// we have array of inheritance templates by extends: resource
// generate corresponding source code sequence $_compiled_code = '<?php $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?>';
$_content =
ExtendsTag::extendsSourceArrayCode($this->template); $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 { } else {
// get template source // get template source
$_content = $this->template->getSource()->getContent(); $_content = $this->template->getSource()->getContent();
}
$_compiled_code = $this->smarty->runPostFilters( $_compiled_code = $this->smarty->runPostFilters(
$this->doCompile( $this->doCompile(
$this->smarty->runPreFilters($_content, $this->template), $this->smarty->runPreFilters($_content, $this->template),
@@ -418,6 +432,8 @@ class Template extends BaseCompiler {
), ),
$this->template $this->template
); );
}
} catch (\Exception $e) { } catch (\Exception $e) {
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
$this->smarty->getDebug()->end_compile($this->template); $this->smarty->getDebug()->end_compile($this->template);
@@ -680,7 +696,8 @@ class Template extends BaseCompiler {
* *
* @return string * @return string
*/ */
public function appendCode($left, $right) { public function appendCode(string $left, string $right): string
{
if (preg_match('/\s*\?>\s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) { if (preg_match('/\s*\?>\s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) {
$left = preg_replace('/\s*\?>\s?$/D', "\n", $left); $left = preg_replace('/\s*\?>\s?$/D', "\n", $left);
$left .= preg_replace('/^<\?php\s+/', '', $right); $left .= preg_replace('/^<\?php\s+/', '', $right);
@@ -1056,7 +1073,7 @@ class Template extends BaseCompiler {
$prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack));
$this->prefixCodeStack[] = []; $this->prefixCodeStack[] = [];
foreach ($prefixArray as $c) { foreach ($prefixArray as $c) {
$code = $this->appendCode($code, $c); $code = $this->appendCode($code, (string) $c);
} }
$this->prefix_code = []; $this->prefix_code = [];
return $code; return $code;

View File

@@ -163,8 +163,6 @@ class Data
* be not cached * be not cached
* *
* @return Data * @return Data
* @link https://www.smarty.net/docs/en/api.append.tpl
*
* @api Smarty::append() * @api Smarty::append()
*/ */
public function append($tpl_var, $value = null, $merge = false, $nocache = false) public function append($tpl_var, $value = null, $merge = false, $nocache = false)
@@ -218,7 +216,6 @@ class Data
* *
* @return mixed variable value or or array of variables * @return mixed variable value or or array of variables
* @api Smarty::getTemplateVars() * @api Smarty::getTemplateVars()
* @link https://www.smarty.net/docs/en/api.get.template.vars.tpl
* *
*/ */
public function getTemplateVars($varName = null, $searchParents = true) public function getTemplateVars($varName = null, $searchParents = true)
@@ -227,7 +224,10 @@ class Data
return $this->getValue($varName, $searchParents); return $this->getValue($varName, $searchParents);
} }
return array_merge($this->parent && $searchParents ? $this->parent->getTemplateVars() : [], $this->tpl_vars); return array_merge(
$this->parent && $searchParents ? $this->parent->getTemplateVars() : [],
array_map(function(Variable $var) { return $var->getValue(); }, $this->tpl_vars)
);
} }
/** /**
@@ -351,7 +351,6 @@ class Data
* @param string|array $tpl_var the template variable(s) to clear * @param string|array $tpl_var the template variable(s) to clear
* *
* @return Data * @return Data
* @link https://www.smarty.net/docs/en/api.clear.assign.tpl
* *
* @api Smarty::clearAssign() * @api Smarty::clearAssign()
*/ */
@@ -371,7 +370,6 @@ class Data
* clear all the assigned template variables. * clear all the assigned template variables.
* *
* @return Data * @return Data
* @link https://www.smarty.net/docs/en/api.clear.all.assign.tpl
* *
* @api Smarty::clearAllAssign() * @api Smarty::clearAllAssign()
*/ */
@@ -387,7 +385,6 @@ class Data
* @param string|null $name variable name or null * @param string|null $name variable name or null
* *
* @return Data * @return Data
* @link https://www.smarty.net/docs/en/api.clear.config.tpl
* *
* @api Smarty::clearConfig() * @api Smarty::clearConfig()
*/ */
@@ -440,7 +437,6 @@ class Data
* *
* @return mixed variable value or or array of variables * @return mixed variable value or or array of variables
* @throws Exception * @throws Exception
* @link https://www.smarty.net/docs/en/api.get.config.vars.tpl
* *
* @api Smarty::getConfigVars() * @api Smarty::getConfigVars()
*/ */
@@ -462,7 +458,6 @@ class Data
* @returns $this * @returns $this
* @throws \Exception * @throws \Exception
* @link https://www.smarty.net/docs/en/api.config.load.tpl
* *
* @api Smarty::configLoad() * @api Smarty::configLoad()
*/ */

View File

@@ -113,7 +113,6 @@ class DefaultExtension extends Base {
* Name: spacify * Name: spacify
* Purpose: add spaces between characters in a string * Purpose: add spaces between characters in a string
* *
* @link https://www.smarty.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input string * @param string $string input string
@@ -234,7 +233,6 @@ class DefaultExtension extends Base {
* - format: strftime format for output * - format: strftime format for output
* - default_date: default date if $string is empty * - default_date: default date if $string is empty
* *
* @link https://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input date string * @param string $string input date string
@@ -386,7 +384,6 @@ class DefaultExtension extends Base {
* Name: escape * Name: escape
* Purpose: escape string for output * Purpose: escape string for output
* *
* @link https://www.smarty.net/docs/en/language.modifier.escape
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input string * @param string $string input string
@@ -654,8 +651,6 @@ class DefaultExtension extends Base {
* Name: regex_replace * Name: regex_replace
* Purpose: regular expression search/replace * Purpose: regular expression search/replace
* *
* @link https://www.smarty.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input string * @param string $string input string
@@ -703,7 +698,6 @@ class DefaultExtension extends Base {
* Name: replace * Name: replace
* Purpose: simple search/replace * Purpose: simple search/replace
* *
* @link https://www.smarty.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* *
@@ -726,7 +720,6 @@ class DefaultExtension extends Base {
* optionally splitting in the middle of a word, and * optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle. * appending the $etc string or inserting $etc into the middle.
* *
* @link https://www.smarty.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param string $string input string * @param string $string input string

View File

@@ -13,8 +13,6 @@ use Smarty\Template;
* @param Template $template template object * @param Template $template template object
* *
* @return string|null * @return string|null
*@link https://www.smarty.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual)
* *
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
*/ */

View File

@@ -26,8 +26,6 @@ use Smarty\Template;
* {cycle name=row values="one,two,three" reset=true} * {cycle name=row values="one,two,three" reset=true}
* {cycle name=row} * {cycle name=row}
* *
* @link https://www.smarty.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com> * @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com> * @author credit to Gerard <gerard@interfold.com>

View File

@@ -10,8 +10,6 @@ use Smarty\Template;
* Name: fetch * Name: fetch
* Purpose: fetch file, web or ftp data and display results * Purpose: fetch file, web or ftp data and display results
* *
* @link https://www.smarty.net/manual/en/language.function.fetch.php {fetch}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -27,8 +27,6 @@ use Smarty\Template;
* - assign (optional) - assign the output as an array to this variable * - assign (optional) - assign the output as an array to this variable
* - escape (optional) - escape the content (not value), defaults to true * - escape (optional) - escape the content (not value), defaults to true
* *
* @link https://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com> * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com> * @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0 * @version 1.0

View File

@@ -20,8 +20,6 @@ use Smarty\Template;
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT * - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
* - path_prefix - prefix for path output (optional, default empty) * - path_prefix - prefix for path output (optional, default empty)
* *
* @link https://www.smarty.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Duda <duda@big.hu> * @author credits to Duda <duda@big.hu>
* @version 1.0 * @version 1.0

View File

@@ -19,8 +19,6 @@ use Smarty\Template;
* - id (optional) - string default not set * - id (optional) - string default not set
* - class (optional) - string default not set * - class (optional) - string default not set
* *
* @link https://www.smarty.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de> * @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de>
* *

View File

@@ -27,8 +27,6 @@ use Smarty\Template;
* {html_radios values=$ids name='box' separator='<br>' output=$names} * {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names} * {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* *
* @link https://www.smarty.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com> * @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com> * @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0 * @version 1.0

View File

@@ -26,8 +26,6 @@ use Smarty\Template;
* - 2.0 complete rewrite for performance, * - 2.0 complete rewrite for performance,
* added attributes month_names, *_id * added attributes month_names, *_id
* *
* @link https://www.smarty.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual)
* @version 2.0 * @version 2.0
* @author Andrei Zmievski * @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>

View File

@@ -9,8 +9,6 @@ use Smarty\Template;
* Name: html_select_time * Name: html_select_time
* Purpose: Prints the dropdowns for time selection * Purpose: Prints the dropdowns for time selection
* *
* @link https://www.smarty.net/manual/en/language.function.html.select.time.php {html_select_time}
* (Smarty online manual)
* @author Roberto Berto <roberto@berto.net> * @author Roberto Berto <roberto@berto.net>
* @author Monte Ohrt <monte AT ohrt DOT com> * @author Monte Ohrt <monte AT ohrt DOT com>
* *

View File

@@ -37,8 +37,6 @@ use Smarty\Template;
* @return string * @return string
*@author credit to boots <boots dot smarty at yahoo dot com> *@author credit to boots <boots dot smarty at yahoo dot com>
* @version 1.1 * @version 1.1
* @link https://www.smarty.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual)
* *
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Messju Mohr <messju at lammfellpuschen dot de> * @author credit to Messju Mohr <messju at lammfellpuschen dot de>

View File

@@ -35,8 +35,6 @@ use Smarty\Template;
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"} * {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'} * {mailto address="me@domain.com" extra='class="mailto"'}
* *
* @link https://www.smarty.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual)
* @version 1.2 * @version 1.2
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Jason Sweat (added cc, bcc and subject functionality) * @author credits to Jason Sweat (added cc, bcc and subject functionality)

View File

@@ -10,8 +10,6 @@ use Smarty\Template;
* Name: math * Name: math
* Purpose: handle math computations in template * Purpose: handle math computations in template
* *
* @link https://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param array $params parameters * @param array $params parameters

View File

@@ -47,18 +47,18 @@ class Dq extends Base
if ($subtree instanceof Code) { if ($subtree instanceof Code) {
$this->subtrees[ $last_subtree ]->data = $this->subtrees[ $last_subtree ]->data =
$parser->compiler->appendCode( $parser->compiler->appendCode(
$this->subtrees[ $last_subtree ]->data, (string) $this->subtrees[ $last_subtree ]->data,
'<?php echo ' . $subtree->data . ';?>' '<?php echo ' . $subtree->data . ';?>'
); );
} elseif ($subtree instanceof DqContent) { } elseif ($subtree instanceof DqContent) {
$this->subtrees[ $last_subtree ]->data = $this->subtrees[ $last_subtree ]->data =
$parser->compiler->appendCode( $parser->compiler->appendCode(
$this->subtrees[ $last_subtree ]->data, (string) $this->subtrees[ $last_subtree ]->data,
'<?php echo "' . $subtree->data . '";?>' '<?php echo "' . $subtree->data . '";?>'
); );
} else { } else {
$this->subtrees[ $last_subtree ]->data = $this->subtrees[ $last_subtree ]->data =
$parser->compiler->appendCode($this->subtrees[ $last_subtree ]->data, $subtree->data); $parser->compiler->appendCode((string) $this->subtrees[ $last_subtree ]->data, (string) $subtree->data);
} }
} else { } else {
$this->subtrees[] = $subtree; $this->subtrees[] = $subtree;

View File

@@ -62,9 +62,9 @@ class Tag extends Base
public function assign_to_var(\Smarty\Parser\TemplateParser $parser) public function assign_to_var(\Smarty\Parser\TemplateParser $parser)
{ {
$var = $parser->compiler->getNewPrefixVariable(); $var = $parser->compiler->getNewPrefixVariable();
$tmp = $parser->compiler->appendCode('<?php ob_start();?>', $this->data); $tmp = $parser->compiler->appendCode('<?php ob_start();?>', (string) $this->data);
$tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>"); $tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
$parser->compiler->appendPrefixCode((string) $tmp); $parser->compiler->appendPrefixCode($tmp);
return $var; return $var;
} }
} }

View File

@@ -114,7 +114,7 @@ class Template extends Base
break; break;
case 'tag': case 'tag':
foreach ($chunk['subtrees'] as $subtree) { foreach ($chunk['subtrees'] as $subtree) {
$text = $parser->compiler->appendCode($text, $subtree->to_smarty_php($parser)); $text = $parser->compiler->appendCode($text, (string) $subtree->to_smarty_php($parser));
} }
$code .= $text; $code .= $text;
break; break;

View File

@@ -2536,7 +2536,7 @@ public static $yy_action = array(
// line 806 "src/Parser/TemplateParser.y" // line 806 "src/Parser/TemplateParser.y"
public function yy_r101(){ public function yy_r101(){
$prefixVar = $this->compiler->getNewPrefixVariable(); $prefixVar = $this->compiler->getNewPrefixVariable();
$tmp = $this->compiler->appendCode('<?php ob_start();?>', $this->yystack[$this->yyidx + 0]->minor); $tmp = $this->compiler->appendCode('<?php ob_start();?>', (string) $this->yystack[$this->yyidx + 0]->minor);
$this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "<?php {$prefixVar} = ob_get_clean();?>")); $this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "<?php {$prefixVar} = ob_get_clean();?>"));
$this->_retvalue = $prefixVar; $this->_retvalue = $prefixVar;
} }

View File

@@ -805,7 +805,7 @@ value(res) ::= varindexed(vi) DOUBLECOLON static_class_access(r). {
// Smarty tag // Smarty tag
value(res) ::= smartytag(st). { value(res) ::= smartytag(st). {
$prefixVar = $this->compiler->getNewPrefixVariable(); $prefixVar = $this->compiler->getNewPrefixVariable();
$tmp = $this->compiler->appendCode('<?php ob_start();?>', st); $tmp = $this->compiler->appendCode('<?php ob_start();?>', (string) st);
$this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "<?php {$prefixVar} = ob_get_clean();?>")); $this->compiler->appendPrefixCode($this->compiler->appendCode($tmp, "<?php {$prefixVar} = ob_get_clean();?>"));
res = $prefixVar; res = $prefixVar;
} }

View File

@@ -116,20 +116,18 @@ class ForeachRuntime {
* *
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0 * @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
* for empty elements * for empty elements
* @throws \Exception
*/ */
public function count($value) { public function count($value): int
if ($value instanceof IteratorAggregate) { {
if ($value instanceof \IteratorAggregate) {
// Note: getIterator() returns a Traversable, not an Iterator // Note: getIterator() returns a Traversable, not an Iterator
// thus rewind() and valid() methods may not be present // thus rewind() and valid() methods may not be present
return iterator_count($value->getIterator()); return iterator_count($value->getIterator());
} elseif ($value instanceof Iterator) { } elseif ($value instanceof \Iterator) {
return $value instanceof Generator ? 1 : iterator_count($value); return $value instanceof \Generator ? 1 : iterator_count($value);
} elseif ($value instanceof Countable) { } elseif ($value instanceof \Countable) {
return count($value); return count($value);
} elseif ($value instanceof PDOStatement) {
return $value->rowCount();
} elseif ($value instanceof Traversable) {
return iterator_count($value);
} }
return count((array) $value); return count((array) $value);
} }

View File

@@ -40,7 +40,6 @@ use Smarty\Runtime\TplFunctionRuntime;
* Smarty mailing list. Send a blank e-mail to * Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com * smarty-discussion-subscribe@googlegroups.com
* *
* @link https://www.smarty.net/
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews <uwe dot tews at gmail dot com> * @author Uwe Tews <uwe dot tews at gmail dot com>
* @author Rodney Rehm * @author Rodney Rehm
@@ -55,7 +54,7 @@ class Smarty extends \Smarty\TemplateBase {
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '5.0.1'; const SMARTY_VERSION = '5.2.0';
/** /**
* define caching modes * define caching modes
@@ -536,8 +535,6 @@ class Smarty extends \Smarty\TemplateBase {
/** /**
* Load an additional extension. * Load an additional extension.
* *
* @param Base $extension
*
* @return void * @return void
*/ */
public function addExtension(ExtensionInterface $extension) { public function addExtension(ExtensionInterface $extension) {
@@ -583,7 +580,7 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param string|\Smarty\Security $security_class if a string is used, it must be class-name * @param string|\Smarty\Security $security_class if a string is used, it must be class-name
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
* @throws \Smarty\Exception * @throws \Smarty\Exception
*/ */
public function enableSecurity($security_class = null) { public function enableSecurity($security_class = null) {
@@ -594,7 +591,7 @@ class Smarty extends \Smarty\TemplateBase {
/** /**
* Disable security * Disable security
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function disableSecurity() { public function disableSecurity() {
$this->security_policy = null; $this->security_policy = null;
@@ -608,7 +605,7 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $key of the array element to assign the template dir to * @param string $key of the array element to assign the template dir to
* @param bool $isConfig true for config_dir * @param bool $isConfig true for config_dir
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function addTemplateDir($template_dir, $key = null, $isConfig = false) { public function addTemplateDir($template_dir, $key = null, $isConfig = false) {
if ($isConfig) { if ($isConfig) {
@@ -673,7 +670,7 @@ class Smarty extends \Smarty\TemplateBase {
* @param string|array $template_dir directory(s) of template sources * @param string|array $template_dir directory(s) of template sources
* @param bool $isConfig true for config_dir * @param bool $isConfig true for config_dir
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function setTemplateDir($template_dir, $isConfig = false) { public function setTemplateDir($template_dir, $isConfig = false) {
if ($isConfig) { if ($isConfig) {
@@ -687,13 +684,28 @@ class Smarty extends \Smarty\TemplateBase {
return $this; return $this;
} }
/**
* Adds a template directory before any existing directoires
*
* @param string $new_template_dir directory of template sources
* @param bool $is_config true for config_dir
*
* @return static current Smarty instance for chaining
*/
public function prependTemplateDir($new_template_dir, $is_config = false) {
$current_template_dirs = $is_config ? $this->config_dir : $this->template_dir;
array_unshift($current_template_dirs, $new_template_dir);
$this->setTemplateDir($current_template_dirs, $is_config);
return $this;
}
/** /**
* Add config directory(s) * Add config directory(s)
* *
* @param string|array $config_dir directory(s) of config sources * @param string|array $config_dir directory(s) of config sources
* @param mixed $key key of the array element to assign the config dir to * @param mixed $key key of the array element to assign the config dir to
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function addConfigDir($config_dir, $key = null) { public function addConfigDir($config_dir, $key = null) {
return $this->addTemplateDir($config_dir, $key, true); return $this->addTemplateDir($config_dir, $key, true);
@@ -715,7 +727,7 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param $config_dir * @param $config_dir
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function setConfigDir($config_dir) { public function setConfigDir($config_dir) {
return $this->setTemplateDir($config_dir, true); return $this->setTemplateDir($config_dir, true);
@@ -731,7 +743,6 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @return $this * @return $this
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.register.plugin.tpl
* *
* @api Smarty::registerPlugin() * @api Smarty::registerPlugin()
*/ */
@@ -758,7 +769,6 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $name name of template tag * @param string $name name of template tag
* *
* @return array|null * @return array|null
* @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
* *
* @api Smarty::unregisterPlugin() * @api Smarty::unregisterPlugin()
*/ */
@@ -776,7 +786,6 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $name name of template tag * @param string $name name of template tag
* *
* @return $this * @return $this
* @link https://www.smarty.net/docs/en/api.unregister.plugin.tpl
* *
* @api Smarty::unregisterPlugin() * @api Smarty::unregisterPlugin()
*/ */
@@ -792,7 +801,7 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param null|array|string $plugins_dir * @param null|array|string $plugins_dir
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
* @deprecated since 5.0 * @deprecated since 5.0
*/ */
public function addPluginsDir($plugins_dir) { public function addPluginsDir($plugins_dir) {
@@ -825,7 +834,7 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param string|array $plugins_dir directory(s) of plugins * @param string|array $plugins_dir directory(s) of plugins
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
* @deprecated since 5.0 * @deprecated since 5.0
*/ */
public function setPluginsDir($plugins_dir) { public function setPluginsDir($plugins_dir) {
@@ -850,7 +859,6 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @return $this * @return $this
* @throws Exception if $callback is not callable * @throws Exception if $callback is not callable
* @link https://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl
* *
* @api Smarty::registerDefaultPluginHandler() * @api Smarty::registerDefaultPluginHandler()
* *
@@ -887,7 +895,7 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param string $compile_dir directory to store compiled templates in * @param string $compile_dir directory to store compiled templates in
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function setCompileDir($compile_dir) { public function setCompileDir($compile_dir) {
$this->_normalizeDir('compile_dir', $compile_dir); $this->_normalizeDir('compile_dir', $compile_dir);
@@ -913,7 +921,7 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param string $cache_dir directory to store cached templates in * @param string $cache_dir directory to store cached templates in
* *
* @return Smarty current Smarty instance for chaining * @return static current Smarty instance for chaining
*/ */
public function setCacheDir($cache_dir) { public function setCacheDir($cache_dir) {
$this->_normalizeDir('cache_dir', $cache_dir); $this->_normalizeDir('cache_dir', $cache_dir);
@@ -1176,7 +1184,7 @@ class Smarty extends \Smarty\TemplateBase {
/** /**
* Get Smarty object * Get Smarty object
* *
* @return Smarty * @return static
*/ */
public function getSmarty() { public function getSmarty() {
return $this; return $this;
@@ -1254,7 +1262,6 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @return int number of cache files deleted * @return int number of cache files deleted
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.clear.cache.tpl
* *
* @api Smarty::clearCache() * @api Smarty::clearCache()
*/ */
@@ -1274,7 +1281,6 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $type resource type * @param string $type resource type
* *
* @return int number of cache files deleted * @return int number of cache files deleted
* @link https://www.smarty.net/docs/en/api.clear.all.cache.tpl
* *
* @api Smarty::clearAllCache() * @api Smarty::clearAllCache()
*/ */
@@ -1291,7 +1297,6 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @return int number of template files deleted * @return int number of template files deleted
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.clear.compiled.template.tpl
* *
* @api Smarty::clearCompiledTemplate() * @api Smarty::clearCompiledTemplate()
*/ */
@@ -1805,7 +1810,6 @@ class Smarty extends \Smarty\TemplateBase {
* @return bool * @return bool
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @api Smarty::loadFilter() * @api Smarty::loadFilter()
* @link https://www.smarty.net/docs/en/api.load.filter.tpl
* *
* @deprecated since 5.0 * @deprecated since 5.0
*/ */
@@ -1853,11 +1857,10 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $type filter type * @param string $type filter type
* @param string $name filter name * @param string $name filter name
* *
* @return TemplateBase * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @api Smarty::unloadFilter() * @api Smarty::unloadFilter()
* *
* @link https://www.smarty.net/docs/en/api.unload.filter.tpl
* *
* @deprecated since 5.0 * @deprecated since 5.0
*/ */
@@ -1900,8 +1903,7 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $name name of resource type * @param string $name name of resource type
* @param Base $resource_handler * @param Base $resource_handler
* *
* @return Smarty * @return static
* @link https://www.smarty.net/docs/en/api.register.cacheresource.tpl
* *
* @api Smarty::registerCacheResource() * @api Smarty::registerCacheResource()
* *
@@ -1922,9 +1924,8 @@ class Smarty extends \Smarty\TemplateBase {
* *
* @param $name * @param $name
* *
* @return Smarty * @return static
* @api Smarty::unregisterCacheResource() * @api Smarty::unregisterCacheResource()
* @link https://www.smarty.net/docs/en/api.unregister.cacheresource.tpl
* *
* @deprecated since 5.0 * @deprecated since 5.0
* *
@@ -1956,9 +1957,8 @@ class Smarty extends \Smarty\TemplateBase {
* @param callable $callback * @param callable $callback
* @param string|null $name optional filter name * @param string|null $name optional filter name
* *
* @return TemplateBase * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.register.filter.tpl
* *
* @api Smarty::registerFilter() * @api Smarty::registerFilter()
*/ */
@@ -2016,11 +2016,10 @@ class Smarty extends \Smarty\TemplateBase {
* @param string $type filter type * @param string $type filter type
* @param callback|string $name the name previously used in ::registerFilter * @param callback|string $name the name previously used in ::registerFilter
* *
* @return TemplateBase * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @api Smarty::unregisterFilter() * @api Smarty::unregisterFilter()
* *
* @link https://www.smarty.net/docs/en/api.unregister.filter.tpl
* *
*/ */
public function unregisterFilter($type, $name) { public function unregisterFilter($type, $name) {
@@ -2054,7 +2053,7 @@ class Smarty extends \Smarty\TemplateBase {
* @param array|string $modifiers modifier or list of modifiers * @param array|string $modifiers modifier or list of modifiers
* to add * to add
* *
* @return Smarty * @return static
* @api Smarty::addDefaultModifiers() * @api Smarty::addDefaultModifiers()
* *
*/ */
@@ -2084,7 +2083,7 @@ class Smarty extends \Smarty\TemplateBase {
* @param array|string $modifiers modifier or list of modifiers * @param array|string $modifiers modifier or list of modifiers
* to set * to set
* *
* @return TemplateBase * @return static
* @api Smarty::setDefaultModifiers() * @api Smarty::setDefaultModifiers()
* *
*/ */
@@ -2203,7 +2202,6 @@ class Smarty extends \Smarty\TemplateBase {
* @return bool cache status * @return bool cache status
* @throws \Exception * @throws \Exception
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.is.cached.tpl
* *
* @api Smarty::isCached() * @api Smarty::isCached()
*/ */
@@ -2244,5 +2242,13 @@ class Smarty extends \Smarty\TemplateBase {
$this->error_unassigned = $error_unassigned; $this->error_unassigned = $error_unassigned;
} }
/**
* 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;
} }
}

View File

@@ -604,7 +604,6 @@ class Template extends TemplateBase {
* @return bool cache status * @return bool cache status
* @throws \Exception * @throws \Exception
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.is.cached.tpl
* *
* @api Smarty::isCached() * @api Smarty::isCached()
*/ */

View File

@@ -73,9 +73,8 @@ abstract class TemplateBase extends Data {
* @param bool $format smarty argument format, else traditional * @param bool $format smarty argument format, else traditional
* @param array $block_methods list of block-methods * @param array $block_methods list of block-methods
* *
* @return \Smarty|\Smarty\Template * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @link https://www.smarty.net/docs/en/api.register.object.tpl
* *
* @api Smarty::registerObject() * @api Smarty::registerObject()
*/ */
@@ -114,9 +113,8 @@ abstract class TemplateBase extends Data {
* *
* @param string $object_name name of object * @param string $object_name name of object
* *
* @return TemplateBase * @return static
* @api Smarty::unregisterObject() * @api Smarty::unregisterObject()
* @link https://www.smarty.net/docs/en/api.unregister.object.tpl
* *
*/ */
public function unregisterObject($object_name) { public function unregisterObject($object_name) {
@@ -179,7 +177,6 @@ abstract class TemplateBase extends Data {
* @return Data data object * @return Data data object
* @throws Exception * @throws Exception
* @api Smarty::createData() * @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl
* *
*/ */
public function createData(Data $parent = null, $name = null) { public function createData(Data $parent = null, $name = null) {
@@ -222,7 +219,6 @@ abstract class TemplateBase extends Data {
* *
* @return object * @return object
* @throws \Smarty\Exception if no such object is found * @throws \Smarty\Exception if no such object is found
* @link https://www.smarty.net/docs/en/api.get.registered.object.tpl
* *
* @api Smarty::getRegisteredObject() * @api Smarty::getRegisteredObject()
*/ */
@@ -255,7 +251,7 @@ abstract class TemplateBase extends Data {
* @param array|string $literals literal or list of literals * @param array|string $literals literal or list of literals
* to addto add * to addto add
* *
* @return TemplateBase * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @api Smarty::addLiterals() * @api Smarty::addLiterals()
* *
@@ -273,7 +269,7 @@ abstract class TemplateBase extends Data {
* @param array|string $literals literal or list of literals * @param array|string $literals literal or list of literals
* to setto set * to setto set
* *
* @return TemplateBase * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @api Smarty::setLiterals() * @api Smarty::setLiterals()
* *
@@ -316,10 +312,9 @@ abstract class TemplateBase extends Data {
* @param string $class_impl the referenced PHP class to * @param string $class_impl the referenced PHP class to
* register * register
* *
* @return TemplateBase * @return static
* @throws \Smarty\Exception * @throws \Smarty\Exception
* @api Smarty::registerClass() * @api Smarty::registerClass()
* @link https://www.smarty.net/docs/en/api.register.class.tpl
* *
*/ */
public function registerClass($class_name, $class_impl) { public function registerClass($class_name, $class_impl) {
@@ -338,7 +333,7 @@ abstract class TemplateBase extends Data {
* *
* @param callable $callback class/method name * @param callable $callback class/method name
* *
* @return TemplateBase * @return static
* @throws Exception if $callback is not callable * @throws Exception if $callback is not callable
* @api Smarty::registerDefaultConfigHandler() * @api Smarty::registerDefaultConfigHandler()
* *
@@ -358,7 +353,7 @@ abstract class TemplateBase extends Data {
* *
* @param callable $callback class/method name * @param callable $callback class/method name
* *
* @return TemplateBase * @return static
* @throws Exception if $callback is not callable * @throws Exception if $callback is not callable
* @api Smarty::registerDefaultTemplateHandler() * @api Smarty::registerDefaultTemplateHandler()
* *
@@ -379,8 +374,7 @@ abstract class TemplateBase extends Data {
* @param string $name name of resource type * @param string $name name of resource type
* @param \Smarty\Resource\BasePlugin $resource_handler instance of Smarty\Resource\BasePlugin * @param \Smarty\Resource\BasePlugin $resource_handler instance of Smarty\Resource\BasePlugin
* *
* @return \Smarty\Smarty|\Smarty\Template * @return static
* @link https://www.smarty.net/docs/en/api.register.resource.tpl
* *
* @api Smarty::registerResource() * @api Smarty::registerResource()
*/ */
@@ -395,9 +389,8 @@ abstract class TemplateBase extends Data {
* *
* @param string $type name of resource type * @param string $type name of resource type
* *
* @return TemplateBase * @return static
* @api Smarty::unregisterResource() * @api Smarty::unregisterResource()
* @link https://www.smarty.net/docs/en/api.unregister.resource.tpl
* *
*/ */
public function unregisterResource($type) { public function unregisterResource($type) {
@@ -413,7 +406,7 @@ abstract class TemplateBase extends Data {
* *
* @param string $tpl_name * @param string $tpl_name
* *
* @return TemplateBase * @return static
* @throws Exception if file is not readable * @throws Exception if file is not readable
* @api Smarty::setDebugTemplate() * @api Smarty::setDebugTemplate()
* *

View File

@@ -91,4 +91,13 @@ class FileResourceIndexedTest extends PHPUnit_Smarty
$this->assertNotEquals($tpl->getCached()->filepath, $tpl2->getCached()->filepath); $this->assertNotEquals($tpl->getCached()->filepath, $tpl2->getCached()->filepath);
} }
public function testPrependTemplatePath()
{
$this->smarty->setTemplateDir(__DIR__ . '/templates');
$this->smarty->prependTemplateDir(__DIR__ . '/templates_4');
$tpl = $this->smarty->createTemplate('dirname.tpl');
$this->assertEquals('templates_4', $this->smarty->fetch($tpl));
}
} }

View File

@@ -10,10 +10,6 @@ use Smarty\CompilerException;
/** /**
* class for security test * class for security test
*
*
*
*
*/ */
class SecurityTest extends PHPUnit_Smarty class SecurityTest extends PHPUnit_Smarty
{ {
@@ -301,16 +297,17 @@ class SecurityTest extends PHPUnit_Smarty
$this->assertTrue($tpl->getSource()->exists); $this->assertTrue($tpl->getSource()->exists);
stream_wrapper_unregister("global"); stream_wrapper_unregister("global");
} }
/**
*
* @group slow
*/
public function testTrustedUri() public function testTrustedUri()
{ {
$this->smarty->security_policy->trusted_uri = array( $this->smarty->security_policy->trusted_uri = array(
'#https://www.smarty.net$#i' '#https://s4otw4nhg.erteorteortert.nusuchtld$#i'
); );
$this->assertStringContainsString('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
$this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('{fetch} cannot read resource \'https://s4otw4nhg.erteorteortert.nusuchtld/docs/en/preface.tpl\'');
$this->smarty->fetch('string:{fetch file="https://s4otw4nhg.erteorteortert.nusuchtld/docs/en/preface.tpl"}');
} }
/** /**
@@ -320,9 +317,12 @@ class SecurityTest extends PHPUnit_Smarty
public function testNotTrustedUri() public function testNotTrustedUri()
{ {
$this->expectException(\Smarty\Exception::class); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('URI \'https://www.smarty.net/docs/en/preface.tpl\' not allowed by security setting'); $this->expectExceptionMessage('URI \'https://example.net\' not allowed by security setting');
$this->smarty->security_policy->trusted_uri = array(); $this->smarty->security_policy->trusted_uri = [];
$this->assertStringContainsString('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}')); $this->assertStringContainsString(
'<title>Preface | Smarty</title>',
$this->smarty->fetch('string:{fetch file="https://example.net"}')
);
} }
/** /**

View File

@@ -1,17 +1,6 @@
<?php <?php
/** /**
* Smarty PHPunit tests getTemplateVars method * Smarty PHPunit tests getTemplateVars method
*
* @author Uwe Tews
*/
/**
* class for getTemplateVars method test
*
*
*
*
*/ */
class GetTemplateVarsTest extends PHPUnit_Smarty class GetTemplateVarsTest extends PHPUnit_Smarty
{ {
@@ -20,7 +9,6 @@ class GetTemplateVarsTest extends PHPUnit_Smarty
$this->setUpSmarty(__DIR__); $this->setUpSmarty(__DIR__);
} }
public function testInit() public function testInit()
{ {
$this->cleanDirs(); $this->cleanDirs();
@@ -109,4 +97,30 @@ class GetTemplateVarsTest extends PHPUnit_Smarty
$this->assertEquals("bar2", $data2->getTemplateVars('foo2', false)); $this->assertEquals("bar2", $data2->getTemplateVars('foo2', false));
$this->assertEquals("", $data2->getTemplateVars('blar', false)); $this->assertEquals("", $data2->getTemplateVars('blar', false));
} }
/**
* test that variable assigned by global assign in template is included in getTemplateVars
*/
public function testAssignedInTemplate()
{
$this->smarty->fetch('string:{assign var="b" value="x" scope="global"}');
$this->assertEquals('x', $this->smarty->getTemplateVars('b'));
}
/**
* test that getTemplateVars returns simple array of values
*/
public function testSimpleCallReturnsArrayWithAllValues()
{
$this->smarty->assign('foo', 'bar');
$this->smarty->assign('i', 3);
$vars = $this->smarty->getTemplateVars();
$this->assertArrayHasKey('foo', $vars);
$this->assertArrayHasKey('i', $vars);
$this->assertEquals('bar', $vars['foo']);
$this->assertEquals(3,$vars['i']);
}
} }

View File

@@ -1197,4 +1197,34 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
$this->assertEquals('Captured content is: Content with lots of html here', $this->smarty->fetch('038_child.tpl')); $this->assertEquals('Captured content is: Content with lots of html here', $this->smarty->fetch('038_child.tpl'));
} }
/**
* Test escaping of file parameter
*/
public function testEscaping()
{
$this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessageMatches('/Unable to load.*/');
$this->assertEquals('hello world', $this->smarty->fetch('escaping.tpl'));
}
/**
* Test escaping of file parameter 2
*/
public function testEscaping2()
{
$this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessageMatches('/Unable to load.*/');
$this->assertEquals('hello world', $this->smarty->fetch('escaping2.tpl'));
}
/**
* Test escaping of file parameter 3
*/
public function testEscaping3()
{
$this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessageMatches('/Unable to load.*/');
$this->assertEquals('hello world', $this->smarty->fetch('escaping3.tpl'));
}
} }

View File

@@ -0,0 +1 @@
{extends "extends:helloworld.tpl', var_dump(shell_exec('ls')), 1, 2, 3);}}?>"}

View File

@@ -0,0 +1 @@
{extends 'extends:"helloworld.tpl\', var_dump(shell_exec(\'ls\')), 1, 2, 3);}}?>'}

View File

@@ -0,0 +1 @@
{extends file='extends:"helloworld.tpl'|cat:"', var_dump(shell_exec('ls')), 1, 2, 3);}}?>"}

View File

@@ -82,6 +82,18 @@ class CompileIncludeTest extends PHPUnit_Smarty
$this->assertEquals('I1I2I3', $content, $text); $this->assertEquals('I1I2I3', $content, $text);
} }
/**
* test template name escaping
*/
public function testIncludeFilenameEscaping()
{
$this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessageMatches('/Unable to load.*/');
$tpl = $this->smarty->createTemplate('test_include_security.tpl');
$content = $this->smarty->fetch($tpl);
$this->assertEquals("hello world", $content);
}
/** /**
* test standard output * test standard output
* *

View File

@@ -0,0 +1 @@
{include file="helloworld.tpl', var_dump(shell_exec('ls')), 1, 2, 3);}}?>"}

View File

@@ -1,17 +1,7 @@
<?php <?php
/**
* Smarty PHPunit tests of modifier
*
* @author Rodney Rehm
*/
/** /**
* class for modifier tests * class testing fetch function
*
*
*
*
*/ */
class PluginFunctionFetchTest extends PHPUnit_Smarty class PluginFunctionFetchTest extends PHPUnit_Smarty
{ {
@@ -25,29 +15,25 @@ class PluginFunctionFetchTest extends PHPUnit_Smarty
$this->cleanDirs(); $this->cleanDirs();
} }
/** /**
* test {fetch} from UIR * test {fetch} from local file
*
*
* @group slow
*/ */
public function testFetchUri() public function testFetchFile()
{ {
$this->assertStringContainsString('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}')); $this->assertStringContainsString(
'ct4hn8nzgm;cgzm;',
$this->smarty->fetch('string:{fetch file="./testfile.txt"}')
);
} }
/** /**
* test {fetch} invalid uri * test {fetch} non-existing file
*
*
*
*/ */
public function testFetchInvalidUri() public function testFetchNonExistingFile()
{ {
$this->expectException(\Smarty\Exception::class); $this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessage('{fetch} cannot read resource \'https://foo.smarty.net/foo.dat\''); $this->expectExceptionMessage('{fetch} cannot read resource \'./no/such/file\'');
$this->smarty->fetch('string:{fetch file="https://foo.smarty.net/foo.dat"}'); $this->smarty->fetch('string:{fetch file="./no/such/file"}');
} }
/** /**

View File

@@ -0,0 +1 @@
ct4hn8nzgm;cgzm;

View File

@@ -32,4 +32,11 @@ class ExtendsIssue419Test extends PHPUnit_Smarty
$this->assertEquals('child', $this->smarty->fetch('extends:001_parent.tpl|001_child.tpl')); $this->assertEquals('child', $this->smarty->fetch('extends:001_parent.tpl|001_child.tpl'));
} }
public function testextendsSecurity()
{
$this->expectException(\Smarty\Exception::class);
$this->expectExceptionMessageMatches('/Unable to load.*/');
$this->assertEquals('child', $this->smarty->fetch('string:{include "001_parent.tpl\', var_dump(shell_exec(\'ls\')), 1, 2, 3);}}?>"}'));
}
} }