diff --git a/change_log.txt b/change_log.txt
index 80f19b5b..1eceade8 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,4 +1,5 @@
04/10/2009
+- check if mb string functions available otherwise fallback to normal string functions
- added global variable scope SMARTY_GLOBAL_SCOPE
- enable 'variable' filter by default
- fixed {$smarty.block.parent.foo}
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index ba7aa894..32c5f4dd 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
// config var settings
public $config_overwrite = true; //Controls whether variables with the same name overwrite each other.
public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean
- public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file.
+ public $config_read_hidden = true; //Controls whether hidden config sections/vars are read from the file.
// config vars
public $config_vars = array();
// assigned tpl vars
@@ -167,13 +167,18 @@ class Smarty extends Smarty_Internal_TemplateBase {
// start time for execution time calculation
public $start_time = 0;
// set default time zone
- public $set_timezone = true;
+ public $set_timezone = true;
+ // has multibyte string functions?
+ public $has_mb = false;
/**
* Class constructor, initializes basic smarty properties
*/
public function __construct()
{
- mb_internal_encoding($this->resource_char_set);
+ if (is_callable('mb_internal_encoding')) {
+ $this->has_mb = true;
+ mb_internal_encoding($this->resource_char_set);
+ }
if ($this->set_timezone and function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
date_default_timezone_set(date_default_timezone_get());
}
@@ -199,7 +204,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
$this->plugin_handler = new Smarty_Internal_Plugin_Handler;
$this->loadPlugin('Smarty_Internal_Run_Filter');
$this->filter_handler = new Smarty_Internal_Run_Filter;
-
if (!$this->debugging && $this->debugging_ctrl == 'URL') {
$_query_string = $this->request_use_auto_globals ? isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING']:'' : isset($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']) ? $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']:'';
if (false !== strpos($_query_string, $this->smarty_debug_id)) {
diff --git a/libs/plugins/modifier.escape.php b/libs/plugins/modifier.escape.php
index bf192459..a8ef9987 100644
--- a/libs/plugins/modifier.escape.php
+++ b/libs/plugins/modifier.escape.php
@@ -72,7 +72,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null)
case 'mail':
// safe way to display e-mail address on a web page
- return mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
+ if ($smarty->has_mb) {
+ return mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
+ } else {
+ return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
+ }
case 'nonstd':
// escape non-standard chars, such as ms document quotes
diff --git a/libs/plugins/modifier.lower.php b/libs/plugins/modifier.lower.php
index 5ae6c1fd..df64c5fc 100644
--- a/libs/plugins/modifier.lower.php
+++ b/libs/plugins/modifier.lower.php
@@ -1,26 +1,31 @@
- * Name: lower
- * Purpose: convert string to lowercase
- * @link http://smarty.php.net/manual/en/language.modifier.lower.php
- * lower (Smarty online manual)
- * @author Monte Ohrt
- * @param string
- * @return string
- */
+* Smarty lower modifier plugin
+*
+* Type: modifier
+* Name: lower
+* Purpose: convert string to lowercase
+*
+* @link http://smarty.php.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
+* @author Monte Ohrt
+* @param string $
+* @return string
+*/
function smarty_modifier_lower($string)
{
- return mb_strtolower($string);
-}
+ $smarty = Smarty::instance();
+ if ($smarty->has_mb) {
+ 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 fac34c85..c2ca0b4e 100644
--- a/libs/plugins/modifier.regex_replace.php
+++ b/libs/plugins/modifier.regex_replace.php
@@ -1,46 +1,61 @@
- * 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
- */
+* Smarty regex_replace modifier plugin
+*
+* Type: modifier
+* 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)
+ $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);
- }
+ $search = _smarty_regex_replace_check($search);
+ }
- return mb_ereg_replace($search, $replace, $string);
-}
+ if ($smarty->has_mb) {
+ return mb_ereg_replace($search, $replace, $string);
+ } else {
+ return ereg_replace($search, $replace, $string);
+ }
+}
function _smarty_regex_replace_check($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)) {
- /* remove eval-modifier from $search */
- $search = mb_substr($search, 0, -mb_strlen($match[1])) . mb_ereg_replace('![e\s]+!', '', $match[1]);
- }
+ 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])) . ereg_replace('![e\s]+!', '', $match[1]);
+ }
+ }
return $search;
-}
+}
?>
diff --git a/libs/plugins/modifier.replace.php b/libs/plugins/modifier.replace.php
index 117ccc7a..57439741 100644
--- a/libs/plugins/modifier.replace.php
+++ b/libs/plugins/modifier.replace.php
@@ -38,7 +38,12 @@ function smarty_modifier_replace($string, $search, $replace)
return $haystack;
}
}
- return mb_str_replace($search, $replace, $string);
+ $smarty = Smarty::instance();
+ if ($smarty->has_mb) {
+ 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 def5375b..391488b7 100644
--- a/libs/plugins/modifier.spacify.php
+++ b/libs/plugins/modifier.spacify.php
@@ -1,27 +1,32 @@
- * Name: spacify
- * Purpose: add spaces between characters in a string
- * @link http://smarty.php.net/manual/en/language.modifier.spacify.php
- * spacify (Smarty online manual)
- * @author Monte Ohrt
- * @param string
- * @param string
- * @return string
- */
+* Smarty spacify modifier plugin
+*
+* Type: modifier
+* Name: spacify
+* Purpose: add spaces between characters in a string
+*
+* @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual)
+* @author Monte Ohrt
+* @param string $
+* @param string $
+* @return string
+*/
function smarty_modifier_spacify($string, $spacify_char = ' ')
{
- return implode($spacify_char,
- mb_split('//', $string, -1));
-}
+ $smarty = Smarty::instance();
+ if ($smarty->has_mb) {
+ return implode($spacify_char, mb_split('//', $string, -1));
+ } else {
+ return implode($spacify_char, split('//', $string, -1));
+ }
+}
+
?>
diff --git a/libs/plugins/modifier.strip.php b/libs/plugins/modifier.strip.php
index 66ba7edc..35eb98be 100644
--- a/libs/plugins/modifier.strip.php
+++ b/libs/plugins/modifier.strip.php
@@ -1,30 +1,36 @@
- * Name: strip
- * Purpose: Replace all repeated spaces, newlines, tabs
- * with a single space or supplied replacement string.
- * Example: {$var|strip} {$var|strip:" "}
- * Date: September 25th, 2002
- * @link http://smarty.php.net/manual/en/language.modifier.strip.php
- * strip (Smarty online manual)
- * @author Monte Ohrt
- * @version 1.0
- * @param string
- * @param string
- * @return string
- */
+* Smarty strip modifier plugin
+*
+* Type: modifier
+* Name: strip
+* Purpose: Replace all repeated spaces, newlines, tabs
+* with a single space or supplied replacement string.
+* Example: {$var|strip} {$var|strip:" "}
+* Date: September 25th, 2002
+*
+* @link http://smarty.php.net/manual/en/language.modifier.strip.php strip (Smarty online manual)
+* @author Monte Ohrt
+* @version 1.0
+* @param string $
+* @param string $
+* @return string
+*/
function smarty_modifier_strip($text, $replace = ' ')
{
- return mb_ereg_replace('!\s+!', $replace, $text,'p');
-}
+ $smarty = Smarty::instance();
+ if ($smarty->has_mb) {
+ return mb_ereg_replace('!\s+!', $replace, $text, 'p');
+ } else {
+ return ereg_replace('!\s+!', $replace, $text, 'p');
+ }
+}
+
?>
diff --git a/libs/plugins/modifier.strip_tags.php b/libs/plugins/modifier.strip_tags.php
index d51f98bf..cfc0929c 100644
--- a/libs/plugins/modifier.strip_tags.php
+++ b/libs/plugins/modifier.strip_tags.php
@@ -1,29 +1,36 @@
- * Name: strip_tags
- * Purpose: strip html tags from text
- * @link http://smarty.php.net/manual/en/language.modifier.strip.tags.php
- * strip_tags (Smarty online manual)
- * @author Monte Ohrt
- * @param string
- * @param boolean
- * @return string
- */
+* Smarty strip_tags modifier plugin
+*
+* Type: modifier
+* Name: strip_tags
+* Purpose: strip html tags from text
+*
+* @link http://smarty.php.net/manual/en/language.modifier.strip.tags.php strip_tags (Smarty online manual)
+* @author Monte Ohrt
+* @param string $
+* @param boolean $
+* @return string
+*/
function smarty_modifier_strip_tags($string, $replace_with_space = true)
{
- if ($replace_with_space)
- return mb_ereg_replace('!<[^>]*?>!', ' ', $string,'p');
- else
+ $smarty = Smarty::instance();
+ if ($replace_with_space) {
+ if ($smarty->has_mb) {
+ return mb_ereg_replace('!<[^>]*?>!', ' ', $string, 'p');
+ } else {
+ return ereg_replace('!<[^>]*?>!', ' ', $string, 'p');
+ }
+ } else {
return strip_tags($string);
-}
+ }
+}
+
?>
diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php
index e7121fea..5e382a6d 100644
--- a/libs/plugins/modifier.truncate.php
+++ b/libs/plugins/modifier.truncate.php
@@ -12,29 +12,30 @@
* Type: modifier
* Name: truncate
* Purpose: Truncate a string to a certain length if necessary,
-* optionally splitting in the middle of a word, and
-* appending the $etc string or inserting $etc into the middle.
+* optionally splitting in the middle of a word, and
+* appending the $etc string or inserting $etc into the middle.
*
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual)
* @author Monte Ohrt
-* @param string $string input string
+* @param string $string input string
* @param integer $length lenght of truncated text
-* @param string $etc end string
+* @param string $etc end string
* @param boolean $break_words truncate at word boundary
* @param boolean $middle truncate in the middle of text
* @return string truncated string
*/
- function smarty_modifier_truncate($string, $length = 80, $etc = '...',
- $break_words = false, $middle = false)
- {
-
- if ($length == 0)
- return '';
+function smarty_modifier_truncate($string, $length = 80, $etc = '...',
+ $break_words = false, $middle = false)
+{
+ if ($length == 0)
+ return '';
+ $smarty = Smarty::instance();
+ if ($smarty->has_mb) {
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
- $string = mb_ereg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1),'p');
+ $string = mb_ereg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p');
}
if (!$middle) {
return mb_substr($string, 0, $length) . $etc;
@@ -44,5 +45,21 @@
} else {
return $string;
}
+ } else {
+ if (strlen($string) > $length) {
+ $length -= min($length, strlen($etc));
+ if (!$break_words && !$middle) {
+ $string = ereg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1), 'p');
+ }
+ if (!$middle) {
+ return substr($string, 0, $length) . $etc;
+ } else {
+ return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
+ }
+ } else {
+ return $string;
+ }
}
+}
+
?>
diff --git a/libs/plugins/modifier.upper.php b/libs/plugins/modifier.upper.php
index dc5fd859..2b5d9b0b 100644
--- a/libs/plugins/modifier.upper.php
+++ b/libs/plugins/modifier.upper.php
@@ -1,26 +1,31 @@
- * Name: upper
- * Purpose: convert string to uppercase
- * @link http://smarty.php.net/manual/en/language.modifier.upper.php
- * upper (Smarty online manual)
- * @author Monte Ohrt
- * @param string
- * @return string
- */
+* Smarty upper modifier plugin
+*
+* Type: modifier
+* Name: upper
+* Purpose: convert string to uppercase
+*
+* @link http://smarty.php.net/manual/en/language.modifier.upper.php upper (Smarty online manual)
+* @author Monte Ohrt
+* @param string $
+* @return string
+*/
function smarty_modifier_upper($string)
{
- return mb_strtoupper($string);
-}
+ $smarty = Smarty::instance();
+ if ($smarty->has_mb) {
+ return mb_strtoupper($string);
+ } else {
+ return strtoupper($string);
+ }
+}
?>
diff --git a/libs/sysplugins/internal.compilebase.php b/libs/sysplugins/internal.compilebase.php
index ab0e415d..4bb1e51f 100644
--- a/libs/sysplugins/internal.compilebase.php
+++ b/libs/sysplugins/internal.compilebase.php
@@ -55,8 +55,8 @@ abstract class Smarty_Internal_CompileBase
if ($this->optional_attributes != array('_any')) {
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes);
foreach ($args as $key => $dummy) {
- if (!in_array($key, $tmp_array) && $key != 0) {
- $this->compiler->trigger_template_error("unexspected \"" . $key . "\" attribute");
+ if (!in_array($key, $tmp_array) && $key !== 0) {
+ $this->compiler->trigger_template_error("unexspected \"" . $key . "\" attribute");
}
}
}