1
0

bugfix release Smarty 3.1.10

This commit is contained in:
Ian
2012-06-09 18:24:23 +02:00
parent f6ad1903b7
commit dbc992f07e
5 changed files with 75 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
Smarty 3.1.9 Smarty 3.1.10
Author: Monte Ohrt <monte at ohrt dot com > Author: Monte Ohrt <monte at ohrt dot com >
Author: Uwe Tews Author: Uwe Tews

View File

@@ -1,4 +1,9 @@
===== Smarty-3.1.9 ===== ===== Smarty-3.1.10 =====
09.06.2012
- bugfix the compiler did ignore registered compiler plugins for closing tags (Forum Topic 22094)
- bugfix the patch for Topic 21856 did break multiline tags (Forum Topic 22124)
===== Smarty-3.1.9 =====
07.06.2012 07.06.2012
- bugfix fetch() and display() with relative paths (Issue 104) - bugfix fetch() and display() with relative paths (Issue 104)
- bugfix treat "0000-00-00" as 0 in modifier.date_format (Issue 103) - bugfix treat "0000-00-00" as 0 in modifier.date_format (Issue 103)

View File

@@ -28,7 +28,7 @@
* @author Uwe Tews * @author Uwe Tews
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
* @version 3.1.9 * @version 3.1.10
*/ */
/** /**
@@ -113,7 +113,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = 'Smarty-3.1.9'; const SMARTY_VERSION = 'Smarty-3.1.10';
/** /**
* define variable scopes * define variable scopes

View File

@@ -1,4 +1,5 @@
<?php <?php
/** /**
* Smarty Internal Plugin Smarty Template Compiler Base * Smarty Internal Plugin Smarty Template Compiler Base
* *
@@ -23,95 +24,112 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @var mixed * @var mixed
*/ */
private $nocache_hash = null; private $nocache_hash = null;
/** /**
* suppress generation of nocache code * suppress generation of nocache code
* *
* @var bool * @var bool
*/ */
public $suppressNocacheProcessing = false; public $suppressNocacheProcessing = false;
/** /**
* suppress generation of merged template code * suppress generation of merged template code
* *
* @var bool * @var bool
*/ */
public $suppressMergedTemplates = false; public $suppressMergedTemplates = false;
/** /**
* compile tag objects * compile tag objects
* *
* @var array * @var array
*/ */
public static $_tag_objects = array(); public static $_tag_objects = array();
/** /**
* tag stack * tag stack
* *
* @var array * @var array
*/ */
public $_tag_stack = array(); public $_tag_stack = array();
/** /**
* current template * current template
* *
* @var Smarty_Internal_Template * @var Smarty_Internal_Template
*/ */
public $template = null; public $template = null;
/** /**
* merged templates * merged templates
* *
* @var array * @var array
*/ */
public $merged_templates = array(); public $merged_templates = array();
/** /**
* flag when compiling {block} * flag when compiling {block}
* *
* @var bool * @var bool
*/ */
public $inheritance = false; public $inheritance = false;
/** /**
* plugins loaded by default plugin handler * plugins loaded by default plugin handler
* *
* @var array * @var array
*/ */
public $default_handler_plugins = array(); public $default_handler_plugins = array();
/** /**
* saved preprocessed modifier list * saved preprocessed modifier list
* *
* @var mixed * @var mixed
*/ */
public $default_modifier_list = null; public $default_modifier_list = null;
/** /**
* force compilation of complete template as nocache * force compilation of complete template as nocache
* @var boolean * @var boolean
*/ */
public $forceNocache = false; public $forceNocache = false;
/** /**
* suppress Smarty header code in compiled template * suppress Smarty header code in compiled template
* @var bool * @var bool
*/ */
public $suppressHeader = false; public $suppressHeader = false;
/** /**
* suppress template property header code in compiled template * suppress template property header code in compiled template
* @var bool * @var bool
*/ */
public $suppressTemplatePropertyHeader = false; public $suppressTemplatePropertyHeader = false;
/** /**
* flag if compiled template file shall we written * flag if compiled template file shall we written
* @var bool * @var bool
*/ */
public $write_compiled_code = true; public $write_compiled_code = true;
/** /**
* flag if currently a template function is compiled * flag if currently a template function is compiled
* @var bool * @var bool
*/ */
public $compiles_template_function = false; public $compiles_template_function = false;
/** /**
* called subfuntions from template function * called subfuntions from template function
* @var array * @var array
*/ */
public $called_functions = array(); public $called_functions = array();
/** /**
* flags for used modifier plugins * flags for used modifier plugins
* @var array * @var array
*/ */
public $modifier_plugins = array(); public $modifier_plugins = array();
/** /**
* type of already compiled modifier * type of already compiled modifier
* @var array * @var array
@@ -121,8 +139,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
/** /**
* Initialize compiler * Initialize compiler
*/ */
public function __construct() public function __construct() {
{
$this->nocache_hash = str_replace('.', '-', uniqid(rand(), true)); $this->nocache_hash = str_replace('.', '-', uniqid(rand(), true));
} }
@@ -132,8 +149,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param Smarty_Internal_Template $template template object to compile * @param Smarty_Internal_Template $template template object to compile
* @return bool true if compiling succeeded, false if it failed * @return bool true if compiling succeeded, false if it failed
*/ */
public function compileTemplate(Smarty_Internal_Template $template) public function compileTemplate(Smarty_Internal_Template $template) {
{
if (empty($template->properties['nocache_hash'])) { if (empty($template->properties['nocache_hash'])) {
$template->properties['nocache_hash'] = $this->nocache_hash; $template->properties['nocache_hash'] = $this->nocache_hash;
} else { } else {
@@ -213,8 +229,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* @return string compiled code * @return string compiled code
*/ */
public function compileTag($tag, $args, $parameter = array()) public function compileTag($tag, $args, $parameter = array()) {
{
// $args contains the attributes parsed and compiled by the lexer/parser // $args contains the attributes parsed and compiled by the lexer/parser
// assume that tag does compile into code, but creates no HTML output // assume that tag does compile into code, but creates no HTML output
$this->has_code = true; $this->has_code = true;
@@ -224,8 +239,8 @@ abstract class Smarty_Internal_TemplateCompilerBase {
$this->template->used_tags[] = array($tag, $args); $this->template->used_tags[] = array($tag, $args);
} }
// check nocache option flag // check nocache option flag
if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args) if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args)
|| in_array(array('nocache'=>'"true"'),$args) || in_array(array('nocache'=>"'true'"),$args)) { || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)) {
$this->tag_nocache = true; $this->tag_nocache = true;
} }
// compile the smarty tag (required compile classes to compile the tag are autoloaded) // compile the smarty tag (required compile classes to compile the tag are autoloaded)
@@ -265,12 +280,12 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) { if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) {
$methode = $parameter['object_methode']; $methode = $parameter['object_methode'];
if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) && if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) { (empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode); return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode);
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) { } elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} else { } else {
return $this->trigger_template_error ('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno); return $this->trigger_template_error('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno);
} }
} }
// check if tag is registered // check if tag is registered
@@ -280,10 +295,10 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($plugin_type == Smarty::PLUGIN_COMPILER) { if ($plugin_type == Smarty::PLUGIN_COMPILER) {
$new_args = array(); $new_args = array();
foreach ($args as $key => $mixed) { foreach ($args as $key => $mixed) {
if (is_array($mixed)) { if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed); $new_args = array_merge($new_args, $mixed);
} else { } else {
$new_args[$key] = $mixed; $new_args[$key] = $mixed;
} }
} }
if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) { if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) {
@@ -302,7 +317,6 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) {
return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag);
} }
} }
} }
// check plugins from plugins folder // check plugins from plugins folder
@@ -313,10 +327,10 @@ abstract class Smarty_Internal_TemplateCompilerBase {
// convert arguments format for old compiler plugins // convert arguments format for old compiler plugins
$new_args = array(); $new_args = array();
foreach ($args as $key => $mixed) { foreach ($args as $key => $mixed) {
if (is_array($mixed)) { if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed); $new_args = array_merge($new_args, $mixed);
} else { } else {
$new_args[$key] = $mixed; $new_args[$key] = $mixed;
} }
} }
return $plugin($new_args, $this->smarty); return $plugin($new_args, $this->smarty);
@@ -330,7 +344,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
throw new SmartyException("Plugin \"{$tag}\" not callable"); throw new SmartyException("Plugin \"{$tag}\" not callable");
} else { } else {
if ($function = $this->getPlugin($tag, $plugin_type)) { if ($function = $this->getPlugin($tag, $plugin_type)) {
if(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function); return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
} }
} }
@@ -383,7 +397,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) { if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} else { } else {
return $this->trigger_template_error ('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno); return $this->trigger_template_error('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
} }
} }
// registered block tag ? // registered block tag ?
@@ -394,6 +408,22 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
} }
// registered compiler plugin ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) {
// if compiler function plugin call it now
$args = array();
if (!$this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][1]) {
$this->tag_nocache = true;
}
$function = $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0];
if (!is_array($function)) {
return $function($args, $this);
} else if (is_object($function[0])) {
return $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0][0]->$function[1]($args, $this);
} else {
return call_user_func_array($function, array($args, $this));
}
}
if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
$plugin = 'smarty_compiler_' . $tag; $plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) { if (is_callable($plugin)) {
@@ -408,7 +438,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
throw new SmartyException("Plugin \"{$tag}\" not callable"); throw new SmartyException("Plugin \"{$tag}\" not callable");
} }
} }
$this->trigger_template_error ("unknown tag \"" . $tag . "\"", $this->lex->taglineno); $this->trigger_template_error("unknown tag \"" . $tag . "\"", $this->lex->taglineno);
} }
} }
@@ -426,8 +456,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param mixed $param3 optional parameter * @param mixed $param3 optional parameter
* @return string compiled code * @return string compiled code
*/ */
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) {
{
// re-use object if already exists // re-use object if already exists
if (isset(self::$_tag_objects[$tag])) { if (isset(self::$_tag_objects[$tag])) {
// compile this tag // compile this tag
@@ -438,10 +467,10 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($this->smarty->loadPlugin($class_name)) { if ($this->smarty->loadPlugin($class_name)) {
// check if tag allowed by security // check if tag allowed by security
if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
// use plugin if found // use plugin if found
self::$_tag_objects[$tag] = new $class_name; self::$_tag_objects[$tag] = new $class_name;
// compile this tag // compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
} }
} }
// no internal compile plugin for this tag // no internal compile plugin for this tag
@@ -455,8 +484,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param string $plugin_type type of plugin * @param string $plugin_type type of plugin
* @return string call name of function * @return string call name of function
*/ */
public function getPlugin($plugin_name, $plugin_type) public function getPlugin($plugin_name, $plugin_type) {
{
$function = null; $function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
@@ -510,14 +538,12 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param string $plugin_type type of plugin * @param string $plugin_type type of plugin
* @return boolean true if found * @return boolean true if found
*/ */
public function getPluginFromDefaultHandler($tag, $plugin_type) public function getPluginFromDefaultHandler($tag, $plugin_type) {
{
$callback = null; $callback = null;
$script = null; $script = null;
$cacheable = true; $cacheable = true;
$result = call_user_func_array( $result = call_user_func_array(
$this->smarty->default_plugin_handler_func, $this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)
array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)
); );
if ($result) { if ($result) {
$this->tag_nocache = $this->tag_nocache || !$cacheable; $this->tag_nocache = $this->tag_nocache || !$cacheable;
@@ -531,7 +557,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
$this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback;
} }
include_once $script; include_once $script;
} else { } else {
$this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found"); $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found");
} }
} }
@@ -559,13 +585,12 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param boolean $is_code true if content is compiled code * @param boolean $is_code true if content is compiled code
* @return string content * @return string content
*/ */
public function processNocacheCode($content, $is_code) public function processNocacheCode($content, $is_code) {
{
// If the template is not evaluated and we have a nocache section and or a nocache tag // If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) { if ($is_code && !empty($content)) {
// generate replacement code // generate replacement code
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing &&
($this->nocache || $this->tag_nocache || $this->forceNocache == 2)) { ($this->nocache || $this->tag_nocache || $this->forceNocache == 2)) {
$this->template->has_nocache_code = true; $this->template->has_nocache_code = true;
$_output = str_replace("'", "\'", $content); $_output = str_replace("'", "\'", $content);
$_output = str_replace('\\\\', '\\\\\\\\', $_output); $_output = str_replace('\\\\', '\\\\\\\\', $_output);
@@ -601,21 +626,20 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param string $line line-number * @param string $line line-number
* @throws SmartyCompilerException when an unexpected token is found * @throws SmartyCompilerException when an unexpected token is found
*/ */
public function trigger_template_error($args = null, $line = null) public function trigger_template_error($args = null, $line = null) {
{
// get template source line which has error // get template source line which has error
if (!isset($line)) { if (!isset($line)) {
$line = $this->lex->line; $line = $this->lex->line;
} }
$match = preg_split("/\n/", $this->lex->data); $match = preg_split("/\n/", $this->lex->data);
$error_text = 'Syntax Error in template "' . $this->template->source->filepath . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!',' ',$match[$line-1]))) . '" '; $error_text = 'Syntax Error in template "' . $this->template->source->filepath . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]))) . '" ';
if (isset($args)) { if (isset($args)) {
// individual error message // individual error message
$error_text .= $args; $error_text .= $args;
} else { } else {
// expected token from parser // expected token from parser
$error_text .= ' - Unexpected "' . $this->lex->value.'"'; $error_text .= ' - Unexpected "' . $this->lex->value . '"';
if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4 ) { if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) {
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
$exp_token = $this->parser->yyTokenName[$token]; $exp_token = $this->parser->yyTokenName[$token];
if (isset($this->lex->smarty_token_names[$exp_token])) { if (isset($this->lex->smarty_token_names[$exp_token])) {

View File

@@ -2544,7 +2544,7 @@ static public $yy_action = array(
#line 2540 "smarty_internal_templateparser.php" #line 2540 "smarty_internal_templateparser.php"
#line 503 "smarty_internal_templateparser.y" #line 503 "smarty_internal_templateparser.y"
function yy_r66(){ function yy_r66(){
$this->_retvalue = array(trim($this->yystack[$this->yyidx + -1]->minor,' =')=>$this->yystack[$this->yyidx + 0]->minor); $this->_retvalue = array(trim($this->yystack[$this->yyidx + -1]->minor," =\n\r")=>$this->yystack[$this->yyidx + 0]->minor);
} }
#line 2545 "smarty_internal_templateparser.php" #line 2545 "smarty_internal_templateparser.php"
#line 511 "smarty_internal_templateparser.y" #line 511 "smarty_internal_templateparser.y"