2011-10-17 21:58:56 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2011 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.
|
|
|
|
*/
|
|
|
|
|
2011-11-13 01:02:04 +04:00
|
|
|
require_once ('../../../lib/base.php');
|
2012-02-23 18:37:38 +04:00
|
|
|
require_once('when/When.php');
|
2012-03-23 20:27:52 +04:00
|
|
|
$l = new OC_L10N('calendar');
|
|
|
|
$unnamed = $l->t('unnamed');
|
2012-02-18 00:39:54 +04:00
|
|
|
function create_return_event($event, $vevent){
|
|
|
|
$return_event = array();
|
2012-03-23 20:27:52 +04:00
|
|
|
global $unnamed;
|
2011-11-13 01:02:04 +04:00
|
|
|
$return_event['id'] = (int)$event['id'];
|
2012-03-23 20:27:52 +04:00
|
|
|
$return_event['title'] = htmlspecialchars(($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: $unnamed);
|
2012-02-02 18:01:05 +04:00
|
|
|
$return_event['description'] = isset($vevent->DESCRIPTION)?htmlspecialchars($vevent->DESCRIPTION->value):'';
|
2011-11-13 01:02:04 +04:00
|
|
|
$last_modified = $vevent->__get('LAST-MODIFIED');
|
|
|
|
if ($last_modified){
|
|
|
|
$lastmodified = $last_modified->getDateTime()->format('U');
|
|
|
|
}else{
|
|
|
|
$lastmodified = 0;
|
|
|
|
}
|
|
|
|
$return_event['lastmodified'] = (int)$lastmodified;
|
|
|
|
return $return_event;
|
2011-10-17 21:58:56 +04:00
|
|
|
}
|
2011-11-13 01:02:04 +04:00
|
|
|
|
|
|
|
OC_JSON::checkLoggedIn();
|
2011-10-17 21:58:56 +04:00
|
|
|
OC_JSON::checkAppEnabled('calendar');
|
|
|
|
|
2012-03-03 17:30:52 +04:00
|
|
|
if(version_compare(PHP_VERSION, '5.3.0', '>=')){
|
|
|
|
$start = DateTime::createFromFormat('U', $_GET['start']);
|
|
|
|
$end = DateTime::createFromFormat('U', $_GET['end']);
|
|
|
|
}else{
|
|
|
|
$start = new DateTime('@' . $_GET['start']);
|
|
|
|
$end = new DateTime('@' . $_GET['end']);
|
|
|
|
}
|
2011-10-17 21:58:56 +04:00
|
|
|
|
2012-03-01 23:51:59 +04:00
|
|
|
$calendar_id = $_GET['calendar_id'];
|
|
|
|
if (is_numeric($calendar_id)) {
|
|
|
|
$calendar = OC_Calendar_App::getCalendar($calendar_id);
|
|
|
|
OC_Response::enableCaching(0);
|
|
|
|
OC_Response::setETagHeader($calendar['ctag']);
|
|
|
|
$events = OC_Calendar_Object::allInPeriod($calendar_id, $start, $end);
|
|
|
|
} else {
|
|
|
|
$events = array();
|
|
|
|
OC_Hook::emit('OC_Calendar', 'getEvents', array('calendar_id' => $calendar_id, 'events' => &$events));
|
|
|
|
}
|
2012-02-18 00:39:54 +04:00
|
|
|
|
2011-12-01 00:08:42 +04:00
|
|
|
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
|
2011-10-17 21:58:56 +04:00
|
|
|
$return = array();
|
2011-11-13 01:02:04 +04:00
|
|
|
foreach($events as $event){
|
2012-03-01 23:51:59 +04:00
|
|
|
if (isset($event['calendardata'])) {
|
|
|
|
$object = OC_VObject::parse($event['calendardata']);
|
|
|
|
$vevent = $object->VEVENT;
|
|
|
|
} else {
|
|
|
|
$vevent = $event['vevent'];
|
|
|
|
}
|
2012-02-18 00:39:54 +04:00
|
|
|
|
|
|
|
$return_event = create_return_event($event, $vevent);
|
|
|
|
|
2011-10-17 21:58:56 +04:00
|
|
|
$dtstart = $vevent->DTSTART;
|
|
|
|
$start_dt = $dtstart->getDateTime();
|
2012-03-01 23:50:00 +04:00
|
|
|
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
|
2011-10-17 21:58:56 +04:00
|
|
|
$end_dt = $dtend->getDateTime();
|
2011-11-13 01:02:04 +04:00
|
|
|
if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
|
2011-10-17 21:58:56 +04:00
|
|
|
$return_event['allDay'] = true;
|
2011-10-22 00:47:31 +04:00
|
|
|
}else{
|
|
|
|
$return_event['allDay'] = false;
|
2012-02-08 01:49:23 +04:00
|
|
|
$start_dt->setTimezone(new DateTimeZone($user_timezone));
|
|
|
|
$end_dt->setTimezone(new DateTimeZone($user_timezone));
|
2011-10-17 21:58:56 +04:00
|
|
|
}
|
2012-02-18 00:39:54 +04:00
|
|
|
|
2011-11-13 01:02:04 +04:00
|
|
|
//Repeating Events
|
|
|
|
if($event['repeating'] == 1){
|
|
|
|
$duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
|
|
|
|
$r = new When();
|
2012-02-18 00:39:54 +04:00
|
|
|
$r->recur($start_dt)->rrule((string) $vevent->RRULE);
|
2011-11-13 01:02:04 +04:00
|
|
|
while($result = $r->next()){
|
2012-02-18 00:39:54 +04:00
|
|
|
if($result < $start){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if($result > $end){
|
2011-11-13 01:02:04 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if($return_event['allDay'] == true){
|
|
|
|
$return_event['start'] = $result->format('Y-m-d');
|
2011-12-25 18:07:53 +04:00
|
|
|
$return_event['end'] = date('Y-m-d', $result->format('U') + --$duration);
|
2011-11-13 01:02:04 +04:00
|
|
|
}else{
|
|
|
|
$return_event['start'] = $result->format('Y-m-d H:i:s');
|
|
|
|
$return_event['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration);
|
|
|
|
}
|
2012-02-18 00:39:54 +04:00
|
|
|
$return[] = $return_event;
|
2011-11-13 01:02:04 +04:00
|
|
|
}
|
2011-11-10 01:17:09 +04:00
|
|
|
}else{
|
2012-02-18 00:39:54 +04:00
|
|
|
if($return_event['allDay'] == true){
|
2011-11-13 01:02:04 +04:00
|
|
|
$return_event['start'] = $start_dt->format('Y-m-d');
|
|
|
|
$end_dt->modify('-1 sec');
|
|
|
|
$return_event['end'] = $end_dt->format('Y-m-d');
|
|
|
|
}else{
|
|
|
|
$return_event['start'] = $start_dt->format('Y-m-d H:i:s');
|
|
|
|
$return_event['end'] = $end_dt->format('Y-m-d H:i:s');
|
|
|
|
}
|
2012-02-18 00:39:54 +04:00
|
|
|
$return[] = $return_event;
|
2011-11-10 01:17:09 +04:00
|
|
|
}
|
2011-10-17 21:58:56 +04:00
|
|
|
}
|
|
|
|
OC_JSON::encodedPrint($return);
|
2012-02-18 00:39:54 +04:00
|
|
|
?>
|