Permalink
Browse files

- added cardDAV-Addressbook Class

- show cardDAV-Addressbook in the addressbook
- show each cardDAV-Server as a group
- first static contact displayed
  • Loading branch information...
1 parent a8a725b commit 5ab999d2dde7b8d52e1923e5e0758be3f580e261 Christian Putzke committed Sep 12, 2011
Showing with 183 additions and 4 deletions.
  1. +3 −0 CHANGELOG
  2. +2 −2 README
  3. +36 −2 carddav.php
  4. +140 −0 carddav_addressbook.php
  5. +1 −0 localization/de_DE.inc
  6. +1 −0 localization/en_US.inc
View
3 CHANGELOG
@@ -1,3 +1,6 @@
+change from 0.1 to 0.2
+-
+
release 0.1
- save / delete cardDAV-Server settings
- realtime cardDAV-Server check
View
4 README
@@ -7,8 +7,8 @@ Features
--------
* add multiple cardDAV-Server for each user
* cardDAV contacts will be synchronized automaticly (not implemented yet)
-* 2-way synchronization (no implemented yet)
-* cardDAV-Contacts are stored in the local database which provides great performance
+* 2-way synchronization (not implemented yet)
+* cardDAV-Contacts are stored in the local database which provides great performance (not implemented yet)
Installation
View
38 carddav.php
@@ -4,6 +4,7 @@
* include required carddav classes
*/
require_once dirname(__FILE__).'/carddav_backend.php';
+require_once dirname(__FILE__).'/carddav_addressbook.php';
/**
@@ -17,18 +18,22 @@
* @author Christian Putzke <cputzke@graviox.de>
* @copyright Graviox Studios
* @since 06.09.2011
- * @version 0.1
+ * @version 0.2
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
*
*/
class carddav extends rcube_plugin
{
public $task = 'settings|addressbook';
-
+ private $abook_id = 'cardDAV-Contacts';
+ private $abook_name = null;
+
+
public function init()
{
$rcmail = rcmail::get_instance();
$this->add_texts('localization/', true);
+ $this->abook_name = $this->gettext('addressbook_contacts');
switch ($rcmail->task)
{
@@ -39,6 +44,11 @@ public function init()
$this->register_action('plugin.carddav-server-delete', array($this, 'carddav_server_delete'));
$this->include_script('carddav_settings.js');
break;
+
+ case 'addressbook':
+ $this->add_hook('addressbooks_list', array($this, 'carddav_addressbook_sources'));
+ $this->add_hook('addressbook_get', array($this, 'get_carddav_addressbook'));
+ break;
}
}
@@ -67,6 +77,30 @@ protected function get_carddav_server()
return $servers;
}
+ public function get_carddav_addressbook($addressbook)
+ {
+ if ($addressbook['id'] === $this->abook_id)
+ {
+ $addressbook['instance'] = new carddav_addressbook($this->abook_name, $this->get_carddav_server());
+ }
+
+ return $addressbook;
+ }
+
+ public function carddav_addressbook_sources($addressbook)
+ {
+ $abook = new carddav_addressbook($this->abook_name);
+
+ $addressbook['sources'][$this->abook_id] = array (
+ 'id' => $this->abook_id,
+ 'name' => $this->abook_name,
+ 'readonly' => $abook->readonly,
+ 'groups' => $abook->groups,
+ );
+
+ return $addressbook;
+ }
+
public function carddav_server()
{
$this->register_handler('plugin.body', array($this, 'carddav_server_form'));
View
140 carddav_addressbook.php
@@ -0,0 +1,140 @@
+<?php
+
+/**
+ * Roundcube cardDAV addressbook extension
+ *
+ *
+ * @author Christian Putzke <cputzke@graviox.de>
+ * @copyright Graviox Studios
+ * @since 12.09.2011
+ * @version 0.2
+ * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
+ *
+ */
+class carddav_addressbook extends rcube_addressbook
+{
+ public $primary_key = 'carddav_contact_id';
+ public $readonly = true;
+ public $groups = true;
+ public $group_id;
+
+ private $filter;
+ private $result;
+ private $name;
+ private $servers;
+ private $cache;
+
+ public function __construct($name, $servers = null)
+ {
+ $this->ready = true;
+ $this->name = $name;
+ $this->servers = $servers;
+ }
+
+ public function get_name()
+ {
+ return $this->name;
+ }
+
+ public function set_search_set($filter)
+ {
+ $this->filter = $filter;
+ }
+
+ public function get_search_set()
+ {
+ return $this->filter;
+ }
+
+ public function reset()
+ {
+ $this->result = null;
+ $this->filter = null;
+ }
+
+ function list_groups($search = null)
+ {
+ $groups = array();
+
+ if (!empty($this->servers))
+ {
+ foreach ($this->servers as $server)
+ {
+ $groups[] = array(
+ 'ID' => 'cardDAV_'.$server['carddav_server_id'],
+ 'name' => $server['label']
+ );
+ }
+ }
+
+ return $groups;
+ }
+
+ public function list_records($cols=null, $subset=0)
+ {
+ $this->result = $this->count();
+ $this->result->add(array('ID' => '111', 'name' => "Example Contact", 'firstname' => "Example", 'surname' => "Contact", 'email' => "example@roundcube.net"));
+
+ return $this->result;
+ }
+
+ public function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
+ {
+ // no search implemented, just list all records
+ return $this->list_records();
+ }
+
+ public function count()
+ {
+ return new rcube_result_set(1, ($this->list_page - 1) * $this->page_size);
+ }
+
+ public function get_result()
+ {
+ return $this->result;
+ }
+
+ 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;
+ }
+
+
+ function create_group($name)
+ {
+ $result = false;
+
+ return $result;
+ }
+
+ 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;
+ }
+
+ function set_group($gid)
+ {
+ $this->group_id = $gid;
+ $this->cache = null;
+ }
+
+}
View
1 localization/de_DE.inc
@@ -4,6 +4,7 @@ $labels = array();
$labels['settings'] = 'CardDAV Einstellungen';
$labels['settings_tab'] = 'CardDAV';
$labels['settings_label'] = 'Label';
+$labels['addressbook_contacts'] = 'CardDAV-Kontakte';
$messages = array();
$messages['settings_empty_values'] = 'Bitte f&uuml;lle alle Felder aus';
View
1 localization/en_US.inc
@@ -4,6 +4,7 @@ $labels = array();
$labels['settings'] = 'CardDAV settings';
$labels['settings_tab'] = 'CardDAV';
$labels['settings_label'] = 'Label';
+$labels['addressbook_contacts'] = 'CardDAV-Contacts';
$messages = array();
$messages['settings_empty_values'] = 'Please fill out all fields';

0 comments on commit 5ab999d

Please sign in to comment.