diff options
author | Mario Vavti <mario@mariovavti.com> | 2019-05-20 12:26:33 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2019-05-20 12:26:33 +0200 |
commit | 34d1f797778c71357989d793a6356ed9f8aeefed (patch) | |
tree | 989446171dcd230aeac1f242323ec677a14ca53d | |
parent | aa120e0478b8a7e0eabcbd7b8d7eefd515ff5347 (diff) | |
download | volse-hubzilla-34d1f797778c71357989d793a6356ed9f8aeefed.tar.gz volse-hubzilla-34d1f797778c71357989d793a6356ed9f8aeefed.tar.bz2 volse-hubzilla-34d1f797778c71357989d793a6356ed9f8aeefed.zip |
calendar merge: initial commit for timezone support
-rw-r--r-- | Zotlabs/Module/Cdav.php | 50 | ||||
-rw-r--r-- | Zotlabs/Module/Channel_calendar.php | 73 | ||||
-rw-r--r-- | include/event.php | 15 | ||||
-rw-r--r-- | include/features.php | 16 | ||||
-rw-r--r-- | view/tpl/cdav_calendar.tpl | 17 |
5 files changed, 89 insertions, 82 deletions
diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index 6b4f57ea5..275873db5 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -271,11 +271,14 @@ class Cdav extends Controller { if(!cdav_perms($id[0],$calendars,true)) return; + $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); + $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $title = $_REQUEST['title']; - $start = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtstart']); + $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); if($_REQUEST['dtend']) { - $end = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtend']); + $end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']); $dtend = new \DateTime($end); } $description = $_REQUEST['description']; @@ -303,14 +306,14 @@ class Cdav extends Controller { ]); if($dtend) { $vcalendar->VEVENT->add('DTEND', $dtend); - $vcalendar->VEVENT->DTEND['TZID'] = App::$timezone; + $vcalendar->VEVENT->DTEND['TZID'] = $tz; } if($description) $vcalendar->VEVENT->add('DESCRIPTION', $description); if($location) $vcalendar->VEVENT->add('LOCATION', $location); - $vcalendar->VEVENT->DTSTART['TZID'] = App::$timezone; + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; $calendarData = $vcalendar->serialize(); @@ -348,12 +351,15 @@ class Cdav extends Controller { if(!cdav_perms($id[0],$calendars,true)) return; + $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); + $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $uri = $_REQUEST['uri']; $title = $_REQUEST['title']; - $start = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtstart']); + $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); if($_REQUEST['dtend']) { - $end = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtend']); + $end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']); $dtend = new \DateTime($end); } $description = $_REQUEST['description']; @@ -406,11 +412,14 @@ class Cdav extends Controller { if(!cdav_perms($id[0],$calendars,true)) return; + $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); + $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $uri = $_REQUEST['uri']; - $start = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtstart']); + $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); if($_REQUEST['dtend']) { - $end = datetime_convert(App::$timezone, 'UTC', $_REQUEST['dtend']); + $end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']); $dtend = new \DateTime($end); } @@ -915,8 +924,13 @@ class Cdav extends Controller { xchan_query($r); $r = fetch_post_tags($r,true); - $r[0]['dtstart'] = (($r[0]['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$r[0]['dtstart'], 'c') : datetime_convert('UTC','UTC',$r[0]['dtstart'],'c')); - $r[0]['dtend'] = (($r[0]['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$r[0]['dtend'], 'c') : datetime_convert('UTC','UTC',$r[0]['dtend'],'c')); + $tz = get_iconfig($r[0], 'event', 'timezone'); + if(! $tz) + $tz = 'UTC'; + + $r[0]['timezone'] = $tz; + $r[0]['dtstart'] = (($r[0]['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $r[0]['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $r[0]['dtstart'], 'c')); + $r[0]['dtend'] = (($r[0]['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $r[0]['dtend'], 'c') : datetime_convert('UTC', 'UTC' ,$r[0]['dtend'], 'c')); $r[0]['plink'] = [$r[0]['plink'], t('Link to source')]; @@ -984,7 +998,7 @@ class Cdav extends Controller { $first_day = feature_enabled(local_channel(), 'cal_first_day'); $first_day = (($first_day) ? $first_day : 0); - $title = ['title', t('Event title')]; + $title = ['title', t('Event title') ]; $dtstart = ['dtstart', t('Start date and time')]; $dtend = ['dtend', t('End date and time')]; $description = ['description', t('Description')]; @@ -1000,14 +1014,13 @@ class Cdav extends Controller { //$acl = (($orig_event['event_xchan']) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $perm_defaults), false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream'))); $acl = populate_acl($perm_defaults, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream')); - //$permissions = ((x($orig_event)) ? $orig_event : $perm_defaults); - $permissions = $perm_defaults; + $permissions = (($resource_id) ? $resource : $perm_defaults); $o .= replace_macros(get_markup_template('cdav_calendar.tpl'), [ '$sources' => $sources, '$color' => $color, '$lang' => App::$language, - '$timezone' => App::$timezone, + '$timezone' => date_default_timezone_get(), '$first_day' => $first_day, '$prev' => t('Previous'), '$next' => t('Next'), @@ -1047,7 +1060,9 @@ class Cdav extends Controller { '$categories_label' => t('Categories'), '$resource' => json_encode($resource), - '$categories' => $categories + '$categories' => $categories, + '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()] : []) + ]); return $o; @@ -1118,8 +1133,9 @@ class Cdav extends Controller { 'calendar_id' => $id, 'uri' => $object['uri'], 'title' => $title, - 'start' => datetime_convert($timezone, $timezone, $dtstart, 'c'), - 'end' => (($dtend) ? datetime_convert($timezone, $timezone, $dtend, 'c') : ''), + 'timezone' => $timezone, + 'start' => datetime_convert($timezone, date_default_timezone_get(), $dtstart, 'c'), + 'end' => (($dtend) ? datetime_convert($timezone, date_default_timezone_get(), $dtend, 'c') : ''), 'description' => $description, 'location' => $location, 'allDay' => $allDay, diff --git a/Zotlabs/Module/Channel_calendar.php b/Zotlabs/Module/Channel_calendar.php index 9229e6eb2..45f5870d0 100644 --- a/Zotlabs/Module/Channel_calendar.php +++ b/Zotlabs/Module/Channel_calendar.php @@ -22,52 +22,20 @@ class Channel_calendar extends \Zotlabs\Web\Controller { $xchan = ((x($_POST,'xchan')) ? dbesc($_POST['xchan']) : ''); $uid = local_channel(); - - $start_text = escape_tags($_REQUEST['dtstart']); - $finish_text = escape_tags($_REQUEST['dtend']); - - $adjust = intval($_POST['adjust']); - $nofinish = intval($_POST['nofinish']); - - $timezone = ((x($_POST,'timezone_select')) ? notags(trim($_POST['timezone_select'])) : ''); - - $tz = (($timezone) ? $timezone : date_default_timezone_get()); - $categories = escape_tags(trim($_POST['categories'])); - // only allow editing your own events. - if(($xchan) && ($xchan !== get_observer_hash())) return; - - if($start_text) { - $start = $start_text; - } - else { - $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute); - } - if($finish_text) { - $finish = $finish_text; - } - else { - $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute); - } + $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); + $tz = (($timezone) ? $timezone : date_default_timezone_get()); - if($nofinish) { - $finish = NULL_DATE; - } + $categories = escape_tags(trim($_POST['categories'])); + + $adjust = intval($_POST['adjust']); - if($adjust) { - $start = datetime_convert($tz,'UTC',$start); - if(! $nofinish) - $finish = datetime_convert($tz,'UTC',$finish); - } - else { - $start = datetime_convert('UTC','UTC',$start); - if(! $nofinish) - $finish = datetime_convert('UTC','UTC',$finish); - } + $start = (($adjust) ? datetime_convert($tz, 'UTC', escape_tags($_REQUEST['dtstart'])) : datetime_convert('UTC', 'UTC', escape_tags($_REQUEST['dtstart']))); + $finish = (($adjust) ? datetime_convert($tz, 'UTC', escape_tags($_REQUEST['dtend'])) : datetime_convert('UTC', 'UTC', escape_tags($_REQUEST['dtend']))); $summary = escape_tags(trim($_POST['summary'])); $desc = escape_tags(trim($_POST['desc'])); @@ -176,7 +144,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller { $datarray['location'] = $location; $datarray['etype'] = $type; $datarray['adjust'] = $adjust; - $datarray['nofinish'] = $nofinish; + $datarray['nofinish'] = 0; $datarray['uid'] = local_channel(); $datarray['account'] = get_account_id(); $datarray['event_xchan'] = $channel['channel_hash']; @@ -188,6 +156,8 @@ class Channel_calendar extends \Zotlabs\Web\Controller { $datarray['id'] = $event_id; $datarray['created'] = $created; $datarray['edited'] = $edited; + $datarray['timezone'] = $tz; + if(intval($_REQUEST['preview'])) { $html = format_event_html($datarray); @@ -322,10 +292,9 @@ class Channel_calendar extends \Zotlabs\Web\Controller { $start = datetime_convert('UTC','UTC',$start); $finish = datetime_convert('UTC','UTC',$finish); - $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); - + if (x($_GET,'id')){ $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan, item.id as item_id from event left join item on item.resource_id = event.event_hash @@ -347,23 +316,21 @@ class Channel_calendar extends \Zotlabs\Web\Controller { // Ultimately the finish date shouldn't be involved in the query. $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan, item.id as item_id - from event left join item on event.event_hash = item.resource_id - where item.resource_type = 'event' and event.uid = %d and event.uid = item.uid $ignored - AND (( event.adjust = 0 AND ( event.dtend >= '%s' or event.nofinish = 1 ) AND event.dtstart <= '%s' ) - OR ( event.adjust = 1 AND ( event.dtend >= '%s' or event.nofinish = 1 ) AND event.dtstart <= '%s' )) ", + from event left join item on event_hash = resource_id + where resource_type = 'event' and event.uid = %d and event.uid = item.uid $ignored + AND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) + OR ( adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish) ); - } if($r && ! $export) { xchan_query($r); $r = fetch_post_tags($r,true); - $r = sort_by_date($r); } @@ -373,11 +340,16 @@ class Channel_calendar extends \Zotlabs\Web\Controller { foreach($r as $rr) { - $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'c') : datetime_convert('UTC','UTC',$rr['dtstart'],'c')); + $tz = get_iconfig($rr, 'event', 'timezone'); + + if(! $tz) + $tz = 'UTC'; + + $start = (($rr['adjust']) ? datetime_convert($tz, date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c')); if ($rr['nofinish']){ $end = null; } else { - $end = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtend'], 'c') : datetime_convert('UTC','UTC',$rr['dtend'],'c')); + $end = (($rr['adjust']) ? datetime_convert($tz, date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c')); // give a fake end to birthdays so they get crammed into a // single day on the calendar @@ -416,6 +388,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller { 'rw' => true, 'id'=>$rr['id'], 'uri' => $rr['event_hash'], + 'timezone' => $tz, 'start'=> $start, 'end' => $end, 'drop' => $drop, diff --git a/include/event.php b/include/event.php index 471fb7afa..9bae69f5c 100644 --- a/include/event.php +++ b/include/event.php @@ -75,17 +75,19 @@ function format_event_obj($jobject) { //ensure compatibility with older items - this check can be removed at a later point if(array_key_exists('description', $object)) { + $tz = (($object['timezone']) ? $object['timezone'] : 'UTC'); + $bd_format = t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8:01 AM $event['header'] = replace_macros(get_markup_template('event_item_header.tpl'),array( '$title' => zidify_links(smilies(bbcode($object['title']))), '$dtstart_label' => t('Starts:'), - '$dtstart_title' => datetime_convert('UTC', 'UTC', $object['dtstart'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )), - '$dtstart_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtstart'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['dtstart'] , $bd_format))), + '$dtstart_title' => datetime_convert($tz, date_default_timezone_get(), $object['dtstart'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )), + '$dtstart_dt' => (($object['adjust']) ? day_translate(datetime_convert($tz, date_default_timezone_get(), $object['dtstart'] , $bd_format )) : day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtstart'] , $bd_format))), '$finish' => (($object['nofinish']) ? false : true), '$dtend_label' => t('Finishes:'), - '$dtend_title' => datetime_convert('UTC','UTC',$object['dtend'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )), - '$dtend_dt' => (($object['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtend'] , $bd_format )) : day_translate(datetime_convert('UTC', 'UTC', $object['dtend'] , $bd_format ))) + '$dtend_title' => datetime_convert($tz, date_default_timezone_get(), $object['dtend'], (($object['adjust']) ? ATOM_TIME : 'Y-m-d\TH:i:s' )), + '$dtend_dt' => (($object['adjust']) ? day_translate(datetime_convert($tz, date_default_timezone_get(), $object['dtend'] , $bd_format )) : day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtend'] , $bd_format ))) )); $event['content'] = replace_macros(get_markup_template('event_item_content.tpl'),array( @@ -1042,6 +1044,7 @@ function event_store_item($arr, $event) { 'type' => ACTIVITY_OBJ_EVENT, 'id' => z_root() . '/event/' . $r[0]['resource_id'], 'title' => $arr['summary'], + 'timezone' => $arr['timezone'], 'dtstart' => $arr['dtstart'], 'dtend' => $arr['dtend'], 'nofinish' => $arr['nofinish'], @@ -1107,6 +1110,8 @@ function event_store_item($arr, $event) { } $item_id = $r[0]['id']; + set_iconfig($item_id, 'event', 'timezone', $arr['timezone'], true); + /** * @hooks event_updated * Called when an event record is modified. @@ -1197,6 +1202,7 @@ function event_store_item($arr, $event) { 'type' => ACTIVITY_OBJ_EVENT, 'id' => z_root() . '/event/' . $event['event_hash'], 'title' => $arr['summary'], + 'timezone' => $arr['timezone'], 'dtstart' => $arr['dtstart'], 'dtend' => $arr['dtend'], 'nofinish' => $arr['nofinish'], @@ -1223,6 +1229,7 @@ function event_store_item($arr, $event) { // activities refer to the item message_id as the parent. set_iconfig($item_arr, 'system','event_id',$event['event_hash'],true); + set_iconfig($item_arr, 'event','timezone',$arr['timezone'],true); $res = item_store($item_arr); diff --git a/include/features.php b/include/features.php index d8607f447..431b199a5 100644 --- a/include/features.php +++ b/include/features.php @@ -87,6 +87,14 @@ function get_features($filtered = true, $level = (-1)) { t('Default is Sunday'), false, get_config('feature_lock','cal_first_day') + ], + + [ + 'event_tz_select', + t('Event Timezone Selection'), + t('Allow event creation in timezones other than your own.'), + false, + get_config('feature_lock','event_tz_select'), ] ], @@ -290,14 +298,6 @@ function get_features($filtered = true, $level = (-1)) { t('Make birthday events timezone aware in case your friends are scattered across the planet.'), true, get_config('feature_lock','smart_birthdays'), - ], - - [ - 'event_tz_select', - t('Event Timezone Selection'), - t('Allow event creation in timezones other than your own.'), - false, - get_config('feature_lock','event_tz_select'), ] ], diff --git a/view/tpl/cdav_calendar.tpl b/view/tpl/cdav_calendar.tpl index 22579227a..533c0add1 100644 --- a/view/tpl/cdav_calendar.tpl +++ b/view/tpl/cdav_calendar.tpl @@ -81,7 +81,6 @@ $(document).ready(function() { }, eventClick: function(info) { - //reset categories $('#id_categories').tagsinput('removeAll'); @@ -131,6 +130,8 @@ $(document).ready(function() { event_uri = event.extendedProps.uri; $('#id_title').val(event.title); $('#calendar_select').val(calendar_id).attr('disabled', true).trigger('change'); + $('#id_timezone_select').val(event.extendedProps.timezone); + $('#id_location').val(event.extendedProps.location); $('#id_categories').tagsinput('add', event.extendedProps.categories); $('#id_dtstart').val(dtstart.toUTCString()); $('#id_dtend').val(dtend.toUTCString()); @@ -183,7 +184,7 @@ $(document).ready(function() { var event = info.event._def; var dtstart = new Date(info.event._instance.range.start); var dtend = new Date(info.event._instance.range.end); - + $('#id_title').val(event.title); $('#id_dtstart').val(dtstart.toUTCString()); $('#id_dtend').val(dtend.toUTCString()); @@ -199,6 +200,7 @@ $(document).ready(function() { 'type': 'event', 'preview': 0, 'summary': event.title, + 'timezone_select': event.extendedProps.timezone, 'dtstart': dtstart.toUTCString(), 'dtend': dtend.toUTCString(), 'adjust': event.extendedProps.item.adjust, @@ -215,6 +217,7 @@ $(document).ready(function() { 'update': 'resize', 'id[]': event.extendedProps.calendar_id, 'uri': event.extendedProps.uri, + 'timezone_select': event.extendedProps.timezone, 'dtstart': dtstart ? dtstart.toUTCString() : '', 'dtend': dtend ? dtend.toUTCString() : '' }) @@ -245,6 +248,7 @@ $(document).ready(function() { 'type': 'event', 'preview': 0, 'summary': event.title, + 'timezone_select': event.extendedProps.timezone, 'dtstart': dtstart.toUTCString(), 'dtend': dtend.toUTCString(), 'adjust': event.extendedProps.item.adjust, @@ -261,6 +265,7 @@ $(document).ready(function() { 'update': 'drop', 'id[]': event.extendedProps.calendar_id, 'uri': event.extendedProps.uri, + 'timezone_select': event.extendedProps.timezone, 'dtstart': dtstart ? dtstart.toUTCString() : '', 'dtend': dtend ? dtend.toUTCString() : '' }) @@ -334,6 +339,7 @@ $(document).ready(function() { $('#id_categories').tagsinput('add', '{{$categories}}'), $('#id_description').val(resource.description); $('#id_location').val(resource.location); + $('#id_timezone_select').val(resource.timezone); if(event_xchan !== '{{$channel_hash}}') $('#event_submit').hide(); @@ -414,10 +420,11 @@ function on_submit() { 'xchan': event_xchan, 'type': 'event', 'preview': 0, + 'timezone_select': $('#id_timezone_select').val(), 'summary': $('#id_title').val(), 'dtstart': $('#id_dtstart').val(), 'dtend': $('#id_dtend').val(), - 'adjust': 0, + 'adjust': 1, 'categories': $('#id_categories').val(), 'desc': $('#id_description').val(), 'location': $('#id_location').val(), @@ -439,6 +446,7 @@ function on_submit() { $.post( 'cdav/calendar', { 'submit': $('#event_submit').val(), 'target': $('#calendar_select').val(), + 'timezone_select': $('#id_timezone_select').val(), 'uri': event_uri, 'title': $('#id_title').val(), 'dtstart': $('#id_dtstart').val(), @@ -569,6 +577,9 @@ function exportDate() { {{/foreach}} </optgroup> </select> + {{if $timezone_select}} + {{include file="field_select_grouped.tpl" field=$timezone_select}} + {{/if}} <div id="more_block" style="display: none;"> {{if $catsenabled}} <div id="id_categories_wrapper" class="form-group"> |