- update of mb support in plugins

This commit is contained in:
Uwe.Tews
2009-08-10 17:52:26 +00:00
parent a693a00280
commit 0ba34008a7
8 changed files with 55 additions and 78 deletions

View File

@@ -1,3 +1,7 @@
08/10/2009
- update of mb support in plugins
08/09/2009 08/09/2009
- fixed problems with doublequoted strings at name attribute of {block} tag - fixed problems with doublequoted strings at name attribute of {block} tag
- bugfix at scope attribute of {append} tag - bugfix at scope attribute of {append} tag

View File

@@ -20,8 +20,7 @@
*/ */
function smarty_modifier_lower($string) function smarty_modifier_lower($string)
{ {
$smarty = Smarty::instance(); if (function_exists('mb_strtolower')) {
if ($smarty->has_mb) {
return mb_strtolower($string); return mb_strtolower($string);
} else { } else {
return strtolower($string); return strtolower($string);

View File

@@ -1,61 +1,48 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* * @package Smarty
* @package Smarty * @subpackage plugins
* @subpackage PluginsModifier */
*/
/** /**
* Smarty regex_replace modifier plugin * Smarty regex_replace modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: regex_replace<br> * Name: regex_replace<br>
* Purpose: regular expression search/replace * Purpose: regular expression search/replace
* * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php regex_replace (Smarty online manual) * regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string $ * @param string
* @param string $ |array * @param string|array
* @param string $ |array * @param string|array
* @return string * @return string
*/ */
function smarty_modifier_regex_replace($string, $search, $replace) function smarty_modifier_regex_replace($string, $search, $replace)
{ {
$smarty = Smarty::instance(); if(is_array($search)) {
foreach($search as $idx => $s)
if (is_array($search)) { $search[$idx] = _smarty_regex_replace_check($s);
foreach($search as $idx => $s) } else {
$search[$idx] = _smarty_regex_replace_check($s); $search = _smarty_regex_replace_check($search);
} else { }
$search = _smarty_regex_replace_check($search);
} return preg_replace($search, $replace, $string);
}
if ($smarty->has_mb) {
return mb_ereg_replace($search, $replace, $string); function _smarty_regex_replace_check($search)
} else { {
return preg_replace($search, $replace, $string); 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 */
function _smarty_regex_replace_check($search) $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
{ }
if ($smarty->has_mb) { return $search;
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)) { /* vim: set expandtab: */
/* 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;
}
?>

View File

@@ -38,8 +38,7 @@ function smarty_modifier_replace($string, $search, $replace)
return $haystack; return $haystack;
} }
} }
$smarty = Smarty::instance(); if (function_exists('mb_substr')) {
if ($smarty->has_mb) {
return mb_str_replace($search, $replace, $string); return mb_str_replace($search, $replace, $string);
} else { } else {
return str_replace($search, $replace, $string); return str_replace($search, $replace, $string);

View File

@@ -21,7 +21,6 @@
*/ */
function smarty_modifier_spacify($string, $spacify_char = ' ') function smarty_modifier_spacify($string, $spacify_char = ' ')
{ {
$smarty = Smarty::instance();
return implode($spacify_char, preg_split('//', $string, -1)); return implode($spacify_char, preg_split('//', $string, -1));
} }

View File

@@ -25,12 +25,7 @@
*/ */
function smarty_modifier_strip($text, $replace = ' ') 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); return preg_replace('!\s+!', $replace, $text);
}
} }
?> ?>

View File

@@ -21,13 +21,8 @@
*/ */
function smarty_modifier_strip_tags($string, $replace_with_space = true) function smarty_modifier_strip_tags($string, $replace_with_space = true)
{ {
$smarty = Smarty::instance();
if ($replace_with_space) { if ($replace_with_space) {
if ($smarty->has_mb) {
return mb_ereg_replace("<[^>]*?>", ' ', $string, 'p');
} else {
return preg_replace('!<[^>]*?>!', ' ', $string); return preg_replace('!<[^>]*?>!', ' ', $string);
}
} else { } else {
return strip_tags($string); return strip_tags($string);
} }

View File

@@ -20,8 +20,7 @@
*/ */
function smarty_modifier_upper($string) function smarty_modifier_upper($string)
{ {
$smarty = Smarty::instance(); if (function_exists('mb_strtoupper')) {
if ($smarty->has_mb) {
return mb_strtoupper($string); return mb_strtoupper($string);
} else { } else {
return strtoupper($string); return strtoupper($string);