- 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
- fixed problems with doublequoted strings at name attribute of {block} tag
- bugfix at scope attribute of {append} tag

View File

@@ -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);

View File

@@ -1,61 +1,48 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifier
*/
/**
* Smarty regex_replace modifier plugin
*
* Type: modifier<br>
* Name: regex_replace<br>
* 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 <monte at ohrt dot com>
* @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;
}
?>
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty regex_replace modifier plugin
*
* Type: modifier<br>
* Name: regex_replace<br>
* 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 <monte at ohrt dot com>
* @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: */
?>

View File

@@ -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);

View File

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

View File

@@ -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);
}
}
?>

View File

@@ -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);
}

View File

@@ -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);