From 860ebb618e621e4560ea05c17f198582b727bf7f Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Wed, 28 Mar 2018 07:35:52 +0200 Subject: [PATCH] - bugfix plugins may not be loaded if {function} or {block} tags are executed in nocache mode --- libs/plugins/block.textformat.php | 15 ++++++-------- libs/plugins/function.html_checkboxes.php | 14 ++++++------- libs/plugins/function.html_image.php | 8 +++----- libs/plugins/function.html_options.php | 8 +++----- libs/plugins/function.html_radios.php | 10 ++++----- libs/plugins/function.html_select_date.php | 14 +++++-------- libs/plugins/function.html_select_time.php | 14 +++++-------- libs/plugins/modifier.escape.php | 22 ++++++++++++-------- libs/plugins/modifiercompiler.escape.php | 24 +++++++++------------- 9 files changed, 55 insertions(+), 74 deletions(-) diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index a363b07f..310a420e 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsBlock */ - /** * Smarty {textformat}{/textformat} block plugin * Type: block function @@ -20,7 +19,7 @@ * - wrap_char - string ("\n") * - indent_char - string (" ") * - wrap_boundary - boolean (true) - * + * * * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} * (Smarty online manual) @@ -32,18 +31,16 @@ * * @return string content re-formatted * @author Monte Ohrt + * @throws \SmartyException */ -function smarty_block_textformat($params, $content, $template, &$repeat) +function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat) { - static $mb_wordwrap_loaded = false; if (is_null($content)) { return; } - if (Smarty::$_MBSTRING && !$mb_wordwrap_loaded) { - if (!is_callable('smarty_modifier_mb_wordwrap')) { - require_once(SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'); - } - $mb_wordwrap_loaded = true; + if (Smarty::$_MBSTRING) { + $template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap', + 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'))); } $style = null; diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 9145d8b3..d654caba 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_checkboxes} function plugin * File: function.html_checkboxes.php @@ -37,18 +36,17 @@ * @author credits to Monte Ohrt * @version 1.0 * - * @param array $params parameters - * @param object $template template object + * @param array $params parameters + * @param Smarty_Internal_Template $template template object * * @return string * @uses smarty_function_escape_special_chars() + * @throws \SmartyException */ -function smarty_function_html_checkboxes($params, $template) +function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template) { - if (!isset($template->smarty->_cache[ '_required_sesc' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - $template->smarty->_cache[ '_required_sesc' ] = true; - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $name = 'checkbox'; $values = null; diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index fda3ff34..4fda72ee 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -36,12 +36,10 @@ * @return string * @uses smarty_function_escape_special_chars() */ -function smarty_function_html_image($params, $template) +function smarty_function_html_image($params, Smarty_Internal_Template $template) { - if (!isset($template->smarty->_cache[ '_required_sesc' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - $template->smarty->_cache[ '_required_sesc' ] = true; - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $alt = ''; $file = ''; diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index d3c2768b..b8b98649 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_options} function plugin * Type: function @@ -34,13 +33,12 @@ * * @return string * @uses smarty_function_escape_special_chars() + * @throws \SmartyException */ function smarty_function_html_options($params, Smarty_Internal_Template $template) { - if (!isset($template->smarty->_cache[ '_required_sesc' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - $template->smarty->_cache[ '_required_sesc' ] = true; - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $name = null; $values = null; diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index 8678ec7d..37feec63 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_radios} function plugin * File: function.html_radios.php @@ -42,13 +41,12 @@ * * @return string * @uses smarty_function_escape_special_chars() + * @throws \SmartyException */ -function smarty_function_html_radios($params, $template) +function smarty_function_html_radios($params, Smarty_Internal_Template $template) { - if (!isset($template->smarty->_cache[ '_required_sesc' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - $template->smarty->_cache[ '_required_sesc' ] = true; - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $name = 'radio'; $values = null; diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index d894435f..1d63800e 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_select_date} plugin * Type: function @@ -42,17 +41,12 @@ * @param \Smarty_Internal_Template $template * * @return string + * @throws \SmartyException */ function smarty_function_html_select_date($params, Smarty_Internal_Template $template) { - if (!isset($template->smarty->_cache[ '_required_sesc' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - $template->smarty->_cache[ '_required_sesc' ] = true; - } - if (!isset($template->smarty->_cache[ '_required_smt' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); - $template->smarty->_cache[ '_required_smt' ] = true; - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); // generate timestamps used for month names only static $_month_timestamps = null; static $_current_year = null; @@ -117,6 +111,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem switch ($_key) { case 'time': if (!is_array($_value) && $_value !== null) { + $template->_checkPlugins(array(array('function' => 'smarty_make_timestamp', + 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))); $time = smarty_make_timestamp($_value); } break; diff --git a/libs/plugins/function.html_select_time.php b/libs/plugins/function.html_select_time.php index 8972c426..f7c3816e 100644 --- a/libs/plugins/function.html_select_time.php +++ b/libs/plugins/function.html_select_time.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsFunction */ - /** * Smarty {html_select_time} function plugin * Type: function @@ -23,17 +22,12 @@ * * @return string * @uses smarty_make_timestamp() + * @throws \SmartyException */ function smarty_function_html_select_time($params, Smarty_Internal_Template $template) { - if (!isset($template->smarty->_cache[ '_required_sesc' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - $template->smarty->_cache[ '_required_sesc' ] = true; - } - if (!isset($template->smarty->_cache[ '_required_smt' ])) { - require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); - $template->smarty->_cache[ '_required_smt' ] = true; - } + $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars', + 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'))); $prefix = 'Time_'; $field_array = null; $field_separator = "\n"; @@ -84,6 +78,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem switch ($_key) { case 'time': if (!is_array($_value) && $_value !== null) { + $template->_checkPlugins(array(array('function' => 'smarty_make_timestamp', + 'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'))); $time = smarty_make_timestamp($_value); } break; diff --git a/libs/plugins/modifier.escape.php b/libs/plugins/modifier.escape.php index a1c4682c..1ae87a7a 100644 --- a/libs/plugins/modifier.escape.php +++ b/libs/plugins/modifier.escape.php @@ -25,7 +25,8 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) { static $_double_encode = null; - static $is_loaded1 = false; + static $is_loaded_1 = false; + static $is_loaded_2 = false; if ($_double_encode === null) { $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); } @@ -123,11 +124,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'hexentity': $return = ''; if (Smarty::$_MBSTRING) { - if (!$is_loaded1) { + if (!$is_loaded_1) { if (!is_callable('smarty_mb_to_unicode')) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); - $is_loaded1 = true; } + $is_loaded_1 = true; } $return = ''; foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { @@ -147,11 +148,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'decentity': $return = ''; if (Smarty::$_MBSTRING) { - if (!$is_loaded1) { + if (!$is_loaded_1) { if (!is_callable('smarty_mb_to_unicode')) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); } - $is_loaded1 = true; + $is_loaded_1 = true; } $return = ''; foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { @@ -179,8 +180,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'mail': if (Smarty::$_MBSTRING) { - if (!is_callable('smarty_mb_str_replace')) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); + if (!$is_loaded_2) { + if (!is_callable('smarty_mb_str_replace')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); + } + $is_loaded_2 = true; } return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', @@ -195,11 +199,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ // escape non-standard chars, such as ms document quotes $return = ''; if (Smarty::$_MBSTRING) { - if (!$is_loaded1) { + if (!$is_loaded_1) { if (!is_callable('smarty_mb_to_unicode')) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); } - $is_loaded1 = true; + $is_loaded_1 = true; } foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { if ($unicode >= 126) { diff --git a/libs/plugins/modifiercompiler.escape.php b/libs/plugins/modifiercompiler.escape.php index 62a1b8be..6a6e0163 100644 --- a/libs/plugins/modifiercompiler.escape.php +++ b/libs/plugins/modifiercompiler.escape.php @@ -5,7 +5,6 @@ * @package Smarty * @subpackage PluginsModifierCompiler */ - /** * Smarty escape modifier plugin * Type: modifier @@ -15,21 +14,18 @@ * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @author Rodney Rehm * - * @param array $params parameters - * @param $compiler + * @param array $params parameters + * @param Smarty_Internal_TemplateCompilerBase $compiler * * @return string with compiled code + * @throws \SmartyException */ -function smarty_modifiercompiler_escape($params, $compiler) +function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler) { static $_double_encode = null; static $is_loaded = false; - if (!$is_loaded) { - if (!is_callable('smarty_literal_compiler_param')) { - require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'); - } - $is_loaded = true; - } + $compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param', + 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'))); if ($_double_encode === null) { $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); } @@ -104,14 +100,14 @@ function smarty_modifiercompiler_escape($params, $compiler) // could not optimize |escape call, so fallback to regular plugin if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { - $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] = + $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; - $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] = + $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] = 'smarty_modifier_escape'; } else { - $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] = + $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; - $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] = + $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] = 'smarty_modifier_escape'; }