calendar merge: cleanup and comment out some unused code

This commit is contained in:
Mario Vavti 2019-05-09 13:43:20 +02:00
parent 44d5cf980a
commit 9efd484e27
5 changed files with 69 additions and 81 deletions

View File

@ -965,7 +965,7 @@ class Cdav extends Controller {
foreach($calendars as $calendar) { foreach($calendars as $calendar) {
$editable = (($calendar['share-access'] == 2) ? 'false' : 'true'); // false/true must be string since we're passing it to javascript $editable = (($calendar['share-access'] == 2) ? 'false' : 'true'); // false/true must be string since we're passing it to javascript
$color = (($calendar['{http://apple.com/ns/ical/}calendar-color']) ? $calendar['{http://apple.com/ns/ical/}calendar-color'] : '#3a87ad'); $color = (($calendar['{http://apple.com/ns/ical/}calendar-color']) ? $calendar['{http://apple.com/ns/ical/}calendar-color'] : '#6cad39');
$sharer = (($calendar['share-access'] == 3) ? $calendar['{urn:ietf:params:xml:ns:caldav}calendar-description'] : ''); $sharer = (($calendar['share-access'] == 3) ? $calendar['{urn:ietf:params:xml:ns:caldav}calendar-description'] : '');
$switch = get_pconfig(local_channel(), 'cdav_calendar', $calendar['id'][0]); $switch = get_pconfig(local_channel(), 'cdav_calendar', $calendar['id'][0]);
if($switch) { if($switch) {
@ -1398,12 +1398,13 @@ class Cdav extends Controller {
$caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo); $caldavBackend = new \Sabre\CalDAV\Backend\PDO($pdo);
$properties = [ $properties = [
'{DAV:}displayname' => t('Default Calendar'), '{DAV:}displayname' => t('Default Calendar'),
'{http://apple.com/ns/ical/}calendar-color' => '#3a87ad', '{http://apple.com/ns/ical/}calendar-color' => '#6cad39',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => $channel['channel_name'] '{urn:ietf:params:xml:ns:caldav}calendar-description' => $channel['channel_name']
]; ];
$id = $caldavBackend->createCalendar($uri, 'default', $properties); $id = $caldavBackend->createCalendar($uri, 'default', $properties);
set_pconfig(local_channel(), 'cdav_calendar' , $id[0], 1); set_pconfig(local_channel(), 'cdav_calendar' , $id[0], 1);
set_pconfig(local_channel(), 'cdav_calendar' , 'channel_calendar', 1);
//create default addressbook //create default addressbook
$carddavBackend = new \Sabre\CardDAV\Backend\PDO($pdo); $carddavBackend = new \Sabre\CardDAV\Backend\PDO($pdo);

View File

@ -72,8 +72,6 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$finish = NULL_DATE; $finish = NULL_DATE;
} }
if($adjust) { if($adjust) {
$start = datetime_convert($tz,'UTC',$start); $start = datetime_convert($tz,'UTC',$start);
if(! $nofinish) if(! $nofinish)
@ -86,13 +84,11 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
} }
// Don't allow the event to finish before it begins. // Don't allow the event to finish before it begins.
// It won't hurt anything, but somebody will file a bug report // It won't hurt anything, but somebody will file a bug report
// and we'll waste a bunch of time responding to it. Time that // and we'll waste a bunch of time responding to it. Time that
// could've been spent doing something else. // could've been spent doing something else.
$summary = escape_tags(trim($_POST['summary'])); $summary = escape_tags(trim($_POST['summary']));
$desc = escape_tags(trim($_POST['desc'])); $desc = escape_tags(trim($_POST['desc']));
$location = escape_tags(trim($_POST['location'])); $location = escape_tags(trim($_POST['location']));
@ -102,28 +98,20 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
linkify_tags($desc, local_channel()); linkify_tags($desc, local_channel());
linkify_tags($location, local_channel()); linkify_tags($location, local_channel());
//$action = ($event_hash == '') ? 'new' : "event/" . $event_hash;
//fixme: this url gives a wsod if there is a linebreak detected in one of the variables ($desc or $location)
//$onerror_url = z_root() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish&type=$type";
//$onerror_url = z_root() . "/events";
if(strcmp($finish,$start) < 0 && !$nofinish) { if(strcmp($finish,$start) < 0 && !$nofinish) {
notice( t('Event can not end before it has started.') . EOL); notice( t('Event can not end before it has started.') . EOL);
if(intval($_REQUEST['preview'])) { if(intval($_REQUEST['preview'])) {
echo( t('Unable to generate preview.')); echo( t('Unable to generate preview.'));
killme();
} }
//goaway($onerror_url); killme();
} }
if((! $summary) || (! $start)) { if((! $summary) || (! $start)) {
notice( t('Event title and start time are required.') . EOL); notice( t('Event title and start time are required.') . EOL);
if(intval($_REQUEST['preview'])) { if(intval($_REQUEST['preview'])) {
echo( t('Unable to generate preview.')); echo( t('Unable to generate preview.'));
killme();
} }
//goaway($onerror_url); killme();
} }
$channel = \App::get_channel(); $channel = \App::get_channel();
@ -275,8 +263,9 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$channel = \App::get_channel(); $channel = \App::get_channel();
$mode = 'view'; $mode = 'view';
$y = 0; $export = false;
$m = 0; //$y = 0;
//$m = 0;
$ignored = ((x($_REQUEST,'ignored')) ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : ''); $ignored = ((x($_REQUEST,'ignored')) ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '');
if(argc() > 1) { if(argc() > 1) {
@ -288,10 +277,13 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$mode = 'drop'; $mode = 'drop';
$event_id = argv(2); $event_id = argv(2);
} }
if(argc() <= 2 && argv(1) === 'export') {
$export = true;
}
if(argc() > 2 && intval(argv(1)) && intval(argv(2))) { if(argc() > 2 && intval(argv(1)) && intval(argv(2))) {
$mode = 'view'; $mode = 'view';
$y = intval(argv(1)); //$y = intval(argv(1));
$m = intval(argv(2)); //$m = intval(argv(2));
} }
if(argc() <= 2) { if(argc() <= 2) {
$mode = 'view'; $mode = 'view';
@ -318,6 +310,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$channel = \App::get_channel(); $channel = \App::get_channel();
/*
// Passed parameters overrides anything found in the DB // Passed parameters overrides anything found in the DB
if(!x($orig_event)) if(!x($orig_event))
$orig_event = array(); $orig_event = array();
@ -370,9 +363,6 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
if(! $m) if(! $m)
$m = intval($thismonth); $m = intval($thismonth);
$export = false;
if(argc() === 4 && argv(3) === 'export')
$export = true;
// Put some limits on dates. The PHP date functions don't seem to do so well before 1900. // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
// An upper limit was chosen to keep search engines from exploring links millions of years in the future. // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
@ -400,7 +390,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$dim = get_dim($y,$m); $dim = get_dim($y,$m);
$start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0); $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
$finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59); $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
*/
if (argv(1) === 'json'){ if (argv(1) === 'json'){
if (x($_GET,'start')) $start = $_GET['start']; if (x($_GET,'start')) $start = $_GET['start'];
@ -414,20 +404,16 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
if (x($_GET,'id')){ if (x($_GET,'id')){
$r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan $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 resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", from event left join item on item.resource_id = event.event_hash
where item.resource_type = 'event' and event.uid = %d and event.id = %d limit 1",
intval(local_channel()), intval(local_channel()),
intval($_GET['id']) intval($_GET['id'])
); );
} elseif($export) { }
$r = q("SELECT * from event where uid = %d elseif($export) {
AND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) $r = q("SELECT * from event where uid = %d",
OR ( adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) ", intval(local_channel())
intval(local_channel()),
dbesc($start),
dbesc($finish),
dbesc($adjust_start),
dbesc($adjust_finish)
); );
} }
else { else {
@ -437,10 +423,10 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
// Ultimately the finish date shouldn't be involved in the query. // 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 $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_hash = resource_id from event left join item on event.event_hash = item.resource_id
where resource_type = 'event' and event.uid = %d and event.uid = item.uid $ignored where item.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' ) AND (( event.adjust = 0 AND ( event.dtend >= '%s' or event.nofinish = 1 ) AND event.dtstart <= '%s' )
OR ( adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) ", OR ( event.adjust = 1 AND ( event.dtend >= '%s' or event.nofinish = 1 ) AND event.dtstart <= '%s' )) ",
intval(local_channel()), intval(local_channel()),
dbesc($start), dbesc($start),
dbesc($finish), dbesc($finish),
@ -448,10 +434,9 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
dbesc($adjust_finish) dbesc($adjust_finish)
); );
} }
$links = array(); //$links = [];
if($r && ! $export) { if($r && ! $export) {
xchan_query($r); xchan_query($r);
@ -460,6 +445,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$r = sort_by_date($r); $r = sort_by_date($r);
} }
/*
if($r) { if($r) {
foreach($r as $rr) { foreach($r as $rr) {
$j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'j') : datetime_convert('UTC','UTC',$rr['dtstart'],'j')); $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'j') : datetime_convert('UTC','UTC',$rr['dtstart'],'j'));
@ -467,18 +453,19 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j; $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
} }
} }
*/
$events=array(); $events = [];
$last_date = ''; //$last_date = '';
$fmt = t('l, F j'); //$fmt = t('l, F j');
if($r) { if($r) {
foreach($r as $rr) { foreach($r as $rr) {
$j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'j') : datetime_convert('UTC','UTC',$rr['dtstart'],'j')); //$j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'j') : datetime_convert('UTC','UTC',$rr['dtstart'],'j'));
$d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], $fmt) : datetime_convert('UTC','UTC',$rr['dtstart'],$fmt)); //$d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], $fmt) : datetime_convert('UTC','UTC',$rr['dtstart'],$fmt));
$d = day_translate($d); //$d = day_translate($d);
$start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'c') : datetime_convert('UTC','UTC',$rr['dtstart'],'c')); $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['dtstart'], 'c') : datetime_convert('UTC','UTC',$rr['dtstart'],'c'));
if ($rr['nofinish']){ if ($rr['nofinish']){
@ -514,23 +501,23 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
if(strpos($start, 'T00:00:00') && strpos($end, 'T00:00:00')) if(strpos($start, 'T00:00:00') && strpos($end, 'T00:00:00'))
$allDay = true; $allDay = true;
$is_first = ($d !== $last_date); //$is_first = ($d !== $last_date);
$last_date = $d; //$last_date = $d;
$edit = ((local_channel() && $rr['author_xchan'] == get_observer_hash()) ? array(z_root().'/events/'.$rr['event_hash'].'?expandform=1',t('Edit event'),'','') : false); $edit = ((local_channel() && $rr['author_xchan'] == get_observer_hash()) ? array(z_root().'/events/'.$rr['event_hash'].'?expandform=1',t('Edit event'),'','') : false);
$drop = array(z_root().'/events/drop/'.$rr['event_hash'],t('Delete event'),'',''); $drop = array(z_root().'/events/drop/'.$rr['event_hash'],t('Delete event'),'','');
$title = strip_tags(html_entity_decode(zidify_links(bbcode($rr['summary'])),ENT_QUOTES,'UTF-8')); //$title = strip_tags(html_entity_decode(zidify_links(bbcode($rr['summary'])),ENT_QUOTES,'UTF-8'));
if(! $title) { //if(! $title) {
list($title, $_trash) = explode("<br",bbcode($rr['desc']),2); // list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);
$title = strip_tags(html_entity_decode($title,ENT_QUOTES,'UTF-8')); // $title = strip_tags(html_entity_decode($title,ENT_QUOTES,'UTF-8'));
} //}
$html = format_event_html($rr); //$html = format_event_html($rr);
$rr['desc'] = zidify_links(smilies(bbcode($rr['desc']))); //$rr['desc'] = zidify_links(smilies(bbcode($rr['desc'])));
$rr['description'] = htmlentities(html2plain(bbcode($rr['description'])),ENT_COMPAT,'UTF-8',false); //$rr['description'] = htmlentities(html2plain(bbcode($rr['description'])),ENT_COMPAT,'UTF-8',false);
$rr['location'] = zidify_links(smilies(bbcode($rr['location']))); //$rr['location'] = zidify_links(smilies(bbcode($rr['location'])));
$events[] = array( $events[] = array(
'calendar_id' => 'channel_calendar', 'calendar_id' => 'channel_calendar',
'rw' => true, 'rw' => true,
@ -541,20 +528,20 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
'end' => $end, 'end' => $end,
'drop' => $drop, 'drop' => $drop,
'allDay' => $allDay, 'allDay' => $allDay,
'title' => $title, 'title' => htmlentities($rr['summary'], ENT_COMPAT, 'UTF-8'),
'j' => $j, //'j' => $j,
'd' => $d, //'d' => $d,
'editable' => $edit ? true : false, 'editable' => $edit ? true : false,
'is_first'=>$is_first, //'is_first'=>$is_first,
'item'=>$rr, 'item'=>$rr,
'html'=>$html, //'html'=>$html,
'plink' => [$rr['plink'], t('Link to source')], 'plink' => [$rr['plink'], t('Link to source')],
'description' => $rr['description'], 'description' => htmlentities($rr['description'], ENT_COMPAT, 'UTF-8'),
'location' => $rr['location'], 'location' => htmlentities($rr['location'], ENT_COMPAT, 'UTF-8'),
'allow_cid' => expand_acl($rr['allow_cid']), 'allow_cid' => expand_acl($rr['allow_cid']),
'allow_gid' => expand_acl($rr['allow_gid']), 'allow_gid' => expand_acl($rr['allow_gid']),

View File

@ -57,7 +57,7 @@ class Cdav {
$switch = get_pconfig(local_channel(), 'cdav_calendar', $sabrecal['id'][0]); $switch = get_pconfig(local_channel(), 'cdav_calendar', $sabrecal['id'][0]);
$color = (($sabrecal['{http://apple.com/ns/ical/}calendar-color']) ? $sabrecal['{http://apple.com/ns/ical/}calendar-color'] : '#3a87ad'); $color = (($sabrecal['{http://apple.com/ns/ical/}calendar-color']) ? $sabrecal['{http://apple.com/ns/ical/}calendar-color'] : '#6cad39');
$editable = (($sabrecal['share-access'] == 2) ? 'false' : 'true'); // false/true must be string since we're passing it to javascript $editable = (($sabrecal['share-access'] == 2) ? 'false' : 'true'); // false/true must be string since we're passing it to javascript

View File

@ -1163,7 +1163,7 @@ function event_store_item($arr, $event) {
$item_arr['item_thread_top'] = $item_thread_top; $item_arr['item_thread_top'] = $item_thread_top;
$attach = array(array( $attach = array(array(
'href' => z_root() . '/events/ical/' . urlencode($event['event_hash']), 'href' => z_root() . '/channel_calendar/ical/' . urlencode($event['event_hash']),
'length' => 0, 'length' => 0,
'type' => 'text/calendar', 'type' => 'text/calendar',
'title' => t('event') . '-' . $event['event_hash'], 'title' => t('event') . '-' . $event['event_hash'],

View File

@ -63,6 +63,11 @@ $(document).ready(function() {
event_uri = ''; event_uri = '';
$('#id_title').val('New event'); $('#id_title').val('New event');
$('#id_title').attr('disabled', false);
$('#id_dtstart').attr('disabled', false);
$('#id_dtend').attr('disabled', false);
$('#id_description').attr('disabled', false);
$('#id_location').attr('disabled', false);
$('#calendar_select').val($("#calendar_select option:first").val()).attr('disabled', false); $('#calendar_select').val($("#calendar_select option:first").val()).attr('disabled', false);
$('#id_dtstart').val(info.date.toUTCString()); $('#id_dtstart').val(info.date.toUTCString());
$('#id_dtend').val(dtend ? dtend.toUTCString() : ''); $('#id_dtend').val(dtend ? dtend.toUTCString() : '');
@ -102,6 +107,11 @@ $(document).ready(function() {
$('.section-content-tools-wrapper, #event_form_wrapper').show(); $('.section-content-tools-wrapper, #event_form_wrapper').show();
$('#recurrence_warning').hide(); $('#recurrence_warning').hide();
$('#id_title').focus().val(''); $('#id_title').focus().val('');
$('#id_title').attr('disabled', false);
$('#id_dtstart').attr('disabled', false);
$('#id_dtend').attr('disabled', false);
$('#id_description').attr('disabled', false);
$('#id_location').attr('disabled', false);
return false; return false;
} }
@ -186,7 +196,6 @@ $(document).ready(function() {
'event_id': event_id, 'event_id': event_id,
'event_hash': event_uri, 'event_hash': event_uri,
'xchan': event_xchan, 'xchan': event_xchan,
//'mid': mid,
'type': 'event', 'type': 'event',
'preview': 0, 'preview': 0,
'summary': event.title, 'summary': event.title,
@ -196,7 +205,6 @@ $(document).ready(function() {
'categories': event.extendedProps.categories, 'categories': event.extendedProps.categories,
'desc': event.extendedProps.description, 'desc': event.extendedProps.description,
'location': event.extendedProps.location, 'location': event.extendedProps.location,
//'submit': $('#event_submit').val()
}) })
.fail(function() { .fail(function() {
info.revert(); info.revert();
@ -234,7 +242,6 @@ $(document).ready(function() {
'event_id': event_id, 'event_id': event_id,
'event_hash': event_uri, 'event_hash': event_uri,
'xchan': event_xchan, 'xchan': event_xchan,
//'mid': mid,
'type': 'event', 'type': 'event',
'preview': 0, 'preview': 0,
'summary': event.title, 'summary': event.title,
@ -244,7 +251,6 @@ $(document).ready(function() {
'categories': event.extendedProps.categories, 'categories': event.extendedProps.categories,
'desc': event.extendedProps.description, 'desc': event.extendedProps.description,
'location': event.extendedProps.location, 'location': event.extendedProps.location,
//'submit': $('#event_submit').val()
}) })
.fail(function() { .fail(function() {
info.revert(); info.revert();
@ -406,7 +412,6 @@ function on_submit() {
'event_id': event_id, 'event_id': event_id,
'event_hash': event_uri, 'event_hash': event_uri,
'xchan': event_xchan, 'xchan': event_xchan,
//'mid': mid,
'type': 'event', 'type': 'event',
'preview': 0, 'preview': 0,
'summary': $('#id_title').val(), 'summary': $('#id_title').val(),
@ -416,7 +421,6 @@ function on_submit() {
'categories': $('#id_categories').val(), 'categories': $('#id_categories').val(),
'desc': $('#id_description').val(), 'desc': $('#id_description').val(),
'location': $('#id_location').val(), 'location': $('#id_location').val(),
//'submit': $('#event_submit').val(),
'contact_allow[]': contact_allow, 'contact_allow[]': contact_allow,
'group_allow[]': group_allow, 'group_allow[]': group_allow,
'contact_deny[]': contact_deny, 'contact_deny[]': contact_deny,
@ -508,11 +512,7 @@ function on_more() {
} }
function exportDate() { function exportDate() {
alert('not implemented'); window.location.href= 'channel_calendar/export';
console.log('not implemented');
//var moment = $('#events-calendar').fullCalendar('getDate');
//var sT = 'events/' + moment.year() + '/' + (moment.month() + 1) + '/export';
//window.location.href=sT;
} }
</script> </script>