summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2015-07-31 09:31:30 +0200
committerAleksander Machniak <alec@alec.pl>2015-07-31 09:31:30 +0200
commitf59ecb4f8acaee229fd668147aa396c88196a47a (patch)
tree8828955e05bdeba66497d2f1602efc2b8d44f781
parent71982ccef591529c61e257acad1578deea7436e9 (diff)
downloadwebadmin-f59ecb4f8acaee229fd668147aa396c88196a47a.tar.gz
Workaround PHP bug with turkish locales (#5082)
-rw-r--r--lib/kolab_api_controller.php7
-rw-r--r--lib/kolab_client_task.php7
-rw-r--r--lib/kolab_recipient_policy.php82
3 files changed, 45 insertions, 51 deletions
diff --git a/lib/kolab_api_controller.php b/lib/kolab_api_controller.php
index 98b1a63..0326419 100644
--- a/lib/kolab_api_controller.php
+++ b/lib/kolab_api_controller.php
@@ -498,7 +498,12 @@ class kolab_api_controller
@include INSTALL_PATH . "/locale/$lang.php";
}
- setlocale(LC_ALL, $lang . '.utf8', 'en_US.utf8');
+ setlocale(LC_ALL, $lang . '.utf8', $lang . 'UTF-8', 'en_US.utf8', 'en_US.UTF-8');
+
+ // workaround for http://bugs.php.net/bug.php?id=18556
+ if (PHP_VERSION_ID < 50500 && in_array($lang, array('tr_TR', 'ku', 'az_AZ'))) {
+ setlocale(LC_CTYPE, 'en_US.utf8', 'en_US.UTF-8');
+ }
self::$translation = $LANG;
}
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 4425303..43e5fea 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -102,7 +102,12 @@ class kolab_client_task
@include INSTALL_PATH . "/locale/$language.php";
}
- setlocale(LC_ALL, $language . '.utf8', 'en_US.utf8');
+ setlocale(LC_ALL, $language . '.utf8', $language . 'UTF-8', 'en_US.utf8', 'en_US.UTF-8');
+
+ // workaround for http://bugs.php.net/bug.php?id=18556
+ if (PHP_VERSION_ID < 50500 && in_array($language, array('tr_TR', 'ku', 'az_AZ'))) {
+ setlocale(LC_CTYPE, 'en_US.utf8', 'en_US.UTF-8');
+ }
self::$translation = $LANG;
}
diff --git a/lib/kolab_recipient_policy.php b/lib/kolab_recipient_policy.php
index 831121e..036f56a 100644
--- a/lib/kolab_recipient_policy.php
+++ b/lib/kolab_recipient_policy.php
@@ -43,28 +43,7 @@ class kolab_recipient_policy
{
//console("IN", $groupdata);
foreach ($groupdata as $key => $value) {
- if (!empty($groupdata['preferredlanguage'])) {
- $locale = $groupdata['preferredlanguage'];
- } else {
- $conf = Conf::get_instance();
- $locale = $conf->get('default_locale');
- }
-
- if (!empty($locale)) {
- setlocale(LC_ALL, $locale.'.utf8', $locale.'.UTF-8', $locale);
- }
-
- if (!is_array($groupdata[$key])) {
- $orig_value = $groupdata[$key];
-
- $result = iconv('UTF-8', 'ASCII//TRANSLIT', $groupdata[$key]);
-
- if (strpos($result, '?')) {
- $result = self::transliterate($groupdata[$key], $locale);
- }
-
- $groupdata[$key] = preg_replace('/[^a-z0-9-_]/i', '', $result);
- }
+ $groupdata[$key] = self::normalize($groupdata[$key], $groupdata['preferredlanguage']);
}
//console("OUT", $groupdata);
@@ -74,8 +53,8 @@ class kolab_recipient_policy
static function normalize_userdata($userdata)
{
$keymap = array(
- 'sn' => 'surname',
- );
+ 'sn' => 'surname',
+ );
$zero_canon = array('ou', 'cn', 'displayname', 'mailhost');
@@ -85,33 +64,10 @@ class kolab_recipient_policy
}
if (isset($keymap[$key])) {
- $_key = $keymap[$key];
- } else {
- $_key = $key;
- }
-
- if (!empty($userdata['preferredlanguage'])) {
- $locale = $userdata['preferredlanguage'];
- } else {
- $conf = Conf::get_instance();
- $locale = $conf->get('default_locale');
- }
-
- if (!empty($locale)) {
- setlocale(LC_ALL, $locale.'.utf8', $locale.'.UTF-8', $locale);
+ $key = $keymap[$key];
}
- if (!is_array($userdata[$_key])) {
- $orig_value = $userdata[$key];
-
- $result = iconv('UTF-8', 'ASCII//TRANSLIT', $userdata[$key]);
-
- if (strstr($result, '?')) {
- $result = self::transliterate($userdata[$key], $locale);
- }
-
- $userdata[$_key] = preg_replace('/[^a-z0-9-_]/i', '', $result);
- }
+ $userdata[$key] = self::normalize($userdata[$key], $userdata['preferredlanguage']);
}
return $userdata;
@@ -462,4 +418,32 @@ class kolab_recipient_policy
return $subject;
}
+
+ public static function normalize($str, $locale = null)
+ {
+ if (empty($locale)) {
+ $conf = Conf::get_instance();
+ $locale = $conf->get('default_locale');
+ }
+
+ if (!empty($locale)) {
+ $old_locale = setlocale(LC_CTYPE, $locale.'.utf8', $locale.'.UTF-8', $locale);
+ }
+
+ if (is_string($str)) {
+ $result = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
+
+ if (strpos($result, '?')) {
+ $result = self::transliterate($str, $locale);
+ }
+
+ $str = preg_replace('/[^a-z0-9-_]/i', '', $result);
+ }
+
+ if ($old_locale && $old_locale != $locale) {
+ setlocale(LC_CTYPE, $old_locale);
+ }
+
+ return $str;
+ }
}