Changeset e44e5cc in github


Ignore:
Timestamp:
May 8, 2012 6:12:13 AM (13 months ago)
Author:
Aleksander Machniak <alec@…>
Branches:
release-0.8
Children:
60d9c79
Parents:
89fc59d
git-author:
thomascube <thomas@…> (05/02/12 16:56:29)
git-committer:
Aleksander Machniak <alec@…> (05/08/12 06:12:13)
Message:
  • Allow to configure the number of values allowed for each LDAP attribute
  • Support for serialized LDAP address values (usually delimited with a $)

Conflicts:

config/main.inc.php.dist

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • config/main.inc.php.dist

    r463ec6b re44e5cc  
    581581  'required_fields' => array('cn', 'sn', 'mail'), 
    582582  'search_fields'   => array('mail', 'cn'),  // fields to search in 
    583   // Map of contact sub-objects (attribute name => objectClass(es)), e.g. 'c' => 'country' 
    584   'sub_fields' => array(), 
    585583  // mapping of contact fields to directory attributes 
     584  //   for every attribute one can specify the number of values (limit) allowed. 
     585  //   default is 1, a wildcard * means unlimited 
    586586  'fieldmap' => array( 
    587     // Roundcube  => LDAP 
     587    // Roundcube  => LDAP:limit 
    588588    'name'        => 'cn', 
    589589    'surname'     => 'sn', 
    590590    'firstname'   => 'givenName', 
    591591    'title'       => 'title', 
    592     'email'       => 'mail', 
     592    'email'       => 'mail:*', 
    593593    'phone:home'  => 'homePhone', 
    594594    'phone:work'  => 'telephoneNumber', 
     
    610610//    'assistant'    => 'secretary', 
    611611  ), 
     612  // Map of contact sub-objects (attribute name => objectClass(es)), e.g. 'c' => 'country' 
     613  'sub_fields' => array(), 
    612614  'sort'          => 'cn',    // The field to sort the listing by. 
    613615  'scope'         => 'sub',   // search mode: sub|base|list 
  • program/include/rcube_ldap.php

    r9336ba2 re44e5cc  
    104104 
    105105        // use fieldmap to advertise supported coltypes to the application 
    106         foreach ($this->fieldmap as $col => $lf) { 
    107             list($col, $type) = explode(':', $col); 
     106        foreach ($this->fieldmap as $colv => $lfv) { 
     107            list($col, $type) = explode(':', $colv); 
     108            list($lf, $limit, $delim) = explode(':', $lfv); 
     109 
     110            if ($limit == '*') $limit = null; 
     111            else               $limit = max(1, intval($limit)); 
     112 
    108113            if (!is_array($this->coltypes[$col])) { 
    109114                $subtypes = $type ? array($type) : null; 
    110                 $this->coltypes[$col] = array('limit' => 1, 'subtypes' => $subtypes); 
     115                $this->coltypes[$col] = array('limit' => $limit, 'subtypes' => $subtypes); 
    111116            } 
    112117            elseif ($type) { 
    113118                $this->coltypes[$col]['subtypes'][] = $type; 
    114                 $this->coltypes[$col]['limit']++; 
    115             } 
     119                $this->coltypes[$col]['limit'] += $limit; 
     120            } 
     121 
     122            if ($delim) 
     123               $this->coltypes[$col]['serialized'][$type] = $delim; 
     124 
    116125            if ($type && !$this->fieldmap[$col]) 
    117                 $this->fieldmap[$col] = $lf; 
     126               $this->fieldmap[$col] = $lf; 
     127 
     128            $this->fieldmap[$colv] = $lf; 
    118129        } 
    119130 
    120131        // support for composite address 
    121132        if ($this->fieldmap['street'] && $this->fieldmap['locality']) { 
    122             $this->coltypes['address'] = array('limit' => max(1, $this->coltypes['locality']['limit']), 'subtypes' => $this->coltypes['locality']['subtypes'], 'childs' => array()); 
     133            $this->coltypes['address'] = array( 
     134               'limit'    => max(1, $this->coltypes['locality']['limit'] + $this->coltypes['address']['limit']), 
     135               'subtypes' => array_merge((array)$this->coltypes['address']['subtypes'], $this->coltypes['locality']['subtypes']), 
     136               'childs' => array(), 
     137               ) + (array)$this->coltypes['address']; 
     138 
    123139            foreach (array('street','locality','zipcode','region','country') as $childcol) { 
    124140                if ($this->fieldmap[$childcol]) { 
     
    11831199            } // end if 
    11841200        } // end foreach 
    1185 /* 
    1186         console($old_data); 
    1187         console($ldap_data); 
    1188         console('----'); 
    1189         console($newdata); 
    1190         console($replacedata); 
    1191         console($deletedata); 
    1192         console('----'); 
    1193         console($subdata); 
    1194         console($subnewdata); 
    1195         console($subdeldata); 
    1196 */ 
     1201 
     1202        // console($old_data, $ldap_data, '----', $newdata, $replacedata, $deletedata, '----', $subdata, $subnewdata, $subdeldata); 
     1203 
    11971204        $dn = self::dn_decode($id); 
    11981205 
     
    14821489                else if (in_array($col, array('street','zipcode','locality','country','region'))) 
    14831490                    $out['address'.($subtype?':':'').$subtype][$i][$col] = $value; 
     1491                else if ($col == 'address' && strpos($value, '$') !== false)  // address data is represented as string separated with $ 
     1492                    list($out[$rf][$i]['street'], $out[$rf][$i]['locality'], $out[$rf][$i]['zipcode'], $out[$rf][$i]['country']) = explode('$', $value); 
    14841493                else if ($rec[$lf]['count'] > 1) 
    14851494                    $out[$rf][] = $value; 
     
    15241533                } 
    15251534            } 
     1535 
     1536            // if addresses are to be saved as serialized string, do so 
     1537            if (is_array($colprop['serialized'])) { 
     1538               foreach ($colprop['serialized'] as $subtype => $delim) { 
     1539                  $key = $col.':'.$subtype; 
     1540                  foreach ((array)$save_cols[$key] as $i => $val) 
     1541                     $save_cols[$key][$i] = join($delim, array($val['street'], $val['locality'], $val['zipcode'], $val['country'])); 
     1542               } 
     1543            } 
    15261544        } 
    15271545 
     
    15441562     * Returns unified attribute name (resolving aliases) 
    15451563     */ 
    1546     private static function _attr_name($name) 
     1564    private static function _attr_name($namev) 
    15471565    { 
    15481566        // list of known attribute aliases 
    1549         $aliases = array( 
     1567        static $aliases = array( 
    15501568            'gn' => 'givenname', 
    15511569            'rfc822mailbox' => 'email', 
     
    15541572            'pkcs9email' => 'email', 
    15551573        ); 
    1556         return isset($aliases[$name]) ? $aliases[$name] : $name; 
     1574 
     1575        list($name, $limit) = explode(':', $namev, 2); 
     1576        $suffix = $limit ? ':'.$limit : ''; 
     1577 
     1578        return (isset($aliases[$name]) ? $aliases[$name] : $name) . $suffix; 
    15571579    } 
    15581580 
Note: See TracChangeset for help on using the changeset viewer.