From: Michael Date: Wed, 13 Nov 2019 16:22:20 +0000 (+0000) Subject: AP: Read different content types for the source and the content X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fa57fead2e1c5a5183fc74450c2bec2983b6e836;p=friendica.git AP: Read different content types for the source and the content --- diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 1bc6f90415..685f3a85e2 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -5,6 +5,8 @@ namespace Friendica\Protocol\ActivityPub; use Friendica\Database\DBA; +use Friendica\Content\Text\HTML; +use Friendica\Content\Text\Markdown; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Model\Contact; @@ -874,6 +876,52 @@ class Receiver return $attachlist; } + /** + * Fetch the original source or content with the "language" Markdown or HTML + * + * @param array $object + * @param array $object_data + * + * @return array + * @throws \Exception + */ + private static function getSource($object, $object_data) + { + $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode'); + $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value'); + if (!empty($object_data['source'])) { + return $object_data; + } + + $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/markdown'); + $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value'); + if (!empty($object_data['source'])) { + $object_data['source'] = Markdown::toBBCode($object_data['source']); + return $object_data; + } + + $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/html'); + $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value'); + if (!empty($object_data['source'])) { + $object_data['source'] = HTML::toBBCode($object_data['source']); + return $object_data; + } + + $markdown = JsonLD::fetchElement($object, 'as:content', '@value', '@language', 'text/markdown'); + if (!empty($markdown)) { + $object_data['source'] = Markdown::toBBCode($markdown); + return $object_data; + } + + $html = JsonLD::fetchElement($object, 'as:content', '@value', '@language', 'text/html'); + if (!empty($html)) { + $object_data['source'] = HTML::toBBCode($markdown); + return $object_data; + } + + return $object_data; + } + /** * Fetches data from the object part of an activity * @@ -924,8 +972,7 @@ class Receiver $object_data['name'] = JsonLD::fetchElement($object, 'as:name', '@value'); $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary', '@value'); $object_data['content'] = JsonLD::fetchElement($object, 'as:content', '@value'); - $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode'); - $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value'); + $object_data = self::getSource($object, $object_data); $object_data['start-time'] = JsonLD::fetchElement($object, 'as:startTime', '@value'); $object_data['end-time'] = JsonLD::fetchElement($object, 'as:endTime', '@value'); $object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');