Skip to content

Commit a8a725b

Browse files
author
Christian Putzke
committed
initial commit
0 parents  commit a8a725b

11 files changed

+1073
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config.inc.php

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
release 0.1
2+
- save / delete cardDAV-Server settings
3+
- realtime cardDAV-Server check
4+
- multiple cardDAV-Server for each user
5+
- English and German translations

LICENSE

+339
Large diffs are not rendered by default.

README

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Description
2+
-----------
3+
This is a cardDAV implementation for roundcube 0.6 or higher
4+
5+
6+
Features
7+
--------
8+
* add multiple cardDAV-Server for each user
9+
* cardDAV contacts will be synchronized automaticly (not implemented yet)
10+
* 2-way synchronization (no implemented yet)
11+
* cardDAV-Contacts are stored in the local database which provides great performance
12+
13+
14+
Installation
15+
------------
16+
* execute SQL-Statements from /plugins/carddav/SQL/
17+
* add 'carddav' to the plugins-array in /config/main.inc.php
18+
* copy /plugins/carddav/config.inc.php.dist to /plugins/carddav/config.inc.php
19+
* login into your roundcube webmail and add your cardDAV-Server in the settings
20+
21+
22+
Contact
23+
-------
24+
* Author: Christian Putzke <[email protected]>
25+
* Report feature requests and bugs here: https://github.com/graviox/Roundcube-cardDAV/issues
26+
* Visit Graviox Studios: http://www.graviox.de/

