]> git.mxchange.org Git - friendica.git/commitdiff
Use the fetched mimetype if present
authorMichael <heluecht@pirati.ca>
Sat, 4 Jan 2025 08:48:22 +0000 (08:48 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 4 Jan 2025 22:19:16 +0000 (22:19 +0000)
src/Model/Post/Media.php
src/Protocol/ActivityPub/Receiver.php

index 6e258bc17492268618e12e06f6d890bb8ac9e763..3ece6e26515def4c6886f8624b53481edf74dcc8 100644 (file)
@@ -157,8 +157,11 @@ class Media
        public static function getAttachElement(string $href, int $length, string $type, string $title = ''): string
        {
                $media = self::fetchAdditionalData([
-                       'type' => self::DOCUMENT, 'url' => $href,
-                       'size' => $length, 'mimetype' => $type, 'description' => $title
+                       'type'        => self::DOCUMENT,
+                       'url'         => $href,
+                       'size'        => $length,
+                       'mimetype'    => $type,
+                       'description' => $title
                ]);
 
                return '[attach]href="' . $media['url'] . '" length="' . $media['size'] .
@@ -184,7 +187,7 @@ class Media
                }
 
                // Fetch the mimetype or size if missing.
-               if (Network::isValidHttpUrl($media['url']) && empty($media['mimetype']) && !in_array($media['type'], [self::IMAGE, self::HLS])) {
+               if (Network::isValidHttpUrl($media['url']) && (empty($media['mimetype']) || $media['type'] == self::HTML) && !in_array($media['type'], [self::IMAGE, self::HLS])) {
                        $timeout = DI::config()->get('system', 'xrd_timeout');
                        try {
                                $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::AS_DEFAULT, HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
@@ -194,8 +197,8 @@ class Media
                                        $curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::AS_DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
                                }
                                if ($curlResult->isSuccess()) {
-                                       if (empty($media['mimetype'])) {
-                                               $media['mimetype'] = $curlResult->getContentType() ?? '';
+                                       if (!empty($curlResult->getContentType())) {
+                                               $media['mimetype'] = $curlResult->getContentType();
                                        }
                                        if (empty($media['size'])) {
                                                $media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? strlen($curlResult->getBodyString() ?? ''));
@@ -419,9 +422,9 @@ class Media
                        $media['preview-width'] = $data['images'][0]['width'] ?? null;
                        $media['blurhash'] = $data['images'][0]['blurhash'] ?? null;
                        $media['description'] = $data['text'] ?? null;
-                       $media['name'] = $data['title'] ?? null;        
+                       $media['name'] = $data['title'] ?? null;
                }
-               
+
                $media['type'] = self::HTML;
                $media['size'] = $data['size'] ?? null;
                $media['author-url'] = $data['author_url'] ?? null;
@@ -612,20 +615,29 @@ class Media
                                        $body = str_replace($picture[0], '', $body);
                                        $image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
                                        $attachments[$image] = [
-                                               'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
-                                               'preview' => $picture[2], 'description' => $picture[3]
+                                               'uri-id'      => $uriid,
+                                               'type'        => self::IMAGE,
+                                               'url'         => $image,
+                                               'preview'     => $picture[2],
+                                               'description' => $picture[3]
                                        ];
                                } elseif (self::isLinkToPhoto($picture[1], $picture[2])) {
                                        $body = str_replace($picture[0], '', $body);
                                        $attachments[$picture[1]] = [
-                                               'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1],
-                                               'preview' => $picture[2], 'description' => $picture[3]
+                                               'uri-id'      => $uriid,
+                                               'type'        => self::IMAGE,
+                                               'url'         => $picture[1],
+                                               'preview'     => $picture[2],
+                                               'description' => $picture[3]
                                        ];
                                } elseif ($removepicturelinks) {
                                        $body = str_replace($picture[0], '', $body);
                                        $attachments[$picture[1]] = [
-                                               'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1],
-                                               'preview' => $picture[2], 'description' => $picture[3]
+                                               'uri-id'      => $uriid,
+                                               'type'        => self::UNKNOWN,
+                                               'url'         => $picture[1],
+                                               'preview'     => $picture[2],
+                                               'description' => $picture[3]
                                        ];
                                }
                        }
@@ -644,20 +656,29 @@ class Media
                                        $body = str_replace($picture[0], '', $body);
                                        $image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
                                        $attachments[$image] = [
-                                               'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
-                                               'preview' => $picture[2], 'description' => null
+                                               'uri-id'      => $uriid,
+                                               'type'        => self::IMAGE,
+                                               'url'         => $image,
+                                               'preview'     => $picture[2],
+                                               'description' => null
                                        ];
                                } elseif (self::isLinkToPhoto($picture[1], $picture[2])) {
                                        $body = str_replace($picture[0], '', $body);
                                        $attachments[$picture[1]] = [
-                                               'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $picture[1],
-                                               'preview' => $picture[2], 'description' => null
+                                               'uri-id'      => $uriid,
+                                               'type'        => self::IMAGE,
+                                               'url'         => $picture[1],
+                                               'preview'     => $picture[2],
+                                               'description' => null
                                        ];
                                } elseif ($removepicturelinks) {
                                        $body = str_replace($picture[0], '', $body);
                                        $attachments[$picture[1]] = [
-                                               'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1],
-                                               'preview' => $picture[2], 'description' => null
+                                               'uri-id'      => $uriid,
+                                               'type'        => self::UNKNOWN,
+                                               'url'         => $picture[1],
+                                               'preview'     => $picture[2],
+                                               'description' => null
                                        ];
                                }
                        }
index 3e8ad6ff8dfe433eb36a0876a2f7337e5795aa81..170d6b7aff990f87a421190160943f1c315a3c38 100644 (file)
@@ -2037,9 +2037,15 @@ class Receiver
 
                // Support for quoted posts (Pleroma, Fedibird and Misskey)
                $object_data['quote-url'] = JsonLD::fetchElement($object, 'as:quoteUrl', '@id');
+               if (empty($object_data['quote-url'])) {
+                       $object_data['quote-url'] = JsonLD::fetchElement($object, 'as:quoteUrl', '@value');
+               }
                if (empty($object_data['quote-url'])) {
                        $object_data['quote-url'] = JsonLD::fetchElement($object, 'fedibird:quoteUri', '@id');
                }
+               if (empty($object_data['quote-url'])) {
+                       $object_data['quote-url'] = JsonLD::fetchElement($object, 'fedibird:quoteUri', '@value');
+               }
                if (empty($object_data['quote-url'])) {
                        $object_data['quote-url'] = JsonLD::fetchElement($object, 'misskey:_misskey_quote', '@id');
                }