From d6c97dbde23c3aa71b8501888a8f8ffa3f5d5b86 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Dec 2021 13:32:20 +0000 Subject: [PATCH] Fix attachment handling --- src/Protocol/ActivityPub/Transmitter.php | 48 +----------------------- src/Protocol/Diaspora.php | 2 +- src/Protocol/Feed.php | 11 +++++- src/Util/ParseUrl.php | 18 ++++++++- 4 files changed, 29 insertions(+), 50 deletions(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 9b5d052138..74c1893d9d 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1293,7 +1293,7 @@ class Transmitter $urls = []; foreach ($uriids as $uriid) { - foreach (Post\Media::getByURIId($uriid, [Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) { + foreach (Post\Media::getByURIId($uriid, [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO, Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) { if (in_array($attachment['url'], $urls)) { continue; } @@ -1320,52 +1320,6 @@ class Transmitter } } - if ($type != 'Note') { - return $attachments; - } - - foreach ($uriids as $uriid) { - foreach (Post\Media::getByURIId($uriid, [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]) as $attachment) { - if (in_array($attachment['url'], $urls)) { - continue; - } - $urls[] = $attachment['url']; - - $attach = ['type' => 'Document', - 'mediaType' => $attachment['mimetype'], - 'url' => $attachment['url'], - 'name' => $attachment['description']]; - - if (!empty($attachment['height'])) { - $attach['height'] = $attachment['height']; - } - - if (!empty($attachment['width'])) { - $attach['width'] = $attachment['width']; - } - - if (!empty($attachment['preview'])) { - $attach['image'] = $attachment['preview']; - } - - $attachments[] = $attach; - } - // Currently deactivated, since it creates side effects on Mastodon and Pleroma. - // It will be activated, once this cleared. - /* - foreach (Post\Media::getByURIId($uriid, [Post\Media::HTML]) as $attachment) { - if (in_array($attachment['url'], $urls)) { - continue; - } - $urls[] = $attachment['url']; - - $attachments[] = ['type' => 'Page', - 'mediaType' => $attachment['mimetype'], - 'url' => $attachment['url'], - 'name' => $attachment['description']]; - }*/ - } - return $attachments; } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 57f3502cc9..5caa6c7a15 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3411,7 +3411,7 @@ class Diaspora $attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]); if (!empty($attachments)) { - $body .= "\n".DI::l10n()->t("Attachments:")."\n"; + $body .= "\n[hr]\n"; foreach ($attachments as $attachment) { $body .= "[" . $attachment['description'] . "](" . $attachment['url'] . ")\n"; } diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index cc65efc143..8cb08f65df 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -401,7 +401,16 @@ class Feed } if (!empty($href)) { - $attachments[] = ['type' => Post\Media::DOCUMENT, 'url' => $href, 'mimetype' => $type, 'size' => $length]; + $attachment = ['type' => Post\Media::UNKNOWN, 'url' => $href, 'mimetype' => $type, 'size' => $length]; + + $attachment = Post\Media::fetchAdditionalData($attachment); + + // By now we separate the visible media types (audio, video, image) from the rest + // In the future we should try to avoid the DOCUMENT type and only use the real one - but not in the RC phase. + if (!in_array($attachment['type'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO])) { + $attachment['type'] = Post\Media::DOCUMENT; + } + $attachments[] = $attachment; } } diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 03cfd7d761..d65ec0bb55 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -451,6 +451,12 @@ class ParseUrl case 'og:site_name': $siteinfo['publisher_name'] = trim($meta_tag['content']); break; + case 'og:locale': + $siteinfo['language'] = trim($meta_tag['content']); + break; + case 'og:type': + $siteinfo['type'] = trim($meta_tag['content']); + break; case 'twitter:description': $siteinfo['text'] = trim($meta_tag['content']); break; @@ -521,7 +527,7 @@ class ParseUrl * * @param string $page_url * @param array $siteinfo - * @return void + * @return array */ private static function checkMedia(string $page_url, array $siteinfo) : array { @@ -967,6 +973,16 @@ class ParseUrl } } + $content = JsonLD::fetchElement($jsonld, 'datePublished'); + if (!empty($content) && is_string($content)) { + $jsonldinfo['published'] = DateTimeFormat::utc($content); + } + + $content = JsonLD::fetchElement($jsonld, 'dateModified'); + if (!empty($content) && is_string($content)) { + $jsonldinfo['modified'] = DateTimeFormat::utc($content); + } + $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld); Logger::info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);