proper export for calendar app - doesn't work with apple ical yet - even though a ics validator says it's valid

This commit is contained in:
Georg Ehrke 2012-06-03 14:54:53 +02:00
parent ad6562d14f
commit c2a51d1f48
3 changed files with 62 additions and 14 deletions

View File

@ -7,6 +7,7 @@ OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php';
OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php'; OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php';
OC::$CLASSPATH['OC_Calendar_Share'] = 'apps/calendar/lib/share.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_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php';
OC::$CLASSPATH['OC_Calendar_Export'] = 'apps/calendar/lib/export.php';
OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); OCP\Util::connectHook('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser');
OCP\Util::addscript('calendar','loader'); OCP\Util::addscript('calendar','loader');
OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min"); OCP\Util::addscript("3rdparty", "chosen/chosen.jquery.min");

View File

@ -5,35 +5,26 @@
* later. * later.
* See the COPYING-README file. * See the COPYING-README file.
*/ */
OCP\User::checkLoggedIn(); OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('calendar'); OCP\App::checkAppEnabled('calendar');
$cal = isset($_GET['calid']) ? $_GET['calid'] : NULL; $cal = isset($_GET['calid']) ? $_GET['calid'] : NULL;
$event = isset($_GET['eventid']) ? $_GET['eventid'] : NULL; $event = isset($_GET['eventid']) ? $_GET['eventid'] : NULL;
$nl = "\r\n";
if(isset($cal)){ if(isset($cal)){
$calendar = OC_Calendar_App::getCalendar($cal, true); $calendar = OC_Calendar_App::getCalendar($cal, true);
if(!$calendar){ if(!$calendar){
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
exit; exit;
} }
$calobjects = OC_Calendar_Object::all($cal);
header('Content-Type: text/Calendar'); header('Content-Type: text/Calendar');
header('Content-Disposition: inline; filename=' . $calendar['displayname'] . '.ics'); header('Content-Disposition: inline; filename=' . $calendar['displayname'] . '.ics');
foreach($calobjects as $calobject){ echo OC_Calendar_Export::export($cal, OC_Calendar_Export::CALENDAR);
echo $calobject['calendardata'] . $nl;
}
}elseif(isset($event)){ }elseif(isset($event)){
$data = OC_Calendar_App::getEventObject($_GET['eventid'], true); $data = OC_Calendar_App::getEventObject($_GET['eventid'], true);
if(!$data){ if(!$data){
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
exit; exit;
} }
$calendarid = $data['calendarid'];
$calendar = OC_Calendar_App::getCalendar($calendarid);
header('Content-Type: text/Calendar'); header('Content-Type: text/Calendar');
header('Content-Disposition: inline; filename=' . $data['summary'] . '.ics'); header('Content-Disposition: inline; filename=' . $data['summary'] . '.ics');
echo $data['calendardata']; echo OC_Calendar_Export::export($event, OC_Calendar_Export::EVENT);
} }
?>

View File

@ -0,0 +1,56 @@
<?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
*/
class OC_Calendar_Export{
const CALENDAR = 'calendar';
const EVENT = 'event';
/*
* @brief export a calendar or an event
* @param (int) $id - id of calendar / event
* @param (const) $type - use OC_Calendar_Export constants
* @return (string)
*/
public static function export($id, $type){
if($type == self::EVENT){
$data = OC_Calendar_App::getEventObject($_GET['eventid'], false);
$return = $data['calendardata'];
}else{
$return = self::calendar($id);
}
return $return;
}
/*
* @brief export a calendar and convert all times to UTC
* @param (int) $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";
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){
$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();
}
$return .= "END:VCALENDAR";
return $return;
}
}