alecpl
2011-06-03 b896b18f87064f523dca82c3fcaa5465ec8328ad
- Call addressbook_get hook only if build-in addressbook doesn't match wanted ID (for better performance), other improvements


3 files modified
37 ■■■■■ changed files
program/include/rcmail.php 16 ●●●●● patch | view | raw | blame | history
program/steps/addressbook/func.inc 17 ●●●●● patch | view | raw | blame | history
program/steps/addressbook/list.inc 4 ●●●● patch | view | raw | blame | history
program/include/rcmail.php
@@ -385,14 +385,8 @@
    $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));
    // 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]) {
@@ -400,6 +394,13 @@
    }
    else if ($id === '0') {
      $contacts = new rcube_contacts($this->db, $this->user->ID);
    }
    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.
@@ -413,6 +414,7 @@
    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]))
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 (!$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'));
}
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'));