]> git.mxchange.org Git - friendica.git/commitdiff
Fix attachment handling
authorMichael <heluecht@pirati.ca>
Wed, 8 Dec 2021 13:32:20 +0000 (13:32 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 8 Dec 2021 13:32:20 +0000 (13:32 +0000)
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Util/ParseUrl.php

index 9b5d05213888918aff1ccb3c3970080292b3f9bc..74c1893d9d5df379989ec5d58daafe636fc90e43 100644 (file)
@@ -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;
        }
 
index 57f3502cc9ebeb32e962d4b9183fa5fd6815c09f..5caa6c7a151147d53b296042af66c5872db6f3c3 100644 (file)
@@ -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";
                                }
index cc65efc1436df56808e7771e4d76f398347e4ff6..8cb08f65df3788a93cf2d528d3837ff360c4dbed 100644 (file)
@@ -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;
                                }
                        }
 
index 03cfd7d7611cf338f71f375763be4dcc28b3fb20..d65ec0bb5542cd56de2e7ba365d27d902ac94dae 100644 (file)
@@ -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]);