From 7082a103384eb41ebcb951ab7a2e52428cb751f7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 4 Feb 2014 16:15:52 +0000 Subject: [PATCH] * API: support for mbstring.func_overload=0 (previously we required mbstring.func_overload=7 to correctly support utf-8) --- etemplate/inc/class.etemplate.inc.php | 4 ++-- phpgwapi/inc/class.egw_db.inc.php | 4 ++-- phpgwapi/inc/common_functions.inc.php | 34 +++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/etemplate/inc/class.etemplate.inc.php b/etemplate/inc/class.etemplate.inc.php index 4f44aba2ad..601dfc18b0 100644 --- a/etemplate/inc/class.etemplate.inc.php +++ b/etemplate/inc/class.etemplate.inc.php @@ -2149,9 +2149,9 @@ class etemplate extends boetemplate { self::set_validation_error($form_name,lang('Field must not be empty !!!'),''); } - if ((int) $attr['maxlength'] > 0 && strlen($value) > (int) $attr['maxlength']) + if ((int) $attr['maxlength'] > 0 && mb_strlen($value) > (int) $attr['maxlength']) { - $value = substr($value,0,(int) $attr['maxlength']); + $value = mb_substr($value,0,(int) $attr['maxlength']); } if ($attr['preg'] && !preg_match($attr['preg'],$value)) { diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index 4048a3f0eb..1af9bb743f 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -1465,9 +1465,9 @@ class egw_db } // only truncate string if length given and <= 255 // to not unnecessary truncate varchar(>255) as PostgreSQL uses text anyway and MySQL truncates itself silently (unless strict mode!) - if (!is_null($length) && $length <= 255 && strlen($value) > $length) + if (!is_null($length) && $length <= 255 && mb_strlen($value) > $length) { - $value = substr($value,0,$length); + $value = mb_substr($value, 0, $length); } // casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling // for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"! diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index 5fe6f0ee2b..a1636feb72 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -65,9 +65,39 @@ function cut_bytes(&$data,$offset,$len=null) if (is_null($len)) { - return $func_overload ? mb_substr($data,$offset,bytes($data),'ascii') : substr($data,$offset); + return $func_overload & 2 ? mb_substr($data,$offset,bytes($data),'ascii') : substr($data,$offset); + } + return $func_overload & 2 ? mb_substr($data,$offset,$len,'ascii') : substr($data,$offset,$len); +} + +if (!function_exists('mb_strlen')) +{ + /** + * Number of characters in a string + * + * @param string $str + * @return int + */ + function mb_strlen($str) + { + return strlen($str); + } +} + +if (!function_exists('mb_substr')) +{ + /** + * Return part of a string + * + * @param string $data + * @param int $offset + * @param int $len + * @return string + */ + function mb_substr(&$data, $offset, $len=null) + { + return is_null($len) ? substr($data, $offset) : substr($data, $offset, $len); } - return $func_overload ? mb_substr($data,$offset,$len,'ascii') : substr($data,$offset,$len); } /**