From 34d1f797778c71357989d793a6356ed9f8aeefed Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 20 May 2019 12:26:33 +0200 Subject: calendar merge: initial commit for timezone support --- Zotlabs/Module/Cdav.php | 50 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'Zotlabs/Module/Cdav.php') 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, -- cgit v1.2.3 From f96958adf84f7f2a45aa7860e52198f3de74f9e0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 21 May 2019 12:29:00 +0200 Subject: fix all day events for caldav calendars --- Zotlabs/Module/Cdav.php | 60 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'Zotlabs/Module/Cdav.php') diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index 275873db5..0c3450c70 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -274,9 +274,12 @@ class Cdav extends Controller { $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $allday = $_REQUEST['allday']; + $title = $_REQUEST['title']; $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); + if($_REQUEST['dtend']) { $end = datetime_convert($tz, 'UTC', $_REQUEST['dtend']); $dtend = new \DateTime($end); @@ -304,16 +307,23 @@ class Cdav extends Controller { 'DTSTART' => $dtstart ] ]); + if($dtend) { $vcalendar->VEVENT->add('DTEND', $dtend); - $vcalendar->VEVENT->DTEND['TZID'] = $tz; + if($allday) + $vcalendar->VEVENT->DTEND['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTEND['TZID'] = $tz; } if($description) $vcalendar->VEVENT->add('DESCRIPTION', $description); if($location) $vcalendar->VEVENT->add('LOCATION', $location); - $vcalendar->VEVENT->DTSTART['TZID'] = $tz; + if($allday) + $vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; $calendarData = $vcalendar->serialize(); @@ -354,6 +364,8 @@ class Cdav extends Controller { $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $allday = $_REQUEST['allday']; + $uri = $_REQUEST['uri']; $title = $_REQUEST['title']; $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); @@ -371,12 +383,23 @@ class Cdav extends Controller { if($title) $vcalendar->VEVENT->SUMMARY = $title; - if($dtstart) + if($dtstart) { $vcalendar->VEVENT->DTSTART = $dtstart; - if($dtend) + if($allday) + $vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; + } + if($dtend) { $vcalendar->VEVENT->DTEND = $dtend; + if($allday) + $vcalendar->VEVENT->DTEND['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTEND['TZID'] = $tz; + } else unset($vcalendar->VEVENT->DTEND); + if($description) $vcalendar->VEVENT->DESCRIPTION = $description; if($location) @@ -415,6 +438,8 @@ class Cdav extends Controller { $timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : ''); $tz = (($timezone) ? $timezone : date_default_timezone_get()); + $allday = $_REQUEST['allday']; + $uri = $_REQUEST['uri']; $start = datetime_convert($tz, 'UTC', $_REQUEST['dtstart']); $dtstart = new \DateTime($start); @@ -429,13 +454,20 @@ class Cdav extends Controller { if($dtstart) { $vcalendar->VEVENT->DTSTART = $dtstart; + if($allday) + $vcalendar->VEVENT->DTSTART['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTSTART['TZID'] = $tz; } if($dtend) { $vcalendar->VEVENT->DTEND = $dtend; + if($allday) + $vcalendar->VEVENT->DTEND['VALUE'] = 'DATE'; + else + $vcalendar->VEVENT->DTEND['TZID'] = $tz; } - else { + else unset($vcalendar->VEVENT->DTEND); - } $calendarData = $vcalendar->serialize(); @@ -1001,6 +1033,9 @@ class Cdav extends Controller { $title = ['title', t('Event title') ]; $dtstart = ['dtstart', t('Start date and time')]; $dtend = ['dtend', t('End date and time')]; + $timezone_select = ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()]; + $allday = ['allday', t('All day event'), '', '', [t('No'), t('Yes')]]; + $description = ['description', t('Description')]; $location = ['location', t('Location')]; @@ -1061,7 +1096,8 @@ class Cdav extends Controller { '$resource' => json_encode($resource), '$categories' => $categories, - '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()] : []) + '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? $timezone_select : ''), + '$allday' => $allday ]); @@ -1091,8 +1127,8 @@ class Cdav extends Controller { $filters['comp-filters'][0]['time-range']['end'] = $end; $uris = $caldavBackend->calendarQuery($id, $filters); - if($uris) { + $objects = $caldavBackend->getMultipleCalendarObjects($id, $uris); foreach($objects as $object) { @@ -1121,13 +1157,7 @@ class Cdav extends Controller { $timezone = $recurrent_timezone; } - $allDay = false; - - // allDay event rules - if(!strpos($dtstart, 'T') && !strpos($dtend, 'T')) - $allDay = true; - if(strpos($dtstart, 'T000000') && strpos($dtend, 'T000000')) - $allDay = true; + $allDay = (((string)$vevent->DTSTART['VALUE'] == 'DATE') ? true : false); $events[] = [ 'calendar_id' => $id, -- cgit v1.2.3 From e834c7fe3e421a7a52e27b274d8ea35bd2ad5bec Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 21 May 2019 12:31:50 +0200 Subject: remove unused code --- Zotlabs/Module/Cdav.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Zotlabs/Module/Cdav.php') diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index 0c3450c70..08d27c850 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -1034,7 +1034,6 @@ class Cdav extends Controller { $dtstart = ['dtstart', t('Start date and time')]; $dtend = ['dtend', t('End date and time')]; $timezone_select = ['timezone_select' , t('Timezone:'), date_default_timezone_get(), '', get_timezones()]; - $allday = ['allday', t('All day event'), '', '', [t('No'), t('Yes')]]; $description = ['description', t('Description')]; $location = ['location', t('Location')]; @@ -1096,9 +1095,7 @@ class Cdav extends Controller { '$resource' => json_encode($resource), '$categories' => $categories, - '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? $timezone_select : ''), - '$allday' => $allday - + '$timezone_select' => ((feature_enabled(local_channel(),'event_tz_select')) ? $timezone_select : '') ]); return $o; -- cgit v1.2.3 From 39613aa2d9298e13629b5b4a7c6b6f1bbe7edca5 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 22 May 2019 12:40:37 +0200 Subject: improve timezone detection for caldav and remove smart birthday feature. Force adjust birthdays until we agree on how to deal with this. --- Zotlabs/Module/Cdav.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module/Cdav.php') diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index 08d27c850..de639e281 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -1144,16 +1144,24 @@ class Cdav extends Controller { $dtend = (string)$vevent->DTEND; $description = (string)$vevent->DESCRIPTION; $location = (string)$vevent->LOCATION; - $timezone = (string)$vevent->DTSTART['TZID']; + $timezone_str = (string)$vevent->DTSTART['TZID']; $rw = ((cdav_perms($id[0],$calendars,true)) ? true : false); $editable = $rw ? true : false; $recurrent = ((isset($vevent->{'RECURRENCE-ID'})) ? true : false); if($recurrent) { $editable = false; - $timezone = $recurrent_timezone; + $timezone_str = $recurrent_timezone; } + // Try to get an usable olson format timezone + $timezone_obj = \Sabre\VObject\TimeZoneUtil::getTimeZone($timezone_str, $vcalendar); + $timezone = $timezone_obj->getName(); + + // If we got nothing fallback to UTC + if(! $timezone) + $timezone = 'UTC'; + $allDay = (((string)$vevent->DTSTART['VALUE'] == 'DATE') ? true : false); $events[] = [ -- cgit v1.2.3