[Svn] r4097 - in trunk/plugins: . kolab_addressbook kolab_addressbook/lib

trac at roundcube.net trac at roundcube.net
Fri Oct 15 19:10:09 CEST 2010


Author: thomasb
Date: 2010-10-15 12:10:08 -0500 (Fri, 15 Oct 2010)
New Revision: 4097

Added:
   trunk/plugins/kolab_addressbook/
   trunk/plugins/kolab_addressbook/kolab_addressbook.php
   trunk/plugins/kolab_addressbook/lib/
   trunk/plugins/kolab_addressbook/lib/rcube_kolab.php
   trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
Log:
First scaffolding for the Kolab address book including lib for general access to Kolab backend

Added: trunk/plugins/kolab_addressbook/kolab_addressbook.php
===================================================================
--- trunk/plugins/kolab_addressbook/kolab_addressbook.php	                        (rev 0)
+++ trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-10-15 17:10:08 UTC (rev 4097)
@@ -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 at 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;
+    }
+ 
+}


Property changes on: trunk/plugins/kolab_addressbook/kolab_addressbook.php
___________________________________________________________________
Added: svn:keywords
   + Id Date Author Revision
Added: svn:eol-style
   + native

Added: trunk/plugins/kolab_addressbook/lib/rcube_kolab.php
===================================================================
--- trunk/plugins/kolab_addressbook/lib/rcube_kolab.php	                        (rev 0)
+++ trunk/plugins/kolab_addressbook/lib/rcube_kolab.php	2010-10-15 17:10:08 UTC (rev 4097)
@@ -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']
+        
+        
+    }
+
+
+}


Property changes on: trunk/plugins/kolab_addressbook/lib/rcube_kolab.php
___________________________________________________________________
Added: svn:keywords
   + Id Date Author Revision
Added: svn:eol-style
   + native

Added: trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
===================================================================
--- trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php	                        (rev 0)
+++ trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php	2010-10-15 17:10:08 UTC (rev 4097)
@@ -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 at 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;
+    }
+  
+}


Property changes on: trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
___________________________________________________________________
Added: svn:keywords
   + Id Date Author Revision
Added: svn:eol-style
   + native

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



More information about the Svn mailing list