From d6c97dbde23c3aa71b8501888a8f8ffa3f5d5b86 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Dec 2021 13:32:20 +0000 Subject: [PATCH 1/2] 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 9b5d05213..74c1893d9 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 57f3502cc..5caa6c7a1 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 cc65efc14..8cb08f65d 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 03cfd7d76..d65ec0bb5 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]); From e6823dac679a97899ad3497ffb08c677c06079dd Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Dec 2021 13:44:03 +0000 Subject: [PATCH 2/2] Updated messages.po --- view/lang/C/messages.po | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index ad74d35fd..17d33bc16 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2021.12-rc\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-12-07 16:06+0100\n" +"POT-Creation-Date: 2021-12-08 13:36+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -8628,19 +8628,19 @@ msgstr "" #: src/Module/Profile/Profile.php:326 src/Module/Profile/Profile.php:329 #: src/Module/Profile/Status.php:65 src/Module/Profile/Status.php:68 -#: src/Protocol/Feed.php:976 src/Protocol/OStatus.php:1242 +#: src/Protocol/Feed.php:985 src/Protocol/OStatus.php:1242 #, php-format msgid "%s's timeline" msgstr "" #: src/Module/Profile/Profile.php:327 src/Module/Profile/Status.php:66 -#: src/Protocol/Feed.php:980 src/Protocol/OStatus.php:1246 +#: src/Protocol/Feed.php:989 src/Protocol/OStatus.php:1246 #, php-format msgid "%s's posts" msgstr "" #: src/Module/Profile/Profile.php:328 src/Module/Profile/Status.php:67 -#: src/Protocol/Feed.php:983 src/Protocol/OStatus.php:1249 +#: src/Protocol/Feed.php:992 src/Protocol/OStatus.php:1249 #, php-format msgid "%s's comments" msgstr "" @@ -10547,10 +10547,6 @@ msgstr "" msgid "Show fewer" msgstr "" -#: src/Protocol/Diaspora.php:3414 -msgid "Attachments:" -msgstr "" - #: src/Protocol/OStatus.php:1645 #, php-format msgid "%s is now following %s."