diff options
Diffstat (limited to 'vendor/smarty/smarty/libs')
10 files changed, 200 insertions, 134 deletions
diff --git a/vendor/smarty/smarty/libs/Smarty.class.php b/vendor/smarty/smarty/libs/Smarty.class.php index 44b77a856..9e0ca7670 100644 --- a/vendor/smarty/smarty/libs/Smarty.class.php +++ b/vendor/smarty/smarty/libs/Smarty.class.php @@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.34-dev-7'; + const SMARTY_VERSION = '3.1.36'; /** * define variable scopes */ diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_assign.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_assign.php index 4b9984888..1f0ab9b7d 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_assign.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_assign.php @@ -83,7 +83,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase 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"; diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_foreach.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_foreach.php index 78b45ea7e..a68da5409 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_foreach.php @@ -219,8 +219,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo 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"; } @@ -296,7 +297,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase if ($restore === 2) { $output .= "{$itemVar} = {$local}saved;\n"; } - $output .= "}\n} else {\n?>"; + $output .= "}\nif ({$itemVar}->do_else) {\n?>"; return $output; } } @@ -332,9 +333,6 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase 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'); diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_registerplugin.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_registerplugin.php index f987f6da5..ed18d84bb 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_registerplugin.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_registerplugin.php @@ -48,6 +48,8 @@ class Smarty_Internal_Method_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); } diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php index 8e716bd5d..477232ef8 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_template.php @@ -85,45 +85,85 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree 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; + } } diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_text.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_text.php index b3100fa09..399e84941 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_text.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_parsetree_text.php @@ -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; } /** diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php index 4476f120f..200c11bb5 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php @@ -265,7 +265,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * * @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 * @@ -301,7 +301,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data * @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 diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php index a72f3a4ab..3cc957dec 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -621,22 +621,18 @@ abstract class Smarty_Internal_TemplateCompilerBase || strcasecmp($name, 'array') === 0 || is_callable($name) ) { $func_name = strtolower($name); - $par = implode(',', $parameter); - $parHasFuction = strpos($par, '(') !== false; + if ($func_name === 'isset') { if (count($parameter) === 0) { $this->trigger_template_error('Illegal number of parameter in "isset()"'); } - if ($parHasFuction) { - $pa = array(); - foreach ($parameter as $p) { - $pa[] = (strpos($p, '(') === false) ? ('isset(' . $p . ')') : ('(' . $p . ' !== null )'); - } - return '(' . implode(' && ', $pa) . ')'; - } else { - $isset_par = str_replace("')->value", "',null,true,false)->value", $par); - } - return $name . '(' . $isset_par . ')'; + + $pa = array(); + foreach ($parameter as $p) { + $pa[] = $this->syntaxMatchesVariable($p) ? 'isset(' . $p . ')' : '(' . $p . ' !== null )'; + } + return '(' . implode(' && ', $pa) . ')'; + } elseif (in_array( $func_name, array( @@ -653,7 +649,7 @@ abstract class Smarty_Internal_TemplateCompilerBase $this->trigger_template_error("Illegal number of parameter in '{$func_name()}'"); } if ($func_name === 'empty') { - if ($parHasFuction && version_compare(PHP_VERSION, '5.5.0', '<')) { + if (!$this->syntaxMatchesVariable($parameter[0]) && version_compare(PHP_VERSION, '5.5.0', '<')) { return '(' . $parameter[ 0 ] . ' === false )'; } else { return $func_name . '(' . @@ -671,74 +667,82 @@ abstract class Smarty_Internal_TemplateCompilerBase } } + /** + * Determines whether the passed string represents a valid (PHP) variable. + * This is important, because `isset()` only works on variables and `empty()` can only be passed + * a variable prior to php5.5 + * @param $string + * @return bool + */ + private function syntaxMatchesVariable($string) { + static $regex_pattern = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*((->)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\[.*]*\])*$/'; + return 1 === preg_match($regex_pattern, trim($string)); + } + /** - * This method is called from parser to process a text content section + * This method is called from parser to process a text content section if strip is enabled * - remove text from inheritance child templates as they may generate output - * - strip text if strip is enabled * * @param string $text * - * @return null|\Smarty_Internal_ParseTree_Text + * @return string */ public function processText($text) { - if ((string)$text != '') { - $store = array(); - $_store = 0; - if ($this->parser->strip) { - if (strpos($text, '<') !== false) { - // capture html elements not to be messed with - $_offset = 0; - if (preg_match_all( - '#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', - $text, - $matches, - PREG_OFFSET_CAPTURE | PREG_SET_ORDER - ) - ) { - foreach ($matches as $match) { - $store[] = $match[ 0 ][ 0 ]; - $_length = strlen($match[ 0 ][ 0 ]); - $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; - $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); - $_offset += $_length - strlen($replace); - $_store++; - } - } - $expressions = array(// replace multiple spaces between tags by a single space - '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', - // remove newline between tags - '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', - // remove multiple spaces between attributes (but not in attribute values!) - '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', - '#>[\040\011]+$#Ss' => '> ', - '#>[\040\011]*[\n]\s*$#Ss' => '>', - $this->stripRegEx => '', - ); - $text = preg_replace(array_keys($expressions), array_values($expressions), $text); - $_offset = 0; - if (preg_match_all( - '#@!@SMARTY:([0-9]+):SMARTY@!@#is', - $text, - $matches, - PREG_OFFSET_CAPTURE | PREG_SET_ORDER - ) - ) { - foreach ($matches as $match) { - $_length = strlen($match[ 0 ][ 0 ]); - $replace = $store[ $match[ 1 ][ 0 ] ]; - $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); - $_offset += strlen($replace) - $_length; - $_store++; - } - } - } else { - $text = preg_replace($this->stripRegEx, '', $text); - } + + if (strpos($text, '<') === false) { + return preg_replace($this->stripRegEx, '', $text); + } + + $store = array(); + $_store = 0; + + // capture html elements not to be messed with + $_offset = 0; + if (preg_match_all( + '#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', + $text, + $matches, + PREG_OFFSET_CAPTURE | PREG_SET_ORDER + ) + ) { + foreach ($matches as $match) { + $store[] = $match[ 0 ][ 0 ]; + $_length = strlen($match[ 0 ][ 0 ]); + $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; + $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); + $_offset += $_length - strlen($replace); + $_store++; + } + } + $expressions = array(// replace multiple spaces between tags by a single space + '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', + // remove newline between tags + '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', + // remove multiple spaces between attributes (but not in attribute values!) + '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', + '#>[\040\011]+$#Ss' => '> ', + '#>[\040\011]*[\n]\s*$#Ss' => '>', + $this->stripRegEx => '', + ); + $text = preg_replace(array_keys($expressions), array_values($expressions), $text); + $_offset = 0; + if (preg_match_all( + '#@!@SMARTY:([0-9]+):SMARTY@!@#is', + $text, + $matches, + PREG_OFFSET_CAPTURE | PREG_SET_ORDER + ) + ) { + foreach ($matches as $match) { + $_length = strlen($match[ 0 ][ 0 ]); + $replace = $store[ $match[ 1 ][ 0 ] ]; + $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); + $_offset += strlen($replace) - $_length; + $_store++; } - return new Smarty_Internal_ParseTree_Text($text); } - return null; + return $text; } /** diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatelexer.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatelexer.php index d29c39b56..867a31d26 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatelexer.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatelexer.php @@ -376,7 +376,7 @@ class Smarty_Internal_Templatelexer continue; } } else { - throw new Exception('Unexpected input at line' . $this->line . + throw new Exception('Unexpected input at line ' . $this->line . ': ' . $this->data[ $this->counter ]); } break; @@ -497,7 +497,7 @@ class Smarty_Internal_Templatelexer continue; } } else { - throw new Exception('Unexpected input at line' . $this->line . + throw new Exception('Unexpected input at line ' . $this->line . ': ' . $this->data[ $this->counter ]); } break; @@ -635,7 +635,7 @@ class Smarty_Internal_Templatelexer continue; } } else { - throw new Exception('Unexpected input at line' . $this->line . + throw new Exception('Unexpected input at line ' . $this->line . ': ' . $this->data[ $this->counter ]); } break; @@ -927,7 +927,7 @@ class Smarty_Internal_Templatelexer continue; } } else { - throw new Exception('Unexpected input at line' . $this->line . + throw new Exception('Unexpected input at line ' . $this->line . ': ' . $this->data[ $this->counter ]); } break; @@ -1014,7 +1014,7 @@ class Smarty_Internal_Templatelexer continue; } } else { - throw new Exception('Unexpected input at line' . $this->line . + throw new Exception('Unexpected input at line ' . $this->line . ': ' . $this->data[ $this->counter ]); } break; @@ -1092,4 +1092,4 @@ class Smarty_Internal_Templatelexer } } -
\ No newline at end of file + diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php index a26e7a147..aaeae63b7 100644 --- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php +++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php @@ -2169,8 +2169,13 @@ class Smarty_Internal_Templateparser // line 255 "../smarty/lexer/smarty_internal_templateparser.y" public function yy_r2() { - $this->current_buffer->append_subtree($this, - $this->compiler->processText($this->yystack[ $this->yyidx + 0 ]->minor)); + $text = $this->yystack[ $this->yyidx + 0 ]->minor; + + if ((string)$text == '') { + $this->current_buffer->append_subtree($this, null); + } + + $this->current_buffer->append_subtree($this, new Smarty_Internal_ParseTree_Text($text, $this->strip)); } // line 259 "../smarty/lexer/smarty_internal_templateparser.y" @@ -2252,7 +2257,7 @@ class Smarty_Internal_Templateparser -$this->compiler->getRdelLength())); if ($tag == 'strip') { $this->strip = true; - $this->_retvalue = null;; + $this->_retvalue = null; } else { if (defined($tag)) { if ($this->security) { |