From c9c8b85cd1628924ff5115fa929b2ee3bfe539e3 Mon Sep 17 00:00:00 2001 From: alec Date: Wed, 24 Jun 2009 09:44:05 +0000 Subject: - Fix non-unicode characters caching in unicode database (#1484608) git-svn-id: https://svn.roundcube.net/trunk@2675 208e9e7b-5314-0410-a742-e7e81cd9613c --- roundcubemail/program/include/rcube_mdb2.php | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'roundcubemail/program/include/rcube_mdb2.php') diff --git a/roundcubemail/program/include/rcube_mdb2.php b/roundcubemail/program/include/rcube_mdb2.php index 266550127..faf653539 100644 --- a/roundcubemail/program/include/rcube_mdb2.php +++ b/roundcubemail/program/include/rcube_mdb2.php @@ -556,6 +556,54 @@ class rcube_mdb2 } + /** + * Encodes non-UTF-8 characters in string/array/object (recursive) + * + * @param mixed Data to fix + * @return mixed Properly UTF-8 encoded data + * @access public + */ + function encode($input) + { + if (is_object($input)) { + foreach (get_object_vars($input) as $idx => $value) + $input->$idx = $this->encode($value); + return $input; + } + else if (is_array($input)) { + foreach ($input as $idx => $value) + $input[$idx] = $this->encode($value); + return $input; + } + + return utf8_encode($input); + } + + + /** + * Decodes encoded UTF-8 string/object/array (recursive) + * + * @param mixed Input data + * @return mixed Decoded data + * @access public + */ + function decode($input) + { + if (is_object($input)) { + foreach (get_object_vars($input) as $idx => $value) + $input->$idx = $this->decode($value); + return $input; + } + else if (is_array($input)) { + foreach ($input as $idx => $value) + $input[$idx] = $this->decode($value); + return $input; + } + + return utf8_decode($input); + } + + /** * Adds a query result and returns a handle ID * -- cgit v1.2.3