summaryrefslogtreecommitdiffstats
path: root/apps/calendar
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-06-30 12:50:26 +0200
committerGeorg Ehrke <dev@georgswebsite.de>2012-06-30 12:50:26 +0200
commit433d15d309b0bade290f028b1365eff77f8dd0a8 (patch)
tree1fa3ddc8279091c4c2fa34c45a1bfb19f60568d4 /apps/calendar
parent34d4eb8edd4b485f65e50fbd4c66f852268f1dab (diff)
parent6e6f90a8a242c96cc90a5ba35248f7abdfddd6b4 (diff)
downloadnextcloud-server-433d15d309b0bade290f028b1365eff77f8dd0a8.tar.gz
nextcloud-server-433d15d309b0bade290f028b1365eff77f8dd0a8.zip
Merge branch 'master' into calendar_import
Diffstat (limited to 'apps/calendar')
-rw-r--r--apps/calendar/appinfo/app.php1
-rw-r--r--apps/calendar/export.php19
-rw-r--r--apps/calendar/lib/export.php93
-rw-r--r--apps/calendar/share.php33
4 files changed, 120 insertions, 26 deletions
diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php
index c9e0f14d7a5..3c8cc76133e 100644
--- a/apps/calendar/appinfo/app.php
+++ b/apps/calendar/appinfo/app.php
@@ -8,6 +8,7 @@ OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre
OC::$CLASSPATH['OC_Calendar_Repeat'] = 'apps/calendar/lib/repeat.php';
OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.php';
OC::$CLASSPATH['OC_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php';
+OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php';
//General Hooks
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
//Repeating Events Hooks
diff --git a/apps/calendar/export.php b/apps/calendar/export.php
index 5780d191a57..1374c49cc0d 100644
--- a/apps/calendar/export.php
+++ b/apps/calendar/export.php
@@ -5,35 +5,26 @@
* later.
* See the COPYING-README file.
*/
-
-
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
$cal = isset($_GET['calid']) ? $_GET['calid'] : NULL;
$event = isset($_GET['eventid']) ? $_GET['eventid'] : NULL;
-$nl = "\r\n";
if(isset($cal)){
$calendar = OC_Calendar_App::getCalendar($cal, true);
if(!$calendar){
header('HTTP/1.0 404 Not Found');
exit;
}
- $calobjects = OC_Calendar_Object::all($cal);
header('Content-Type: text/Calendar');
- header('Content-Disposition: inline; filename=' . $calendar['displayname'] . '.ics');
- foreach($calobjects as $calobject){
- echo $calobject['calendardata'] . $nl;
- }
+ header('Content-Disposition: inline; filename=' . str_replace(' ', '-', $calendar['displayname']) . '.ics');
+ echo OC_Calendar_Export::export($cal, OC_Calendar_Export::CALENDAR);
}elseif(isset($event)){
$data = OC_Calendar_App::getEventObject($_GET['eventid'], true);
if(!$data){
header('HTTP/1.0 404 Not Found');
exit;
}
- $calendarid = $data['calendarid'];
- $calendar = OC_Calendar_App::getCalendar($calendarid);
header('Content-Type: text/Calendar');
- header('Content-Disposition: inline; filename=' . $data['summary'] . '.ics');
- echo $data['calendardata'];
-}
-?>
+ header('Content-Disposition: inline; filename=' . str_replace(' ', '-', $data['summary']) . '.ics');
+ echo OC_Calendar_Export::export($event, OC_Calendar_Export::EVENT);
+} \ No newline at end of file
diff --git a/apps/calendar/lib/export.php b/apps/calendar/lib/export.php
new file mode 100644
index 00000000000..cd248ce92a6
--- /dev/null
+++ b/apps/calendar/lib/export.php
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Copyright (c) 2012 Georg Ehrke <ownclouddev@georgswebsite.de>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+/*
+ * 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';
+
+ /*
+ * @brief export a calendar or an event
+ * @param integer $id id of calendar / event
+ * @param string $type use OC_Calendar_Export constants
+ * @return string
+ */
+ public static function export($id, $type){
+ if($type == self::EVENT){
+ $return = self::event($id);
+ }else{
+ $return = self::calendar($id);
+ }
+ return self::fixLineBreaks($return);
+ }
+
+ /*
+ * @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 " . OCP\App::getAppVersion('calendar') . "\n";
+ foreach($events as $event){
+ $return .= self::generateEvent($event);
+ }
+ $return .= "END:VCALENDAR";
+ 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;
+ }
+}
diff --git a/apps/calendar/share.php b/apps/calendar/share.php
index 68c7d0ffae2..bffcf0b4709 100644
--- a/apps/calendar/share.php
+++ b/apps/calendar/share.php
@@ -1,22 +1,31 @@
<?php
+/**
+ * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
$token = strip_tags($_GET['t']);
$shared = OC_Calendar_Share::getElementByToken($token);
-$nl = "\n\r";
if($shared['type'] == OC_Calendar_Share::CALENDAR){
$calendar = OC_Calendar_App::getCalendar($shared['id'], false);
- $calobjects = OC_Calendar_Object::all($shared['id']);
- header('Content-Type: text/Calendar');
- header('Content-Disposition: inline; filename=' . $calendar['displayname'] . '.ics');
- foreach($calobjects as $calobject){
- echo $calobject['calendardata'] . $nl;
+ if(!$calendar){
+ header('HTTP/1.0 404 Not Found');
+ exit;
}
+ header('Content-Type: text/Calendar');
+ header('Content-Disposition: inline; filename=' . str_replace(' ', '-', $calendar['displayname']) . '.ics');
+ echo OC_Calendar_Export::export($shared['id'], OC_Calendar_Export::CALENDAR);
}elseif($shared['type'] == OC_Calendar_Share::EVENT){
$data = OC_Calendar_App::getEventObject($shared['id'], false);
- $calendarid = $data['calendarid'];
- $calendar = OC_Calendar_App::getCalendar($calendarid);
+ if(!$data){
+ header('HTTP/1.0 404 Not Found');
+ exit;
+ }
header('Content-Type: text/Calendar');
- header('Content-Disposition: inline; filename=' . $data['summary'] . '.ics');
- echo $data['calendardata'];
+ header('Content-Disposition: inline; filename=' . str_replace(' ', '-', $data['summary']) . '.ics');
+ echo OC_Calendar_Export::export($shared['id'], OC_Calendar_Export::EVENT);
}else{
- header('Error 404: Not Found');
-} \ No newline at end of file
+ header('HTTP/1.0 404 Not Found');
+ exit;
+}