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.php129
1 files changed, 95 insertions, 34 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 9b3cab9d0..8e24dde41 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -670,24 +670,36 @@ class Activity {
return $ret;
}
- static function decode_attachment($item) {
+ public static function decode_attachment($item) {
$ret = [];
if (array_key_exists('attachment', $item) && is_array($item['attachment'])) {
- foreach ($item['attachment'] as $att) {
+ $ptr = $item['attachment'];
+ if (!array_key_exists(0, $ptr)) {
+ $ptr = [$ptr];
+ }
+ foreach ($ptr as $att) {
$entry = [];
- if (array_key_exists('href', $att))
+ if (array_key_exists('href', $att) && $att['href']) {
$entry['href'] = $att['href'];
- elseif (array_key_exists('url', $att))
+ } elseif (array_key_exists('url', $att) && $att['url']) {
$entry['href'] = $att['url'];
- if (array_key_exists('mediaType', $att))
+ }
+ if (array_key_exists('mediaType', $att) && $att['mediaType']) {
$entry['type'] = $att['mediaType'];
- elseif (array_key_exists('type', $att) && $att['type'] === 'Image')
+ } elseif (array_key_exists('type', $att) && $att['type'] === 'Image') {
$entry['type'] = 'image/jpeg';
- if ($entry)
+ }
+ if (array_key_exists('name', $att) && $att['name']) {
+ $entry['name'] = html2plain(purify_html($att['name']), 256);
+ }
+ if ($entry) {
$ret[] = $entry;
+ }
}
+ } elseif (isset($item['attachment']) && is_string($item['attachment'])) {
+ btlogger('not an array: ' . $item['attachment']);
}
return $ret;
@@ -1013,7 +1025,7 @@ class Activity {
'type' => 'Image',
'mediaType' => (($p['xchan_photo_mimetype']) ? $p['xchan_photo_mimetype'] : 'image/png'),
'updated' => datetime_convert('UTC', 'UTC', $p['xchan_photo_date'], ATOM_TIME),
- 'url' => $p['xchan_photo_l'],
+ 'url' => $p['xchan_photo_l'] . '?rev=' . strtotime($p['xchan_photo_date']),
'height' => 300,
'width' => 300,
];
@@ -2195,20 +2207,20 @@ class Activity {
$s['created'] = datetime_convert('UTC', 'UTC', $act->data['published']);
$s['commented'] = $s['created'];
}
- elseif (array_key_exists('published', $act->obj)) {
+ elseif (is_array($act->obj) && array_key_exists('published', $act->obj)) {
$s['created'] = datetime_convert('UTC', 'UTC', $act->obj['published']);
$s['commented'] = $s['created'];
}
if (array_key_exists('updated', $act->data)) {
$s['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']);
}
- elseif (array_key_exists('updated', $act->obj)) {
+ elseif (is_array($act->obj) && array_key_exists('updated', $act->obj)) {
$s['edited'] = datetime_convert('UTC', 'UTC', $act->obj['updated']);
}
if (array_key_exists('expires', $act->data)) {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->data['expires']);
}
- elseif (array_key_exists('expires', $act->obj)) {
+ elseif (is_array($act->obj) && array_key_exists('expires', $act->obj)) {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']);
}
@@ -2270,9 +2282,18 @@ class Activity {
$s['mid'] = $act->obj['id'];
$s['parent_mid'] = $act->obj['id'];
}
+
if ($act->type === 'emojiReaction') {
$content['content'] = (($act->tgt && $act->tgt['type'] === 'Image') ? '[img=32x32]' . $act->tgt['url'] . '[/img]' : '&#x' . $act->tgt['name'] . ';');
}
+
+ if (in_array($act->type, ['EmojiReaction', 'EmojiReact'])) {
+ // Pleroma reactions
+ $t = trim(self::get_textfield($act->data, 'content'));
+ if (mb_strlen($t) === 1) {
+ $content['content'] = $t;
+ }
+ }
}
$s['item_thread_top'] = 0;
@@ -2408,7 +2429,6 @@ class Activity {
}
}
}
-
}
$a = self::decode_attachment($act->obj);
@@ -2423,8 +2443,11 @@ class Activity {
if (array_key_exists('type', $act->obj)) {
- if ($act->obj['type'] === 'Note' && $s['attach']) {
- $s['body'] = self::bb_attach($s['attach'], $s['body']) . $s['body'];
+ // Objects that might have media attachments which aren't already provided in the content element.
+ // We'll check specific media objects separately.
+
+ if (in_array($act->obj['type'], ['Article', 'Document', 'Event', 'Note', 'Page', 'Place', 'Question']) && isset($s['attach']) && $s['attach']) {
+ $s = self::bb_attach($s);
}
if ($act->obj['type'] === 'Question' && in_array($act->type, ['Create', 'Update'])) {
@@ -2513,13 +2536,13 @@ class Activity {
usort($mps,[ '\Zotlabs\Lib\Activity', 'vid_sort' ]);
foreach ($mps as $m) {
if (intval($m['height']) < 500 && Activity::media_not_in_body($m['href'],$s['body'])) {
- $s['body'] = $tag . $m['href'] . '[/video]' . "\n\n" . $s['body'];
+ $s['body'] = $tag . $m['href'] . '[/video]' . "\r\n" . $s['body'];
break;
}
}
}
elseif (is_string($act->obj['url']) && Activity::media_not_in_body($act->obj['url'],$s['body'])) {
- $s['body'] = $tag . $act->obj['url'] . '[/video]' . "\n\n" . $s['body'];
+ $s['body'] = $tag . $act->obj['url'] . '[/video]' . "\r\n" . $s['body'];
}
}
@@ -2545,13 +2568,13 @@ class Activity {
}
foreach ($ptr as $vurl) {
if (in_array($vurl['mediaType'], $atypes) && self::media_not_in_body($vurl['href'], $s['body'])) {
- $s['body'] = '[audio]' . $vurl['href'] . '[/audio]' . "\n\n" . $s['body'];
+ $s['body'] = '[audio]' . $vurl['href'] . '[/audio]' . "\r\n" . $s['body'];
break;
}
}
}
elseif (is_string($act->obj['url']) && self::media_not_in_body($act->obj['url'], $s['body'])) {
- $s['body'] = '[audio]' . $act->obj['url'] . '[/audio]' . "\n\n" . $s['body'];
+ $s['body'] = '[audio]' . $act->obj['url'] . '[/audio]' . "\r\n" . $s['body'];
}
}
@@ -2571,7 +2594,7 @@ class Activity {
}
foreach ($ptr as $vurl) {
if (strpos($s['body'], $vurl['href']) === false) {
- $bb_imgs = '[zmg]' . $vurl['href'] . '[/zmg]' . "\n\n";
+ $bb_imgs = '[zmg]' . $vurl['href'] . '[/zmg]' . "\r\n";
break;
}
}
@@ -2579,7 +2602,7 @@ class Activity {
}
elseif (is_string($act->obj['url'])) {
if (strpos($s['body'], $act->obj['url']) === false) {
- $s['body'] .= '[zmg]' . $act->obj['url'] . '[/zmg]' . "\n\n" . $s['body'];
+ $s['body'] .= '[zmg]' . $act->obj['url'] . '[/zmg]' . "\r\n" . $s['body'];
}
}
}
@@ -2616,10 +2639,10 @@ class Activity {
if ($purl) {
$li = z_fetch_url(z_root() . '/linkinfo?binurl=' . bin2hex($purl));
if ($li['success'] && $li['body']) {
- $s['body'] .= "\n" . $li['body'];
+ $s['body'] .= "\r\n" . $li['body'];
}
else {
- $s['body'] .= "\n\n" . $purl;
+ $s['body'] .= "\r\n" . $purl;
}
}
}
@@ -3574,38 +3597,76 @@ class Activity {
return;
}
- static function bb_attach($attach, $body) {
+ public static function bb_attach($item) {
$ret = false;
- foreach ($attach as $a) {
+ if (!(is_array($item['attach']) && $item['attach'])) {
+ return $item;
+ }
+
+ foreach ($item['attach'] as $a) {
+
if (array_key_exists('type', $a) && stripos($a['type'], 'image') !== false) {
- if (self::media_not_in_body($a['href'], $body)) {
- $ret .= "\n\n" . '[img]' . $a['href'] . '[/img]';
+ // don't add inline image if it's an svg and we already have an inline svg
+ if ($a['type'] === 'image/svg+xml' && strpos($item['body'], '[/svg]')) {
+ continue;
+ }
+ if (self::media_not_in_body($a['href'], $item['body'])) {
+ if (isset($a['name']) && $a['name']) {
+ $alt = htmlspecialchars($a['name'], ENT_QUOTES);
+ $item['body'] = '[img=' . $a['href'] . ']' . $alt . '[/img]' . "\r\n" . $item['body'];
+ } else {
+ $item['body'] = '[img]' . $a['href'] . '[/img]' . "\r\n" . $item['body'];
+ }
}
}
+
if (array_key_exists('type', $a) && stripos($a['type'], 'video') !== false) {
- if (self::media_not_in_body($a['href'], $body)) {
- $ret .= "\n\n" . '[video]' . $a['href'] . '[/video]';
+ if (self::media_not_in_body($a['href'], $item['body'])) {
+ $item['body'] = '[video]' . $a['href'] . '[/video]' . "\r\n" . $item['body'];
}
}
if (array_key_exists('type', $a) && stripos($a['type'], 'audio') !== false) {
- if (self::media_not_in_body($a['href'], $body)) {
- $ret .= "\n\n" . '[audio]' . $a['href'] . '[/audio]';
+ if (self::media_not_in_body($a['href'], $item['body'])) {
+ $item['body'] = '[audio]' . $a['href'] . '[/audio]' . "\r\n" . $item['body'];
}
}
+ //if (array_key_exists('type', $a) && stripos($a['type'], 'activity') !== false) {
+ //if (self::media_not_in_body($a['href'], $item['body'])) {
+ //$item = self::get_quote($a['href'], $item);
+ //}
+ //}
}
- return $ret;
+ return $item;
}
+
// check for the existence of existing media link in body
- static function media_not_in_body($s, $body) {
- if ((strpos($body, ']' . $s . '[/img]') === false) &&
+ public static function media_not_in_body($s, $body) {
+
+ $s_alt = htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
+
+ if (
+ (strpos($body, ']' . $s . '[/img]') === false) &&
+ (strpos($body, '[img=' . $s . ']') === false) &&
(strpos($body, ']' . $s . '[/zmg]') === false) &&
+ (strpos($body, '[zmg=' . $s . ']') === false) &&
(strpos($body, ']' . $s . '[/video]') === false) &&
- (strpos($body, ']' . $s . '[/audio]') === false)) {
+ (strpos($body, ']' . $s . '[/zvideo]') === false) &&
+ (strpos($body, ']' . $s . '[/audio]') === false) &&
+ (strpos($body, ']' . $s . '[/zaudio]') === false) &&
+ (strpos($body, ']' . $s_alt . '[/img]') === false) &&
+ (strpos($body, '[img=' . $s_alt . ']') === false) &&
+ (strpos($body, ']' . $s_alt . '[/zmg]') === false) &&
+ (strpos($body, '[zmg=' . $s_alt . ']') === false) &&
+ (strpos($body, ']' . $s_alt . '[/video]') === false) &&
+ (strpos($body, ']' . $s_alt . '[/zvideo]') === false) &&
+ (strpos($body, ']' . $s_alt . '[/audio]') === false) &&
+ (strpos($body, ']' . $s_alt . '[/zaudio]') === false)
+ ) {
return true;
}
return false;