From: Michael Date: Thu, 9 Nov 2023 21:31:34 +0000 (+0000) Subject: The transmitted language is now stored X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dbda317c6d77c73ded7663712f6943063743b7b8;p=friendica.git The transmitted language is now stored --- diff --git a/src/Model/Item.php b/src/Model/Item.php index 491050c582..06838630ac 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2002,13 +2002,23 @@ class Item return $item['language']; } + $transmitted = []; + foreach ($item['transmitted-languages'] ?? [] as $language) { + $transmitted[$language] = 0; + } + if (!in_array($item['gravity'], [self::GRAVITY_PARENT, self::GRAVITY_COMMENT]) || empty($item['body'])) { - return ''; + return empty($transmitted) ? '' : json_encode($transmitted); } $languages = self::getLanguageArray($item['title'] . ' ' . ($item['content-warning'] ?? '') . ' ' . $item['body'], 3, $item['uri-id'], $item['author-id']); if (empty($languages)) { - return ''; + return empty($transmitted) ? '' : json_encode($transmitted); + } + + if (!empty($transmitted)) { + $languages = array_merge($transmitted, $languages); + arsort($languages); } return json_encode($languages); @@ -2209,7 +2219,7 @@ class Item // Glue it together to be able to make a hash from it if (!empty($parsed)) { - $host_id = implode('/', $parsed); + $host_id = implode('/', (array)$parsed); } else { $host_id = $uri; } @@ -3435,7 +3445,7 @@ class Item unset($urlparts['fragment']); try { - $url = (string)Uri::fromParts($urlparts); + $url = (string)Uri::fromParts((array)$urlparts); } catch (\InvalidArgumentException $e) { DI::logger()->notice('Invalid URL', ['$url' => $url, '$urlparts' => $urlparts]); /* See https://github.com/friendica/friendica/issues/12113 diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 83c068e0ed..49116444ad 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -854,6 +854,8 @@ class Processor $item['language'] = self::processLanguages($activity['languages']); } + $item['transmitted-languages'] = $activity['transmitted-languages']; + if (!empty($activity['emojis'])) { $content = self::replaceEmojis($item['uri-id'], $content, $activity['emojis']); } @@ -1727,7 +1729,7 @@ class Processor } } - $languages = self::getPostLanguages($activity); + $languages = self::getPostLanguages($activity['as:object'] ?? ''); return Relay::isSolicitedPost($messageTags, $content, $authorid, $id, Protocol::ACTIVITYPUB, $activity['thread-completion'] ?? 0, $languages); } @@ -1738,10 +1740,10 @@ class Processor * @param array $activity * @return array */ - private static function getPostLanguages(array $activity): array + public static function getPostLanguages(array $activity): array { - $content = JsonLD::fetchElement($activity['as:object'], 'as:content') ?? ''; - $languages = JsonLD::fetchElementArray($activity['as:object'], 'as:content', '@language') ?? []; + $content = JsonLD::fetchElement($activity, 'as:content') ?? ''; + $languages = JsonLD::fetchElementArray($activity, 'as:content', '@language') ?? []; if (empty($languages)) { return []; } diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index bb671003da..cd48768cc7 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -2005,6 +2005,7 @@ class Receiver $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag') ?? []); $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', null, '@type', 'toot:Emoji') ?? []); $object_data['languages'] = self::processLanguages(JsonLD::fetchElementArray($object, 'sc:inLanguage') ?? []); + $object_data['transmitted-languages'] = Processor::getPostLanguages($object); $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application'); $object_data['generator'] = JsonLD::fetchElement($object_data, 'generator', '@value'); $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url', '@id');