From c95d7c69eb3135f137390323a09eb105776ce29c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 24 Feb 2016 18:54:52 -0800 Subject: issue #216 - calendar sharing --- mod/cal.php | 343 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 343 insertions(+) create mode 100755 mod/cal.php (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php new file mode 100755 index 000000000..9899b33b0 --- /dev/null +++ b/mod/cal.php @@ -0,0 +1,343 @@ + 1) { + $nick = argv(1); + + profile_load($a,$nick); + + $channelx = channelx_by_nick($nick); + + if(! $channelx) + return; + + $a->data['channel'] = $channelx; + + $observer = $a->get_observer(); + $a->data['observer'] = $observer; + + $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); + + head_set_icon($a->data['channel']['xchan_photo_s']); + + $a->page['htmlhead'] .= "" ; + + } + + return; +} + + + +function cal_content(&$a) { + + $channel = null; + + if(argc() > 1) { + $channel = channelx_by_nick(argv(1)); + } + + + if(! $channel) { + notice( t('Channel not found.') . EOL); + return; + } + + // since we don't currently have an event permission - use the stream permission + + if(! perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_stream')) { + notice( t('Permissions denied.') . EOL); + return; + } + + $sql_extra = permissions_sql($channel['channel_id'],get_observer_hash(),'event'); + + $first_day = get_pconfig(local_channel(),'system','cal_first_day'); + $first_day = (($first_day) ? $first_day : 0); + + $htpl = get_markup_template('event_head.tpl'); + $a->page['htmlhead'] .= replace_macros($htpl,array( + '$baseurl' => $a->get_baseurl(), + '$module_url' => '/cal/' . $channel['channel_address'], + '$modparams' => 2, + '$lang' => $a->language, + '$first_day' => $first_day + )); + + $o = ''; + + $mode = 'view'; + $y = 0; + $m = 0; + $ignored = ((x($_REQUEST,'ignored')) ? " and ignored = " . intval($_REQUEST['ignored']) . " " : ''); + +logger('args: ' . print_r($a->argv,true)); + + if(argc() > 3 && intval(argv(2)) && intval(argv(3))) { + $mode = 'view'; + $y = intval(argv(2)); + $m = intval(argv(3)); + } + if(argc() <= 3) { + $mode = 'view'; + $event_id = argv(2); + } + + if($mode == 'view') { + + /* edit/create form */ + if($event_id) { + $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", + dbesc($event_id), + intval($channel['channel_id']) + ); + if(count($r)) + $orig_event = $r[0]; + } + + + // Passed parameters overrides anything found in the DB + if(!x($orig_event)) + $orig_event = array(); + + + + $tz = date_default_timezone_get(); + if(x($orig_event)) + $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); + + $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); + $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); + $sday = datetime_convert('UTC', $tz, $sdt, 'd'); + $shour = datetime_convert('UTC', $tz, $sdt, 'H'); + $sminute = datetime_convert('UTC', $tz, $sdt, 'i'); + + $stext = datetime_convert('UTC',$tz,$sdt); + $stext = substr($stext,0,14) . "00:00"; + + $fyear = datetime_convert('UTC', $tz, $fdt, 'Y'); + $fmonth = datetime_convert('UTC', $tz, $fdt, 'm'); + $fday = datetime_convert('UTC', $tz, $fdt, 'd'); + $fhour = datetime_convert('UTC', $tz, $fdt, 'H'); + $fminute = datetime_convert('UTC', $tz, $fdt, 'i'); + + $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) + $f = 'ymd'; + + $catsenabled = feature_enabled($channel['channel_id'],'categories'); + + + $show_bd = perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_contacts'); + if(! $show_bd) { + $sql_extra .= " and event.type != 'birthday' "; + } + + + $category = ''; + + $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); + $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); + if(! $y) + $y = intval($thisyear); + if(! $m) + $m = intval($thismonth); + + // 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. + + if($y < 1901) + $y = 1900; + if($y > 2099) + $y = 2100; + + $nextyear = $y; + $nextmonth = $m + 1; + if($nextmonth > 12) { + $nextmonth = 1; + $nextyear ++; + } + + $prevyear = $y; + if($m > 1) + $prevmonth = $m - 1; + else { + $prevmonth = 12; + $prevyear --; + } + + $dim = get_dim($y,$m); + $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); + + + if (argv(2) === 'json'){ + if (x($_GET,'start')) $start = $_GET['start']; + if (x($_GET,'end')) $finish = $_GET['end']; + } + + $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 + from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d $sql_extra limit 1", + intval($channel['channel_id']), + intval($_GET['id']) + ); + } + 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. + // 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 + from event left join item on event_hash = resource_id + 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' )) $sql_extra ", + intval($channel['channel_id']), + dbesc($start), + dbesc($finish), + dbesc($adjust_start), + dbesc($adjust_finish) + ); + + } + + $links = array(); + + if($r) { + 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)) + $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j; + } + } + + $events=array(); + + $last_date = ''; + $fmt = t('l, F j'); + + 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')); + $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt)); + $d = day_translate($d); + + $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'c') : datetime_convert('UTC','UTC',$rr['start'],'c')); + if ($rr['nofinish']){ + $end = null; + } else { + $end = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['finish'], 'c') : datetime_convert('UTC','UTC',$rr['finish'],'c')); + } + + + $is_first = ($d !== $last_date); + + $last_date = $d; + + $edit = false; + + $drop = false; + + $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); + if(! $title) { + list($title, $_trash) = explode("$rr['id'], + 'hash' => $rr['event_hash'], + 'start'=> $start, + 'end' => $end, + 'drop' => $drop, + 'allDay' => false, + 'title' => $title, + + 'j' => $j, + 'd' => $d, + 'edit' => $edit, + 'is_first'=>$is_first, + 'item'=>$rr, + 'html'=>$html, + 'plink' => array($rr['plink'],t('Link to Source'),'',''), + ); + + + } + } + + if (argv(2) === 'json'){ + echo json_encode($events); killme(); + } + + // links: array('href', 'text', 'extra css classes', 'title') + if (x($_GET,'id')){ + $tpl = get_markup_template("event_cal.tpl"); + } + else { + $tpl = get_markup_template("events_cal-js.tpl"); + } + + $nick = $channel['channel_address']; + + $o = replace_macros($tpl, array( + '$baseurl' => $a->get_baseurl(), + '$new_event' => array($a->get_baseurl().'/cal',(($event_id) ? t('Edit Event') : t('Create Event')),'',''), + '$previus' => array($a->get_baseurl()."/cal/$nick/$prevyear/$prevmonth",t('Previous'),'',''), + '$next' => array($a->get_baseurl()."/cal/$nick/$nextyear/$nextmonth",t('Next'),'',''), + '$export' => array($a->get_baseurl()."/cal/$nick/$y/$m/export",t('Export'),'',''), + '$calendar' => cal($y,$m,$links, ' eventcal'), + '$events' => $events, + '$upload' => t('Import'), + '$submit' => t('Submit'), + '$prev' => t('Previous'), + '$next' => t('Next'), + '$today' => t('Today'), + '$form' => $form, + '$expandform' => ((x($_GET,'expandform')) ? true : false), + )); + + if (x($_GET,'id')){ echo $o; killme(); } + + return $o; + } + +} -- cgit v1.2.3 From ebfa1a12b9cc3d939ed49a7f66e5687267a409d3 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 25 Feb 2016 00:36:35 -0800 Subject: when creating an event from a post in our stream, if the original post was private, set the event permissions to "just me". If it was a public event, set the event permissions to the channel default permissions. --- mod/cal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php index 9899b33b0..1e2405cd0 100755 --- a/mod/cal.php +++ b/mod/cal.php @@ -85,7 +85,7 @@ function cal_content(&$a) { $m = 0; $ignored = ((x($_REQUEST,'ignored')) ? " and ignored = " . intval($_REQUEST['ignored']) . " " : ''); -logger('args: ' . print_r($a->argv,true)); + // logger('args: ' . print_r($a->argv,true)); if(argc() > 3 && intval(argv(2)) && intval(argv(3))) { $mode = 'view'; -- cgit v1.2.3 From be27fb56440c6687add239e10c5e46ee7f3018f1 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 25 Feb 2016 13:40:15 +0100 Subject: we have got a button for events in the nav. no need for it in the tabs if we are local. --- mod/cal.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php index 1e2405cd0..453f46f69 100755 --- a/mod/cal.php +++ b/mod/cal.php @@ -80,6 +80,8 @@ function cal_content(&$a) { $o = ''; + $tabs = profile_tabs($a, True, $channel['channel_address']); + $mode = 'view'; $y = 0; $m = 0; @@ -333,6 +335,7 @@ function cal_content(&$a) { '$today' => t('Today'), '$form' => $form, '$expandform' => ((x($_GET,'expandform')) ? true : false), + '$tabs' => $tabs )); if (x($_GET,'id')){ echo $o; killme(); } -- cgit v1.2.3 From 1cd3b4182595b838a535dd6b6990251db05d49e6 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 30 Mar 2016 22:13:24 -0700 Subject: deprecate $a->get_baseurl() --- mod/cal.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php index 453f46f69..80a484c27 100755 --- a/mod/cal.php +++ b/mod/cal.php @@ -71,7 +71,7 @@ function cal_content(&$a) { $htpl = get_markup_template('event_head.tpl'); $a->page['htmlhead'] .= replace_macros($htpl,array( - '$baseurl' => $a->get_baseurl(), + '$baseurl' => z_root(), '$module_url' => '/cal/' . $channel['channel_address'], '$modparams' => 2, '$lang' => $a->language, @@ -243,7 +243,7 @@ function cal_content(&$a) { 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)) - $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j; + $links[$j] = z_root() . '/' . $a->cmd . '#link-' . $j; } } @@ -321,11 +321,11 @@ function cal_content(&$a) { $nick = $channel['channel_address']; $o = replace_macros($tpl, array( - '$baseurl' => $a->get_baseurl(), - '$new_event' => array($a->get_baseurl().'/cal',(($event_id) ? t('Edit Event') : t('Create Event')),'',''), - '$previus' => array($a->get_baseurl()."/cal/$nick/$prevyear/$prevmonth",t('Previous'),'',''), - '$next' => array($a->get_baseurl()."/cal/$nick/$nextyear/$nextmonth",t('Next'),'',''), - '$export' => array($a->get_baseurl()."/cal/$nick/$y/$m/export",t('Export'),'',''), + '$baseurl' => z_root(), + '$new_event' => array(z_root().'/cal',(($event_id) ? t('Edit Event') : t('Create Event')),'',''), + '$previus' => array(z_root()."/cal/$nick/$prevyear/$prevmonth",t('Previous'),'',''), + '$next' => array(z_root()."/cal/$nick/$nextyear/$nextmonth",t('Next'),'',''), + '$export' => array(z_root()."/cal/$nick/$y/$m/export",t('Export'),'',''), '$calendar' => cal($y,$m,$links, ' eventcal'), '$events' => $events, '$upload' => t('Import'), -- cgit v1.2.3 From 9abd95fad3784a10fc48bc40f9b8a75d7d74edda Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 31 Mar 2016 16:06:03 -0700 Subject: static App --- mod/cal.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php index 80a484c27..ffefd895e 100755 --- a/mod/cal.php +++ b/mod/cal.php @@ -25,16 +25,16 @@ function cal_init(&$a) { if(! $channelx) return; - $a->data['channel'] = $channelx; + App::$data['channel'] = $channelx; - $observer = $a->get_observer(); - $a->data['observer'] = $observer; + $observer = App::get_observer(); + App::$data['observer'] = $observer; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); - head_set_icon($a->data['channel']['xchan_photo_s']); + head_set_icon(App::$data['channel']['xchan_photo_s']); - $a->page['htmlhead'] .= "" ; + App::$page['htmlhead'] .= "" ; } @@ -70,11 +70,11 @@ function cal_content(&$a) { $first_day = (($first_day) ? $first_day : 0); $htpl = get_markup_template('event_head.tpl'); - $a->page['htmlhead'] .= replace_macros($htpl,array( + App::$page['htmlhead'] .= replace_macros($htpl,array( '$baseurl' => z_root(), '$module_url' => '/cal/' . $channel['channel_address'], '$modparams' => 2, - '$lang' => $a->language, + '$lang' => App::$language, '$first_day' => $first_day )); @@ -87,7 +87,7 @@ function cal_content(&$a) { $m = 0; $ignored = ((x($_REQUEST,'ignored')) ? " and ignored = " . intval($_REQUEST['ignored']) . " " : ''); - // logger('args: ' . print_r($a->argv,true)); + // logger('args: ' . print_r(App::$argv,true)); if(argc() > 3 && intval(argv(2)) && intval(argv(3))) { $mode = 'view'; @@ -243,7 +243,7 @@ function cal_content(&$a) { 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)) - $links[$j] = z_root() . '/' . $a->cmd . '#link-' . $j; + $links[$j] = z_root() . '/' . App::$cmd . '#link-' . $j; } } -- cgit v1.2.3 From 5d884c2f3dddabb475e4246fc9837e1ac3b5750f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 1 Apr 2016 00:59:30 -0700 Subject: suddenly we have includepath issues - provide the explicit paths --- mod/cal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php index ffefd895e..b58f3a1f1 100755 --- a/mod/cal.php +++ b/mod/cal.php @@ -5,7 +5,7 @@ require_once('include/bbcode.php'); require_once('include/datetime.php'); require_once('include/event.php'); require_once('include/items.php'); -require_once('Contact.php'); +require_once('include/Contact.php'); function cal_init(&$a) { -- cgit v1.2.3 From abfbe9c9375c7505e0422b8adc1d9d5426d7df1a Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 10 Apr 2016 16:56:08 -0700 Subject: a few issues: block public not blocking mod_cal, typo in sql for one clone file sync operation, fix_system_urls not catching cached contact photos, extend sessionhandler expiration when remember_me is enabled as the stored session is expiring long before the browser session. --- mod/cal.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mod/cal.php') diff --git a/mod/cal.php b/mod/cal.php index b58f3a1f1..56d65d3f2 100755 --- a/mod/cal.php +++ b/mod/cal.php @@ -45,6 +45,11 @@ function cal_init(&$a) { function cal_content(&$a) { + if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + return; + } + + $channel = null; if(argc() > 1) { -- cgit v1.2.3