From 0ba34008a7e2c9c3dd46a4c3e5c6ce2bfcf4b691 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Mon, 10 Aug 2009 17:52:26 +0000 Subject: [PATCH] - update of mb support in plugins --- change_log.txt | 4 + libs/plugins/modifier.lower.php | 3 +- libs/plugins/modifier.regex_replace.php | 109 +++++++++++------------- libs/plugins/modifier.replace.php | 3 +- libs/plugins/modifier.spacify.php | 1 - libs/plugins/modifier.strip.php | 5 -- libs/plugins/modifier.strip_tags.php | 5 -- libs/plugins/modifier.upper.php | 3 +- 8 files changed, 55 insertions(+), 78 deletions(-) diff --git a/change_log.txt b/change_log.txt index d0838dde..fec61e0a 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +08/10/2009 +- update of mb support in plugins + + 08/09/2009 - fixed problems with doublequoted strings at name attribute of {block} tag - bugfix at scope attribute of {append} tag diff --git a/libs/plugins/modifier.lower.php b/libs/plugins/modifier.lower.php index df64c5fc..34a609e6 100644 --- a/libs/plugins/modifier.lower.php +++ b/libs/plugins/modifier.lower.php @@ -20,8 +20,7 @@ */ function smarty_modifier_lower($string) { - $smarty = Smarty::instance(); - if ($smarty->has_mb) { + if (function_exists('mb_strtolower')) { return mb_strtolower($string); } else { return strtolower($string); diff --git a/libs/plugins/modifier.regex_replace.php b/libs/plugins/modifier.regex_replace.php index 914602e5..39cdf0a0 100644 --- a/libs/plugins/modifier.regex_replace.php +++ b/libs/plugins/modifier.regex_replace.php @@ -1,61 +1,48 @@ - -* Name: regex_replace
-* Purpose: regular expression search/replace -* -* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php regex_replace (Smarty online manual) -* @author Monte Ohrt -* @param string $ -* @param string $ |array -* @param string $ |array -* @return string -*/ -function smarty_modifier_regex_replace($string, $search, $replace) -{ - $smarty = Smarty::instance(); - - if (is_array($search)) { - foreach($search as $idx => $s) - $search[$idx] = _smarty_regex_replace_check($s); - } else { - $search = _smarty_regex_replace_check($search); - } - - if ($smarty->has_mb) { - return mb_ereg_replace($search, $replace, $string); - } else { - return preg_replace($search, $replace, $string); - } -} - -function _smarty_regex_replace_check($search) -{ - if ($smarty->has_mb) { - if (($pos = mb_strpos($search, "\0")) !== false) - $search = mb_substr($search, 0, $pos); - if (mb_preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (mb_strpos($match[1], 'e') !== false)) { - /* remove eval-modifier from $search */ - $search = mb_substr($search, 0, - mb_strlen($match[1])) . mb_ereg_replace('![e\s]+!', '', $match[1]); - } - } else { - if (($pos = strpos($search, "\0")) !== false) - $search = substr($search, 0, $pos); - if (mb_preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { - /* remove eval-modifier from $search */ - $search = substr($search, 0, - strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); - } - } - return $search; -} - -?> + + * Name: regex_replace
+ * Purpose: regular expression search/replace + * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php + * regex_replace (Smarty online manual) + * @author Monte Ohrt + * @param string + * @param string|array + * @param string|array + * @return string + */ +function smarty_modifier_regex_replace($string, $search, $replace) +{ + if(is_array($search)) { + foreach($search as $idx => $s) + $search[$idx] = _smarty_regex_replace_check($s); + } else { + $search = _smarty_regex_replace_check($search); + } + + return preg_replace($search, $replace, $string); +} + +function _smarty_regex_replace_check($search) +{ + if (($pos = strpos($search,"\0")) !== false) + $search = substr($search,0,$pos); + if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) { + /* remove eval-modifier from $search */ + $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]); + } + return $search; +} + +/* vim: set expandtab: */ + +?> diff --git a/libs/plugins/modifier.replace.php b/libs/plugins/modifier.replace.php index 57439741..5f70979f 100644 --- a/libs/plugins/modifier.replace.php +++ b/libs/plugins/modifier.replace.php @@ -38,8 +38,7 @@ function smarty_modifier_replace($string, $search, $replace) return $haystack; } } - $smarty = Smarty::instance(); - if ($smarty->has_mb) { + if (function_exists('mb_substr')) { return mb_str_replace($search, $replace, $string); } else { return str_replace($search, $replace, $string); diff --git a/libs/plugins/modifier.spacify.php b/libs/plugins/modifier.spacify.php index 8b2d9498..d2593ec3 100644 --- a/libs/plugins/modifier.spacify.php +++ b/libs/plugins/modifier.spacify.php @@ -21,7 +21,6 @@ */ function smarty_modifier_spacify($string, $spacify_char = ' ') { - $smarty = Smarty::instance(); return implode($spacify_char, preg_split('//', $string, -1)); } diff --git a/libs/plugins/modifier.strip.php b/libs/plugins/modifier.strip.php index 1890263b..39f0f9f7 100644 --- a/libs/plugins/modifier.strip.php +++ b/libs/plugins/modifier.strip.php @@ -25,12 +25,7 @@ */ function smarty_modifier_strip($text, $replace = ' ') { - $smarty = Smarty::instance(); - if ($smarty->has_mb) { - return mb_ereg_replace("\s+", $replace, $text, 'p'); - } else { return preg_replace('!\s+!', $replace, $text); - } } ?> diff --git a/libs/plugins/modifier.strip_tags.php b/libs/plugins/modifier.strip_tags.php index 1bd406d2..6af08b2f 100644 --- a/libs/plugins/modifier.strip_tags.php +++ b/libs/plugins/modifier.strip_tags.php @@ -21,13 +21,8 @@ */ function smarty_modifier_strip_tags($string, $replace_with_space = true) { - $smarty = Smarty::instance(); if ($replace_with_space) { - if ($smarty->has_mb) { - return mb_ereg_replace("<[^>]*?>", ' ', $string, 'p'); - } else { return preg_replace('!<[^>]*?>!', ' ', $string); - } } else { return strip_tags($string); } diff --git a/libs/plugins/modifier.upper.php b/libs/plugins/modifier.upper.php index 2b5d9b0b..fefa854f 100644 --- a/libs/plugins/modifier.upper.php +++ b/libs/plugins/modifier.upper.php @@ -20,8 +20,7 @@ */ function smarty_modifier_upper($string) { - $smarty = Smarty::instance(); - if ($smarty->has_mb) { + if (function_exists('mb_strtoupper')) { return mb_strtoupper($string); } else { return strtoupper($string);