From 38f3ad7cd62bcaa1df0e3e2bd5c0bebcdd5a2f18 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Mon, 5 Dec 2016 17:48:28 +0100 Subject: [PATCH 1/2] Added empty check for optional events --- .idea/workspace.xml | 206 ++++++++++++++++------------------------ php/module.calendar.php | 12 ++- 2 files changed, 90 insertions(+), 128 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e3ee7ea..7379bc3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,7 @@ - + @@ -23,34 +23,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + @@ -59,40 +37,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -104,6 +48,11 @@ @@ -152,10 +102,10 @@ - @@ -182,8 +132,6 @@ - - @@ -318,6 +266,8 @@ + + @@ -389,17 +339,21 @@ + + + + - - + - + @@ -436,11 +390,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -448,7 +436,6 @@ - @@ -456,7 +443,6 @@ - @@ -464,7 +450,6 @@ - @@ -472,7 +457,6 @@ - @@ -487,9 +471,6 @@ - - - @@ -536,13 +517,6 @@ - - - - - - - @@ -562,9 +536,6 @@ - - - @@ -587,12 +558,6 @@ - - - - - - @@ -607,7 +572,6 @@ - @@ -622,7 +586,6 @@ - @@ -644,7 +607,6 @@ - @@ -659,7 +621,6 @@ - @@ -698,7 +659,6 @@ - @@ -721,7 +681,6 @@ - @@ -736,7 +695,6 @@ - @@ -744,15 +702,12 @@ - - - - + @@ -762,38 +717,22 @@ - + - - - - - - - - - - - - - - - + - - + - @@ -801,8 +740,23 @@ + + + + + + + + + + + + + + - + + diff --git a/php/module.calendar.php b/php/module.calendar.php index 80da133..53e9b94 100644 --- a/php/module.calendar.php +++ b/php/module.calendar.php @@ -680,8 +680,16 @@ class CalendarModule extends Module if (!empty((string)$vEvent->{'X-ZARAFA-LABEL'})) { $properties["label"] = array_search((string)$vEvent->{'X-ZARAFA-LABEL'}, $this->labels); } - $properties["last_modification_time"] = (string)$vEvent->{'LAST-MODIFIED'}->getDateTime()->getTimestamp(); - $properties["creation_time"] = (string)$vEvent->CREATED->getDateTime()->getTimestamp(); + if (!empty((string)$vEvent->{'LAST-MODIFIED'})) { + $properties["last_modification_time"] = (string)$vEvent->{'LAST-MODIFIED'}->getDateTime()->getTimestamp(); + } else { + $properties["last_modification_time"] = time(); + } + if (!empty((string)$vEvent->CREATED)) { + $properties["creation_time"] = (string)$vEvent->CREATED->getDateTime()->getTimestamp(); + } else { + $properties["creation_time"] = time(); + } $properties["rrule"] = (string)$vEvent->RRULE; // Attendees From 92660c34b18f4f7caa543bc313cc08308dc75d02 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Mon, 5 Dec 2016 18:47:21 +0100 Subject: [PATCH 2/2] Import and export of free/busy state --- .idea/workspace.xml | 130 +++++++++++++++++++++++++++++++++------- php/module.calendar.php | 42 +++++++++++-- 2 files changed, 147 insertions(+), 25 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7379bc3..a0be335 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,6 @@ - @@ -27,16 +26,39 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -196,6 +218,46 @@ - @@ -397,6 +477,9 @@ + + + @@ -677,13 +760,6 @@ - - - - - - - @@ -736,13 +812,6 @@ - - - - - - - @@ -750,13 +819,32 @@ + + + + + + + + + + + + + + + + - - + + + + + diff --git a/php/module.calendar.php b/php/module.calendar.php index 53e9b94..4f5fbe1 100644 --- a/php/module.calendar.php +++ b/php/module.calendar.php @@ -58,6 +58,13 @@ class CalendarModule extends Module "OOF" ); + $this->freeBusyStates = array( // http://www.kanzaki.com/docs/ical/fbtype.html + "FREE", + "BUSY-TENTATIVE", + "BUSY", + "BUSY-UNAVAILABLE" + ); + $this->labels = array( "NONE", "IMPORTANT", @@ -270,17 +277,20 @@ class CalendarModule extends Module 'DTEND' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "duedate")), 'CREATED' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "creation_time")), 'LAST-MODIFIED' => date_timestamp_set(new DateTime(), $this->getProp($messageProps, "last_modification_time")), - 'PRIORITY' => $this->getProp($messageProps, "importance"), + 'PRIORITY' => intval($this->getProp($messageProps, "importance")), 'X-MICROSOFT-CDO-INTENDEDSTATUS' => $this->busyStates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... 'X-MICROSOFT-CDO-BUSYSTATUS' => $this->busyStates[intval($this->getProp($messageProps, "busystatus"))], // both seem to be valid... + 'FBTYPE' => $this->freeBusyStates[intval($this->getProp($messageProps, "busystatus"))], 'X-ZARAFA-LABEL' => $this->labels[intval($this->getProp($messageProps, "label"))], 'CLASS' => $this->getProp($messageProps, "private") ? "PRIVATE" : "PUBLIC", 'COMMENT' => "eid:" . $records[$index] ]); // Add organizer - $vEvent->add('ORGANIZER', 'mailto:' . $this->getProp($messageProps, "sender_email_address")); - $vEvent->ORGANIZER['CN'] = $this->getProp($messageProps, "sender_name"); + if(!empty( $this->getProp($messageProps, "sender_email_address"))) { + $vEvent->add('ORGANIZER', 'mailto:' . $this->getProp($messageProps, "sender_email_address")); + $vEvent->ORGANIZER['CN'] = $this->getProp($messageProps, "sender_name"); + } // Add Attendees if (isset($messageProps["recipients"]) && count($messageProps["recipients"]["item"]) > 0) { @@ -318,6 +328,13 @@ class CalendarModule extends Module if (!empty($body)) { $vEvent->add('DESCRIPTION', $body); } + + // Add categories + if (!empty($this->getProp($messageProps, "categories"))) { + $categories = array_map('trim', explode(';', trim($this->getProp($messageProps, "categories"), " ;"))); + + $vEvent->add('CATEGORIES', $categories); + } } // write combined ics file @@ -672,7 +689,15 @@ class CalendarModule extends Module $properties["comment"] = (string)$vEvent->COMMENT; $properties["timezone"] = (string)$vEvent->DTSTART["TZID"]; $properties["organizer"] = (string)$vEvent->ORGANIZER; - $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}, $this->busyStates); // X-MICROSOFT-CDO-BUSYSTATUS + if(!empty((string)$vEvent->FBTYPE)) { + $properties["busystatus"] = array_search((string)$vEvent->FBTYPE, $this->freeBusyStates); + } else if(!empty((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'})) { + $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-INTENDEDSTATUS'}, $this->busyStates); + } else if(!empty((string)$vEvent->{'X-MICROSOFT-CDO-BUSYSTATUS'})) { + $properties["busystatus"] = array_search((string)$vEvent->{'X-MICROSOFT-CDO-BUSYSTATUS'}, $this->busyStates); + } else { + $properties["busystatus"] = array_search("BUSY", $this->busyStates); + } $properties["transp"] = (string)$vEvent->TRANSP; //$properties["trigger"] = (string)$vEvent->COMMENT; $properties["priority"] = (string)$vEvent->PRIORITY; @@ -692,6 +717,15 @@ class CalendarModule extends Module } $properties["rrule"] = (string)$vEvent->RRULE; + if (isset($vEvent->CATEGORIES) && count($vEvent->CATEGORIES) > 0) { + $categories = array(); + foreach ($vEvent->CATEGORIES as $category) { + $categories[] = (string) $category; + } + + $properties["categories"] = $categories; + } + // Attendees $properties["attendees"] = array(); if (isset($vEvent->ATTENDEE) && count($vEvent->ATTENDEE) > 0) {