Code

Updated class ldap
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 21 Sep 2010 09:57:23 +0000 (09:57 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 21 Sep 2010 09:57:23 +0000 (09:57 +0000)
-Added emthod which allows to replace all non readable characters by the readable ones.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19784 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_baseSelector.inc
gosa-core/include/class_ldap.inc

index 8a30178d724a5b4fa24de9f321e8b4a7528f2105..84d76e3d60b8b05e2b44a5de07d369704e3297e0 100644 (file)
@@ -170,7 +170,7 @@ class baseSelector {
             onmouseout=\"   mouseIsStillOver=false;
         rtimer=Element.hide.delay(0.25,'bs_".$this->pid."')\"
 
-            value=\"".preg_replace('/"/','&quot;',$this->pathMapping[$this->base])."\">";
+            value=\"".htmlentities(LDAP::makeReadable($this->pathMapping[$this->base]),ENT_COMPAT,'utf-8')."\">";
 
 
         // Autocompleter
index ce237a6ac28a37cabbf6e06e5a75eadd28b077d1..0d22eb19ebca11d556292ff48288bdf2ad6d2b16 100644 (file)
@@ -33,6 +33,8 @@ class LDAP
     public static $characterMap = NULL;
     public static $characterMapRegFrom = NULL;
     public static $characterMapRegTo = NULL;
+    public static $readableMapRegFrom = NULL;
+    public static $readableMapRegTo = NULL;
 
     var $hascon   =false;
     var $reconnect=false;
@@ -117,6 +119,11 @@ class LDAP
         LDAP::$characterMapRegFrom = array("/\001CO/", "/\001OB/", "/\001CB/", "/\001SL/", "/\001DQ/");
         LDAP::$characterMapRegTo = array("\,", "(", ")", "/", '\"');
 
+        // Set a default mapping to make readable strings out of dns.
+        LDAP::$readableMapRegFrom = array("/\001CO/", "/\001OB/", "/\001CB/", "/\001SL/", "/\001DQ/",
+                "/\\\\,/", "/\\\\2C/", "/\(/", "/\)/", "/\//", "/\\\\22/", '/\\\\"/');
+        LDAP::$readableMapRegTo = array(",", "(", ")", "/", '"',",", ",", "(", ")", "/", '"', '"');
+
         if(LDAP::$characterMap === NULL){
             LDAP::$characterMap = detectLdapSpecialCharHandling();
 
@@ -124,10 +131,19 @@ class LDAP
             if(LDAP::$characterMap !== NULL){
                 LDAP::$characterMapRegFrom = array();
                 LDAP::$characterMapRegTo = array();
+                LDAP::$readableMapRegFrom = array();
+                LDAP::$readableMapRegTo = array();
                 foreach(LDAP::$characterMap as $from => $to){
-                    $from = LDAP::convert($from);
-                    LDAP::$characterMapRegFrom[] = "/{$from}/";
+                   
+                    // Append entry character conversion  
+                    LDAP::$characterMapRegFrom[] = "/".preg_quote(LDAP::convert($from),'/')."/";
                     LDAP::$characterMapRegTo[] = addslashes($to);
+
+                    // Append entry make readable array
+                    LDAP::$readableMapRegFrom[] = "/".preg_quote(stripslashes($to),'/')."/";
+                    LDAP::$readableMapRegTo[] = stripslashes($from);
+                    LDAP::$readableMapRegFrom[] = "/".preg_quote(LDAP::convert($to),'/')."/";
+                    LDAP::$readableMapRegTo[] = stripslashes($from);
                 }
             }else{
                 // To avoid querying a hundred times without any success, stop here.
@@ -140,6 +156,16 @@ class LDAP
     }
 
 
+    static function makeReadable($dn)
+    {
+        if(LDAP::$characterMap === NULL) LDAP::updateSpecialCharHandling();
+
+        print_a(array(LDAP::$readableMapRegFrom,LDAP::$readableMapRegTo,$dn, preg_replace(LDAP::$readableMapRegFrom,LDAP::$readableMapRegTo,$dn)));
+
+        return (preg_replace(LDAP::$readableMapRegFrom,LDAP::$readableMapRegTo,$dn));
+    }
+
+
     /* \brief   Function to fix all problematic characters inside a DN by replacing \001XX
      *           codes to their original values. See "convert" for more information. 
      *          The ',' characters are always expanded to \, (not \2C), since all tested LDAP