[Svn] r3302 - in trunk/roundcubemail/program: include steps/addressbook

trac at roundcube.net trac at roundcube.net
Tue Mar 2 15:35:53 CET 2010


Author: alec
Date: 2010-03-02 08:35:53 -0600 (Tue, 02 Mar 2010)
New Revision: 3302

Modified:
   trunk/roundcubemail/program/include/rcmail.php
   trunk/roundcubemail/program/steps/addressbook/func.inc
Log:
- Added function to get addressbooks list rcmail::get_address_sources() (#1486248)


Modified: trunk/roundcubemail/program/include/rcmail.php
===================================================================
--- trunk/roundcubemail/program/include/rcmail.php	2010-03-02 13:08:12 UTC (rev 3301)
+++ trunk/roundcubemail/program/include/rcmail.php	2010-03-02 14:35:53 UTC (rev 3302)
@@ -244,6 +244,7 @@
   /**
    * Return instance of the internal address book class
    *
+   * @param string  Address book identifier
    * @param boolean True if the address book needs to be writeable
    * @return object rcube_contacts Address book object
    */
@@ -274,12 +275,60 @@
         }
       }
     }
-    else {
+    else { // $id == 'sql'
       $contacts = new rcube_contacts($this->db, $this->user->ID);
     }
     
     return $contacts;
   }
+
+
+  /**
+   * Return address books list
+   *
+   * @param boolean True if the address book needs to be writeable
+   * @return array  Address books array
+   */
+  public function get_address_sources($writeable = false)
+  {
+    $abook_type = strtolower($this->config->get('address_book_type'));
+    $ldap_config = (array)$this->config->get('ldap_public');
+    $autocomplete = (array)$this->config->get('autocomplete_addressbooks');
+    $list = array();
+
+    // We are using the DB address book
+    if ($abook_type != 'ldap') {
+      $list['0'] = array(
+        'id' => 0,
+	'name' => rcube_label('personaladrbook'),
+        'readonly' => false,
+	'autocomplete' => in_array('sql', $autocomplete)
+      );
+    }
+
+    if (is_array($ldap_config)) {
+      foreach ($ldap_config as $id => $prop)
+        $list[$id] = array(
+	  'id' => $id,
+	  'name' => $prop['name'],
+	  'readonly' => !$prop['writable'],
+	  'autocomplete' => in_array('sql', $autocomplete)
+        );
+    }
+
+    $plugin = $this->plugins->exec_hook('address_sources', array('sources' => $list));
+    $list = $plugin['sources'];
+
+    if ($writeable && !empty($list)) {
+      foreach ($list as $idx => $item) {
+        if ($item['readonly']) {
+	  unset($list[$idx]);
+        }
+      }
+    }
+    
+    return $list;
+  }
   
   
   /**

Modified: trunk/roundcubemail/program/steps/addressbook/func.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/func.inc	2010-03-02 13:08:12 UTC (rev 3301)
+++ trunk/roundcubemail/program/steps/addressbook/func.inc	2010-03-02 14:35:53 UTC (rev 3302)
@@ -20,19 +20,8 @@
 */
 
 // add list of address sources to client env
-$js_list = array();
-if (strtolower($CONFIG['address_book_type']) != 'ldap') {
-  // We are using the DB address book, add it.
-  $js_list['0'] = array('id' => 0, 'name' => rcube_label('personaladrbook'), 'readonly' => false);
-}
-if (is_array($CONFIG['ldap_public'])) {
-  foreach ($CONFIG['ldap_public'] as $id => $prop)
-    $js_list[$id] = array('id' => $id, 'name' => $prop['name'], 'readonly' => !$prop['writable']);
-}
+$js_list = $RCMAIL->get_address_sources();
 
-$plugin = $RCMAIL->plugins->exec_hook('address_sources', array('sources' => $js_list));
-$js_list = $plugin['sources'];
-
 // select source
 $source = get_input_value('_source', RCUBE_INPUT_GPC);
 
@@ -40,7 +29,6 @@
 if (empty($source))
   $source = $js_list[key($js_list)]['id'];
 
-
 // instantiate a contacts object according to the given source
 $CONTACTS = $RCMAIL->get_address_book($source);
 

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list