From d645ad2ea12400304a755b5fed19130bf633cdf0 Mon Sep 17 00:00:00 2001 From: rodneyrehm Date: Sun, 18 Dec 2011 18:20:09 +0000 Subject: [PATCH] - changed internals to use Smarty::$_MBSTRING ($_CHARSET, $_DATE_FORMAT) for better unit testing --- change_log.txt | 1 + libs/Smarty.class.php | 14 ++++++++++++-- libs/plugins/block.textformat.php | 2 +- libs/plugins/modifier.capitalize.php | 10 +++++----- libs/plugins/modifier.date_format.php | 5 ++++- libs/plugins/modifier.debug_print_var.php | 12 ++++++------ libs/plugins/modifier.escape.php | 18 +++++++++--------- libs/plugins/modifier.replace.php | 2 +- libs/plugins/modifier.truncate.php | 12 ++++++------ .../modifiercompiler.count_characters.php | 4 ++-- libs/plugins/modifiercompiler.count_words.php | 2 +- libs/plugins/modifiercompiler.escape.php | 6 +++--- libs/plugins/modifiercompiler.from_charset.php | 4 ++-- libs/plugins/modifiercompiler.lower.php | 4 ++-- libs/plugins/modifiercompiler.to_charset.php | 4 ++-- libs/plugins/modifiercompiler.unescape.php | 4 ++-- libs/plugins/modifiercompiler.upper.php | 4 ++-- libs/plugins/modifiercompiler.wordwrap.php | 2 +- libs/plugins/shared.escape_special_chars.php | 2 +- libs/plugins/shared.mb_wordwrap.php | 8 ++++---- .../variablefilter.htmlspecialchars.php | 2 +- ...ternal_compile_private_print_expression.php | 2 +- 22 files changed, 69 insertions(+), 55 deletions(-) diff --git a/change_log.txt b/change_log.txt index 3f9de636..2a092f79 100644 --- a/change_log.txt +++ b/change_log.txt @@ -4,6 +4,7 @@ - added chaining to Smarty_Internal_Templatebase - changed unloadFilter() to not return a boolean in favor of chaining and API conformity - bugfix unregisterObject() raised notice when object to unregister did not exist +- changed internals to use Smarty::$_MBSTRING ($_CHARSET, $_DATE_FORMAT) for better unit testing 17.12.2011 - improvement of compiling speed by new handling of plain text blocks in the lexer/parser (issue 68) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 510fbd90..6f72b49d 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -166,7 +166,12 @@ class Smarty extends Smarty_Internal_TemplateBase { * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors() */ public static $_muted_directories = array(); - + + public static $_MBSTRING = SMARTY_MBSTRING; + public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET; + public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT; + public static $_UTF8_MODIFIER = 'u'; + /**#@+ * variables */ @@ -584,7 +589,7 @@ class Smarty extends Smarty_Internal_TemplateBase { // selfpointer needed by some other class methods $this->smarty = $this; if (is_callable('mb_internal_encoding')) { - mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET); + mb_internal_encoding(Smarty::$_CHARSET); } $this->start_time = microtime(true); // set default dirs @@ -1432,6 +1437,11 @@ class Smarty extends Smarty_Internal_TemplateBase { } } +// let PREG treat strings as ISO-8859-1 if we're not dealing with UTF-8 +if (Smarty::$_CHARSET !== 'UTF-8') { + Smarty::$_UTF8_MODIFIER = ''; +} + /** * Smarty exception class * @package Smarty diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index bdd80673..93f8a52b 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -90,7 +90,7 @@ function smarty_block_textformat($params, $content, $template, &$repeat) $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; } // wordwrap sentences - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); } else { diff --git a/libs/plugins/modifier.capitalize.php b/libs/plugins/modifier.capitalize.php index 1e199096..d264f049 100644 --- a/libs/plugins/modifier.capitalize.php +++ b/libs/plugins/modifier.capitalize.php @@ -24,23 +24,23 @@ */ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = false) { - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { if ($lc_rest) { // uppercase (including hyphenated words) - $upper_string = mb_convert_case( $string, MB_CASE_TITLE, SMARTY_RESOURCE_CHAR_SET ); + $upper_string = mb_convert_case( $string, MB_CASE_TITLE, Smarty::$_CHARSET ); } else { // uppercase word breaks - $upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!ueS", "stripslashes('\\1').mb_convert_case(stripslashes('\\2'),MB_CASE_UPPER, SMARTY_RESOURCE_CHAR_SET)", $string); + $upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!ueS", "stripslashes('\\1').mb_convert_case(stripslashes('\\2'),MB_CASE_UPPER, '" . addslashes(Smarty::$_CHARSET) . "')", $string); } // check uc_digits case if (!$uc_digits) { if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!u", $string, $matches, PREG_OFFSET_CAPTURE)) { foreach($matches[1] as $match) { - $upper_string = substr_replace($upper_string, mb_strtolower($match[0], SMARTY_RESOURCE_CHAR_SET), $match[1], strlen($match[0])); + $upper_string = substr_replace($upper_string, mb_strtolower($match[0], Smarty::$_CHARSET), $match[1], strlen($match[0])); } } } - $upper_string = preg_replace("!((^|\s)['\"])(\w)!ue", "stripslashes('\\1').mb_convert_case(stripslashes('\\3'),MB_CASE_UPPER, SMARTY_RESOURCE_CHAR_SET)", $upper_string); + $upper_string = preg_replace("!((^|\s)['\"])(\w)!ue", "stripslashes('\\1').mb_convert_case(stripslashes('\\3'),MB_CASE_UPPER, '" . addslashes(Smarty::$_CHARSET) . "')", $upper_string); return $upper_string; } diff --git a/libs/plugins/modifier.date_format.php b/libs/plugins/modifier.date_format.php index 729322b2..3cca7d39 100644 --- a/libs/plugins/modifier.date_format.php +++ b/libs/plugins/modifier.date_format.php @@ -26,8 +26,11 @@ * @return string |void * @uses smarty_make_timestamp() */ -function smarty_modifier_date_format($string, $format = SMARTY_RESOURCE_DATE_FORMAT, $default_date = '',$formatter='auto') +function smarty_modifier_date_format($string, $format=null, $default_date='', $formatter='auto') { + if ($format === null) { + $format = Smarty::$_DATE_FORMAT; + } /** * Include the {@link shared.make_timestamp.php} plugin */ diff --git a/libs/plugins/modifier.debug_print_var.php b/libs/plugins/modifier.debug_print_var.php index 747c87fd..fa44100e 100644 --- a/libs/plugins/modifier.debug_print_var.php +++ b/libs/plugins/modifier.debug_print_var.php @@ -70,9 +70,9 @@ function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) case 'string' : $results = strtr($var, $_replace); - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { - if (mb_strlen($var, SMARTY_RESOURCE_CHAR_SET) > $length) { - $results = mb_substr($var, 0, $length - 3, SMARTY_RESOURCE_CHAR_SET) . '...'; + if (Smarty::$_MBSTRING) { + if (mb_strlen($var, Smarty::$_CHARSET) > $length) { + $results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...'; } } else { if (isset($var[$length])) { @@ -86,9 +86,9 @@ function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) case 'unknown type' : default : $results = strtr((string) $var, $_replace); - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { - if (mb_strlen($results, SMARTY_RESOURCE_CHAR_SET) > $length) { - $results = mb_substr($results, 0, $length - 3, SMARTY_RESOURCE_CHAR_SET) . '...'; + if (Smarty::$_MBSTRING) { + if (mb_strlen($results, Smarty::$_CHARSET) > $length) { + $results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...'; } } else { if (strlen($results) > $length) { diff --git a/libs/plugins/modifier.escape.php b/libs/plugins/modifier.escape.php index 5e865a8f..523d0653 100644 --- a/libs/plugins/modifier.escape.php +++ b/libs/plugins/modifier.escape.php @@ -24,7 +24,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) { if (!$char_set) { - $char_set = SMARTY_RESOURCE_CHAR_SET; + $char_set = Smarty::$_CHARSET; } switch ($esc_type) { @@ -32,7 +32,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); case 'htmlall': - if (SMARTY_MBSTRING /* ^phpunit */ && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { // mb_convert_encoding ignores htmlspecialchars() $string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode); // htmlentities() won't convert everything, so use mb_convert_encoding @@ -64,10 +64,10 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'hexentity': $return = ''; - if (SMARTY_MBSTRING /* ^phpunit */ && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); $return = ''; - foreach (smarty_mb_to_unicode($string, SMARTY_RESOURCE_CHAR_SET) as $unicode) { + foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { $return .= '&#x' . strtoupper(dechex($unicode)) . ';'; } return $return; @@ -81,10 +81,10 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'decentity': $return = ''; - if (SMARTY_MBSTRING /* ^phpunit */ && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); $return = ''; - foreach (smarty_mb_to_unicode($string, SMARTY_RESOURCE_CHAR_SET) as $unicode) { + foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { $return .= '&#' . $unicode . ';'; } return $return; @@ -101,7 +101,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', ' '<\/')); case 'mail': - if (SMARTY_MBSTRING /* ^phpunit */ && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); } @@ -111,9 +111,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $ case 'nonstd': // escape non-standard chars, such as ms document quotes $return = ''; - if (SMARTY_MBSTRING /* ^phpunit */ && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); - foreach (smarty_mb_to_unicode($string, SMARTY_RESOURCE_CHAR_SET) as $unicode) { + foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { if ($unicode >= 126) { $return .= '&#' . $unicode . ';'; } else { diff --git a/libs/plugins/modifier.replace.php b/libs/plugins/modifier.replace.php index ce671b1f..4d71a6e9 100644 --- a/libs/plugins/modifier.replace.php +++ b/libs/plugins/modifier.replace.php @@ -22,7 +22,7 @@ */ function smarty_modifier_replace($string, $search, $replace) { - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); return smarty_mb_str_replace($search, $replace, $string); } diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php index 99ae5437..d1eabd19 100644 --- a/libs/plugins/modifier.truncate.php +++ b/libs/plugins/modifier.truncate.php @@ -28,16 +28,16 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo if ($length == 0) return ''; - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { - if (mb_strlen($string, SMARTY_RESOURCE_CHAR_SET) > $length) { - $length -= min($length, mb_strlen($etc, SMARTY_RESOURCE_CHAR_SET)); + if (Smarty::$_MBSTRING) { + if (mb_strlen($string, Smarty::$_CHARSET) > $length) { + $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); if (!$break_words && !$middle) { - $string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1, SMARTY_RESOURCE_CHAR_SET)); + $string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); } if (!$middle) { - return mb_substr($string, 0, $length, SMARTY_RESOURCE_CHAR_SET) . $etc; + return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; } - return mb_substr($string, 0, $length / 2, SMARTY_RESOURCE_CHAR_SET) . $etc . mb_substr($string, - $length / 2, $length, SMARTY_RESOURCE_CHAR_SET); + return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET); } return $string; } diff --git a/libs/plugins/modifiercompiler.count_characters.php b/libs/plugins/modifiercompiler.count_characters.php index ae95fda4..f7a8dd26 100644 --- a/libs/plugins/modifiercompiler.count_characters.php +++ b/libs/plugins/modifiercompiler.count_characters.php @@ -23,8 +23,8 @@ function smarty_modifiercompiler_count_characters($params, $compiler) if (!isset($params[1]) || $params[1] != 'true') { return 'preg_match_all(\'/[^\s]/u\',' . $params[0] . ', $tmp)'; } - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { - return 'mb_strlen(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET)'; + if (Smarty::$_MBSTRING) { + return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; } // no MBString fallback return 'strlen(' . $params[0] . ')'; diff --git a/libs/plugins/modifiercompiler.count_words.php b/libs/plugins/modifiercompiler.count_words.php index cd9ae5bf..ce97c658 100644 --- a/libs/plugins/modifiercompiler.count_words.php +++ b/libs/plugins/modifiercompiler.count_words.php @@ -20,7 +20,7 @@ */ function smarty_modifiercompiler_count_words($params, $compiler) { - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { // return 'preg_match_all(\'#[\w\pL]+#u\', ' . $params[0] . ', $tmp)'; // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592 return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/u\', ' . $params[0] . ', $tmp)'; diff --git a/libs/plugins/modifiercompiler.escape.php b/libs/plugins/modifiercompiler.escape.php index c536d5f4..b4cd3c88 100644 --- a/libs/plugins/modifiercompiler.escape.php +++ b/libs/plugins/modifiercompiler.escape.php @@ -27,11 +27,11 @@ function smarty_modifiercompiler_escape($params, $compiler) { try { $esc_type = smarty_literal_compiler_param($params, 1, 'html'); - $char_set = smarty_literal_compiler_param($params, 2, SMARTY_RESOURCE_CHAR_SET); + $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); $double_encode = smarty_literal_compiler_param($params, 3, true); if (!$char_set) { - $char_set = SMARTY_RESOURCE_CHAR_SET; + $char_set = Smarty::$_CHARSET; } switch ($esc_type) { @@ -42,7 +42,7 @@ function smarty_modifiercompiler_escape($params, $compiler) . var_export($double_encode, true) . ')'; case 'htmlall': - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { return 'mb_convert_encoding(htmlspecialchars(' . $params[0] .', ENT_QUOTES, ' . var_export($char_set, true) . ', ' diff --git a/libs/plugins/modifiercompiler.from_charset.php b/libs/plugins/modifiercompiler.from_charset.php index 1561fbc0..93b568a5 100644 --- a/libs/plugins/modifiercompiler.from_charset.php +++ b/libs/plugins/modifiercompiler.from_charset.php @@ -19,7 +19,7 @@ */ function smarty_modifiercompiler_from_charset($params, $compiler) { - if (!SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (!Smarty::$_MBSTRING) { // FIXME: (rodneyrehm) shouldn't this throw an error? return $params[0]; } @@ -28,7 +28,7 @@ function smarty_modifiercompiler_from_charset($params, $compiler) $params[1] = '"ISO-8859-1"'; } - return 'mb_convert_encoding(' . $params[0] . ', SMARTY_RESOURCE_CHAR_SET, ' . $params[1] . ')'; + return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')'; } ?> \ No newline at end of file diff --git a/libs/plugins/modifiercompiler.lower.php b/libs/plugins/modifiercompiler.lower.php index 17441584..1845cc1d 100644 --- a/libs/plugins/modifiercompiler.lower.php +++ b/libs/plugins/modifiercompiler.lower.php @@ -21,8 +21,8 @@ function smarty_modifiercompiler_lower($params, $compiler) { - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { - return 'mb_strtolower(' . $params[0] . ',SMARTY_RESOURCE_CHAR_SET)' ; + if (Smarty::$_MBSTRING) { + return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; } // no MBString fallback return 'strtolower(' . $params[0] . ')'; diff --git a/libs/plugins/modifiercompiler.to_charset.php b/libs/plugins/modifiercompiler.to_charset.php index e0877b78..f5cdf455 100644 --- a/libs/plugins/modifiercompiler.to_charset.php +++ b/libs/plugins/modifiercompiler.to_charset.php @@ -19,7 +19,7 @@ */ function smarty_modifiercompiler_to_charset($params, $compiler) { - if (!SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (!Smarty::$_MBSTRING) { // FIXME: (rodneyrehm) shouldn't this throw an error? return $params[0]; } @@ -28,7 +28,7 @@ function smarty_modifiercompiler_to_charset($params, $compiler) $params[1] = '"ISO-8859-1"'; } - return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', SMARTY_RESOURCE_CHAR_SET)'; + return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; } ?> \ No newline at end of file diff --git a/libs/plugins/modifiercompiler.unescape.php b/libs/plugins/modifiercompiler.unescape.php index 7e77cb49..ce0bd639 100644 --- a/libs/plugins/modifiercompiler.unescape.php +++ b/libs/plugins/modifiercompiler.unescape.php @@ -23,7 +23,7 @@ function smarty_modifiercompiler_unescape($params, $compiler) $params[1] = 'html'; } if (!isset($params[2])) { - $params[2] = "SMARTY_RESOURCE_CHAR_SET"; + $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; } else { $params[2] = "'" . $params[2] . "'"; } @@ -32,7 +32,7 @@ function smarty_modifiercompiler_unescape($params, $compiler) case 'entity': return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; case 'htmlall': - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; } return 'html_entity_decode(' . $params[0] . ', ENT_QUOTES, ' . $params[2] . ')'; diff --git a/libs/plugins/modifiercompiler.upper.php b/libs/plugins/modifiercompiler.upper.php index 739057ce..f368e37d 100644 --- a/libs/plugins/modifiercompiler.upper.php +++ b/libs/plugins/modifiercompiler.upper.php @@ -20,8 +20,8 @@ */ function smarty_modifiercompiler_upper($params, $compiler) { - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { - return 'mb_strtoupper(' . $params[0] . ',SMARTY_RESOURCE_CHAR_SET)' ; + if (Smarty::$_MBSTRING) { + return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; } // no MBString fallback return 'strtoupper(' . $params[0] . ')'; diff --git a/libs/plugins/modifiercompiler.wordwrap.php b/libs/plugins/modifiercompiler.wordwrap.php index 577135ad..f6845ad3 100644 --- a/libs/plugins/modifiercompiler.wordwrap.php +++ b/libs/plugins/modifiercompiler.wordwrap.php @@ -30,7 +30,7 @@ function smarty_modifiercompiler_wordwrap($params, $compiler) $params[3] = 'false'; } $function = 'wordwrap'; - if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + if (Smarty::$_MBSTRING) { if ($compiler->tag_nocache | $compiler->nocache) { $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; diff --git a/libs/plugins/shared.escape_special_chars.php b/libs/plugins/shared.escape_special_chars.php index c087be1f..d2609b67 100644 --- a/libs/plugins/shared.escape_special_chars.php +++ b/libs/plugins/shared.escape_special_chars.php @@ -21,7 +21,7 @@ if (version_compare(PHP_VERSION, '5.2.3', '>=')) { function smarty_function_escape_special_chars($string) { if (!is_array($string)) { - $string = htmlspecialchars($string, ENT_COMPAT, SMARTY_RESOURCE_CHAR_SET, false); + $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false); } return $string; } diff --git a/libs/plugins/shared.mb_wordwrap.php b/libs/plugins/shared.mb_wordwrap.php index 89e8fbfa..c65d63f9 100644 --- a/libs/plugins/shared.mb_wordwrap.php +++ b/libs/plugins/shared.mb_wordwrap.php @@ -28,11 +28,11 @@ if(!function_exists('smarty_mb_wordwrap')) { $_previous = false; foreach ($tokens as $_token) { - $token_length = mb_strlen($_token, SMARTY_RESOURCE_CHAR_SET); + $token_length = mb_strlen($_token, Smarty::$_CHARSET); $_tokens = array($_token); if ($token_length > $width) { // remove last space - $t = mb_substr($t, 0, -1, SMARTY_RESOURCE_CHAR_SET); + $t = mb_substr($t, 0, -1, Smarty::$_CHARSET); $_previous = false; $length = 0; @@ -45,13 +45,13 @@ if(!function_exists('smarty_mb_wordwrap')) { foreach ($_tokens as $token) { $_space = !!preg_match('!^\s$!uS', $token); - $token_length = mb_strlen($token, SMARTY_RESOURCE_CHAR_SET); + $token_length = mb_strlen($token, Smarty::$_CHARSET); $length += $token_length; if ($length > $width) { // remove space before inserted break if ($_previous && $token_length < $width) { - $t = mb_substr($t, 0, -1, SMARTY_RESOURCE_CHAR_SET); + $t = mb_substr($t, 0, -1, Smarty::$_CHARSET); } // add the break before the token diff --git a/libs/plugins/variablefilter.htmlspecialchars.php b/libs/plugins/variablefilter.htmlspecialchars.php index aeaeb600..aff711e4 100644 --- a/libs/plugins/variablefilter.htmlspecialchars.php +++ b/libs/plugins/variablefilter.htmlspecialchars.php @@ -15,7 +15,7 @@ */ function smarty_variablefilter_htmlspecialchars($source, $smarty) { - return htmlspecialchars($source, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET); + return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET); } ?> \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_compile_private_print_expression.php b/libs/sysplugins/smarty_internal_compile_private_print_expression.php index 1e9a502f..a3711954 100644 --- a/libs/sysplugins/smarty_internal_compile_private_print_expression.php +++ b/libs/sysplugins/smarty_internal_compile_private_print_expression.php @@ -83,7 +83,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C } // autoescape html if ($compiler->template->smarty->escape_html) { - $output = "htmlspecialchars({$output}, ENT_QUOTES, SMARTY_RESOURCE_CHAR_SET)"; + $output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')"; } // loop over registerd filters if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {