From a4caaefd32ca68f45f7526dde61d17e8ca3dc3af Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 19 Aug 2015 16:50:32 -0700 Subject: event integration improvements --- mod/events.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'mod/events.php') diff --git a/mod/events.php b/mod/events.php index c2bacfe44..08527b930 100755 --- a/mod/events.php +++ b/mod/events.php @@ -8,7 +8,7 @@ require_once('include/items.php'); function events_post(&$a) { - logger('post: ' . print_r($_REQUEST,true)); + logger('post: ' . print_r($_REQUEST,true), LOGGER_DATA); if(! local_channel()) return; @@ -282,6 +282,10 @@ function events_content(&$a) { $mode = 'edit'; $event_id = argv(2); } + if(argc() > 2 && argv(1) == 'ical') { + $mode = 'ical'; + $event_id = argv(2); + } if(argc() > 2 && argv(1) === 'add') { $mode = 'add'; $item_id = intval(argv(2)); @@ -306,6 +310,26 @@ function events_content(&$a) { killme(); } + + if($mode === 'ical') { + $r = q("select * from event where event_hash = '%s' and uid = %d limit 1", + dbesc($event_id), + intval(local_channel()) + ); + if($r) { + header('Content-type: text/calendar'); + header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"' ); + echo ical_wrapper($r); + killme(); + } + else { + notice( t('Event not found.') . EOL ); + return; + } + } + + + if($mode == 'view') { -- cgit v1.2.3 From 863a9797544a80671c179355ff31c73032e88fb7 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 19 Aug 2015 17:16:19 -0700 Subject: check perms on ical attachments --- mod/events.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'mod/events.php') diff --git a/mod/events.php b/mod/events.php index 08527b930..7894f960b 100755 --- a/mod/events.php +++ b/mod/events.php @@ -312,9 +312,12 @@ function events_content(&$a) { if($mode === 'ical') { - $r = q("select * from event where event_hash = '%s' and uid = %d limit 1", - dbesc($event_id), - intval(local_channel()) + + require_once('include/security.php'); + $sql_extra = permissions_sql(local_channel()); + + $r = q("select * from event where event_hash = '%s' $sql_extra limit 1", + dbesc($event_id) ); if($r) { header('Content-type: text/calendar'); -- cgit v1.2.3 From a322254f2aa02f662667eeb0bdd4e8646cd029c2 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 20 Aug 2015 04:51:03 -0700 Subject: do ical export before checking logged in channel --- mod/events.php | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'mod/events.php') diff --git a/mod/events.php b/mod/events.php index 7894f960b..630b8191f 100755 --- a/mod/events.php +++ b/mod/events.php @@ -228,6 +228,27 @@ function events_post(&$a) { function events_content(&$a) { + if(argc() > 2 && argv(1) == 'ical') { + $event_id = argv(2); + + require_once('include/security.php'); + $sql_extra = permissions_sql(local_channel()); + + $r = q("select * from event where event_hash = '%s' $sql_extra limit 1", + dbesc($event_id) + ); + if($r) { + header('Content-type: text/calendar'); + header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"' ); + echo ical_wrapper($r); + killme(); + } + else { + notice( t('Event not found.') . EOL ); + return; + } + } + if(! local_channel()) { notice( t('Permission denied.') . EOL); return; @@ -282,10 +303,6 @@ function events_content(&$a) { $mode = 'edit'; $event_id = argv(2); } - if(argc() > 2 && argv(1) == 'ical') { - $mode = 'ical'; - $event_id = argv(2); - } if(argc() > 2 && argv(1) === 'add') { $mode = 'add'; $item_id = intval(argv(2)); @@ -311,25 +328,6 @@ function events_content(&$a) { } - if($mode === 'ical') { - - require_once('include/security.php'); - $sql_extra = permissions_sql(local_channel()); - - $r = q("select * from event where event_hash = '%s' $sql_extra limit 1", - dbesc($event_id) - ); - if($r) { - header('Content-type: text/calendar'); - header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"' ); - echo ical_wrapper($r); - killme(); - } - else { - notice( t('Event not found.') . EOL ); - return; - } - } -- cgit v1.2.3 From 6590ca02de462acd141e1f890aff36877adafa80 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 20 Aug 2015 16:49:13 -0700 Subject: some event related fixes and some base work for implementing native tasks (to-do lists); which should already be importable and exportable. --- mod/events.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'mod/events.php') diff --git a/mod/events.php b/mod/events.php index 630b8191f..56c4ece54 100755 --- a/mod/events.php +++ b/mod/events.php @@ -89,14 +89,14 @@ function events_post(&$a) { $summary = escape_tags(trim($_POST['summary'])); $desc = escape_tags(trim($_POST['desc'])); $location = escape_tags(trim($_POST['location'])); - $type = 'event'; + $type = escape_tags(trim($_POST['type'])); require_once('include/text.php'); linkify_tags($a, $desc, local_channel()); linkify_tags($a, $location, local_channel()); $action = ($event_hash == '') ? 'new' : "event/" . $event_hash; - $onerror_url = $a->get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish"; + $onerror_url = $a->get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish&type=$type"; if(strcmp($finish,$start) < 0 && !$nofinish) { notice( t('Event can not end before it has started.') . EOL); if(intval($_REQUEST['preview'])) { @@ -400,7 +400,7 @@ function events_content(&$a) { $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan from event left join item on event_hash = resource_id - where resource_type = 'event' and event.uid = %d $ignored + where resource_type in ( 'event', 'birthday' ) and event.uid = %d $ignored AND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) OR ( `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", intval(local_channel()), @@ -409,7 +409,6 @@ function events_content(&$a) { dbesc($adjust_start), dbesc($adjust_finish) ); - } $links = array(); @@ -572,9 +571,7 @@ function events_content(&$a) { if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; if(x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; if(x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; - } - - if($mode === 'edit' || $mode === 'new') { + if(x($_REQUEST,'type')) $orig_event['type'] = $_REQUEST['type']; $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); @@ -593,9 +590,6 @@ function events_content(&$a) { if($orig_event['event_xchan']) $sh_checked .= ' disabled="disabled" '; - - - $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); @@ -621,6 +615,7 @@ function events_content(&$a) { $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0); $ftext = datetime_convert('UTC',$tz,$fdt); $ftext = substr($ftext,0,14) . "00:00"; + $type = ((x($orig_event)) ? $orig_event['type'] : 'event'); $f = get_config('system','event_input_format'); if(! $f) @@ -660,6 +655,7 @@ function events_content(&$a) { $o .= replace_macros($tpl,array( '$post' => $a->get_baseurl() . '/events', '$eid' => $eid, + '$type' => $type, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, -- cgit v1.2.3 From afbbc9cd72e48a9eb4fb035eb01cd6e742d0088e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 20 Aug 2015 18:43:01 -0700 Subject: more work on tasks --- mod/events.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'mod/events.php') diff --git a/mod/events.php b/mod/events.php index 56c4ece54..15fed9df2 100755 --- a/mod/events.php +++ b/mod/events.php @@ -391,8 +391,18 @@ function events_content(&$a) { intval(local_channel()), intval($_GET['id']) ); - } else { - + } elseif($export) { + $r = q("SELECT * from event where uid = %d + AND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) + OR ( `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", + intval(local_channel()), + dbesc($start), + dbesc($finish), + dbesc($adjust_start), + dbesc($adjust_finish) + ); + } + else { // fixed an issue with "nofinish" events not showing up in the calendar. // There's still an issue if the finish date crosses the end of month. // Noting this for now - it will need to be fixed here and in Friendica. @@ -400,7 +410,7 @@ function events_content(&$a) { $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan from event left join item on event_hash = resource_id - where resource_type in ( 'event', 'birthday' ) and event.uid = %d $ignored + where resource_type = 'event' and event.uid = %d $ignored AND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) OR ( `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", intval(local_channel()), @@ -411,14 +421,17 @@ function events_content(&$a) { ); } + $links = array(); - if($r) { + if($r && ! $export) { xchan_query($r); $r = fetch_post_tags($r,true); $r = sort_by_date($r); + } + if($r) { foreach($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); if(! x($links,$j)) @@ -426,7 +439,6 @@ function events_content(&$a) { } } - $events=array(); $last_date = ''; -- cgit v1.2.3