summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-06-28 18:54:13 +0200
committerGeorg Ehrke <dev@georgswebsite.de>2012-06-28 18:54:13 +0200
commit9dd7ca26671d2c6640210e59071135e8f69cca7f (patch)
tree57dc5f30e717785439711ef2ec69336700c1310b /apps
parent9a4709e68db5cff184816ed9d01086ba00f62b35 (diff)
downloadnextcloud-server-9dd7ca26671d2c6640210e59071135e8f69cca7f.tar.gz
nextcloud-server-9dd7ca26671d2c6640210e59071135e8f69cca7f.zip
some changes and more doc for OC_Calendar_Export class
Diffstat (limited to 'apps')
-rw-r--r--apps/calendar/lib/export.php74
1 files changed, 55 insertions, 19 deletions
diff --git a/apps/calendar/lib/export.php b/apps/calendar/lib/export.php
index 7c98d94fcc6..cd248ce92a6 100644
--- a/apps/calendar/lib/export.php
+++ b/apps/calendar/lib/export.php
@@ -6,9 +6,12 @@
* See the COPYING-README file.
*/
/*
- * This class does export
+ * This class does export and converts all times to UTC
*/
class OC_Calendar_Export{
+ /*
+ * @brief Use one of these constants as second parameter if you call OC_Calendar_Export::export()
+ */
const CALENDAR = 'calendar';
const EVENT = 'event';
@@ -20,38 +23,71 @@ class OC_Calendar_Export{
*/
public static function export($id, $type){
if($type == self::EVENT){
- $data = OC_Calendar_App::getEventObject($_GET['eventid'], false);
- $return = $data['calendardata'];
+ $return = self::event($id);
}else{
$return = self::calendar($id);
}
- return $return;
+ return self::fixLineBreaks($return);
}
/*
- * @brief export a calendar and convert all times to UTC
+ * @brief exports a calendar and convert all times to UTC
* @param integer $id id of the calendar
* @return string
*/
private static function calendar($id){
$events = OC_Calendar_Object::all($id);
- $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar\n";
+ $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar " . OCP\App::getAppVersion('calendar') . "\n";
foreach($events as $event){
- $object = OC_VObject::parse($event['calendardata']);
- $dtstart = $object->VEVENT->DTSTART;
- $start_dt = $dtstart->getDateTime();
- $dtend = OC_Calendar_Object::getDTEndFromVEvent($object->VEVENT);
- $end_dt = $dtend->getDateTime();
- if($dtstart->getDateType() !== Sabre_VObject_Element_DateTime::DATE){
- $object->VEVENT->DTSTART->offsetUnset('VALUE');
- $object->VEVENT->DTEND->offsetUnset('VALUE');
- }
- $return .= $object->VEVENT->serialize();
+ $return .= self::generateEvent($event);
}
$return .= "END:VCALENDAR";
- $return = str_replace("\r\n", "\n", $return);
- $return = str_replace("\r", "\n", $return);
- $return = str_replace("\n", "\r\n", $return);
return $return;
}
+
+ /*
+ * @brief exports an event and convert all times to UTC
+ * @param integer $id id of the event
+ * @return string
+ */
+ private static function event($id){
+ $event = OC_Calendar_Object::find($id);
+ $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar " . OCP\App::getAppVersion('calendar') . "\n";
+ $return .= self::generateEvent($event);
+ $return .= "END:VCALENDAR";
+ return $return;
+ }
+
+ /*
+ * @brief generates the VEVENT with UTC dates
+ * @param array $event
+ * @return string
+ */
+ private static function generateEvent($event){
+ $object = OC_VObject::parse($event['calendardata']);
+ $dtstart = $object->VEVENT->DTSTART;
+ $start_dt = $dtstart->getDateTime();
+ $dtend = OC_Calendar_Object::getDTEndFromVEvent($object->VEVENT);
+ $end_dt = $dtend->getDateTime();
+ if($dtstart->getDateType() !== Sabre_VObject_Element_DateTime::DATE){
+ $start_dt->setTimezone(new DateTimeZone('UTC'));
+ $end_dt->setTimezone(new DateTimeZone('UTC'));
+ $object->VEVENT->setDateTime('DTSTART', $start_dt, Sabre_VObject_Property_DateTime::UTC);
+ $object->VEVENT->setDateTime('DTEND', $end_dt, Sabre_VObject_Property_DateTime::UTC);
+ }
+ return $object->VEVENT->serialize();
+ }
+
+ /*
+ * @brief fixes new line breaks
+ * (fixes problems with Apple iCal)
+ * @param string $string to fix
+ * @return string
+ */
+ private static function fixLineBreaks($string){
+ $string = str_replace("\r\n", "\n", $string);
+ $string = str_replace("\r", "\n", $string);
+ $string = str_replace("\n", "\r\n", $string);
+ return $string;
+ }
}