mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 02:14:26 +02:00
- performance store flag for already required shared plugin functions in static variable or
Smarty's $_cache to improve performance when plugins are often called
51e0d5cd40 (commitcomment-22280086)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
===== 3.1.32 - dev ===
|
||||
21.5.2017
|
||||
- performance store flag for already required shared plugin functions in static variable or
|
||||
Smarty's $_cache to improve performance when plugins are often called
|
||||
https://github.com/smarty-php/smarty/commit/51e0d5cd405d764a4ea257d1bac1fb1205f74528#commitcomment-22280086
|
||||
- bugfix remove special treatment of classes implementing ArrayAccess in {foreach}
|
||||
https://github.com/smarty-php/smarty/issues/332
|
||||
- bugfix remove deleted files by clear_cache() and clear_compiled_template() from
|
||||
|
@@ -108,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.32-dev-7';
|
||||
const SMARTY_VERSION = '3.1.32-dev-8';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -38,8 +38,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
|
||||
if (is_null($content)) {
|
||||
return;
|
||||
}
|
||||
if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_smw' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
|
||||
$template->smarty->_cache[ '_required_smw' ] = true;
|
||||
}
|
||||
|
||||
$style = null;
|
||||
@@ -87,8 +88,10 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
|
||||
}
|
||||
// convert mult. spaces & special chars to single space
|
||||
$_paragraph =
|
||||
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
|
||||
array(' ', ''), $_paragraph);
|
||||
preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER,
|
||||
'!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
|
||||
array(' ',
|
||||
''), $_paragraph);
|
||||
// indent first line
|
||||
if ($indent_first > 0) {
|
||||
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
|
||||
|
@@ -45,8 +45,9 @@
|
||||
*/
|
||||
function smarty_function_html_checkboxes($params, $template)
|
||||
{
|
||||
if (!is_callable('smarty_function_escape_special_chars')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_sesc' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$template->smarty->_cache[ '_required_sesc' ] = true;
|
||||
}
|
||||
|
||||
$name = 'checkbox';
|
||||
|
@@ -38,8 +38,9 @@
|
||||
*/
|
||||
function smarty_function_html_image($params, $template)
|
||||
{
|
||||
if (!is_callable('smarty_function_escape_special_chars')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_sesc' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$template->smarty->_cache[ '_required_sesc' ] = true;
|
||||
}
|
||||
|
||||
$alt = '';
|
||||
|
@@ -30,13 +30,16 @@
|
||||
*
|
||||
* @param array $params parameters
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_options($params)
|
||||
function smarty_function_html_options($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
if (!is_callable('smarty_function_escape_special_chars')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_sesc' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$template->smarty->_cache[ '_required_sesc' ] = true;
|
||||
}
|
||||
|
||||
$name = null;
|
||||
|
@@ -45,8 +45,9 @@
|
||||
*/
|
||||
function smarty_function_html_radios($params, $template)
|
||||
{
|
||||
if (!is_callable('smarty_function_escape_special_chars')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_sesc' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$template->smarty->_cache[ '_required_sesc' ] = true;
|
||||
}
|
||||
|
||||
$name = 'radio';
|
||||
|
@@ -39,15 +39,19 @@
|
||||
*
|
||||
* @param array $params parameters
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_html_select_date($params)
|
||||
function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
if (!is_callable('smarty_function_escape_special_chars')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_sesc' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$template->smarty->_cache[ '_required_sesc' ] = true;
|
||||
}
|
||||
if (!is_callable('smarty_make_timestamp')) {
|
||||
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
|
||||
static $_month_timestamps = null;
|
||||
@@ -177,7 +181,9 @@ function smarty_function_html_select_date($params)
|
||||
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
|
||||
if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
|
||||
// $_REQUEST[$field_array] given
|
||||
foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) {
|
||||
foreach (array('Y' => 'Year',
|
||||
'm' => 'Month',
|
||||
'd' => 'Day') as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName =
|
||||
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
|
||||
@@ -185,7 +191,9 @@ function smarty_function_html_select_date($params)
|
||||
}
|
||||
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
|
||||
// $_REQUEST given
|
||||
foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) {
|
||||
foreach (array('Y' => 'Year',
|
||||
'm' => 'Month',
|
||||
'd' => 'Day') as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
|
||||
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
|
||||
@@ -206,7 +214,8 @@ function smarty_function_html_select_date($params)
|
||||
|
||||
// make syntax "+N" or "-N" work with $start_year and $end_year
|
||||
// Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr
|
||||
foreach (array('start', 'end') as $key) {
|
||||
foreach (array('start',
|
||||
'end') as $key) {
|
||||
$key .= '_year';
|
||||
$t = $$key;
|
||||
if ($t === null) {
|
||||
|
@@ -19,16 +19,20 @@
|
||||
*
|
||||
* @param array $params parameters
|
||||
*
|
||||
* @param \Smarty_Internal_Template $template
|
||||
*
|
||||
* @return string
|
||||
* @uses smarty_make_timestamp()
|
||||
*/
|
||||
function smarty_function_html_select_time($params)
|
||||
function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
|
||||
{
|
||||
if (!is_callable('smarty_function_escape_special_chars')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_sesc' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
$template->smarty->_cache[ '_required_sesc' ] = true;
|
||||
}
|
||||
if (!is_callable('smarty_make_timestamp')) {
|
||||
if (!isset($template->smarty->_cache[ '_required_smt' ])) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
||||
$template->smarty->_cache[ '_required_smt' ] = true;
|
||||
}
|
||||
$prefix = "Time_";
|
||||
$field_array = null;
|
||||
@@ -148,7 +152,9 @@ function smarty_function_html_select_time($params)
|
||||
if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
|
||||
if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
|
||||
// $_REQUEST[$field_array] given
|
||||
foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
|
||||
foreach (array('H' => 'Hour',
|
||||
'i' => 'Minute',
|
||||
's' => 'Second') as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName =
|
||||
isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
|
||||
@@ -161,7 +167,9 @@ function smarty_function_html_select_time($params)
|
||||
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
|
||||
} elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
|
||||
// $_REQUEST given
|
||||
foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
|
||||
foreach (array('H' => 'Hour',
|
||||
'i' => 'Minute',
|
||||
's' => 'Second') as $_elementKey => $_elementName) {
|
||||
$_variableName = '_' . strtolower($_elementName);
|
||||
$$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
|
||||
$params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
|
||||
@@ -350,7 +358,10 @@ function smarty_function_html_select_time($params)
|
||||
}
|
||||
|
||||
$_html = '';
|
||||
foreach (array('_html_hours', '_html_minutes', '_html_seconds', '_html_meridian') as $k) {
|
||||
foreach (array('_html_hours',
|
||||
'_html_minutes',
|
||||
'_html_seconds',
|
||||
'_html_meridian') as $k) {
|
||||
if (isset($$k)) {
|
||||
if ($_html) {
|
||||
$_html .= $field_separator;
|
||||
|
@@ -35,9 +35,13 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
|
||||
/**
|
||||
* require_once the {@link shared.make_timestamp.php} plugin
|
||||
*/
|
||||
static $is_loaded = false;
|
||||
if (!$is_loaded) {
|
||||
if (!is_callable('smarty_make_timestamp')) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
||||
}
|
||||
$is_loaded = true;
|
||||
}
|
||||
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
|
||||
$timestamp = smarty_make_timestamp($string);
|
||||
} elseif ($default_date != '') {
|
||||
@@ -47,8 +51,20 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
|
||||
}
|
||||
if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
|
||||
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');
|
||||
$_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) {
|
||||
$_win_from[] = '%e';
|
||||
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
|
||||
|
@@ -25,6 +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_loaded2 = false;
|
||||
if ($_double_encode === null) {
|
||||
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
|
||||
}
|
||||
@@ -46,7 +48,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
// php <5.2.3 - prevent double encoding
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'), array('&',
|
||||
';'), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -67,7 +71,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string =
|
||||
str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
str_replace(array('%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'), array('&',
|
||||
';'), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -86,7 +92,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
} else {
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlentities($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%',
|
||||
'%%%SMARTY_END%%%'), array('&',
|
||||
';'), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -116,8 +124,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
case 'hexentity':
|
||||
$return = '';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (!$is_loaded1) {
|
||||
if (!is_callable('smarty_mb_to_unicode')) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
|
||||
$is_loaded1 = true;
|
||||
}
|
||||
}
|
||||
$return = '';
|
||||
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
|
||||
@@ -137,9 +148,12 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
case 'decentity':
|
||||
$return = '';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (!$is_loaded1) {
|
||||
if (!is_callable('smarty_mb_to_unicode')) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
|
||||
}
|
||||
$is_loaded1 = true;
|
||||
}
|
||||
$return = '';
|
||||
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
|
||||
$return .= '&#' . $unicode . ';';
|
||||
@@ -157,7 +171,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
|
||||
case 'javascript':
|
||||
// escape quotes and backslashes, newlines, etc.
|
||||
return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n',
|
||||
return strtr($string, array('\\' => '\\\\',
|
||||
"'" => "\\'",
|
||||
'"' => '\\"',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
'</' => '<\/'));
|
||||
|
||||
case 'mail':
|
||||
@@ -165,18 +183,25 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
||||
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);
|
||||
return smarty_mb_str_replace(array('@',
|
||||
'.'), array(' [AT] ',
|
||||
' [DOT] '), $string);
|
||||
}
|
||||
// no MBString fallback
|
||||
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
|
||||
return str_replace(array('@',
|
||||
'.'), array(' [AT] ',
|
||||
' [DOT] '), $string);
|
||||
|
||||
case 'nonstd':
|
||||
// escape non-standard chars, such as ms document quotes
|
||||
$return = '';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (!$is_loaded1) {
|
||||
if (!is_callable('smarty_mb_to_unicode')) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
|
||||
}
|
||||
$is_loaded1 = true;
|
||||
}
|
||||
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
|
||||
if ($unicode >= 126) {
|
||||
$return .= '&#' . $unicode . ';';
|
||||
|
@@ -24,9 +24,13 @@
|
||||
*/
|
||||
function smarty_modifier_replace($string, $search, $replace)
|
||||
{
|
||||
static $is_loaded = false;
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (!$is_loaded) {
|
||||
if (!is_callable('smarty_mb_str_replace')) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
|
||||
}
|
||||
$is_loaded = true;
|
||||
}
|
||||
return smarty_mb_str_replace($search, $replace, $string);
|
||||
}
|
||||
|
@@ -23,9 +23,13 @@
|
||||
function smarty_modifiercompiler_escape($params, $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;
|
||||
}
|
||||
if ($_double_encode === null) {
|
||||
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
|
||||
}
|
||||
|
Reference in New Issue
Block a user