2011-05-20 19:04:25 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
+-------------------------------------------------------------------------+
|
|
|
|
| iCalendar functions for the Calendar Plugin |
|
2011-07-06 22:42:23 +02:00
|
|
|
| Version 0.3 beta |
|
2011-05-20 19:04:25 +02:00
|
|
|
| |
|
|
|
|
| This program is free software; you can redistribute it and/or modify |
|
|
|
|
| it under the terms of the GNU General Public License version 2 |
|
|
|
|
| as published by the Free Software Foundation. |
|
|
|
|
| |
|
|
|
|
| This program is distributed in the hope that it will be useful, |
|
|
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
| GNU General Public License for more details. |
|
|
|
|
| |
|
|
|
|
| You should have received a copy of the GNU General Public License along |
|
|
|
|
| with this program; if not, write to the Free Software Foundation, Inc., |
|
|
|
|
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
|
|
|
| |
|
|
|
|
+-------------------------------------------------------------------------+
|
|
|
|
| Author: Lazlo Westerhof <hello@lazlo.me> |
|
|
|
|
+-------------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
class calendar_ical
|
|
|
|
{
|
|
|
|
private $rc;
|
|
|
|
private $driver;
|
|
|
|
|
2011-07-06 22:42:23 +02:00
|
|
|
function __construct($rc, $driver)
|
|
|
|
{
|
2011-05-20 19:04:25 +02:00
|
|
|
$this->rc = $rc;
|
|
|
|
$this->driver = $driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Import events from iCalendar format
|
|
|
|
*
|
|
|
|
* @param array Associative events array
|
|
|
|
* @access public
|
|
|
|
*/
|
2011-07-06 22:42:23 +02:00
|
|
|
public function import($events)
|
|
|
|
{
|
2011-05-20 19:04:25 +02:00
|
|
|
//TODO
|
|
|
|
// for ($events as $event)
|
|
|
|
// $this->backend->newEvent(...);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export events to iCalendar format
|
|
|
|
*
|
|
|
|
* @param array Events as array
|
|
|
|
* @return string Events in iCalendar format (http://tools.ietf.org/html/rfc5545)
|
|
|
|
*/
|
2011-07-06 22:42:23 +02:00
|
|
|
public function export($events)
|
|
|
|
{
|
2011-05-20 19:04:25 +02:00
|
|
|
if (!empty($this->rc->user->ID)) {
|
|
|
|
$ical = "BEGIN:VCALENDAR\n";
|
|
|
|
$ical .= "VERSION:2.0\n";
|
2011-07-06 22:42:23 +02:00
|
|
|
$ical .= "PRODID:-//Roundcube Webmail " . RCMAIL_VERSION . "//NONSGML Calendar//EN\n";
|
|
|
|
$ical .= "CALSCALE:GREGORIAN\n";
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
foreach ($events as $event) {
|
|
|
|
$ical .= "BEGIN:VEVENT\n";
|
2011-07-06 22:42:23 +02:00
|
|
|
$ical .= "UID:" . $event['uid'] . "\n";
|
|
|
|
$ical .= "DTSTART:" . gmdate('Ymd\THis\Z', $event['start']) . "\n";
|
|
|
|
$ical .= "DTEND:" . gmdate('Ymd\THis\Z', $event['end']) . "\n";
|
2011-05-20 19:04:25 +02:00
|
|
|
$ical .= "SUMMARY:" . $event['title'] . "\n";
|
|
|
|
$ical .= "DESCRIPTION:" . $event['description'] . "\n";
|
|
|
|
if (!empty($event['location'])) {
|
|
|
|
$ical .= "LOCATION:" . $event['location'] . "\n";
|
|
|
|
}
|
2011-07-06 22:42:23 +02:00
|
|
|
if ($event['recurrence']) {
|
|
|
|
$ical .= "RRULE:" . calendar::to_rrule($event['recurrence']) . "\n";
|
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
if(!empty($event['categories'])) {
|
|
|
|
$ical .= "CATEGORIES:" . strtoupper($event['categories']) . "\n";
|
|
|
|
}
|
2011-07-06 22:42:23 +02:00
|
|
|
if ($event['sensitivity'] > 0) {
|
|
|
|
$ical .= "X-CALENDARSERVER-ACCESS:CONFIDENTIAL";
|
|
|
|
}
|
|
|
|
if ($event['alarms']) {
|
|
|
|
list($trigger, $action) = explode(':', $event['alarms']);
|
|
|
|
$val = calendar::parse_alaram_value($trigger);
|
|
|
|
|
|
|
|
$ical .= "BEGIN:VALARM\n";
|
|
|
|
if ($val[1]) $ical .= "TRIGGER:" . preg_replace('/^([-+])(.+)/', '\\1PT\\2', $trigger) . "\n";
|
|
|
|
else $ical .= "TRIGGER;VALUE=DATE-TIME:" . gmdate('Ymd\THis\Z', $val[0]) . "\n";
|
|
|
|
if ($action)
|
|
|
|
$ical .= "ACTION:" . strtoupper($action) . "\n";
|
|
|
|
$ical .= "END:VALARM\n";
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2011-07-06 22:42:23 +02:00
|
|
|
$ical .= "TRANSP:" . ($event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE') . "\n";
|
|
|
|
|
|
|
|
// TODO: export attachments
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
$ical .= "END:VEVENT\n";
|
|
|
|
}
|
2011-07-06 22:42:23 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
$ical .= "END:VCALENDAR";
|
|
|
|
|
|
|
|
return $ical;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|