SQL/mysql.sql

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE IF NOT EXISTS `carddav_server` (
2+
`carddav_server_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
3+
`user_id` int(10) unsigned NOT NULL,
4+
`url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
5+
`username` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
6+
`password` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
7+
`label` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
8+
PRIMARY KEY (`carddav_server_id`),
9+
KEY `user_id` (`user_id`)
10+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
11+
12+
ALTER TABLE `carddav_server` ADD CONSTRAINT `carddav_server_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE;
13+
14+
CREATE TABLE IF NOT EXISTS `carddav_contacts` (
15+
`carddav_contact_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
16+
`carddav_server_id` int(10) unsigned NOT NULL,
17+
`etag` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
18+
`vcard` text COLLATE utf8_unicode_ci NOT NULL,
19+
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
20+
`email` text COLLATE utf8_unicode_ci,
21+
PRIMARY KEY (`carddav_contact_id`)
22+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
23+
24+
ALTER TABLE `carddav_contacts` ADD CONSTRAINT `carddav_contacts_ibfk_1` FOREIGN KEY (`carddav_server_id`) REFERENCES `carddav_server` (`carddav_server_id`) ON DELETE CASCADE;

carddav.php

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
<?php
2+
3+
/**
4+
* include required carddav classes
5+
*/
6+
require_once dirname(__FILE__).'/carddav_backend.php';
7+
8+
9+
/**
10+
* Roundcube cardDAV implementation
11+
*
12+
* This is a cardDAV implementation for roundcube 0.6 or higher. It allows every user to add
13+
* multiple cardDAV server in their settings. The cardDAV contacts will be synchronized
14+
* automaticly with their addressbook.
15+
*
16+
*
17+
* @author Christian Putzke <[email protected]>
18+
* @copyright Graviox Studios
19+
* @since 06.09.2011
20+
* @version 0.1
21+
* @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
22+
*
23+
*/
24+
class carddav extends rcube_plugin
25+
{
26+
public $task = 'settings|addressbook';
27+
28+
public function init()
29+
{
30+
$rcmail = rcmail::get_instance();
31+
$this->add_texts('localization/', true);
32+
33+
switch ($rcmail->task)
34+
{
35+
case 'settings':
36+
$this->register_action('plugin.carddav-server', array($this, 'carddav_server'));
37+
$this->register_action('plugin.carddav-server-check', array($this, 'carddav_server_check'));
38+
$this->register_action('plugin.carddav-server-save', array($this, 'carddav_server_save'));
39+
$this->register_action('plugin.carddav-server-delete', array($this, 'carddav_server_delete'));
40+
$this->include_script('carddav_settings.js');
41+
break;
42+
}
43+
}
44+
45+
protected function get_carddav_server()
46+
{
47+
$servers = array();
48+
$rcmail = rcmail::get_instance();
49+
$user_id = $rcmail->user->data['user_id'];
50+
51+
$query = "
52+
SELECT
53+
*
54+
FROM
55+
".get_table_name('carddav_server')."
56+
WHERE
57+
user_id = ?
58+
";
59+
60+
$result = $rcmail->db->query($query, $user_id);
61+
62+
while($server = $rcmail->db->fetch_assoc($result))
63+
{
64+
$servers[] = $server;
65+
}
66+
67+
return $servers;
68+
}
69+
70+
public function carddav_server()
71+
{
72+
$this->register_handler('plugin.body', array($this, 'carddav_server_form'));
73+
74+
$rcmail = rcmail::get_instance();
75+
$rcmail->output->set_pagetitle($this->gettext('settings'));
76+
$rcmail->output->send('plugin');
77+
}
78+
79+
public function carddav_server_check()
80+
{
81+
$rcmail = rcmail::get_instance();
82+
$url = get_input_value('_server_url', RCUBE_INPUT_POST);
83+
$username = get_input_value('_username', RCUBE_INPUT_POST);
84+
$password = get_input_value('_password', RCUBE_INPUT_POST);
85+
86+
$carddav_backend = new carddav_backend($url);
87+
$carddav_backend->set_auth($username, $password);
88+
89+
if ($carddav_backend->check_connection() === true)
90+
{
91+
$rcmail->output->command('plugin.carddav_server_check', array('check' => 'true'));
92+
}
93+
else
94+
{
95+
$rcmail->output->command('plugin.carddav_server_check', array('check' => 'false'));
96+
}
97+
}
98+
99+
public function carddav_server_form()
100+
{
101+
$rcmail = rcmail::get_instance();
102+
$servers = $this->get_carddav_server();
103+
104+
$table = new html_table(array('cols' => 5));
105+
$table->add('title', $this->gettext('settings_label'));
106+
$table->add('title', $this->gettext('server'));
107+
$table->add('title', $this->gettext('username'));
108+
$table->add('title', $this->gettext('password'));
109+
$table->add(null, null);
110+
111+
if (!empty($servers))
112+
{
113+
foreach ($servers as $server)
114+
{
115+
$table->add(null, $server['label']);
116+
$table->add(null, $server['url']);
117+
$table->add(null, $server['username']);
118+
$table->add(null, '**********');
119+
$table->add(null, html::a(array('href' => './?_task=settings&_action=plugin.carddav-server-delete&id='.$server['carddav_server_id']), 'delete'));
120+
}
121+
}
122+
123+
$input_label = new html_inputfield(array(
124+
'name' => '_label',
125+
'id' => '_label',
126+
'size' => '20'
127+
));
128+
129+
$input_server_url = new html_inputfield(array(
130+
'name' => '_server_url',
131+
'id' => '_server_url',
132+
'size' => '50'
133+
));
134+
135+
$input_username = new html_inputfield(array(
136+
'name' => '_username',
137+
'id' => '_username',
138+
'size' => '20'
139+
));
140+
141+
$input_password = new html_passwordfield(array(
142+
'name' => '_password',
143+
'id' => '_password',
144+
'size' => '20'
145+
));
146+
147+
$input_submit = $rcmail->output->button(array(
148+
'command' => 'plugin.carddav-server-save',
149+
'type' => 'input',
150+
'class' => 'button mainaction',
151+
'label' => 'save'
152+
));
153+
154+
$table->add(null, $input_label->show());
155+
$table->add(null, $input_server_url->show());
156+
$table->add(null, $input_username->show());
157+
$table->add(null, $input_password->show());
158+
$table->add(null, $input_submit);
159+
160+
$rcmail->output->add_gui_object('carddavserverform', 'carddav-server-form');
161+
162+
$out = html::div(
163+
array('class' => 'box'),
164+
html::div(array('class' => 'boxtitle'), $this->gettext('settings')).
165+
html::div(array('class' => 'boxcontent'), $table->show())
166+
);
167+
168+
return $rcmail->output->form_tag(array(
169+
'id' => 'carddav-server-form',
170+
'name' => 'carddav-server-form',
171+
'method' => 'post',
172+
'action' => './?_task=settings&_action=plugin.carddav-server-save',
173+
), $out);
174+
}
175+
176+
public function carddav_server_save()
177+
{
178+
$rcmail = rcmail::get_instance();
179+
$user_id = $rcmail->user->data['user_id'];
180+
$url = get_input_value('_server_url', RCUBE_INPUT_POST);
181+
$username = get_input_value('_username', RCUBE_INPUT_POST);
182+
$password = get_input_value('_password', RCUBE_INPUT_POST);
183+
$label = get_input_value('_label', RCUBE_INPUT_POST);
184+
185+
$query = "
186+
INSERT INTO
187+
".get_table_name('carddav_server')." (user_id, url, username, password, label)
188+
VALUES
189+
(?, ?, ?, ?, ?)
190+
";
191+
192+
$rcmail->db->query($query, $user_id, $url, $username, $rcmail->encrypt($password), $label);
193+
194+
if ($rcmail->db->affected_rows())
195+
{
196+
$rcmail->output->show_message($this->gettext('settings_saved'), 'confirmation');
197+
}
198+
else
199+
{
200+
$rcmail->output->show_message($this->gettext('settings_save_failed'), 'error');
201+
}
202+
203+
return $this->carddav_server();
204+
}
205+
206+
public function carddav_server_delete()
207+
{
208+
$rcmail = rcmail::get_instance();
209+
$user_id = $rcmail->user->data['user_id'];
210+
$carddav_server_id = $_GET['id'];
211+
212+
$query = "
213+
DELETE FROM
214+
".get_table_name('carddav_server')."
215+
WHERE
216+
user_id = ?
217+
AND
218+
carddav_server_id = ?
219+
";
220+
221+
$rcmail->db->query($query, $user_id, $carddav_server_id);
222+
223+
if ($rcmail->db->affected_rows())
224+
{
225+
$rcmail->output->show_message($this->gettext('settings_deleted'), 'confirmation');
226+
}
227+
else
228+
{
229+
$rcmail->output->show_message($this->gettext('settings_delete_failed'), 'error');
230+
}
231+
232+
return $this->carddav_server();
233+
}
234+
}

0 commit comments

Comments
 (0)