aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Module/Channel_calendar.php144
1 files changed, 71 insertions, 73 deletions
diff --git a/Zotlabs/Module/Channel_calendar.php b/Zotlabs/Module/Channel_calendar.php
index ae4afb2f3..1fa9a45df 100644
--- a/Zotlabs/Module/Channel_calendar.php
+++ b/Zotlabs/Module/Channel_calendar.php
@@ -1,7 +1,11 @@
<?php
namespace Zotlabs\Module;
+use App;
+use Zotlabs\Web\Controller;
use Zotlabs\Lib\Libsync;
+use Zotlabs\Access\AccessList;
+use Zotlabs\Daemon\Master;
require_once('include/conversation.php');
require_once('include/bbcode.php');
@@ -10,36 +14,36 @@ require_once('include/event.php');
require_once('include/items.php');
require_once('include/html2plain.php');
-class Channel_calendar extends \Zotlabs\Web\Controller {
+class Channel_calendar extends Controller {
function post() {
-
+
logger('post: ' . print_r($_REQUEST,true), LOGGER_DATA);
-
- if(! local_channel())
+
+ $uid = local_channel();
+
+ if(! $uid)
return;
$event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
- $event_hash = ((x($_POST,'event_hash')) ? $_POST['event_hash'] : '');
-
+
$xchan = ((x($_POST,'xchan')) ? dbesc($_POST['xchan']) : '');
- $uid = local_channel();
// only allow editing your own events.
if(($xchan) && ($xchan !== get_observer_hash()))
return;
$categories = escape_tags(trim($_POST['categories']));
-
+
// allday events have adjust = 0, normal events have adjust = 1
$adjust = intval($_POST['adjust']);
- $start = datetime_convert((($adjust) ? $tz : 'UTC'), 'UTC', escape_tags($_REQUEST['dtstart']));
- $finish = datetime_convert((($adjust) ? $tz : 'UTC'), 'UTC', escape_tags($_REQUEST['dtend']));
-
$timezone = ((x($_POST,'timezone_select')) ? escape_tags(trim($_POST['timezone_select'])) : '');
$tz = (($timezone) ? $timezone : date_default_timezone_get());
+ $start = datetime_convert((($adjust) ? $tz : 'UTC'), 'UTC', escape_tags($_REQUEST['dtstart']));
+ $finish = datetime_convert((($adjust) ? $tz : 'UTC'), 'UTC', escape_tags($_REQUEST['dtend']));
+
if(! $adjust)
$tz = 'UTC';
@@ -52,15 +56,15 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
// 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
// could've been spent doing something else.
-
- if(strcmp($finish,$start) < 0 && !$nofinish) {
+
+ if(strcmp($finish,$start) < 0) {
notice( t('Event can not end before it has started.') . EOL);
if(intval($_REQUEST['preview'])) {
echo( t('Unable to generate preview.'));
}
killme();
}
-
+
if((! $summary) || (! $start)) {
notice( t('Event title and start time are required.') . EOL);
if(intval($_REQUEST['preview'])) {
@@ -69,14 +73,12 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
killme();
}
- $channel = \App::get_channel();
-
- $acl = new \Zotlabs\Access\AccessList(false);
-
+ $acl = new AccessList([]);
+
if($event_id) {
$x = q("select * from event where id = %d and uid = %d limit 1",
intval($event_id),
- intval(local_channel())
+ intval($uid)
);
if(! $x) {
notice( t('Event not found.') . EOL);
@@ -86,9 +88,9 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
}
return;
}
-
+
$acl->set($x[0]);
-
+
$created = $x[0]['created'];
$edited = datetime_convert();
}
@@ -96,9 +98,9 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$created = $edited = datetime_convert();
$acl->set_from_array($_POST);
}
-
+
$post_tags = array();
- $channel = \App::get_channel();
+ $channel = App::get_channel();
$ac = $acl->get();
$str_contact_allow = $ac['allow_cid'];
@@ -109,22 +111,22 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$private = $acl->is_private();
require_once('include/text.php');
- $results = linkify_tags($desc, local_channel());
+ $results = linkify_tags($desc, $uid);
if($results) {
// Set permissions based on tag replacements
- set_linkified_perms($results, $str_contact_allow, $str_group_allow, local_channel(), false, $private);
+ set_linkified_perms($results, $str_contact_allow, $str_group_allow, $uid, false, $private);
foreach($results as $result) {
$success = $result['success'];
if($success['replaced']) {
$post_tags[] = array(
- 'uid' => local_channel(),
+ 'uid' => $uid,
'ttype' => $success['termtype'],
'otype' => TERM_OBJ_POST,
'term' => $success['term'],
'url' => $success['url']
- );
+ );
}
}
}
@@ -133,7 +135,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$cats = explode(',',$categories);
foreach($cats as $cat) {
$post_tags[] = array(
- 'uid' => local_channel(),
+ 'uid' => $uid,
'ttype' => TERM_CATEGORY,
'otype' => TERM_OBJ_POST,
'term' => trim($cat),
@@ -141,7 +143,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
);
}
}
-
+
$datarray = array();
$datarray['dtstart'] = $start;
$datarray['dtend'] = $finish;
@@ -151,7 +153,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$datarray['etype'] = $type;
$datarray['adjust'] = $adjust;
$datarray['nofinish'] = 0;
- $datarray['uid'] = local_channel();
+ $datarray['uid'] = $uid;
$datarray['account'] = get_account_id();
$datarray['event_xchan'] = $channel['channel_hash'];
$datarray['allow_cid'] = $str_contact_allow;
@@ -164,20 +166,20 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$datarray['edited'] = $edited;
$datarray['timezone'] = $tz;
-
+
if(intval($_REQUEST['preview'])) {
$html = format_event_html($datarray);
echo $html;
killme();
}
-
+
$event = event_store_event($datarray);
-
- if($post_tags)
+
+ if($post_tags)
$datarray['term'] = $post_tags;
-
+
$item_id = event_store_item($datarray,$event);
-
+
if($item_id) {
$r = q("select * from item where id = %d",
intval($item_id)
@@ -194,27 +196,27 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
}
}
}
-
- \Zotlabs\Daemon\Master::Summon(array('Notifier','event',$item_id));
+
+ Master::Summon(array('Notifier','event',$item_id));
killme();
-
+
}
-
-
-
+
+
+
function get() {
-
+
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) {
+ if($r) {
header('Content-type: text/calendar');
header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"' );
echo ical_wrapper($r);
@@ -225,28 +227,26 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
return;
}
}
-
+
if(! local_channel()) {
notice( t('Permission denied.') . EOL);
return;
}
if((argc() > 2) && (argv(1) === 'ignore') && intval(argv(2))) {
- $r = q("update event set dismissed = 1 where id = %d and uid = %d",
+ q("update event set dismissed = 1 where id = %d and uid = %d",
intval(argv(2)),
intval(local_channel())
);
}
-
+
if((argc() > 2) && (argv(1) === 'unignore') && intval(argv(2))) {
- $r = q("update event set dismissed = 0 where id = %d and uid = %d",
+ q("update event set dismissed = 0 where id = %d and uid = %d",
intval(argv(2)),
intval(local_channel())
);
}
- $channel = \App::get_channel();
-
$mode = 'view';
$export = false;
$ignored = ((x($_REQUEST,'ignored')) ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '');
@@ -271,31 +271,29 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$event_id = argv(1);
}
}
-
+
if($mode === 'add') {
event_addtocal($item_id,local_channel());
killme();
}
-
+
if($mode == 'view') {
-
+
/* edit/create form */
if($event_id) {
- $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
+ q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
dbesc($event_id),
intval(local_channel())
);
- if(count($r))
- $orig_event = $r[0];
}
-
- $channel = \App::get_channel();
+
+ $channel = App::get_channel();
if (argv(1) === '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);
@@ -335,7 +333,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
dbesc($adjust_finish)
);
}
-
+
if($r && ! $export) {
xchan_query($r);
$r = fetch_post_tags($r,true);
@@ -345,7 +343,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
$events = [];
if($r) {
-
+
foreach($r as $rr) {
$start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c'));
@@ -369,9 +367,9 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
}
$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'),'','');
-
+
$tz = get_iconfig($rr, 'event', 'timezone');
if(! $tz)
@@ -401,7 +399,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
);
}
}
-
+
if($export) {
header('Content-type: text/calendar');
header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"' );
@@ -409,20 +407,20 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
killme();
}
- if (\App::$argv[1] === 'json'){
+ if (App::$argv[1] === 'json'){
json_return_and_die($events);
}
}
-
+
if($mode === 'drop' && $event_id) {
$r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
dbesc($event_id),
intval(local_channel())
);
-
+
$sync_event = $r[0];
-
+
if($r) {
$r = q("delete from event where event_hash = '%s' and uid = %d",
dbesc($event_id),
@@ -464,7 +462,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
// if this is a different page type or it's just a local delete
// but not by the item author or owner, do a simple deletion
- $complex = false;
+ $complex = false;
if(intval($i[0]['item_type']) || ($local_delete && (! $can_delete))) {
drop_item($i[0]['id']);
@@ -495,7 +493,7 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
killme();
}
}
-
+
}
-
+
}