summaryrefslogtreecommitdiffstats
path: root/lib/kolab_utils.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-07-03 19:03:56 +0200
committerAleksander Machniak <alec@alec.pl>2013-07-03 19:03:56 +0200
commit6d502c35f04970d1379a99c21d37f69723be67fc (patch)
treedcc183aa9acf8c41560db0b4a72c05bb35a46da6 /lib/kolab_utils.php
parent5ce6595a60ad67281da58cf7c06fecb4b158d199 (diff)
downloadwebadmin-6d502c35f04970d1379a99c21d37f69723be67fc.tar.gz
Fix ldap_dn2ufn() output, so unicode characters are handled properly.
This fixes issue where unicode characters in OU selector were "encoded"
Diffstat (limited to 'lib/kolab_utils.php')
-rw-r--r--lib/kolab_utils.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php
index 2c4c2a0..9f064e3 100644
--- a/lib/kolab_utils.php
+++ b/lib/kolab_utils.php
@@ -154,4 +154,26 @@ class kolab_utils
return is_array($arr) && count(array_filter(array_keys($arr), 'is_string')) == count($arr);
}
+ /**
+ * Unicode-aware ldap_dn2ufn() wrapper
+ *
+ * @param string $dn LDAP DN string
+ *
+ * @return string Human-readable string
+ */
+ public static function dn2ufn($dn)
+ {
+ $name = ldap_dn2ufn($dn);
+ $pos = 0;
+
+ // example: "\C3\A4" => "รค"
+ while (preg_match('/\\\\[0-9a-fA-F]{2}/', $name, $matches, PREG_OFFSET_CAPTURE, $pos)) {
+ $char = chr(hexdec(substr($matches[0][0], 1)));
+ $pos = $matches[0][1];
+ $name = substr_replace($name, $char, $pos, 3);
+ $pos += 1;
+ }
+
+ return $name;
+ }
}