diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-03-19 08:33:36 +0100 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-03-19 08:33:36 +0100 |
commit | 33b06c448443bb0085ff986c341594d80903f43b (patch) | |
tree | e80977f084f5f149471995976edb4a01eee886a9 /apps/calendar | |
parent | 097ce76fc4383c68856ee70db0c87f0e9f5fefb4 (diff) | |
parent | de09883d860d6507a2d287d0b8bae394963c4b94 (diff) | |
download | nextcloud-server-33b06c448443bb0085ff986c341594d80903f43b.tar.gz nextcloud-server-33b06c448443bb0085ff986c341594d80903f43b.zip |
Merge branch 'master' into sabredav_1.6
Diffstat (limited to 'apps/calendar')
-rwxr-xr-x | apps/calendar/ajax/events.php | 33 | ||||
-rw-r--r-- | apps/calendar/ajax/import/import.php | 4 | ||||
-rw-r--r-- | apps/calendar/ajax/settings/getfirstday.php | 12 | ||||
-rwxr-xr-x | apps/calendar/ajax/settings/guesstimezone.php | 45 | ||||
-rw-r--r-- | apps/calendar/ajax/settings/setfirstday.php | 17 | ||||
-rw-r--r-- | apps/calendar/appinfo/app.php | 44 | ||||
-rw-r--r-- | apps/calendar/caldav.php | 2 | ||||
-rw-r--r-- | apps/calendar/index.php | 4 | ||||
-rw-r--r-- | apps/calendar/js/calendar.js | 7 | ||||
-rwxr-xr-x | apps/calendar/js/geo.js | 1 | ||||
-rw-r--r-- | apps/calendar/js/settings.js | 12 | ||||
-rw-r--r-- | apps/calendar/lib/calendar.php | 3 | ||||
-rw-r--r-- | apps/calendar/lib/hooks.php | 15 | ||||
-rw-r--r-- | apps/calendar/lib/object.php | 15 | ||||
-rw-r--r-- | apps/calendar/lib/search.php | 5 | ||||
-rwxr-xr-x | apps/calendar/templates/calendar.php | 1 | ||||
-rw-r--r-- | apps/calendar/templates/settings.php | 9 |
17 files changed, 142 insertions, 87 deletions
diff --git a/apps/calendar/ajax/events.php b/apps/calendar/ajax/events.php index 6ea556a7abf..dff02e15875 100755 --- a/apps/calendar/ajax/events.php +++ b/apps/calendar/ajax/events.php @@ -27,25 +27,40 @@ function create_return_event($event, $vevent){ OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); -$start = DateTime::createFromFormat('U', $_GET['start']); -$end = DateTime::createFromFormat('U', $_GET['end']); +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']); +} -$calendar = OC_Calendar_App::getCalendar($_GET['calendar_id']); -OC_Response::enableCaching(0); -OC_Response::setETagHeader($calendar['ctag']); +$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)); +} -$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end); $user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); $return = array(); foreach($events as $event){ - $object = OC_VObject::parse($event['calendardata']); - $vevent = $object->VEVENT; + if (isset($event['calendardata'])) { + $object = OC_VObject::parse($event['calendardata']); + $vevent = $object->VEVENT; + } else { + $vevent = $event['vevent']; + } $return_event = create_return_event($event, $vevent); $dtstart = $vevent->DTSTART; - $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $start_dt = $dtstart->getDateTime(); + $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); $end_dt = $dtend->getDateTime(); if ($dtstart->getDateType() == Sabre_VObject_Property_DateTime::DATE){ $return_event['allDay'] = true; diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php index 96d7af48341..c0797f6e425 100644 --- a/apps/calendar/ajax/import/import.php +++ b/apps/calendar/ajax/import/import.php @@ -11,7 +11,7 @@ require_once('../../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); $nl = "\n"; -$progressfile = OC::$SERVERROOT . '/apps/calendar/import_tmp/' . md5(session_id()) . '.txt'; +$progressfile = OC::$APPSROOT . '/apps/calendar/import_tmp/' . md5(session_id()) . '.txt'; if(is_writable('import_tmp/')){ $progressfopen = fopen($progressfile, 'w'); fwrite($progressfopen, '10'); @@ -117,4 +117,4 @@ sleep(3); if(is_writable('import_tmp/')){ unlink($progressfile); } -OC_JSON::success();
\ No newline at end of file +OC_JSON::success(); diff --git a/apps/calendar/ajax/settings/getfirstday.php b/apps/calendar/ajax/settings/getfirstday.php new file mode 100644 index 00000000000..cab5870509a --- /dev/null +++ b/apps/calendar/ajax/settings/getfirstday.php @@ -0,0 +1,12 @@ +<?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. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +$firstday = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstday', 'mo'); +OC_JSON::encodedPrint(array('firstday' => $firstday)); +?> diff --git a/apps/calendar/ajax/settings/guesstimezone.php b/apps/calendar/ajax/settings/guesstimezone.php index cfa92e1aee8..d45a70e1ce3 100755 --- a/apps/calendar/ajax/settings/guesstimezone.php +++ b/apps/calendar/ajax/settings/guesstimezone.php @@ -5,44 +5,23 @@ * later. * See the COPYING-README file. */ -function make_array_out_of_xml ($xml){ - $returnarray = array(); - $xml = (array)$xml ; - foreach ($xml as $property => $value){ - $value = (array)$value; - if(!isset($value[0])){ - $returnarray[$property] = make_array_out_of_xml($value); - }else{ - $returnarray[$property] = trim($value[0]); - } - } - return $returnarray; -} require_once('../../../../lib/base.php'); + OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('calendar'); + $l = new OC_L10N('calendar'); + $lat = $_GET['lat']; -$long = $_GET['long']; -if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'position') == $lat . '-' . $long && OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone') != null){ - OC_JSON::success(); - exit; -} -OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'position', $lat . '-' . $long); -$geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . '&lng=' . $long); -//Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License -$geoxml = simplexml_load_string($geolocation); -$geoarray = make_array_out_of_xml($geoxml); -if($geoarray['timezone']['timezoneId'] == OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone')){ +$lng = $_GET['long']; + +$timezone = OC_Geo::timezone($lat, $lng); + +if($timezone == OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone')){ OC_JSON::success(); exit; } -if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers())){ - OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']); - $message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']); - OC_JSON::success($message); -}else{ - OC_JSON::error(); -} - -?> +OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $timezone); +$message = array('message'=> $l->t('New Timezone:') . $timezone); +OC_JSON::success($message); +?>
\ No newline at end of file diff --git a/apps/calendar/ajax/settings/setfirstday.php b/apps/calendar/ajax/settings/setfirstday.php new file mode 100644 index 00000000000..3b652212205 --- /dev/null +++ b/apps/calendar/ajax/settings/setfirstday.php @@ -0,0 +1,17 @@ +<?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. + */ +require_once('../../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +if(isset($_POST["firstday"])){ + OC_Preferences::setValue(OC_User::getUser(), 'calendar', 'firstday', $_POST["firstday"]); + OC_JSON::success(); +}else{ + OC_JSON::error(); +} +?> + diff --git a/apps/calendar/appinfo/app.php b/apps/calendar/appinfo/app.php index 9c95768895f..f297c4d16d4 100644 --- a/apps/calendar/appinfo/app.php +++ b/apps/calendar/appinfo/app.php @@ -1,23 +1,23 @@ <?php -if(version_compare(PHP_VERSION, '5.3.0', '>=')){ - $l=new OC_L10N('calendar'); - OC::$CLASSPATH['OC_Calendar_App'] = 'apps/calendar/lib/app.php'; - OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php'; - OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php'; - OC::$CLASSPATH['OC_Calendar_Hooks'] = 'apps/calendar/lib/hooks.php'; - OC::$CLASSPATH['OC_Connector_Sabre_CalDAV'] = 'apps/calendar/lib/connector_sabre.php'; - OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); - OC_Util::addScript('calendar','loader'); - OC_App::register( array( - 'order' => 10, - 'id' => 'calendar', - 'name' => 'Calendar' )); - OC_App::addNavigationEntry( array( - 'id' => 'calendar_index', - 'order' => 10, - 'href' => OC_Helper::linkTo( 'calendar', 'index.php' ), - 'icon' => OC_Helper::imagePath( 'calendar', 'icon.svg' ), - 'name' => $l->t('Calendar'))); - OC_App::registerPersonal('calendar', 'settings'); - require_once('apps/calendar/lib/search.php'); -} +$l=new OC_L10N('calendar'); +OC::$CLASSPATH['OC_Calendar_App'] = 'apps/calendar/lib/app.php'; +OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php'; +OC::$CLASSPATH['OC_Calendar_Object'] = 'apps/calendar/lib/object.php'; +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_Search_Provider_Calendar'] = 'apps/calendar/lib/search.php'; +OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Calendar_Hooks', 'deleteUser'); +OC_Hook::connect('OC_DAV', 'initialize', 'OC_Calendar_Hooks', 'initializeCalDAV'); +OC_Util::addScript('calendar','loader'); +OC_App::register( array( + 'order' => 10, + 'id' => 'calendar', + 'name' => 'Calendar' )); +OC_App::addNavigationEntry( array( + 'id' => 'calendar_index', + 'order' => 10, + 'href' => OC_Helper::linkTo( 'calendar', 'index.php' ), + 'icon' => OC_Helper::imagePath( 'calendar', 'icon.svg' ), + 'name' => $l->t('Calendar'))); +OC_App::registerPersonal('calendar', 'settings'); +OC_Search::registerProvider('OC_Search_Provider_Calendar');
\ No newline at end of file diff --git a/apps/calendar/caldav.php b/apps/calendar/caldav.php index db0b35da118..b710b99ea43 100644 --- a/apps/calendar/caldav.php +++ b/apps/calendar/caldav.php @@ -25,7 +25,7 @@ $nodes = array( // Fire up server $server = new Sabre_DAV_Server($nodes); -$server->setBaseUri(OC::$WEBROOT.'/apps/calendar/caldav.php'); +$server->setBaseUri(OC::$APPSWEBROOT.'/apps/calendar/caldav.php'); // Add plugins $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud')); $server->addPlugin(new Sabre_CalDAV_Plugin()); diff --git a/apps/calendar/index.php b/apps/calendar/index.php index 12b51f564b4..c00a4098f7a 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -9,16 +9,20 @@ require_once ('../../lib/base.php'); OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); + // Create default calendar ... $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); if( count($calendars) == 0){ OC_Calendar_Calendar::addCalendar(OC_User::getUser(),'Default calendar'); $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); } + $eventSources = array(); foreach($calendars as $calendar){ $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar); } +OC_Hook::emit('OC_Calendar', 'getSources', array('sources' => &$eventSources)); + //Fix currentview for fullcalendar if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){ OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "agendaWeek"); diff --git a/apps/calendar/js/calendar.js b/apps/calendar/js/calendar.js index 84b76a3c88f..907d94edb02 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -73,6 +73,9 @@ Calendar={ } }, editEvent:function(calEvent, jsEvent, view){ + if (calEvent.editable == false || calEvent.source.editable == false) { + return; + } var id = calEvent.id; if($('#event').dialog('isOpen') == true){ // TODO: save event @@ -214,7 +217,7 @@ Calendar={ }, initScroll:function(){ if(window.addEventListener) - document.addEventListener('DOMMouseScroll', Calendar.UI.scrollCalendar); + document.addEventListener('DOMMouseScroll', Calendar.UI.scrollCalendar, false); //}else{ document.onmousewheel = Calendar.UI.scrollCalendar; //} @@ -661,7 +664,7 @@ $(document).ready(function(){ Calendar.UI.initScroll(); $('#calendar_holder').fullCalendar({ header: false, - firstDay: 1, + firstDay: firstDay, editable: true, defaultView: defaultView, timeFormat: { diff --git a/apps/calendar/js/geo.js b/apps/calendar/js/geo.js index c9cc5dd0955..7018c6298a2 100755 --- a/apps/calendar/js/geo.js +++ b/apps/calendar/js/geo.js @@ -10,7 +10,6 @@ if (navigator.geolocation) { function(data){ if (data.status == 'success' && typeof(data.message) != 'undefined'){ $('#notification').html(data.message); - $('#notification').attr('title', 'CC BY 3.0 by Geonames.org'); $('#notification').slideDown(); window.setTimeout(function(){$('#notification').slideUp();}, 5000); }else{ diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js index fcbfc423db3..c768a47a797 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -17,6 +17,14 @@ $(document).ready(function(){ } }); }); + $('#firstday').change( function(){ + var data = $('#firstday').serialize(); + $.post( OC.filePath('calendar', 'ajax/settings', 'setfirstday.php'), data, function(data){ + if(data == 'error'){ + console.log('saving firstday failed'); + } + }); + }); $('#timezonedetection').change( function(){ var post = $('#timezonedetection').serialize(); $.post( OC.filePath('calendar', 'ajax/settings', 'timezonedetection.php'), post, function(data){ @@ -32,4 +40,8 @@ $(document).ready(function(){ $('#timezonedetection').attr('checked', 'checked'); } }); + $.getJSON(OC.filePath('calendar', 'ajax/settings', 'getfirstday.php'), function(jsondata, status) { + $('#' + jsondata.firstday).attr('selected',true); + $('#firstday').chosen(); + }); }); diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 277539af97d..7eeb004d181 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -240,9 +240,10 @@ class OC_Calendar_Calendar{ '#9fc6e7', // "light blue" ); } + public static function getEventSourceInfo($calendar){ return array( - 'url' => 'ajax/events.php?calendar_id='.$calendar['id'], + 'url' => OC_Helper::linkTo('calendar', 'ajax/events.php').'?calendar_id='.$calendar['id'], 'backgroundColor' => $calendar['calendarcolor'], 'borderColor' => '#888', 'textColor' => 'black', diff --git a/apps/calendar/lib/hooks.php b/apps/calendar/lib/hooks.php index 14f96bb5fe1..54f1680a36e 100644 --- a/apps/calendar/lib/hooks.php +++ b/apps/calendar/lib/hooks.php @@ -17,11 +17,24 @@ class OC_Calendar_Hooks{ */ public static function deleteUser($parameters) { $calendars = OC_Calendar_Calendar::allCalendars($parameters['uid']); - + foreach($calendars as $calendar) { OC_Calendar_Calendar::deleteCalendar($calendar['id']); } return true; } + + /** + * @brief Adds the CardDAV resource to the DAV server + * @param paramters parameters from initialize-Hook + * @return array + */ + public static function initializeCalDAV($parameters){ + // We need a backend, the root node and the caldav plugin + $parameters['backends']['caldav'] = new OC_Connector_Sabre_CalDAV(); + $parameters['nodes'][] = new Sabre_CalDAV_CalendarRootNode($parameters['backends']['principal'], $parameters['backends']['caldav']); + $parameters['plugins'][] = new Sabre_CalDAV_Plugin(); + return true; + } } diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index 0b2cbb38157..a471aa84034 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -96,8 +96,7 @@ class OC_Calendar_Object{ list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object); if(is_null($uid)){ - $uid = self::createUID(); - $object->add('UID',$uid); + $object->setUID(); $data = $object->serialize(); } @@ -209,14 +208,6 @@ class OC_Calendar_Object{ } /** - * @brief Creates a UID - * @return string - */ - protected static function createUID(){ - return substr(md5(rand().time()),0,10); - } - - /** * @brief Extracts data from a vObject-Object * @param Sabre_VObject $object * @return array @@ -309,6 +300,8 @@ class OC_Calendar_Object{ $dtend = $vevent->DTEND; }else{ $dtend = clone $vevent->DTSTART; + // clone creates a shallow copy, also clone DateTime + $dtend->setDateTime(clone $dtend->getDateTime(), $dtend->getDateType()); if ($vevent->DURATION){ $duration = strval($vevent->DURATION); $invert = 0; @@ -817,4 +810,4 @@ class OC_Calendar_Object{ return $vcalendar; } -}
\ No newline at end of file +} diff --git a/apps/calendar/lib/search.php b/apps/calendar/lib/search.php index 79c8dba0f4d..10fc3f84346 100644 --- a/apps/calendar/lib/search.php +++ b/apps/calendar/lib/search.php @@ -1,6 +1,6 @@ <?php -class OC_Search_Provider_Calendar extends OC_Search_Provider{ - function search($query){ +class OC_Search_Provider_Calendar implements OC_Search_Provider{ + static function search($query){ $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); if(count($calendars)==0 || !OC_App::isEnabled('calendar')){ //return false; @@ -44,4 +44,3 @@ class OC_Search_Provider_Calendar extends OC_Search_Provider{ return $results; } } -new OC_Search_Provider_Calendar(); diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index eb82d0d02ad..63c3b500296 100755 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -19,6 +19,7 @@ var missing_field_startsbeforeends = '<?php echo addslashes($l->t('The event ends before it starts')) ?>'; var missing_field_dberror = '<?php echo addslashes($l->t('There was a database fail')) ?>'; var totalurl = '<?php echo OC_Helper::linkToAbsolute('calendar', 'caldav.php'); ?>/calendars'; + var firstDay = '<?php echo (OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'firstday', 'mo') == 'mo' ? '1' : '0'); ?>'; $(document).ready(function() { <?php if(array_key_exists('showevent', $_)){ diff --git a/apps/calendar/templates/settings.php b/apps/calendar/templates/settings.php index 979634874e4..fb2a04a6498 100644 --- a/apps/calendar/templates/settings.php +++ b/apps/calendar/templates/settings.php @@ -31,12 +31,19 @@ </select><input type="checkbox" name="timezonedetection" id="timezonedetection"><label for="timezonedetection"><?php echo $l->t('Check always for changes of the timezone'); ?></label></td></tr> <tr><td><label for="timeformat" class="bold"><?php echo $l->t('Timeformat');?></label></td><td> - <select style="display: none;" id="timeformat" title="<?php echo "timeformat"; ?>" name="timeformat"> + <select style="display: none; width: 60px;" id="timeformat" title="<?php echo "timeformat"; ?>" name="timeformat"> <option value="24" id="24h"><?php echo $l->t("24h"); ?></option> <option value="ampm" id="ampm"><?php echo $l->t("12h"); ?></option> </select> </td></tr> + <tr><td><label for="firstday" class="bold"><?php echo $l->t('First day of the week');?></label></td><td> + <select style="display: none;" id="firstday" title="<?php echo "First day"; ?>" name="firstday"> + <option value="mo" id="mo"><?php echo $l->t("Monday"); ?></option> + <option value="su" id="su"><?php echo $l->t("Sunday"); ?></option> + </select> + </td></tr> + </table> <?php echo $l->t('Calendar CalDAV syncing address:');?> |