diff options
| author | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2010-10-15 17:10:08 +0000 |
|---|---|---|
| committer | thomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2010-10-15 17:10:08 +0000 |
| commit | eb21692fc7602de5f66f72951d4677322da74350 (patch) | |
| tree | 4434056cedca32a805b558291c6472962be88054 | |
| parent | 27aac995fd8d929a0231fc8ed2d20612c48f4fb4 (diff) | |
First scaffolding for the Kolab address book including lib for general access to Kolab backend
git-svn-id: https://svn.roundcube.net/trunk@4097 208e9e7b-5314-0410-a742-e7e81cd9613c
| -rw-r--r-- | plugins/kolab_addressbook/kolab_addressbook.php | 75 | ||||
| -rw-r--r-- | plugins/kolab_addressbook/lib/rcube_kolab.php | 32 | ||||
| -rw-r--r-- | plugins/kolab_addressbook/rcube_kolab_contacts.php | 187 |
3 files changed, 294 insertions, 0 deletions
diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php new file mode 100644 index 000000000..0e29c2ebb --- /dev/null +++ b/plugins/kolab_addressbook/kolab_addressbook.php @@ -0,0 +1,75 @@ +<?php + +require_once(dirname(__FILE__) . '/rcube_kolab_contacts.php'); + +/** + * Kolab address book + * + * Sample plugin to add a new address book source with data from Kolab storage + * + * This is work-in-progress for the Roundcube+Kolab integration. + * The library part is to be moved into a separate PEAR package or plugin + * that this and other Kolab-related plugins will depend on. + * + * @author Thomas Bruederli <roundcube@gmail.com> + * + */ +class kolab_addressbook extends rcube_plugin +{ + private $abook_id = 'kolab'; + + /** + * Required startup method of a Roundcube plugin + */ + public function init() + { + $this->add_hook('addressbooks_list', array($this, 'address_sources')); + $this->add_hook('addressbook_get', array($this, 'get_address_book')); + + // use this address book for autocompletion queries + // (maybe this should be configurable by the user?) + $config = rcmail::get_instance()->config; + $sources = (array) $config->get('autocomplete_addressbooks', array('sql')); + if (!in_array($this->abook_id, $sources)) { + $sources[] = $this->abook_id; + $config->set('autocomplete_addressbooks', $sources); + } + } + + /** + * Handler for the addressbooks_list hook. + * + * This will add all instances of available Kolab-based address books + * to the list of address sources of Roundcube. + * + * @param array Hash array with hook parameters + * @return array Hash array with modified hook parameters + */ + public function address_sources($p) + { + // could be changed to a factory call + $abook = new rcube_kolab_contacts; + + // maybe here we add more than one item. + $p['sources'][$this->abook_id] = array( + 'id' => $this->abook_id, + 'name' => 'Kolab', + 'readonly' => $abook->readonly, + 'groups' => $abook->groups, + ); + return $p; + } + + /** + * + */ + public function get_address_book($p) + { + if ($p['id'] === $this->abook_id) { + $p['instance'] = new rcube_kolab_contacts; + } + + return $p; + } + +} diff --git a/plugins/kolab_addressbook/lib/rcube_kolab.php b/plugins/kolab_addressbook/lib/rcube_kolab.php new file mode 100644 index 000000000..e3588f8f5 --- /dev/null +++ b/plugins/kolab_addressbook/lib/rcube_kolab.php @@ -0,0 +1,32 @@ +<?php + +/** + * Glue class to handle access to the Kolab data using the Kolab_* classes + * from the Horde project. + * + * @author Thomas Bruederli + */ +class rcube_kolab +{ + /** + * Setup the environment needed by the Kolab_* classes to access Kolab data + */ + public static function setup() + { + $rcmail = rcmail::get_instance(); + + // if we need IMAP access through Roundcube IMAP class + // $rcmail->imap_init(); + + // get some config settings for the IMAP connection + $imap_auth_method = $rcmail->config->get('imap_auth_type', 'check'); + $imap_delimiter = isset($_SESSION['imap_delimiter']) ? $_SESSION['imap_delimiter'] : $rcmail->config->get('imap_delimiter'); + + // this is how we get the current IMAP authentication credentials: + // $_SESSION['imap_host'], $_SESSION['username'], $rcmail->decrypt($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl'] + + + } + + +} diff --git a/plugins/kolab_addressbook/rcube_kolab_contacts.php b/plugins/kolab_addressbook/rcube_kolab_contacts.php new file mode 100644 index 000000000..d209cce63 --- /dev/null +++ b/plugins/kolab_addressbook/rcube_kolab_contacts.php @@ -0,0 +1,187 @@ +<?php + +require_once(dirname(__FILE__) . '/lib/rcube_kolab.php'); + + +/** + * Backend class for a custom address book + * + * This part of the Roundcube+Kolab integration and connects the + * rcube_addressbook interface with the rcube_kolab wrapper for Kolab_Storage + * + * @author Thomas Bruederli + * @see rcube_addressbook + */ +class rcube_kolab_contacts extends rcube_addressbook +{ + public $primary_key = 'ID'; + public $readonly = true; + public $groups = true; + + private $filter; + private $result; + + + public function __construct() + { + // setup Kolab backend + rcube_kolab::setup(); + + // $this->share = Kolab_Storage::getShare(); + + $this->ready = true; + } + + + /** + * Save a search string for future listings + * + * @param mixed Search params to use in listing method, obtained by get_search_set() + */ + public function set_search_set($filter) + { + $this->filter = $filter; + } + + + /** + * Getter for saved search properties + * + * @return mixed Search properties used by this class + */ + public function get_search_set() + { + return $this->filter; + } + + + /** + * Reset saved results and search parameters + */ + public function reset() + { + $this->result = null; + $this->filter = null; + } + + + /** + * List all active contact groups of this source + * + * @return array Indexed list of contact groups, each a hash array + */ + function list_groups($search = null) + { + return array( + #array('ID' => 'testgroup1', 'name' => "Testgroup"), + #array('ID' => 'testgroup2', 'name' => "Sample Group"), + ); + } + + /** + * List the current set of contact records + * + * @param array List of cols to show + * @param int Only return this number of records, use negative values for tail + * @return array Indexed list of contact records, each a hash array + */ + public function list_records($cols=null, $subset=0) + { + $this->result = $this->count(); + + // Just return a sample contact record for now + $this->result->add(array('ID' => '111', 'name' => "Kolab Contact", 'firstname' => "Kolab", 'surname' => "Contact", 'email' => "example@kolab.org")); + + return $this->result; + } + + + /** + * Search records + * + * @param array List of fields to search in + * @param string Search value + * @param boolean True if results are requested, False if count only + * @return Indexed list of contact records and 'count' value + */ + public function search($fields, $value, $strict=false, $select=true) + { + // no search implemented, just list all records + return $this->list_records(); + } + + + /** + * Count number of available contacts in database + * + * @return rcube_result_set Result set with values for 'count' and 'first' + */ + public function count() + { + return new rcube_result_set(1, ($this->list_page-1) * $this->page_size); + } + + + /** + * Return the last result set + * + * @return rcube_result_set Current result set or NULL if nothing selected yet + */ + public function get_result() + { + return $this->result; + } + + /** + * Get a specific contact record + * + * @param mixed record identifier(s) + * @param boolean True to return record as associative array, otherwise a result set is returned + * @return mixed Result object with all record fields or False if not found + */ + public function get_record($id, $assoc=false) + { + $this->list_records(); + $first = $this->result->first(); + $sql_arr = $first['ID'] == $id ? $first : null; + + return $assoc && $sql_arr ? $sql_arr : $this->result; + } + + + /** + * Close connection to source + * Called on script shutdown + */ + function close() + { + + } + + + function create_group($name) + { + return false; + } + + function delete_group($gid) + { + return false; + } + + function rename_group($gid, $newname) + { + return $newname; + } + + function add_to_group($group_id, $ids) + { + return false; + } + + function remove_from_group($group_id, $ids) + { + return false; + } + +} |
