- bugfix plugins may not be loaded if {function} or {block} tags are executed in nocache mode

This commit is contained in:
Uwe Tews
2018-03-28 07:35:52 +02:00
parent 336c07c23f
commit 860ebb618e
9 changed files with 55 additions and 74 deletions

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsBlock * @subpackage PluginsBlock
*/ */
/** /**
* Smarty {textformat}{/textformat} block plugin * Smarty {textformat}{/textformat} block plugin
* Type: block function * Type: block function
@@ -32,18 +31,16 @@
* *
* @return string content re-formatted * @return string content re-formatted
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @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)) { if (is_null($content)) {
return; return;
} }
if (Smarty::$_MBSTRING && !$mb_wordwrap_loaded) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_modifier_mb_wordwrap')) { $template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap',
require_once(SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'); 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')));
}
$mb_wordwrap_loaded = true;
} }
$style = null; $style = null;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_checkboxes} function plugin * Smarty {html_checkboxes} function plugin
* File: function.html_checkboxes.php * File: function.html_checkboxes.php
@@ -37,18 +36,17 @@
* @author credits to Monte Ohrt <monte at ohrt dot com> * @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0 * @version 1.0
* *
* @param array $params parameters * @param array $params parameters
* @param object $template template object * @param Smarty_Internal_Template $template template object
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @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' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$name = 'checkbox'; $name = 'checkbox';
$values = null; $values = null;

View File

@@ -36,12 +36,10 @@
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @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' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$alt = ''; $alt = '';
$file = ''; $file = '';

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_options} function plugin * Smarty {html_options} function plugin
* Type: function * Type: function
@@ -34,13 +33,12 @@
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/ */
function smarty_function_html_options($params, Smarty_Internal_Template $template) function smarty_function_html_options($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$name = null; $name = null;
$values = null; $values = null;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_radios} function plugin * Smarty {html_radios} function plugin
* File: function.html_radios.php * File: function.html_radios.php
@@ -42,13 +41,12 @@
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @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' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$name = 'radio'; $name = 'radio';
$values = null; $values = null;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_select_date} plugin * Smarty {html_select_date} plugin
* Type: function * Type: function
@@ -42,17 +41,12 @@
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* *
* @return string * @return string
* @throws \SmartyException
*/ */
function smarty_function_html_select_date($params, Smarty_Internal_Template $template) function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => 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;
}
// generate timestamps used for month names only // generate timestamps used for month names only
static $_month_timestamps = null; static $_month_timestamps = null;
static $_current_year = null; static $_current_year = null;
@@ -117,6 +111,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value) && $_value !== null) { 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); $time = smarty_make_timestamp($_value);
} }
break; break;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_select_time} function plugin * Smarty {html_select_time} function plugin
* Type: function * Type: function
@@ -23,17 +22,12 @@
* *
* @return string * @return string
* @uses smarty_make_timestamp() * @uses smarty_make_timestamp()
* @throws \SmartyException
*/ */
function smarty_function_html_select_time($params, Smarty_Internal_Template $template) function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => 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;
}
$prefix = 'Time_'; $prefix = 'Time_';
$field_array = null; $field_array = null;
$field_separator = "\n"; $field_separator = "\n";
@@ -84,6 +78,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value) && $_value !== null) { 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); $time = smarty_make_timestamp($_value);
} }
break; break;

View File

@@ -25,7 +25,8 @@
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{ {
static $_double_encode = null; static $_double_encode = null;
static $is_loaded1 = false; static $is_loaded_1 = false;
static $is_loaded_2 = false;
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_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': case 'hexentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
$is_loaded1 = true;
} }
$is_loaded_1 = true;
} }
$return = ''; $return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { 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': case 'decentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
} }
$is_loaded1 = true; $is_loaded_1 = true;
} }
$return = ''; $return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { 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': case 'mail':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) { if (!$is_loaded_2) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); 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('@', return smarty_mb_str_replace(array('@',
'.'), array(' [AT] ', '.'), 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 // escape non-standard chars, such as ms document quotes
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); 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) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) { if ($unicode >= 126) {

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* Type: modifier * Type: modifier
@@ -15,21 +14,18 @@
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm * @author Rodney Rehm
* *
* @param array $params parameters * @param array $params parameters
* @param $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
* *
* @return string with compiled code * @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 $_double_encode = null;
static $is_loaded = false; static $is_loaded = false;
if (!$is_loaded) { $compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param',
if (!is_callable('smarty_literal_compiler_param')) { 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')));
require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
}
$is_loaded = true;
}
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_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 // could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { 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'; 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'; 'smarty_modifier_escape';
} else { } 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'; 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'; 'smarty_modifier_escape';
} }