aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/Activity.php91
-rw-r--r--include/event.php178
2 files changed, 208 insertions, 61 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index e7739977a..b7153dd6d 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -2247,6 +2247,21 @@ class Activity {
static function decode_note($act) {
+ $response_activity = false;
+
+ $s = [];
+
+ // These activities should have been handled separately in the Inbox module and should not be turned into posts
+
+ if (
+ in_array($act->type, ['Follow', 'Accept', 'Reject', 'Create', 'Update']) &&
+ is_array($act->obj) &&
+ array_key_exists('type', $act->obj) &&
+ ($act->obj['type'] === 'Follow' || ActivityStreams::is_an_actor($act->obj['type']))
+ ) {
+ return false;
+ }
+
// Within our family of projects, Follow/Unfollow of a thread is an internal activity which should not be transmitted,
// hence if we receive it - ignore or reject it.
// Unfollow is not defined by ActivityStreams, which prefers Undo->Follow.
@@ -2256,19 +2271,20 @@ class Activity {
return false;
}
- $response_activity = false;
-
- $s = [];
-
- if (is_array($act->obj)) {
- $content = self::get_content($act->obj);
+ if (!isset($act->actor['id'])) {
+ logger('No actor!');
+ return false;
}
+ // ensure we store the original actor
+ self::actor_store($act->actor['id'], $act->actor);
+
$s['owner_xchan'] = $act->actor['id'];
$s['author_xchan'] = $act->actor['id'];
- // ensure we store the original actor
- self::actor_store($act->actor['id'], $act->actor);
+ if (is_array($act->obj)) {
+ $content = self::get_content($act->obj);
+ }
$s['mid'] = ((is_array($act->obj) && isset($act->obj['id'])) ? $act->obj['id'] : $act->obj);
@@ -2303,6 +2319,10 @@ class Activity {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']);
}
+ if ($act->type === 'Invite' && is_array($act->obj) && array_key_exists('type', $act->obj) && $act->obj['type'] === 'Event') {
+ $s['mid'] = $s['parent_mid'] = $act->id;
+ }
+
if (ActivityStreams::is_response_activity($act->type)) {
$response_activity = true;
@@ -2423,6 +2443,12 @@ class Activity {
$s['obj_type'] = ACTIVITY_OBJ_COMMENT;
}
+ $s['obj'] = $act->obj;
+ if (is_array($s['obj']) && array_path_exists('actor/id', $s['obj'])) {
+ $s['obj']['actor'] = $s['obj']['actor']['id'];
+ }
+
+/*
$eventptr = null;
if ($act->obj['type'] === 'Invite' && array_path_exists('object/type', $act->obj) && $act->obj['object']['type'] === 'Event') {
@@ -2443,19 +2469,19 @@ class Activity {
$s['obj']['asld'] = $eventptr;
$s['obj']['type'] = ACTIVITY_OBJ_EVENT;
$s['obj']['id'] = $eventptr['id'];
- $s['obj']['title'] = $eventptr['name'];
+ $s['obj']['title'] = html2plain($eventptr['name']);
if (strpos($act->obj['startTime'], 'Z'))
$s['obj']['adjust'] = true;
else
- $s['obj']['adjust'] = false;
+ $s['obj']['adjust'] = true;
$s['obj']['dtstart'] = datetime_convert('UTC', 'UTC', $eventptr['startTime']);
if ($act->obj['endTime'])
$s['obj']['dtend'] = datetime_convert('UTC', 'UTC', $eventptr['endTime']);
else
$s['obj']['nofinish'] = true;
- $s['obj']['description'] = $eventptr['content'];
+ $s['obj']['description'] = html2bbcode($eventptr['content']);
if (array_path_exists('location/content', $eventptr))
$s['obj']['location'] = $eventptr['location']['content'];
@@ -2464,6 +2490,7 @@ class Activity {
else {
$s['obj'] = $act->obj;
}
+*/
$generator = $act->get_property_obj('generator');
if ((!$generator) && (!$response_activity)) {
@@ -3740,7 +3767,49 @@ class Activity {
$event['nofinish'] = true;
}
}
+/*
+ $eventptr = null;
+
+ if ($act->obj['type'] === 'Invite' && array_path_exists('object/type', $act->obj) && $act->obj['object']['type'] === 'Event') {
+ $eventptr = $act->obj['object'];
+ $s['mid'] = $s['parent_mid'] = $act->obj['id'];
+ }
+
+ if ($act->obj['type'] === 'Event') {
+ if ($act->type === 'Invite') {
+ $s['mid'] = $s['parent_mid'] = $act->id;
+ }
+ $eventptr = $act->obj;
+ }
+ if ($eventptr) {
+
+ $s['obj'] = [];
+ $s['obj']['asld'] = $eventptr;
+ $s['obj']['type'] = ACTIVITY_OBJ_EVENT;
+ $s['obj']['id'] = $eventptr['id'];
+ $s['obj']['title'] = html2plain($eventptr['name']);
+
+ if (strpos($act->obj['startTime'], 'Z'))
+ $s['obj']['adjust'] = true;
+ else
+ $s['obj']['adjust'] = true;
+
+ $s['obj']['dtstart'] = datetime_convert('UTC', 'UTC', $eventptr['startTime']);
+ if ($act->obj['endTime'])
+ $s['obj']['dtend'] = datetime_convert('UTC', 'UTC', $eventptr['endTime']);
+ else
+ $s['obj']['nofinish'] = true;
+ $s['obj']['description'] = html2bbcode($eventptr['content']);
+
+ if (array_path_exists('location/content', $eventptr))
+ $s['obj']['location'] = $eventptr['location']['content'];
+
+ }
+ else {
+ $s['obj'] = $act->obj;
+ }
+*/
foreach (['name', 'summary', 'content'] as $a) {
if (($x = self::get_textfield($act, $a)) !== false) {
$content[$a] = $x;
diff --git a/include/event.php b/include/event.php
index 440f559da..fbfa4c6d2 100644
--- a/include/event.php
+++ b/include/event.php
@@ -70,8 +70,83 @@ function format_event_html($ev) {
}
function format_event_obj($jobject) {
+
$event = [];
+ $object = json_decode($jobject, true);
+
+/*******
+ This is our encoded format
+
+ $x = [
+ 'type' => 'Event',
+ 'id' => z_root() . '/event/' . $r[0]['resource_id'],
+ 'summary' => bbcode($arr['summary']),
+ // RFC3339 Section 4.3
+ 'startTime' => (($arr['adjust']) ? datetime_convert('UTC','UTC',$arr['dtstart'], ATOM_TIME) : datetime_convert('UTC','UTC',$arr['dtstart'],'Y-m-d\\TH:i:s-00:00')),
+ 'content' => bbcode($arr['description']),
+ 'location' => [ 'type' => 'Place', 'content' => $arr['location'] ],
+ 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ],
+ 'url' => [ [ 'mediaType' => 'text/calendar', 'href' => z_root() . '/events/ical/' . $event['event_hash'] ] ],
+ 'actor' => Activity::encode_person($r[0],false),
+ ];
+ if(! $arr['nofinish']) {
+ $x['endTime'] = (($arr['adjust']) ? datetime_convert('UTC','UTC',$arr['dtend'], ATOM_TIME) : datetime_convert('UTC','UTC',$arr['dtend'],'Y-m-d\\TH:i:s-00:00'));
+ }
+
+******/
+
+ if (is_array($object) && (array_key_exists('summary', $object) || array_key_exists('name', $object))) {
+
+ $dtend = ((array_key_exists('endTime', $object)) ? $object['endTime'] : NULL_DATE);
+ $title = ((isset($object['summary']) && $object['summary']) ? zidify_links(smilies(bbcode($object['summary']))) : $object['name']);
+
+ // mobilizon sets a timezone in the object
+ // we will assume that events with an timezone should be adjusted
+ $tz = $object['timezone'] ?? '';
+ $adjust = ((strpos($object['startTime'], 'Z') !== false) || $tz);
+
+ $allday = (($adjust) ? false : true);
+
+ $dtstart = new DateTime($object['startTime']);
+ $dtend_obj = new DateTime($dtend);
+ $dtdiff = $dtstart->diff($dtend_obj);
+
+ if($allday && ($dtdiff->days < 2))
+ $oneday = true;
+
+ if($allday && !$oneday) {
+ // Subtract one day from the end date so we can use the "first day - last day" format for display.
+ $dtend_obj->modify('-1 day');
+ $dtend = datetime_convert('UTC', 'UTC', $dtend_obj->format('Y-m-d H:i:s'));
+ }
+
+ $bd_format = (($allday) ? t('l F d, Y') : t('l F d, Y \@ g:i A')); // Friday January 18, 2011 @ 8:01 AM or Friday January 18, 2011 for allday events
+
+ $event['header'] = replace_macros(get_markup_template('event_item_header.tpl'), array(
+ '$title' => $title,
+ '$dtstart_label' => t('Start:'),
+ '$dtstart_title' => datetime_convert('UTC', 'UTC', $object['startTime'], ((strpos($object['startTime'], 'Z')) ? ATOM_TIME : 'Y-m-d\TH:i:s' )),
+ '$dtstart_dt' => (($adjust) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['startTime'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $object['startTime'], $bd_format))),
+ '$finish' => ((array_key_exists('endTime', $object)) ? true : false),
+ '$dtend_label' => t('End:'),
+ '$dtend_title' => datetime_convert('UTC', 'UTC', $dtend, ((strpos($object['startTime'], 'Z')) ? ATOM_TIME : 'Y-m-d\TH:i:s' )),
+ '$dtend_dt' => (($adjust) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $dtend, $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $dtend, $bd_format))),
+ '$allday' => $allday,
+ '$oneday' => $oneday,
+ '$event_tz' => ['label' => t('Timezone'), 'value' => (($tz === date_default_timezone_get()) ? '' : $tz)]
+ ));
+
+ $event['content'] = replace_macros(get_markup_template('event_item_content.tpl'), array(
+ '$description' => $object['content'],
+ '$location_label' => t('Location:'),
+ '$location' => ((array_path_exists('location/content', $object)) ? zidify_links(smilies(bbcode($object['location']['content']))) : EMPTY_STR)
+ ));
+ }
+
+ return $event;
+/*
+ $event = [];
$object = json_decode($jobject,true);
$event_tz = '';
@@ -136,6 +211,7 @@ function format_event_obj($jobject) {
));
return $event;
+*/
}
function ical_wrapper($ev) {
@@ -1122,34 +1198,35 @@ function event_store_item($arr, $event) {
if($r) {
- set_iconfig($r[0]['id'], 'event', 'timezone', $arr['timezone'], true);
- xchan_query($r);
- $r = fetch_post_tags($r,true);
-
- $object = json_encode(array(
- 'type' => ACTIVITY_OBJ_EVENT,
- 'id' => z_root() . '/event/' . $r[0]['resource_id'],
- 'title' => $arr['summary'],
- 'timezone' => $arr['timezone'],
- 'dtstart' => $arr['dtstart'],
- 'dtend' => $arr['dtend'],
- 'nofinish' => $arr['nofinish'],
- 'description' => $arr['description'],
- 'location' => $arr['location'],
- 'adjust' => $arr['adjust'],
- 'content' => format_event_bbcode($arr),
+ //set_iconfig($r[0]['id'], 'event', 'timezone', $arr['timezone'], true);
+ //xchan_query($r);
+ //$r = fetch_post_tags($r,true);
+
+ $x = [
+ 'type' => 'Event',
+ 'id' => z_root() . '/event/' . $r[0]['resource_id'],
+ 'name' => $arr['summary'],
+// 'summary' => bbcode($arr['summary']),
+ // RFC3339 Section 4.3
+ 'startTime' => (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtstart'], ATOM_TIME) : datetime_convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')),
+ 'content' => bbcode($arr['description']),
+ 'location' => [ 'type' => 'Place', 'content' => $arr['location'] ],
+ 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ],
+ 'url' => [ [ 'mediaType' => 'text/calendar', 'href' => z_root() . '/events/ical/' . $event['event_hash'] ] ],
+ 'actor' => Activity::encode_person($r[0], false),
'attachment' => Activity::encode_attachment($r[0]),
- 'author' => array(
- 'name' => $r[0]['author']['xchan_name'],
- 'address' => $r[0]['author']['xchan_addr'],
- 'guid' => $r[0]['author']['xchan_guid'],
- 'guid_sig' => $r[0]['author']['xchan_guid_sig'],
- 'link' => array(
- array('rel' => 'alternate', 'type' => 'text/html', 'href' => $r[0]['author']['xchan_url']),
- array('rel' => 'photo', 'type' => $r[0]['author']['xchan_photo_mimetype'], 'href' => $r[0]['author']['xchan_photo_m'])
- ),
- ),
- ));
+ 'tag' => Activity::encode_taxonomy($r[0])
+ ];
+
+ if (! $arr['nofinish']) {
+ $x['endTime'] = (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtend'], ATOM_TIME) : datetime_convert('UTC', 'UTC', $arr['dtend'], 'Y-m-d\\TH:i:s-00:00'));
+ }
+
+ if ($event['event_repeat']) {
+ $x['eventRepeat'] = $event['event_repeat'];
+ }
+
+ $object = json_encode($x);
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
@@ -1285,29 +1362,30 @@ function event_store_item($arr, $event) {
dbesc($arr['event_xchan'])
);
if($x) {
- $item_arr['obj'] = json_encode(array(
- 'type' => ACTIVITY_OBJ_EVENT,
- 'id' => z_root() . '/event/' . $event['event_hash'],
- 'title' => $arr['summary'],
- 'timezone' => $arr['timezone'],
- 'dtstart' => $arr['dtstart'],
- 'dtend' => $arr['dtend'],
- 'nofinish' => $arr['nofinish'],
- 'description' => $arr['description'],
- 'location' => $arr['location'],
- 'adjust' => $arr['adjust'],
- 'content' => format_event_bbcode($arr),
- 'attachment' => Activity::encode_attachment($item_arr),
- 'author' => array(
- 'name' => $x[0]['xchan_name'],
- 'address' => $x[0]['xchan_addr'],
- 'guid' => $x[0]['xchan_guid'],
- 'guid_sig' => $x[0]['xchan_guid_sig'],
- 'link' => array(
- array('rel' => 'alternate', 'type' => 'text/html', 'href' => $x[0]['xchan_url']),
- array('rel' => 'photo', 'type' => $x[0]['xchan_photo_mimetype'], 'href' => $x[0]['xchan_photo_m'])),
- ),
- ));
+ $y = [
+ 'type' => 'Event',
+ 'id' => z_root() . '/event/' . $event['event_hash'],
+ 'name' => $arr['summary'],
+// 'summary' => bbcode($arr['summary']),
+ // RFC3339 Section 4.3
+ 'startTime' => (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtstart'], ATOM_TIME) : datetime_convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')),
+ 'content' => bbcode($arr['description']),
+ 'location' => [ 'type' => 'Place', 'content' => bbcode($arr['location']) ],
+ 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ],
+ 'url' => [ [ 'mediaType' => 'text/calendar', 'href' => z_root() . '/events/ical/' . $event['event_hash'] ] ],
+ 'actor' => Activity::encode_person($z, false),
+ 'attachment' => Activity::encode_attachment($item_arr),
+ 'tag' => Activity::encode_taxonomy($item_arr)
+ ];
+
+ if (! $arr['nofinish']) {
+ $y['endTime'] = (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtend'], ATOM_TIME) : datetime_convert('UTC', 'UTC', $arr['dtend'], 'Y-m-d\\TH:i:s-00:00'));
+ }
+ if ($arr['event_repeat']) {
+ $y['eventRepeat'] = $arr['event_repeat'];
+ }
+
+ $item_arr['obj'] = json_encode($y);
}
// propagate the event resource_id so that posts containing it are easily searchable in downstream copies