From 26272c42525e63fedcf2b35d3d875fbec860eae1 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 11 Nov 2011 15:51:44 +0100 Subject: [PATCH] automatic timezone detection --- apps/calendar/ajax/guesstimezone.php | 39 ++++++++++++++++++++++++++++ apps/calendar/index.php | 5 +++- apps/calendar/js/geo.js | 20 ++++++++++++++ apps/calendar/templates/calendar.php | 37 +++++++++++++------------- 4 files changed, 82 insertions(+), 19 deletions(-) create mode 100755 apps/calendar/ajax/guesstimezone.php create mode 100755 apps/calendar/js/geo.js mode change 100644 => 100755 apps/calendar/templates/calendar.php diff --git a/apps/calendar/ajax/guesstimezone.php b/apps/calendar/ajax/guesstimezone.php new file mode 100755 index 00000000000..a3594498b0f --- /dev/null +++ b/apps/calendar/ajax/guesstimezone.php @@ -0,0 +1,39 @@ + + * This file is licensed under the Affero General Public License version 3 or + * 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']; +$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(isset($geoarray['timezone']['timezoneId']) && $geoarray['timezone']['timezoneId'] != ''){ + 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(); +} + +?> \ No newline at end of file diff --git a/apps/calendar/index.php b/apps/calendar/index.php index e5326d26e97..3313750d52e 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -32,6 +32,9 @@ if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'mont OC_Util::addScript('3rdparty/fullcalendar', 'fullcalendar'); OC_Util::addStyle('3rdparty/fullcalendar', 'fullcalendar'); +if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == null){ + OC_UTIL::addScript('calendar', 'geo'); +} OC_Util::addScript('calendar', 'calendar'); OC_Util::addStyle('calendar', 'style'); OC_Util::addScript('', 'jquery.multiselect'); @@ -39,4 +42,4 @@ OC_Util::addStyle('', 'jquery.multiselect'); OC_App::setActiveNavigationEntry('calendar_index'); $tmpl = new OC_Template('calendar', 'calendar', 'user'); $tmpl->assign('eventSources', $eventSources); -$tmpl->printPage(); +$tmpl->printPage(); \ No newline at end of file diff --git a/apps/calendar/js/geo.js b/apps/calendar/js/geo.js new file mode 100755 index 00000000000..acea17c0269 --- /dev/null +++ b/apps/calendar/js/geo.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2011 Georg Ehrke + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(function(position) { + $.getJSON(OC.filePath('calendar', 'ajax', 'guesstimezone.php?lat=' + position.coords.latitude + '&long=' + position.coords.longitude + ''), + function(data){ + if (data.status == 'success'){ + $('#notification').html(data.message); + $('#notification').slideDown(); + window.setTimeout(function(){$('#notification').slideUp();}, 5000); + }else{ + console.log('Can\'t set new timezone.'); + } + }); + }); +} \ No newline at end of file diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php old mode 100644 new mode 100755 index 0a6a7008fc1..6654568f5ad --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -1,21 +1,21 @@ - +
@@ -40,6 +40,7 @@ var missing_field_dberror = 't('There was a database fail') ?>';
+
-- 2.39.5