diff options
author | alecpl <alec@alec.pl> | 2011-06-03 12:34:48 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2011-06-03 12:34:48 +0000 |
commit | b896b18f87064f523dca82c3fcaa5465ec8328ad (patch) | |
tree | 4608edfbf9029a2bf26fa604fef4688f0104f1a2 | |
parent | a5be870d6c7ca8913e0e3accaf6d4cf188a3c3cd (diff) |
- Call addressbook_get hook only if build-in addressbook doesn't match wanted ID (for better performance), other improvements
-rw-r--r-- | program/include/rcmail.php | 38 | ||||
-rw-r--r-- | program/steps/addressbook/func.inc | 23 | ||||
-rw-r--r-- | program/steps/addressbook/list.inc | 4 |
3 files changed, 38 insertions, 27 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php index e93d546d6..4fc1262b3 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -381,18 +381,12 @@ class rcmail */ 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')); - - $plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable)); + $abook_type = strtolower($this->config->get('address_book_type')); - // 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,17 +395,25 @@ class rcmail 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 diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index df86fced2..62fde971c 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -21,15 +21,21 @@ $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 @@ else 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')); } diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc index 0eb4b806a..864ad939b 100644 --- a/program/steps/addressbook/list.inc +++ b/program/steps/addressbook/list.inc @@ -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')); |