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: 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
- bugfix fetch() and display() with relative paths (Issue 104)
- bugfix treat "0000-00-00" as 0 in modifier.date_format (Issue 103)

View File

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

View File

@ -1,4 +1,5 @@
<?php
/**
* Smarty Internal Plugin Smarty Template Compiler Base
*
@ -23,95 +24,112 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @var mixed
*/
private $nocache_hash = null;
/**
* suppress generation of nocache code
*
* @var bool
*/
public $suppressNocacheProcessing = false;
/**
* suppress generation of merged template code
*
* @var bool
*/
public $suppressMergedTemplates = false;
/**
* compile tag objects
*
* @var array
*/
public static $_tag_objects = array();
/**
* tag stack
*
* @var array
*/
public $_tag_stack = array();
/**
* current template
*
* @var Smarty_Internal_Template
*/
public $template = null;
/**
* merged templates
*
* @var array
*/
public $merged_templates = array();
/**
* flag when compiling {block}
*
* @var bool
*/
public $inheritance = false;
/**
* plugins loaded by default plugin handler
*
* @var array
*/
public $default_handler_plugins = array();
/**
* saved preprocessed modifier list
*
* @var mixed
*/
public $default_modifier_list = null;
/**
* force compilation of complete template as nocache
* @var boolean
*/
public $forceNocache = false;
/**
* suppress Smarty header code in compiled template
* @var bool
*/
public $suppressHeader = false;
/**
* suppress template property header code in compiled template
* @var bool
*/
public $suppressTemplatePropertyHeader = false;
/**
* flag if compiled template file shall we written
* @var bool
*/
public $write_compiled_code = true;
/**
* flag if currently a template function is compiled
* @var bool
*/
public $compiles_template_function = false;
/**
* called subfuntions from template function
* @var array
*/
public $called_functions = array();
/**
* flags for used modifier plugins
* @var array
*/
public $modifier_plugins = array();
/**
* type of already compiled modifier
* @var array
@ -121,8 +139,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
/**
* Initialize compiler
*/
public function __construct()
{
public function __construct() {
$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
* @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'])) {
$template->properties['nocache_hash'] = $this->nocache_hash;
} else {
@ -213,8 +229,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param array $parameter array with compilation parameter
* @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
// assume that tag does compile into code, but creates no HTML output
$this->has_code = true;
@ -224,8 +239,8 @@ abstract class Smarty_Internal_TemplateCompilerBase {
$this->template->used_tags[] = array($tag, $args);
}
// check nocache option flag
if (in_array("'nocache'",$args) || in_array(array('nocache'=>'true'),$args)
|| in_array(array('nocache'=>'"true"'),$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)) {
$this->tag_nocache = true;
}
// 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'])) {
$methode = $parameter['object_methode'];
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);
} elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} 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
@ -280,10 +295,10 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($plugin_type == Smarty::PLUGIN_COMPILER) {
$new_args = array();
foreach ($args as $key => $mixed) {
if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed);
if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed);
} else {
$new_args[$key] = $mixed;
$new_args[$key] = $mixed;
}
}
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) {
return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag);
}
}
}
// check plugins from plugins folder
@ -313,10 +327,10 @@ abstract class Smarty_Internal_TemplateCompilerBase {
// convert arguments format for old compiler plugins
$new_args = array();
foreach ($args as $key => $mixed) {
if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed);
if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed);
} else {
$new_args[$key] = $mixed;
$new_args[$key] = $mixed;
}
}
return $plugin($new_args, $this->smarty);
@ -330,7 +344,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
throw new SmartyException("Plugin \"{$tag}\" not callable");
} else {
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);
}
}
@ -383,7 +397,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode);
} 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 ?
@ -394,6 +408,22 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
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)) {
$plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) {
@ -408,7 +438,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
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
* @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
if (isset(self::$_tag_objects[$tag])) {
// compile this tag
@ -438,10 +467,10 @@ abstract class Smarty_Internal_TemplateCompilerBase {
if ($this->smarty->loadPlugin($class_name)) {
// check if tag allowed by security
if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
// use plugin if found
self::$_tag_objects[$tag] = new $class_name;
// compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
// use plugin if found
self::$_tag_objects[$tag] = new $class_name;
// compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
}
}
// no internal compile plugin for this tag
@ -455,8 +484,7 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param string $plugin_type type of plugin
* @return string call name of function
*/
public function getPlugin($plugin_name, $plugin_type)
{
public function getPlugin($plugin_name, $plugin_type) {
$function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
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
* @return boolean true if found
*/
public function getPluginFromDefaultHandler($tag, $plugin_type)
{
public function getPluginFromDefaultHandler($tag, $plugin_type) {
$callback = null;
$script = null;
$cacheable = true;
$result = call_user_func_array(
$this->smarty->default_plugin_handler_func,
array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)
$this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)
);
if ($result) {
$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;
}
include_once $script;
} else {
} else {
$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
* @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 ($is_code && !empty($content)) {
// generate replacement code
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;
$_output = str_replace("'", "\'", $content);
$_output = str_replace('\\\\', '\\\\\\\\', $_output);
@ -601,21 +626,20 @@ abstract class Smarty_Internal_TemplateCompilerBase {
* @param string $line line-number
* @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
if (!isset($line)) {
$line = $this->lex->line;
}
$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)) {
// individual error message
$error_text .= $args;
} else {
// expected token from parser
$error_text .= ' - Unexpected "' . $this->lex->value.'"';
if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4 ) {
$error_text .= ' - Unexpected "' . $this->lex->value . '"';
if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) {
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
$exp_token = $this->parser->yyTokenName[$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 503 "smarty_internal_templateparser.y"
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 511 "smarty_internal_templateparser.y"