diff --git a/change_log.txt b/change_log.txt index e1d2b17a..1b890355 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +09.06.2012 +- bugfix the compiler did ignore registered compiler plugins for closing tags (Forum Topic 22094) + ===== Smarty-3.1.9 ===== 07.06.2012 - bugfix fetch() and display() with relative paths (Issue 104) diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 4cd31183..85906239 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -1,4 +1,5 @@ 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])) {