Fix attachment handling

This commit is contained in:
Michael 2021-12-08 13:32:20 +00:00
parent e01bda56c5
commit d6c97dbde2
4 changed files with 29 additions and 50 deletions

View File

@ -1293,7 +1293,7 @@ class Transmitter
$urls = []; $urls = [];
foreach ($uriids as $uriid) { 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)) { if (in_array($attachment['url'], $urls)) {
continue; 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; return $attachments;
} }

View File

@ -3411,7 +3411,7 @@ class Diaspora
$attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]); $attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]);
if (!empty($attachments)) { if (!empty($attachments)) {
$body .= "\n".DI::l10n()->t("Attachments:")."\n"; $body .= "\n[hr]\n";
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
$body .= "[" . $attachment['description'] . "](" . $attachment['url'] . ")\n"; $body .= "[" . $attachment['description'] . "](" . $attachment['url'] . ")\n";
} }

View File

@ -401,7 +401,16 @@ class Feed
} }
if (!empty($href)) { 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;
} }
} }

View File

@ -451,6 +451,12 @@ class ParseUrl
case 'og:site_name': case 'og:site_name':
$siteinfo['publisher_name'] = trim($meta_tag['content']); $siteinfo['publisher_name'] = trim($meta_tag['content']);
break; break;
case 'og:locale':
$siteinfo['language'] = trim($meta_tag['content']);
break;
case 'og:type':
$siteinfo['type'] = trim($meta_tag['content']);
break;
case 'twitter:description': case 'twitter:description':
$siteinfo['text'] = trim($meta_tag['content']); $siteinfo['text'] = trim($meta_tag['content']);
break; break;
@ -521,7 +527,7 @@ class ParseUrl
* *
* @param string $page_url * @param string $page_url
* @param array $siteinfo * @param array $siteinfo
* @return void * @return array
*/ */
private static function checkMedia(string $page_url, array $siteinfo) : 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); $jsonldinfo = self::parseJsonLdAuthor($jsonldinfo, $jsonld);
Logger::info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]); Logger::info('Fetched article information', ['url' => $siteinfo['url'], 'fetched' => $jsonldinfo]);