/** * 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 rcube_contacts Address book object */ public function get_address_book($id, $writeable = false) { $contacts = null; $ldap_config = (array) $this->config->get('ldap_public'); $abook_type = strtolower($this->config->get('address_book_type')); // 'sql' is the alias for '0' used by autocomplete if ($id == 'sql') { $id = '0'; } // use existing instance if (isset($this->address_books[$id]) && is_object($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]) { $contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host'])); } 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 (!$id) { $source = reset($this->get_address_sources($writeable)); if (!empty($source)) { $contacts = $this->get_address_book($source['id']); if ($contacts) { $id = $source['id']; } } } } } } } if (!$contacts) { raise_error(array('code' => 700, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Addressbook source ({$id}) not found!"), true, true); } // set configured sort order if ($sort_col = $this->config->get('addressbook_sort_col')) { $contacts->set_sort_order($sort_col); } // add to the 'books' array for shutdown function $this->address_books[$id] = $contacts; return $contacts; }
/** * 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 rcube_contacts Address book object */ public function get_address_book($id, $writeable = false) { $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)); // plugin returned instance of a rcube_addressbook if ($plugin['instance'] instanceof rcube_addressbook) { $contacts = $plugin['instance']; } else { if ($id && $ldap_config[$id]) { $contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host'])); } 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 { // $id == 'sql' $contacts = new rcube_contacts($this->db, $this->user->ID); } } } } // add to the 'books' array for shutdown function if (!in_array($contacts, $this->books)) { $this->books[] = $contacts; } return $contacts; }