diff options
Diffstat (limited to 'lib/kolab_utils.php')
-rw-r--r-- | lib/kolab_utils.php | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php index 9f064e3..e2602af 100644 --- a/lib/kolab_utils.php +++ b/lib/kolab_utils.php @@ -163,17 +163,47 @@ class kolab_utils */ public static function dn2ufn($dn) { - $name = ldap_dn2ufn($dn); + return self::decode_dn(ldap_dn2ufn($dn)); + } + + /** + * Unicode-aware ldap_explode_dn() wrapper + * + * @param string $dn LDAP DN string + * + * @return array Exploded DN (uses unicode encoding) + */ + public static function explode_dn($dn) + { + $result = ldap_explode_dn($dn, 0); + + // get rid of count + unset($result['count']); + + $result = array_map(array('kolab_utils', 'decode_dn'), $result); + + return $result; + } + + /** + * Decode \XX sequences into characters + * + * @param string $str String to decode + * + * @return string Decoded string + */ + public static function decode_dn($str) + { $pos = 0; // example: "\C3\A4" => "รค" - while (preg_match('/\\\\[0-9a-fA-F]{2}/', $name, $matches, PREG_OFFSET_CAPTURE, $pos)) { + while (preg_match('/\\\\[0-9a-fA-F]{2}/', $str, $matches, PREG_OFFSET_CAPTURE, $pos)) { $char = chr(hexdec(substr($matches[0][0], 1))); $pos = $matches[0][1]; - $name = substr_replace($name, $char, $pos, 3); + $str = substr_replace($str, $char, $pos, 3); $pos += 1; } - return $name; + return $str; } } |