diff --git a/change_log.txt b/change_log.txt index dbdbeb92..390eb471 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== 3.1.31-dev ===== (xx.xx.xx) + 01.09.2016 + - performance require_once should be called only once for shared plugins https://github.com/smarty-php/smarty/issues/280 + 26.08.2016 - bugfix change of 23.08.2016 failed on linux when use_include_path = true diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index c08eb747..ad1eb955 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.31-dev/7'; + const SMARTY_VERSION = '3.1.31-dev/8'; /** * define variable scopes diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index e9f5fe2d..e2c5e3de 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -38,6 +38,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat) if (is_null($content)) { return; } + if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); + } $style = null; $indent = 0; @@ -92,7 +95,6 @@ function smarty_block_textformat($params, $content, $template, &$repeat) } // wordwrap sentences if (Smarty::$_MBSTRING) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); } else { $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index 33f2efe1..04ce4573 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -45,7 +45,9 @@ */ function smarty_function_html_checkboxes($params, $template) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(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 854af61b..6da8fc54 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -38,7 +38,9 @@ */ function smarty_function_html_image($params, $template) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(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 20e66771..bc8f36e0 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -35,7 +35,9 @@ */ function smarty_function_html_options($params) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(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 53b342de..6ef84328 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -45,7 +45,9 @@ */ function smarty_function_html_radios($params, $template) { - require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(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 8191700d..3a48da0b 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -6,15 +6,6 @@ * @subpackage PluginsFunction */ -/** - * @ignore - */ -require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); -/** - * @ignore - */ -require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); - /** * Smarty {html_select_date} plugin * Type: function
@@ -52,6 +43,12 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); */ function smarty_function_html_select_date($params) { + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + } + if (!is_callable('smarty_make_timestamp')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); + } // generate timestamps used for month names only static $_month_timestamps = null; static $_current_year = null; diff --git a/libs/plugins/function.html_select_time.php b/libs/plugins/function.html_select_time.php index 4a3639bc..89f0406f 100644 --- a/libs/plugins/function.html_select_time.php +++ b/libs/plugins/function.html_select_time.php @@ -6,15 +6,6 @@ * @subpackage PluginsFunction */ -/** - * @ignore - */ -require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); -/** - * @ignore - */ -require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); - /** * Smarty {html_select_time} function plugin * Type: function
@@ -33,6 +24,12 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); */ function smarty_function_html_select_time($params) { + if (!is_callable('smarty_function_escape_special_chars')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + } + if (!is_callable('smarty_make_timestamp')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); + } $prefix = "Time_"; $field_array = null; $field_separator = "\n"; diff --git a/libs/plugins/modifier.date_format.php b/libs/plugins/modifier.date_format.php index ba716c47..a9b2997c 100644 --- a/libs/plugins/modifier.date_format.php +++ b/libs/plugins/modifier.date_format.php @@ -32,10 +32,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = '' if ($format === null) { $format = Smarty::$_DATE_FORMAT; } - /** - * require_once the {@link shared.make_timestamp.php} plugin - */ - require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') { $timestamp = smarty_make_timestamp($string); } elseif ($default_date != '') { @@ -44,7 +40,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = '' return; } if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) { - if (DIRECTORY_SEPARATOR == '\\') { + if (Smarty::$_IS_WINDOWS) { $_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T'); $_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S'); if (strpos($format, '%e') !== false) { diff --git a/libs/plugins/modifier.escape.php b/libs/plugins/modifier.escape.php index b9842aaf..9c247b93 100644 --- a/libs/plugins/modifier.escape.php +++ b/libs/plugins/modifier.escape.php @@ -116,7 +116,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'hexentity': $return = ''; if (Smarty::$_MBSTRING) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); + if (!is_callable('smarty_mb_to_unicode')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); + } $return = ''; foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { $return .= '&#x' . strtoupper(dechex($unicode)) . ';'; @@ -135,7 +137,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'decentity': $return = ''; if (Smarty::$_MBSTRING) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); + if (!is_callable('smarty_mb_to_unicode')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); + } $return = ''; foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { $return .= '&#' . $unicode . ';'; @@ -158,8 +162,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'mail': if (Smarty::$_MBSTRING) { - 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'); + } return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); } // no MBString fallback @@ -169,7 +174,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ // escape non-standard chars, such as ms document quotes $return = ''; if (Smarty::$_MBSTRING) { - require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); + if (!is_callable('smarty_mb_to_unicode')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); + } foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { if ($unicode >= 126) { $return .= '&#' . $unicode . ';'; diff --git a/libs/plugins/modifier.replace.php b/libs/plugins/modifier.replace.php index aa5e8570..9dca259d 100644 --- a/libs/plugins/modifier.replace.php +++ b/libs/plugins/modifier.replace.php @@ -25,8 +25,9 @@ function smarty_modifier_replace($string, $search, $replace) { if (Smarty::$_MBSTRING) { - 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'); + } return smarty_mb_str_replace($search, $replace, $string); } diff --git a/libs/plugins/modifiercompiler.escape.php b/libs/plugins/modifiercompiler.escape.php index 48161066..11565c2d 100644 --- a/libs/plugins/modifiercompiler.escape.php +++ b/libs/plugins/modifiercompiler.escape.php @@ -6,11 +6,6 @@ * @subpackage PluginsModifierCompiler */ -/** - * @ignore - */ -require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'); - /** * Smarty escape modifier plugin * Type: modifier
@@ -28,6 +23,9 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'); function smarty_modifiercompiler_escape($params, $compiler) { static $_double_encode = null; + if (!is_callable('smarty_literal_compiler_param')) { + require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'); + } if ($_double_encode === null) { $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); }