2012-06-03 16:54:53 +04:00
|
|
|
<?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
|
2012-06-28 00:27:48 +04:00
|
|
|
* @param integer $id id of calendar / event
|
|
|
|
* @param string $type use OC_Calendar_Export constants
|
|
|
|
* @return string
|
2012-06-03 16:54:53 +04:00
|
|
|
*/
|
|
|
|
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
|
2012-06-28 00:27:48 +04:00
|
|
|
* @param integer $id id of the calendar
|
|
|
|
* @return string
|
2012-06-03 16:54:53 +04:00
|
|
|
*/
|
|
|
|
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){
|
2012-06-04 14:28:05 +04:00
|
|
|
$object->VEVENT->DTSTART->offsetUnset('VALUE');
|
|
|
|
$object->VEVENT->DTEND->offsetUnset('VALUE');
|
2012-06-03 16:54:53 +04:00
|
|
|
}
|
|
|
|
$return .= $object->VEVENT->serialize();
|
|
|
|
}
|
|
|
|
$return .= "END:VCALENDAR";
|
2012-06-28 18:41:00 +04:00
|
|
|
$return = str_replace("\r\n", "\n", $return);
|
|
|
|
$return = str_replace("\r", "\n", $return);
|
|
|
|
$return = str_replace("\n", "\r\n", $return);
|
2012-06-03 16:54:53 +04:00
|
|
|
return $return;
|
|
|
|
}
|
2012-06-04 14:28:05 +04:00
|
|
|
}
|