Use PageInfo::appendDataToBody in ActivityPub\Processor::constructAttachList

This commit is contained in:
Hypolite Petovan 2020-07-17 19:39:12 -04:00
parent 972b65ba33
commit 911a23f18b
1 changed files with 11 additions and 12 deletions

View File

@ -21,6 +21,7 @@
namespace Friendica\Protocol\ActivityPub; namespace Friendica\Protocol\ActivityPub;
use Friendica\Content\PageInfo;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\Logger; use Friendica\Core\Logger;
@ -96,18 +97,16 @@ class Processor
foreach ($activity['attachments'] as $attach) { foreach ($activity['attachments'] as $attach) {
switch ($attach['type']) { switch ($attach['type']) {
case 'link': case 'link':
// Only one [attachment] tag is allowed $data = [
$existingAttachmentPos = strpos($item['body'], '[attachment'); 'url' => $attach['url'],
if ($existingAttachmentPos !== false) { 'type' => $attach['type'],
$linkTitle = $attach['title'] ?: $attach['url']; 'title' => $attach['title'] ?? '',
// Additional link attachments are prepended before the existing [attachment] tag 'text' => $attach['desc'] ?? '',
$item['body'] = substr_replace($item['body'], "\n[bookmark=" . $attach['url'] . ']' . $linkTitle . "[/bookmark]\n", $existingAttachmentPos, 0); 'image' => $attach['image'] ?? '',
} else { 'images' => [],
// Strip the link preview URL from the end of the body if any 'keywords' => [],
$quotedUrl = preg_quote($attach['url'], '#'); ];
$item['body'] = preg_replace("#\s*(?:\[bookmark={$quotedUrl}].+?\[/bookmark]|\[url={$quotedUrl}].+?\[/url]|\[url]{$quotedUrl}\[/url]|{$quotedUrl})\s*$#", '', $item['body']); $item['body'] = PageInfo::appendDataToBody($item['body'], $data);
$item['body'] .= "\n[attachment type='link' url='" . $attach['url'] . "' title='" . htmlspecialchars($attach['title'] ?? '', ENT_QUOTES) . "' image='" . ($attach['image'] ?? '') . "']" . ($attach['desc'] ?? '') . '[/attachment]';
}
break; break;
default: default:
$filetype = strtolower(substr($attach['mediaType'], 0, strpos($attach['mediaType'], '/'))); $filetype = strtolower(substr($attach['mediaType'], 0, strpos($attach['mediaType'], '/')));