aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Activity.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/Activity.php')
-rw-r--r--Zotlabs/Lib/Activity.php183
1 files changed, 89 insertions, 94 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 24fe5e5c0..6e8344def 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -104,7 +104,10 @@ class Activity {
if ($x['success']) {
$m = parse_url($url);
if ($m) {
- $site_url = unparse_url(['scheme' => $m['scheme'], 'host' => $m['host'], 'port' => $m['port'] ]);
+ $y = [ 'scheme' => $m['scheme'], 'host' => $m['host'] ];
+ if (array_key_exists('port', $m))
+ $y['port'] = $m['port'];
+ $site_url = unparse_url($y);
q("UPDATE site SET site_update = '%s', site_dead = 0 WHERE site_url = '%s' AND site_update < %s - INTERVAL %s",
dbesc(datetime_convert()),
dbesc($site_url),
@@ -129,8 +132,8 @@ class Activity {
}
static function fetch_profile($x) {
- $r = q("select * from xchan where xchan_url like '%s' limit 1",
- dbesc($x['id'] . '/%')
+ $r = q("select * from xchan where xchan_url = '%s' limit 1",
+ dbesc($x['id'])
);
if (!$r) {
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
@@ -572,7 +575,7 @@ class Activity {
$ret = [];
- if ($item['tag'] && is_array($item['tag'])) {
+ if (array_key_exists('tag', $item) && is_array($item['tag'])) {
$ptr = $item['tag'];
if (!array_key_exists(0, $ptr)) {
$ptr = [$ptr];
@@ -581,23 +584,25 @@ class Activity {
if (!array_key_exists('type', $t))
$t['type'] = 'Hashtag';
- switch ($t['type']) {
- case 'Hashtag':
- $ret[] = ['ttype' => TERM_HASHTAG, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '#') ? substr($t['name'], 1) : $t['name'])];
- break;
+ if (array_key_exists('href', $t) && array_key_exists('name', $t)) {
+ switch ($t['type']) {
+ case 'Hashtag':
+ $ret[] = ['ttype' => TERM_HASHTAG, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '#') ? substr($t['name'], 1) : $t['name'])];
+ break;
- case 'Mention':
- $mention_type = substr($t['name'], 0, 1);
- if ($mention_type === '!') {
- $ret[] = ['ttype' => TERM_FORUM, 'url' => $t['href'], 'term' => escape_tags(substr($t['name'], 1))];
- }
- else {
- $ret[] = ['ttype' => TERM_MENTION, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '@') ? substr($t['name'], 1) : $t['name'])];
- }
- break;
+ case 'Mention':
+ $mention_type = substr($t['name'], 0, 1);
+ if ($mention_type === '!') {
+ $ret[] = ['ttype' => TERM_FORUM, 'url' => $t['href'], 'term' => escape_tags(substr($t['name'], 1))];
+ }
+ else {
+ $ret[] = ['ttype' => TERM_MENTION, 'url' => $t['href'], 'term' => escape_tags((substr($t['name'], 0, 1) === '@') ? substr($t['name'], 1) : $t['name'])];
+ }
+ break;
- default:
- break;
+ default:
+ break;
+ }
}
}
}
@@ -609,7 +614,7 @@ class Activity {
$ret = [];
- if ($item['term']) {
+ if (array_key_exists('term', $item) && is_array($item['term'])) {
foreach ($item['term'] as $t) {
switch ($t['ttype']) {
case TERM_HASHTAG:
@@ -640,7 +645,7 @@ class Activity {
$ret = [];
- if ($item['attach']) {
+ if (array_key_exists('attach', $item)) {
$atts = ((is_array($item['attach'])) ? $item['attach'] : json_decode($item['attach'], true));
if ($atts) {
foreach ($atts as $att) {
@@ -653,7 +658,7 @@ class Activity {
}
}
}
- if ($item['iconfig']) {
+ if (array_key_exists('iconfig', $item) && is_array($item['iconfig'])) {
foreach ($item['iconfig'] as $att) {
if ($att['sharing']) {
$value = ((is_string($att['v']) && preg_match('|^a:[0-9]+:{.*}$|s', $att['v'])) ? unserialize($att['v']) : $att['v']);
@@ -697,16 +702,16 @@ class Activity {
$ret = [];
- if ($item['attachment']) {
+ if (array_key_exists('attachment', $item) && is_array($item['attachment'])) {
foreach ($item['attachment'] as $att) {
$entry = [];
- if ($att['href'])
+ if (array_key_exists('href', $att))
$entry['href'] = $att['href'];
- elseif ($att['url'])
+ elseif (array_key_exists('url', $att))
$entry['href'] = $att['url'];
- if ($att['mediaType'])
+ if (array_key_exists('mediaType', $att))
$entry['type'] = $att['mediaType'];
- elseif ($att['type'] === 'Image')
+ elseif (array_key_exists('type', $att) && $att['type'] === 'Image')
$entry['type'] = 'image/jpeg';
if ($entry)
$ret[] = $entry;
@@ -978,19 +983,17 @@ class Activity {
// Returns an array of URLS for any mention tags found in the item array $i.
static function map_mentions($i) {
- if (!$i['term']) {
- return [];
- }
-
$list = [];
- foreach ($i['term'] as $t) {
- if (!$t['url']) {
- continue;
- }
- if ($t['ttype'] == TERM_MENTION) {
- $url = self::lookup_term_url($t['url']);
- $list[] = (($url) ? $url : $t['url']);
+ if (array_key_exists('term', $i) && is_array($i['term'])) {
+ foreach ($i['term'] as $t) {
+ if (!$t['url']) {
+ continue;
+ }
+ if ($t['ttype'] == TERM_MENTION) {
+ $url = self::lookup_term_url($t['url']);
+ $list[] = (($url) ? $url : $t['url']);
+ }
}
}
@@ -1091,18 +1094,7 @@ class Activity {
'height' => 300,
'width' => 300,
];
- $ret['url'] = [
- [
- 'type' => 'Link',
- 'mediaType' => 'text/html',
- 'href' => $p['xchan_url']
- ],
- [
- 'type' => 'Link',
- 'mediaType' => 'text/x-zot+json',
- 'href' => $p['xchan_url']
- ]
- ];
+ $ret['url'] = $p['xchan_url'];
$ret['publicKey'] = [
'id' => $p['xchan_url'],
@@ -1331,12 +1323,12 @@ class Activity {
*
*/
- $person_obj = $act->actor;
-
- if ($act->type === 'Follow') {
+ if (in_array($act->type, [ 'Follow', 'Invite', 'Join'])) {
$their_follow_id = $act->id;
}
+ $person_obj = (($act->type == 'Invite') ? $act->obj : $act->actor);
+
if (is_array($person_obj)) {
// store their xchan and hubloc
@@ -1354,9 +1346,8 @@ class Activity {
}
}
- $x = PermissionRoles::role_perms('social');
- $p = Permissions::FilledPerms($x['perms_connect']);
- $their_perms = Permissions::serialise($p);
+ $x = \Zotlabs\Access\PermissionRoles::role_perms('social');
+ $their_perms = \Zotlabs\Access\Permissions::FilledPerms($x['perms_connect']);
if ($contact && $contact['abook_id']) {
@@ -1365,18 +1356,18 @@ class Activity {
switch ($act->type) {
case 'Follow':
+ case 'Invite':
+ case 'Join':
// A second Follow request, but we haven't approved the first one
-
if ($contact['abook_pending']) {
return;
}
// We've already approved them or followed them first
// Send an Accept back to them
-
set_abconfig($channel['channel_id'], $person_obj['id'], 'pubcrawl', 'their_follow_id', $their_follow_id);
- Master::Summon(['Notifier', 'permissions_accept', $contact['abook_id']]);
+ Master::Summon(['Notifier', 'permission_accept', $contact['abook_id']]);
return;
case 'Accept':
@@ -1430,8 +1421,8 @@ class Activity {
}
$ret = $r[0];
- $p = Permissions::connect_perms($channel['channel_id']);
- $my_perms = Permissions::serialise($p['perms']);
+ $p = \Zotlabs\Access\Permissions::connect_perms($channel['channel_id']);
+ $my_perms = $p['perms'];
$automatic = $p['automatic'];
$closeness = get_pconfig($channel['channel_id'], 'system', 'new_abook_closeness', 80);
@@ -1451,12 +1442,13 @@ class Activity {
]
);
- if ($my_perms)
- set_abconfig($channel['channel_id'], $ret['xchan_hash'], 'system', 'my_perms', $my_perms);
-
- if ($their_perms)
- set_abconfig($channel['channel_id'], $ret['xchan_hash'], 'system', 'their_perms', $their_perms);
+ if($my_perms)
+ foreach($my_perms as $k => $v)
+ set_abconfig($channel['channel_id'],$ret['xchan_hash'],'my_perms',$k,$v);
+ if($their_perms)
+ foreach($their_perms as $k => $v)
+ set_abconfig($channel['channel_id'],$ret['xchan_hash'],'their_perms',$k,$v);
if ($r) {
logger("New ActivityPub follower for {$channel['channel_name']}");
@@ -1477,9 +1469,9 @@ class Activity {
if ($my_perms && $automatic) {
// send an Accept for this Follow activity
- Master::Summon(['Notifier', 'permissions_accept', $new_connection[0]['abook_id']]);
+ Master::Summon(['Notifier', 'permission_accept', $new_connection[0]['abook_id']]);
// Send back a Follow notification to them
- Master::Summon(['Notifier', 'permissions_create', $new_connection[0]['abook_id']]);
+ Master::Summon(['Notifier', 'permission_create', $new_connection[0]['abook_id']]);
}
$clone = [];
@@ -1604,13 +1596,13 @@ class Activity {
if ($inbox) {
$collections['inbox'] = $inbox;
- if ($person_obj['outbox'])
+ if (array_key_exists('outbox', $person_obj))
$collections['outbox'] = $person_obj['outbox'];
- if ($person_obj['followers'])
+ if (array_key_exists('followers', $person_obj))
$collections['followers'] = $person_obj['followers'];
- if ($person_obj['following'])
+ if (array_key_exists('following', $person_obj))
$collections['following'] = $person_obj['following'];
- if ($person_obj['endpoints'] && $person_obj['endpoints']['sharedInbox'])
+ if (array_key_exists('endpoints', $person_obj) && array_key_exists('sharedInbox', $person_obj['endpoints']))
$collections['sharedInbox'] = $person_obj['endpoints']['sharedInbox'];
}
@@ -2123,22 +2115,22 @@ class Activity {
$s['uuid'] = $act->obj['diaspora:guid'];
$s['parent_mid'] = $act->parent_id;
- if ($act->data['published']) {
+ if (array_key_exists('published', $act->data)) {
$s['created'] = datetime_convert('UTC', 'UTC', $act->data['published']);
}
- elseif ($act->obj['published']) {
+ elseif (array_key_exists('published', $act->obj)) {
$s['created'] = datetime_convert('UTC', 'UTC', $act->obj['published']);
}
- if ($act->data['updated']) {
+ if (array_key_exists('updated', $act->data)) {
$s['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']);
}
- elseif ($act->obj['updated']) {
+ elseif (array_key_exists('updated', $act->obj)) {
$s['edited'] = datetime_convert('UTC', 'UTC', $act->obj['updated']);
}
- if ($act->data['expires']) {
+ if (array_key_exists('expires', $act->data)) {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->data['expires']);
}
- elseif ($act->obj['expires']) {
+ elseif (array_key_exists('expires', $act->obj)) {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']);
}
@@ -2198,10 +2190,10 @@ class Activity {
}
}
- if (!$s['created'])
+ if (! array_key_exists('created', $s))
$s['created'] = datetime_convert();
- if (!$s['edited'])
+ if (! array_key_exists('edited', $s))
$s['edited'] = $s['created'];
$s['title'] = (($response_activity) ? EMPTY_STR : self::bb_content($content, 'name'));
@@ -2315,7 +2307,7 @@ class Activity {
}
}
- if ($act->obj['closed']) {
+ if (array_key_exists('closed', $act->obj)) {
$s['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['closed']);
}
@@ -2731,7 +2723,7 @@ class Activity {
}
}
- if ($act->obj['conversation']) {
+ if (array_key_exists('conversation', $act->obj)) {
set_iconfig($item, 'ostatus', 'conversation', $act->obj['conversation'], 1);
}
@@ -3384,22 +3376,25 @@ class Activity {
require_once('include/event.php');
$ret = false;
- if (is_array($content[$field])) {
- foreach ($content[$field] as $k => $v) {
- $ret .= html2bbcode($v);
- // save this for auto-translate or dynamic filtering
- // $ret .= '[language=' . $k . ']' . html2bbcode($v) . '[/language]';
- }
- }
- else {
- if ($field === 'bbcode' && array_key_exists('bbcode', $content)) {
- $ret = $content[$field];
+ if (array_key_exists($field, $content)) {
+ if (is_array($content[$field])) {
+ foreach ($content[$field] as $k => $v) {
+ $ret .= html2bbcode($v);
+ // save this for auto-translate or dynamic filtering
+ // $ret .= '[language=' . $k . ']' . html2bbcode($v) . '[/language]';
+ }
}
else {
- $ret = html2bbcode($content[$field]);
+ if ($field === 'bbcode' && array_key_exists('bbcode', $content)) {
+ $ret = $content[$field];
+ }
+ else {
+ $ret = html2bbcode($content[$field]);
+ }
}
}
- if ($field === 'content' && $content['event'] && (!strpos($ret, '[event'))) {
+
+ if ($field === 'content' && array_key_exists('event', $content) && (!strpos($ret, '[event'))) {
$ret .= format_event_bbcode($content['event']);
}