Changeset 3302 in subversion


Ignore:
Timestamp:
Mar 2, 2010 9:35:53 AM (3 years ago)
Author:
alec
Message:
  • Added function to get addressbooks list rcmail::get_address_sources() (#1486248)
Location:
trunk/roundcubemail/program
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcmail.php

    r3296 r3302  
    245245   * Return instance of the internal address book class 
    246246   * 
     247   * @param string  Address book identifier 
    247248   * @param boolean True if the address book needs to be writeable 
    248249   * @return object rcube_contacts Address book object 
     
    275276      } 
    276277    } 
    277     else { 
     278    else { // $id == 'sql' 
    278279      $contacts = new rcube_contacts($this->db, $this->user->ID); 
    279280    } 
    280281     
    281282    return $contacts; 
     283  } 
     284 
     285 
     286  /** 
     287   * Return address books list 
     288   * 
     289   * @param boolean True if the address book needs to be writeable 
     290   * @return array  Address books array 
     291   */ 
     292  public function get_address_sources($writeable = false) 
     293  { 
     294    $abook_type = strtolower($this->config->get('address_book_type')); 
     295    $ldap_config = (array)$this->config->get('ldap_public'); 
     296    $autocomplete = (array)$this->config->get('autocomplete_addressbooks'); 
     297    $list = array(); 
     298 
     299    // We are using the DB address book 
     300    if ($abook_type != 'ldap') { 
     301      $list['0'] = array( 
     302        'id' => 0, 
     303        'name' => rcube_label('personaladrbook'), 
     304        'readonly' => false, 
     305        'autocomplete' => in_array('sql', $autocomplete) 
     306      ); 
     307    } 
     308 
     309    if (is_array($ldap_config)) { 
     310      foreach ($ldap_config as $id => $prop) 
     311        $list[$id] = array( 
     312          'id' => $id, 
     313          'name' => $prop['name'], 
     314          'readonly' => !$prop['writable'], 
     315          'autocomplete' => in_array('sql', $autocomplete) 
     316        ); 
     317    } 
     318 
     319    $plugin = $this->plugins->exec_hook('address_sources', array('sources' => $list)); 
     320    $list = $plugin['sources']; 
     321 
     322    if ($writeable && !empty($list)) { 
     323      foreach ($list as $idx => $item) { 
     324        if ($item['readonly']) { 
     325          unset($list[$idx]); 
     326        } 
     327      } 
     328    } 
     329     
     330    return $list; 
    282331  } 
    283332   
  • trunk/roundcubemail/program/steps/addressbook/func.inc

    r2894 r3302  
    2121 
    2222// add list of address sources to client env 
    23 $js_list = array(); 
    24 if (strtolower($CONFIG['address_book_type']) != 'ldap') { 
    25   // We are using the DB address book, add it. 
    26   $js_list['0'] = array('id' => 0, 'name' => rcube_label('personaladrbook'), 'readonly' => false); 
    27 } 
    28 if (is_array($CONFIG['ldap_public'])) { 
    29   foreach ($CONFIG['ldap_public'] as $id => $prop) 
    30     $js_list[$id] = array('id' => $id, 'name' => $prop['name'], 'readonly' => !$prop['writable']); 
    31 } 
    32  
    33 $plugin = $RCMAIL->plugins->exec_hook('address_sources', array('sources' => $js_list)); 
    34 $js_list = $plugin['sources']; 
     23$js_list = $RCMAIL->get_address_sources(); 
    3524 
    3625// select source 
     
    4029if (empty($source)) 
    4130  $source = $js_list[key($js_list)]['id']; 
    42  
    4331 
    4432// instantiate a contacts object according to the given source 
Note: See TracChangeset for help on using the changeset viewer.