Skip to content

Commit

Permalink
update smarty-php/smarty Release 3.1.35
Browse files Browse the repository at this point in the history
  • Loading branch information
osben committed Jun 4, 2020
1 parent aab18e2 commit 4f3de2a
Show file tree
Hide file tree
Showing 19 changed files with 4,988 additions and 1,359 deletions.
3,438 changes: 3,438 additions & 0 deletions Smarty/CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Smarty/NEW_FEATURES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ Smarty 3.1.32
will be treated now as literal. (This does apply for any number of delimiter repeatations).
However {{foo}} is not an literal but will be interpreted as a recursive Smarty tag.
If you use
$smarty->setLiteral(array('{{','}}'));
$smarty->setLiterals(array('{{','}}'));
{{foo}} is now a literal as well.
NOTE: In the last example nested Smarty tags starting with '{{' or ending with '}}' will not
work any longer, but this should be very very raw occouring restriction.
B) Example 2
Assume your delimiter are '<-' , '->' and '<--' , '-->' shall be literals
$smarty->setLiteral(array('<--','-->'));
$smarty->setLiterals(array('<--','-->'));


The capture buffers can now be accessed as array
Expand Down
6 changes: 6 additions & 0 deletions Smarty/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Smarty 3 template engine
[smarty.net](https://www.smarty.net/)

[![Build Status](https://travis-ci.org/smarty-php/smarty.svg?branch=master)](https://travis-ci.org/smarty-php/smarty)

## Documentation

For documentation see
[www.smarty.net/docs/en/](https://www.smarty.net/docs/en/)

## Requirements

Smarty can be run with PHP 5.2 to PHP 7.4.

## Distribution repository

> Smarty 3.1.28 introduces run time template inheritance
Expand Down
10 changes: 7 additions & 3 deletions Smarty/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
"php": ">=5.2"
},
"autoload": {
"files": [
"libs/bootstrap.php"
"classmap": [
"libs/"
]
},
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
}
},
"require-dev": {
"phpunit/phpunit": "6.4.1",
"smarty/smarty-lexer": "^3.1"
}
}
}
2 changes: 1 addition & 1 deletion Smarty/libs/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function register($prepend = false)
*/
public static function autoload($class)
{
if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) {
if ($class[ 0 ] !== 'S' || strpos($class, 'Smarty') !== 0) {
return;
}
$_class = strtolower($class);
Expand Down
4 changes: 2 additions & 2 deletions Smarty/libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @author Uwe Tews <uwe dot tews at gmail dot com>
* @author Rodney Rehm
* @package Smarty
* @version 3.1.33
* @version 3.1.34-dev
*/
/**
* set SMARTY_DIR to absolute path to Smarty library files.
Expand Down Expand Up @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.33';
const SMARTY_VERSION = '3.1.34-dev-7';
/**
* define variable scopes
*/
Expand Down
4 changes: 2 additions & 2 deletions Smarty/libs/plugins/modifier.date_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
}
$is_loaded = true;
}
if ($string !== '' && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
if (!empty($string) && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string);
} elseif ($default_date !== '') {
} elseif (!empty($default_date)) {
$timestamp = smarty_make_timestamp($default_date);
} else {
return;
Expand Down
2 changes: 1 addition & 1 deletion Smarty/libs/sysplugins/smarty_internal_compile_assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
if (isset($parameter[ 'smarty_internal_index' ])) {
$output =
"<?php \$_tmp_array = isset(\$_smarty_tpl->tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n";
$output .= "if (!is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess) {\n";
$output .= "if (!(is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess)) {\n";
$output .= "settype(\$_tmp_array, 'array');\n";
$output .= "}\n";
$output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";
Expand Down
10 changes: 4 additions & 6 deletions Smarty/libs/sysplugins/smarty_internal_compile_foreach.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if (isset($itemAttr[ 'index' ])) {
$output .= "{$itemVar}->index = -1;\n";
}
$output .= "if (\$_from !== null) {\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = true;\n";
$output .= "if (\$_from !== null) foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->do_else = false;\n";
if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
Expand Down Expand Up @@ -296,7 +297,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n} else {\n?>";
$output .= "}\nif ({$itemVar}->do_else) {\n?>";
return $output;
}
}
Expand Down Expand Up @@ -332,9 +333,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
if ($restore === 2) {
$output .= "{$itemVar} = {$local}saved;\n";
}
if ($restore > 0) {
$output .= "}\n";
}
$output .= "}\n";
/* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
Expand Down
1 change: 1 addition & 0 deletions Smarty/libs/sysplugins/smarty_internal_compile_insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
}
}
$compiler->template->compiled->has_nocache_code = true;
return $_output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->processNocacheCode(
"<?php echo '{$output}';?>",
"<?php echo '{$output}';?>\n",
true
)
)
Expand Down Expand Up @@ -77,7 +77,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
new Smarty_Internal_ParseTree_Tag(
$compiler->parser,
$compiler->processNocacheCode(
"<?php echo '{$output}';?>",
"<?php echo '{$output}';?>\n",
true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function registerPlugin(
throw new SmartyException("Plugin tag '{$name}' already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin '{$name}' not callable");
} elseif ($cacheable && $cache_attr) {
throw new SmartyException("Cannot set caching attributes for plugin '{$name}' when it is cacheable.");
} else {
$smarty->registered_plugins[ $type ][ $name ] = array($callback, (bool)$cacheable, (array)$cache_attr);
}
Expand Down
116 changes: 78 additions & 38 deletions Smarty/libs/sysplugins/smarty_internal_parsetree_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,85 @@ public function prepend_array(Smarty_Internal_Templateparser $parser, $array = a
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
$code = '';
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
$subtree = $this->subtrees[ $key ]->to_smarty_php($parser);
while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Text ||
$this->subtrees[ $key + 1 ]->data === '')) {
$key++;
if ($this->subtrees[ $key ]->data === '') {
continue;
}
$subtree .= $this->subtrees[ $key ]->to_smarty_php($parser);
}
if ($subtree === '') {
continue;
}
$code .= preg_replace(
'/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
"<?php echo '\$1'; ?>\n",
$subtree
);
continue;
}
if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
$subtree = $this->subtrees[ $key ]->to_smarty_php($parser);
while ($key + 1 < $cnt && ($this->subtrees[ $key + 1 ] instanceof Smarty_Internal_ParseTree_Tag ||
$this->subtrees[ $key + 1 ]->data === '')) {
$key++;
if ($this->subtrees[ $key ]->data === '') {
continue;
}
$subtree = $parser->compiler->appendCode($subtree, $this->subtrees[ $key ]->to_smarty_php($parser));
}
if ($subtree === '') {
continue;
}
$code .= $subtree;
continue;
}
$code .= $this->subtrees[ $key ]->to_smarty_php($parser);

foreach ($this->getChunkedSubtrees() as $chunk) {
$text = '';
switch ($chunk['mode']) {
case 'textstripped':
foreach ($chunk['subtrees'] as $subtree) {
$text .= $subtree->to_smarty_php($parser);
}
$code .= preg_replace(
'/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
"<?php echo '\$1'; ?>\n",
$parser->compiler->processText($text)
);
break;
case 'text':
foreach ($chunk['subtrees'] as $subtree) {
$text .= $subtree->to_smarty_php($parser);
}
$code .= preg_replace(
'/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
"<?php echo '\$1'; ?>\n",
$text
);
break;
case 'tag':
foreach ($chunk['subtrees'] as $subtree) {
$text = $parser->compiler->appendCode($text, $subtree->to_smarty_php($parser));
}
$code .= $text;
break;
default:
foreach ($chunk['subtrees'] as $subtree) {
$text = $subtree->to_smarty_php($parser);
}
$code .= $text;

}
}
return $code;
}

private function getChunkedSubtrees() {
$chunks = [];
$currentMode = null;
$currentChunk = [];
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {

if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, ['textstripped', 'text', 'tag'])) {
continue;
}

if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text
&& $this->subtrees[ $key ]->isToBeStripped()) {
$newMode = 'textstripped';
} elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
$newMode = 'text';
} elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
$newMode = 'tag';
} else {
$newMode = 'other';
}

if ($newMode == $currentMode) {
$currentChunk[] = $this->subtrees[ $key ];
} else {
$chunks[] = [
'mode' => $currentMode,
'subtrees' => $currentChunk
];
$currentMode = $newMode;
$currentChunk = [$this->subtrees[ $key ]];
}
}
if ($currentMode && $currentChunk) {
$chunks[] = [
'mode' => $currentMode,
'subtrees' => $currentChunk
];
}
return $chunks;
}
}
29 changes: 23 additions & 6 deletions Smarty/libs/sysplugins/smarty_internal_parsetree_text.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,31 @@
*/
class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
{
/**
* Create template text buffer
*
* @param string $data text
*/
public function __construct($data)

/**
* Wether this section should be stripped on output to smarty php
* @var bool
*/
private $toBeStripped = false;

/**
* Create template text buffer
*
* @param string $data text
* @param bool $toBeStripped wether this section should be stripped on output to smarty php
*/
public function __construct($data, $toBeStripped = false)
{
$this->data = $data;
$this->toBeStripped = $toBeStripped;
}

/**
* Wether this section should be stripped on output to smarty php
* @return bool
*/
public function isToBeStripped() {
return $this->toBeStripped;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function instanceBlock(Smarty_Internal_Template $tpl, $className, $name,
return;
}
// make sure we got child block of child template of current block
while ($block->child && $block->tplIndex <= $block->child->tplIndex) {
while ($block->child && $block->child->child && $block->tplIndex <= $block->child->tplIndex) {
$block->child = $block->child->child;
}
$this->process($tpl, $block);
Expand Down
4 changes: 2 additions & 2 deletions Smarty/libs/sysplugins/smarty_internal_templatebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private function _execute($template, $cache_id, $compile_id, $parent, $function)
*
* @param string $type plugin type
* @param string $name name of template tag
* @param callback $callback PHP callback to register
* @param callable $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any
*
Expand Down Expand Up @@ -301,7 +301,7 @@ public function loadFilter($type, $name)
* @link http://www.smarty.net/docs/en/api.register.filter.tpl
*
* @param string $type filter type
* @param callback $callback
* @param callable $callback
* @param string|null $name optional filter name
*
* @return \Smarty|\Smarty_Internal_Template
Expand Down
Loading

0 comments on commit 4f3de2a

Please sign in to comment.