09.06.2012

- bugfix the compiler did ignore registered compiler plugins for closing tags (Forum Topic 22094)
This commit is contained in:
uwe.tews@googlemail.com
2012-06-09 14:00:57 +00:00
parent 7133a3c85c
commit 42d2ee98dd
2 changed files with 68 additions and 41 deletions

View File

@@ -1,4 +1,7 @@
===== trunk ===== ===== trunk =====
09.06.2012
- bugfix the compiler did ignore registered compiler plugins for closing tags (Forum Topic 22094)
===== Smarty-3.1.9 ===== ===== 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)

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;
@@ -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
@@ -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)) {
@@ -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
@@ -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;
@@ -559,8 +585,7 @@ 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
@@ -601,8 +626,7 @@ 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;