Adding rules according to rfc2445#section-4.1 and adding Organizer and Attendees information in VEVENT block.
This commit is contained in:
parent
d0111b6e01
commit
f610167cc1
1 changed files with 66 additions and 18 deletions
|
@ -19,6 +19,7 @@
|
|||
| |
|
||||
+-------------------------------------------------------------------------+
|
||||
| Author: Lazlo Westerhof <hello@lazlo.me> |
|
||||
| Bogomil "Bogo" Shopov <shopov@kolabsys.com> |
|
||||
+-------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
|
@ -55,26 +56,32 @@ class calendar_ical
|
|||
public function export($events)
|
||||
{
|
||||
if (!empty($this->rc->user->ID)) {
|
||||
$ical = "BEGIN:VCALENDAR\n";
|
||||
$ical .= "VERSION:2.0\n";
|
||||
$ical .= "PRODID:-//Roundcube Webmail " . RCMAIL_VERSION . "//NONSGML Calendar//EN\n";
|
||||
$ical .= "CALSCALE:GREGORIAN\n";
|
||||
$ical = "BEGIN:VCALENDAR\r\n";
|
||||
$ical .= "VERSION:2.0\r\n";
|
||||
$ical .= "PRODID:-//Roundcube Webmail " . RCMAIL_VERSION . "//NONSGML Calendar//EN\r\n";
|
||||
$ical .= "CALSCALE:GREGORIAN\r\n";
|
||||
|
||||
foreach ($events as $event) {
|
||||
$ical .= "BEGIN:VEVENT\n";
|
||||
$ical .= "UID:" . self::escpape($event['uid']) . "\n";
|
||||
$ical .= "DTSTART:" . gmdate('Ymd\THis\Z', $event['start']) . "\n";
|
||||
$ical .= "DTEND:" . gmdate('Ymd\THis\Z', $event['end']) . "\n";
|
||||
$ical .= "SUMMARY:" . self::escpape($event['title']) . "\n";
|
||||
$ical .= "DESCRIPTION:" . self::escpape($event['description']) . "\n";
|
||||
$ical .= "BEGIN:VEVENT\r\n";
|
||||
$ical .= "UID:" . self::escpape($event['uid']) . "\r\n";
|
||||
$ical .= "DTSTART:" . gmdate('Ymd\THis\Z', $event['start']) . "\r\n";
|
||||
$ical .= "DTEND:" . gmdate('Ymd\THis\Z', $event['end']) . "\r\n";
|
||||
$ical .= "SUMMARY:" . self::escpape($event['title']) . "\r\n";
|
||||
$ical .= "DESCRIPTION:" . wordwrap(self::escpape($event['description']),75,'\r\n ') . "\r\n";
|
||||
|
||||
if (!empty($event['attendees'])){
|
||||
|
||||
$ical .= $this->_get_attendees($event['attendees']);
|
||||
}
|
||||
|
||||
if (!empty($event['location'])) {
|
||||
$ical .= "LOCATION:" . self::escpape($event['location']) . "\n";
|
||||
$ical .= "LOCATION:" . self::escpape($event['location']) . "\r\n";
|
||||
}
|
||||
if ($event['recurrence']) {
|
||||
$ical .= "RRULE:" . calendar::to_rrule($event['recurrence']) . "\n";
|
||||
$ical .= "RRULE:" . calendar::to_rrule($event['recurrence']) . "\r\n";
|
||||
}
|
||||
if(!empty($event['categories'])) {
|
||||
$ical .= "CATEGORIES:" . self::escpape(strtoupper($event['categories'])) . "\n";
|
||||
$ical .= "CATEGORIES:" . self::escpape(strtoupper($event['categories'])) . "\r\n";
|
||||
}
|
||||
if ($event['sensitivity'] > 0) {
|
||||
$ical .= "X-CALENDARSERVER-ACCESS:CONFIDENTIAL";
|
||||
|
@ -84,16 +91,16 @@ class calendar_ical
|
|||
$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:" . self::escpape(strtoupper($action)) . "\n";
|
||||
if ($val[1]) $ical .= "TRIGGER:" . preg_replace('/^([-+])(.+)/', '\\1PT\\2', $trigger) . "\r\n";
|
||||
else $ical .= "TRIGGER;VALUE=DATE-TIME:" . gmdate('Ymd\THis\Z', $val[0]) . "\r\n";
|
||||
if ($action) $ical .= "ACTION:" . self::escpape(strtoupper($action)) . "\r\n";
|
||||
$ical .= "END:VALARM\n";
|
||||
}
|
||||
$ical .= "TRANSP:" . ($event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE') . "\n";
|
||||
$ical .= "TRANSP:" . ($event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE') . "\r\n";
|
||||
|
||||
// TODO: export attachments
|
||||
|
||||
$ical .= "END:VEVENT\n";
|
||||
$ical .= "END:VEVENT\r\n";
|
||||
}
|
||||
|
||||
$ical .= "END:VCALENDAR";
|
||||
|
@ -106,4 +113,45 @@ class calendar_ical
|
|||
{
|
||||
return preg_replace('/(?<!\\\\)([\:\;\,\\n\\r])/', '\\\$1', $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the orginizer of the event.
|
||||
* @param Array Attendees and roles
|
||||
*
|
||||
*/
|
||||
private function _get_attendees($ats)
|
||||
{
|
||||
$organizer = "";
|
||||
$attendees = "";
|
||||
foreach ($ats as $at){
|
||||
|
||||
if ($at['role']=="ORGANIZER"){
|
||||
//I am an orginizer
|
||||
$organizer .= "ORGANIZER;";
|
||||
if (!empty($at['name']))
|
||||
$organizer .="CN=".$at['name'].":";
|
||||
//handling limitations according to rfc2445#section-4.1
|
||||
$organizer .="MAILTO:"."\r\n ".$at['email'];
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
//I am an attendee
|
||||
$attendees .= "ATTENDEE;ROLE=".$at['role'].";PARTSTAT=".$at['status'];
|
||||
$attendees .= "\r\n "; ////handling limitations according to rfc2445#section-4.1
|
||||
if (!empty($at['name']))
|
||||
$attendees .=";CN=".$at['name'].":";
|
||||
|
||||
$attendees .="MAILTO:".$at['email']."\r\n";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $organizer."\r\n".$attendees;
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue