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

trac at roundcube.net trac at roundcube.net
Fri Jun 3 14:34:48 CEST 2011


Author: alec
Date: 2011-06-03 07:34:48 -0500 (Fri, 03 Jun 2011)
New Revision: 4836

Modified:
   trunk/roundcubemail/program/include/rcmail.php
   trunk/roundcubemail/program/steps/addressbook/func.inc
   trunk/roundcubemail/program/steps/addressbook/list.inc
Log:
- Call addressbook_get hook only if build-in addressbook doesn't match wanted ID (for better performance), other improvements


Modified: trunk/roundcubemail/program/include/rcmail.php
===================================================================
--- trunk/roundcubemail/program/include/rcmail.php	2011-06-03 12:09:10 UTC (rev 4835)
+++ trunk/roundcubemail/program/include/rcmail.php	2011-06-03 12:34:48 UTC (rev 4836)
@@ -381,18 +381,12 @@
    */
   public function get_address_book($id, $writeable = false)
   {
-    $contacts = null;
+    $contacts    = null;
     $ldap_config = (array)$this->config->get('ldap_public');
-    $abook_type = strtolower($this->config->get('address_book_type'));
+    $abook_type  = strtolower($this->config->get('address_book_type'));
 
-    $plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable));
-
-    // plugin returned instance of a rcube_addressbook
-    if ($plugin['instance'] instanceof rcube_addressbook) {
-      $contacts = $plugin['instance'];
-    }
     // use existing instance
-    else if (isset($this->address_books[$id]) && is_a($this->address_books[$id], 'rcube_addressbook') && (!$writeable || !$this->address_books[$id]->readonly)) {
+    if (isset($this->address_books[$id]) && is_a($this->address_books[$id], 'rcube_addressbook') && (!$writeable || !$this->address_books[$id]->readonly)) {
       $contacts = $this->address_books[$id];
     }
     else if ($id && $ldap_config[$id]) {
@@ -401,18 +395,26 @@
     else if ($id === '0') {
       $contacts = new rcube_contacts($this->db, $this->user->ID);
     }
-    else if ($abook_type == 'ldap') {
-      // Use the first writable LDAP address book.
-      foreach ($ldap_config as $id => $prop) {
-        if (!$writeable || $prop['writable']) {
-          $contacts = new rcube_ldap($prop, $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host']));
-          break;
+    else {
+      $plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable));
+
+      // plugin returned instance of a rcube_addressbook
+      if ($plugin['instance'] instanceof rcube_addressbook) {
+        $contacts = $plugin['instance'];
+      }
+      else if ($abook_type == 'ldap') {
+        // Use the first writable LDAP address book.
+        foreach ($ldap_config as $id => $prop) {
+          if (!$writeable || $prop['writable']) {
+            $contacts = new rcube_ldap($prop, $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host']));
+            break;
+          }
         }
       }
+      else { // $id == 'sql'
+        $contacts = new rcube_contacts($this->db, $this->user->ID);
+      }
     }
-    else { // $id == 'sql'
-      $contacts = new rcube_contacts($this->db, $this->user->ID);
-    }
 
     // add to the 'books' array for shutdown function
     if (!isset($this->address_books[$id]))

Modified: trunk/roundcubemail/program/steps/addressbook/func.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/func.inc	2011-06-03 12:09:10 UTC (rev 4835)
+++ trunk/roundcubemail/program/steps/addressbook/func.inc	2011-06-03 12:34:48 UTC (rev 4836)
@@ -21,16 +21,22 @@
 
 $SEARCH_MODS_DEFAULT = array('name'=>1, 'firstname'=>1, 'surname'=>1, 'email'=>1, '*'=>1);
 
-// add list of address sources to client env
-$js_list = $RCMAIL->get_address_sources();
-
 // select source
 $source = get_input_value('_source', RCUBE_INPUT_GPC);
 
-// if source is not set use first directory
-if (empty($source))
-    $source = $js_list[key($js_list)]['id'];
+if (!$RCMAIL->action && !$OUTPUT->ajax_call) {
+    // add list of address sources to client env
+    $js_list = $RCMAIL->get_address_sources();
 
+    // if source is not set use first directory
+    if (empty($source))
+        $source = $js_list[key($js_list)]['id'];
+
+    $search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT);
+    $OUTPUT->set_env('search_mods', $search_mods);
+    $OUTPUT->set_env('address_sources', $js_list);
+}
+
 // instantiate a contacts object according to the given source
 $CONTACTS = $RCMAIL->get_address_book($source);
 
@@ -44,18 +50,17 @@
 
 if (!empty($_REQUEST['_gid']))
     $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
-
+/*
 // set message set for search result
 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
     $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
-
+*/
 // set data source env
 $OUTPUT->set_env('source', $source ? $source : '0');
 $OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
 if (!$OUTPUT->ajax_call) {
     $search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT);
     $OUTPUT->set_env('search_mods', $search_mods);
-    $OUTPUT->set_env('address_sources', $js_list);
     $OUTPUT->set_pagetitle(rcube_label('addressbook'));
 }
 

Modified: trunk/roundcubemail/program/steps/addressbook/list.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/list.inc	2011-06-03 12:09:10 UTC (rev 4835)
+++ trunk/roundcubemail/program/steps/addressbook/list.inc	2011-06-03 12:34:48 UTC (rev 4836)
@@ -19,6 +19,10 @@
 
 */
 
+// set message set for search result
+if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
+    $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
+
 // get contacts for this user
 $result = $CONTACTS->list_records(array('name'));
 

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



More information about the Svn mailing list