3 * @file src/Protocol/ActivityPub/Receiver.php
5 namespace Friendica\Protocol\ActivityPub;
7 use Friendica\Database\DBA;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Protocol;
10 use Friendica\Model\Contact;
11 use Friendica\Model\APContact;
12 use Friendica\Model\Conversation;
13 use Friendica\Model\Item;
14 use Friendica\Model\User;
15 use Friendica\Protocol\ActivityPub;
16 use Friendica\Util\DateTimeFormat;
17 use Friendica\Util\HTTPSignature;
18 use Friendica\Util\JsonLD;
19 use Friendica\Util\LDSignature;
20 use Friendica\Util\Strings;
23 * @brief ActivityPub Receiver Protocol class
28 * Check what this is meant to do:
37 const PUBLIC_COLLECTION = 'as:Public';
38 const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
39 const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event'];
40 const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept'];
43 * Checks if the web request is done for the AP protocol
47 public static function isRequest()
49 return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') ||
50 stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json');
54 * Checks incoming message from the inbox
58 * @param integer $uid User ID
60 public static function processInbox($body, $header, $uid)
62 $http_signer = HTTPSignature::getSigner($body, $header);
63 if (empty($http_signer)) {
64 Logger::log('Invalid HTTP signature, message will be discarded.', Logger::DEBUG);
67 Logger::log('HTTP signature is signed by ' . $http_signer, Logger::DEBUG);
70 $activity = json_decode($body, true);
72 if (empty($activity)) {
73 Logger::log('Invalid body.', Logger::DEBUG);
77 $ldactivity = JsonLD::compact($activity);
79 $actor = JsonLD::fetchElement($ldactivity, 'as:actor');
81 Logger::log('Message for user ' . $uid . ' is from actor ' . $actor, Logger::DEBUG);
83 if (LDSignature::isSigned($activity)) {
84 $ld_signer = LDSignature::getSigner($activity);
85 if (empty($ld_signer)) {
86 Logger::log('Invalid JSON-LD signature from ' . $actor, Logger::DEBUG);
88 if (!empty($ld_signer && ($actor == $http_signer))) {
89 Logger::log('The HTTP and the JSON-LD signature belong to ' . $ld_signer, Logger::DEBUG);
91 } elseif (!empty($ld_signer)) {
92 Logger::log('JSON-LD signature is signed by ' . $ld_signer, Logger::DEBUG);
94 } elseif ($actor == $http_signer) {
95 Logger::log('Bad JSON-LD signature, but HTTP signer fits the actor.', Logger::DEBUG);
98 Logger::log('Invalid JSON-LD signature and the HTTP signer is different.', Logger::DEBUG);
99 $trust_source = false;
101 } elseif ($actor == $http_signer) {
102 Logger::log('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', Logger::DEBUG);
103 $trust_source = true;
105 Logger::log('No JSON-LD signature, different actor.', Logger::DEBUG);
106 $trust_source = false;
109 self::processActivity($ldactivity, $body, $uid, $trust_source);
113 * Fetches the object type for a given object id
115 * @param array $activity
116 * @param string $object_id Object ID of the the provided object
117 * @param integer $uid User ID
119 * @return string with object type
121 private static function fetchObjectType($activity, $object_id, $uid = 0)
123 if (!empty($activity['as:object'])) {
124 $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
125 if (!empty($object_type)) {
130 if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
131 // We just assume "note" since it doesn't make a difference for the further processing
135 $profile = APContact::getByURL($object_id);
136 if (!empty($profile['type'])) {
137 return 'as:' . $profile['type'];
140 $data = ActivityPub::fetchContent($object_id, $uid);
142 $object = JsonLD::compact($data);
143 $type = JsonLD::fetchElement($object, '@type');
153 * Prepare the object array
155 * @param array $activity
156 * @param integer $uid User ID
157 * @param $trust_source
159 * @return array with object data
161 private static function prepareObjectData($activity, $uid, &$trust_source)
163 $actor = JsonLD::fetchElement($activity, 'as:actor');
165 Logger::log('Empty actor', Logger::DEBUG);
169 $type = JsonLD::fetchElement($activity, '@type');
171 // Fetch all receivers from to, cc, bto and bcc
172 $receivers = self::getReceivers($activity, $actor);
174 // When it is a delivery to a personal inbox we add that user to the receivers
176 $additional = ['uid:' . $uid => $uid];
177 $receivers = array_merge($receivers, $additional);
179 // We possibly need some user to fetch private content,
180 // so we fetch the first out ot the list.
181 $uid = self::getFirstUserFromReceivers($receivers);
184 Logger::log('Receivers: ' . $uid . ' - ' . json_encode($receivers), Logger::DEBUG);
186 $object_id = JsonLD::fetchElement($activity, 'as:object');
187 if (empty($object_id)) {
188 Logger::log('No object found', Logger::DEBUG);
192 $object_type = self::fetchObjectType($activity, $object_id, $uid);
194 // Fetch the content only on activities where this matters
195 if (in_array($type, ['as:Create', 'as:Update', 'as:Announce'])) {
196 if ($type == 'as:Announce') {
197 $trust_source = false;
199 $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source, $uid);
200 if (empty($object_data)) {
201 Logger::log("Object data couldn't be processed", Logger::DEBUG);
204 // We had been able to retrieve the object data - so we can trust the source
205 $trust_source = true;
206 } elseif (in_array($type, ['as:Like', 'as:Dislike'])) {
207 // Create a mostly empty array out of the activity data (instead of the object).
208 // This way we later don't have to check for the existence of ech individual array element.
209 $object_data = self::processObject($activity);
210 $object_data['name'] = $type;
211 $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor');
212 $object_data['object_id'] = $object_id;
213 $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
216 $object_data['id'] = JsonLD::fetchElement($activity, '@id');
217 $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object');
218 $object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor');
219 $object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
220 $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
222 // An Undo is done on the object of an object, so we need that type as well
223 if ($type == 'as:Undo') {
224 $object_data['object_object_type'] = self::fetchObjectType([], $object_data['object_object'], $uid);
228 $object_data = self::addActivityFields($object_data, $activity);
230 if (empty($object_data['object_type'])) {
231 $object_data['object_type'] = $object_type;
234 $object_data['type'] = $type;
235 $object_data['actor'] = $actor;
236 $object_data['item_receiver'] = $receivers;
237 $object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers);
239 Logger::log('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], Logger::DEBUG);
245 * Fetches the first user id from the receiver array
247 * @param array $receivers Array with receivers
248 * @return integer user id;
250 public static function getFirstUserFromReceivers($receivers)
252 foreach ($receivers as $receiver) {
253 if (!empty($receiver)) {
261 * Store the unprocessed data into the conversation table
262 * This has to be done outside the regular function,
263 * since we store everything - not only item posts.
265 * @param array $activity Array with activity data
266 * @param string $body The raw message
268 private static function storeConversation($activity, $body)
270 if (empty($body) || empty($activity['id'])) {
275 'protocol' => Conversation::PARCEL_ACTIVITYPUB,
276 'item-uri' => $activity['id'],
277 'reply-to-uri' => defaults($activity, 'reply-to-id', ''),
278 'conversation-href' => defaults($activity, 'context', ''),
279 'conversation-uri' => defaults($activity, 'conversation', ''),
281 'received' => DateTimeFormat::utcNow()];
283 DBA::insert('conversation', $conversation, true);
287 * Processes the activity object
289 * @param array $activity Array with activity data
290 * @param string $body
291 * @param integer $uid User ID
292 * @param boolean $trust_source Do we trust the source?
294 public static function processActivity($activity, $body = '', $uid = null, $trust_source = false)
296 $type = JsonLD::fetchElement($activity, '@type');
298 Logger::log('Empty type', Logger::DEBUG);
302 if (!JsonLD::fetchElement($activity, 'as:object')) {
303 Logger::log('Empty object', Logger::DEBUG);
307 if (!JsonLD::fetchElement($activity, 'as:actor')) {
308 Logger::log('Empty actor', Logger::DEBUG);
313 // Don't trust the source if "actor" differs from "attributedTo". The content could be forged.
314 if ($trust_source && ($type == 'as:Create') && is_array($activity['as:object'])) {
315 $actor = JsonLD::fetchElement($activity, 'as:actor');
316 $attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo');
317 $trust_source = ($actor == $attributed_to);
318 if (!$trust_source) {
319 Logger::log('Not trusting actor: ' . $actor . '. It differs from attributedTo: ' . $attributed_to, Logger::DEBUG);
323 // $trust_source is called by reference and is set to true if the content was retrieved successfully
324 $object_data = self::prepareObjectData($activity, $uid, $trust_source);
325 if (empty($object_data)) {
326 Logger::log('No object data found', Logger::DEBUG);
330 if (!$trust_source) {
331 Logger::log('No trust for activity type "' . $type . '", so we quit now.', Logger::DEBUG);
335 // Only store content related stuff - and no announces, since they possibly overwrite the original content
336 if (in_array($object_data['object_type'], self::CONTENT_TYPES) && ($type != 'as:Announce')) {
337 self::storeConversation($object_data, $body);
340 // Internal flag for thread completion. See Processor.php
341 if (!empty($activity['thread-completion'])) {
342 $object_data['thread-completion'] = $activity['thread-completion'];
348 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
349 ActivityPub\Processor::createItem($object_data);
354 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
355 ActivityPub\Processor::createActivity($object_data, ACTIVITY_LIKE);
360 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
361 ActivityPub\Processor::createActivity($object_data, ACTIVITY_DISLIKE);
365 case 'as:TentativeAccept':
366 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
367 ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDMAYBE);
372 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
373 ActivityPub\Processor::updateItem($object_data);
374 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
375 ActivityPub\Processor::updatePerson($object_data, $body);
380 if ($object_data['object_type'] == 'as:Tombstone') {
381 ActivityPub\Processor::deleteItem($object_data, $body);
382 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
383 ActivityPub\Processor::deletePerson($object_data, $body);
388 if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
389 ActivityPub\Processor::followUser($object_data);
394 if ($object_data['object_type'] == 'as:Follow') {
395 ActivityPub\Processor::acceptFollowUser($object_data);
396 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
397 ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTEND);
402 if ($object_data['object_type'] == 'as:Follow') {
403 ActivityPub\Processor::rejectFollowUser($object_data);
404 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
405 ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDNO);
410 if (($object_data['object_type'] == 'as:Follow') &&
411 in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
412 ActivityPub\Processor::undoFollowUser($object_data);
413 } elseif (($object_data['object_type'] == 'as:Accept') &&
414 in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
415 ActivityPub\Processor::rejectFollowUser($object_data);
416 } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES) &&
417 in_array($object_data['object_object_type'], self::CONTENT_TYPES)) {
418 ActivityPub\Processor::undoActivity($object_data);
423 Logger::log('Unknown activity: ' . $type . ' ' . $object_data['object_type'], Logger::DEBUG);
429 * Fetch the receiver list from an activity array
431 * @param array $activity
432 * @param string $actor
435 * @return array with receivers (user id)
437 private static function getReceivers($activity, $actor, $tags = [])
441 // When it is an answer, we inherite the receivers from the parent
442 $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo');
443 if (!empty($replyto)) {
444 $parents = Item::select(['uid'], ['uri' => $replyto]);
445 while ($parent = Item::fetch($parents)) {
446 $receivers['uid:' . $parent['uid']] = $parent['uid'];
450 if (!empty($actor)) {
451 $profile = APContact::getByURL($actor);
452 $followers = defaults($profile, 'followers', '');
454 Logger::log('Actor: ' . $actor . ' - Followers: ' . $followers, Logger::DEBUG);
456 Logger::log('Empty actor', Logger::DEBUG);
460 foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
461 $receiver_list = JsonLD::fetchElementArray($activity, $element);
462 if (empty($receiver_list)) {
466 foreach ($receiver_list as $receiver) {
467 if ($receiver == self::PUBLIC_COLLECTION) {
468 $receivers['uid:0'] = 0;
471 if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
472 // This will most likely catch all OStatus connections to Mastodon
473 $condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
474 , 'archive' => false, 'pending' => false];
475 $contacts = DBA::select('contact', ['uid'], $condition);
476 while ($contact = DBA::fetch($contacts)) {
477 if ($contact['uid'] != 0) {
478 $receivers['uid:' . $contact['uid']] = $contact['uid'];
481 DBA::close($contacts);
484 if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
485 $receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags));
489 // Fetching all directly addressed receivers
490 $condition = ['self' => true, 'nurl' => Strings::normaliseLink($receiver)];
491 $contact = DBA::selectFirst('contact', ['uid', 'contact-type'], $condition);
492 if (!DBA::isResult($contact)) {
496 // Check if the potential receiver is following the actor
497 // Exception: The receiver is targetted via "to" or this is a comment
498 if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY)) {
499 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
500 $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
501 'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
503 // Forum posts are only accepted from forum contacts
504 if ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
505 $condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
508 if (!DBA::exists('contact', $condition)) {
513 $receivers['uid:' . $contact['uid']] = $contact['uid'];
517 self::switchContacts($receivers, $actor);
523 * Fetch the receiver list of a given actor
525 * @param string $actor
528 * @return array with receivers (user id)
530 public static function getReceiverForActor($actor, $tags)
533 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
534 $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
535 'network' => $networks, 'archive' => false, 'pending' => false];
536 $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
537 while ($contact = DBA::fetch($contacts)) {
538 if (self::isValidReceiverForActor($contact, $actor, $tags)) {
539 $receivers['uid:' . $contact['uid']] = $contact['uid'];
542 DBA::close($contacts);
547 * Tests if the contact is a valid receiver for this actor
549 * @param array $contact
550 * @param string $actor
553 * @return array with receivers (user id)
555 private static function isValidReceiverForActor($contact, $actor, $tags)
557 // Public contacts are no valid receiver
558 if ($contact['uid'] == 0) {
562 // Are we following the contact? Then this is a valid receiver
563 if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
567 // When the possible receiver isn't a community, then it is no valid receiver
568 $owner = User::getOwnerDataById($contact['uid']);
569 if (empty($owner) || ($owner['contact-type'] != Contact::ACCOUNT_TYPE_COMMUNITY)) {
573 // Is the community account tagged?
574 foreach ($tags as $tag) {
575 if ($tag['type'] != 'Mention') {
579 if ($tag['href'] == $owner['url']) {
588 * Switches existing contacts to ActivityPub
590 * @param integer $cid Contact ID
591 * @param integer $uid User ID
592 * @param string $url Profile URL
594 public static function switchContact($cid, $uid, $url)
596 $profile = ActivityPub::probeProfile($url);
597 if (empty($profile)) {
601 Logger::log('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
603 $photo = defaults($profile, 'photo', null);
604 unset($profile['photo']);
605 unset($profile['baseurl']);
606 unset($profile['guid']);
608 $profile['nurl'] = Strings::normaliseLink($profile['url']);
609 DBA::update('contact', $profile, ['id' => $cid]);
611 Contact::updateAvatar($photo, $uid, $cid);
613 // Send a new follow request to be sure that the connection still exists
614 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
615 ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
616 Logger::log('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, Logger::DEBUG);
626 private static function switchContacts($receivers, $actor)
632 foreach ($receivers as $receiver) {
633 $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => Strings::normaliseLink($actor)]);
634 if (DBA::isResult($contact)) {
635 self::switchContact($contact['id'], $receiver, $actor);
638 $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [Strings::normaliseLink($actor), $actor]]);
639 if (DBA::isResult($contact)) {
640 self::switchContact($contact['id'], $receiver, $actor);
648 * @param $object_data
649 * @param array $activity
653 private static function addActivityFields($object_data, $activity)
655 if (!empty($activity['published']) && empty($object_data['published'])) {
656 $object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
659 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
660 $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
663 $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
669 * Fetches the object data from external ressources if needed
671 * @param string $object_id Object ID of the the provided object
672 * @param array $object The provided object array
673 * @param boolean $trust_source Do we trust the provided object?
674 * @param integer $uid User ID for the signature that we use to fetch data
676 * @return array with trusted and valid object data
678 private static function fetchObject($object_id, $object = [], $trust_source = false, $uid = 0)
680 // By fetching the type we check if the object is complete.
681 $type = JsonLD::fetchElement($object, '@type');
683 if (!$trust_source || empty($type)) {
684 $data = ActivityPub::fetchContent($object_id, $uid);
686 $object = JsonLD::compact($data);
687 Logger::log('Fetched content for ' . $object_id, Logger::DEBUG);
689 Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
691 $item = Item::selectFirst([], ['uri' => $object_id]);
692 if (!DBA::isResult($item)) {
693 Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
696 Logger::log('Using already stored item for url ' . $object_id, Logger::DEBUG);
697 $data = ActivityPub\Transmitter::createNote($item);
698 $object = JsonLD::compact($data);
701 Logger::log('Using original object for url ' . $object_id, Logger::DEBUG);
704 $type = JsonLD::fetchElement($object, '@type');
707 Logger::log('Empty type', Logger::DEBUG);
711 if (in_array($type, self::CONTENT_TYPES)) {
712 return self::processObject($object);
715 if ($type == 'as:Announce') {
716 $object_id = JsonLD::fetchElement($object, 'object');
717 if (empty($object_id)) {
720 return self::fetchObject($object_id, [], false, $uid);
723 Logger::log('Unhandled object type: ' . $type, Logger::DEBUG);
727 * Convert tags from JSON-LD format into a simplified format
729 * @param array $tags Tags in JSON-LD format
731 * @return array with tags in a simplified format
733 private static function processTags($tags)
741 foreach ($tags as $tag) {
746 $element = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
747 'href' => JsonLD::fetchElement($tag, 'as:href'),
748 'name' => JsonLD::fetchElement($tag, 'as:name')];
750 if (empty($element['type'])) {
754 $taglist[] = $element;
760 * Convert emojis from JSON-LD format into a simplified format
762 * @param array $tags Tags in JSON-LD format
764 * @return array with emojis in a simplified format
766 private static function processEmojis($emojis)
770 if (empty($emojis)) {
774 foreach ($emojis as $emoji) {
775 if (empty($emoji) || (JsonLD::fetchElement($emoji, '@type') != 'toot:Emoji') || empty($emoji['as:icon'])) {
779 $url = JsonLD::fetchElement($emoji['as:icon'], 'as:url');
780 $element = ['name' => JsonLD::fetchElement($emoji, 'as:name'),
783 $emojilist[] = $element;
789 * Convert attachments from JSON-LD format into a simplified format
791 * @param array $attachments Attachments in JSON-LD format
793 * @return array with attachmants in a simplified format
795 private static function processAttachments($attachments)
799 if (empty($attachments)) {
803 foreach ($attachments as $attachment) {
804 if (empty($attachment)) {
808 $attachlist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
809 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType'),
810 'name' => JsonLD::fetchElement($attachment, 'as:name'),
811 'url' => JsonLD::fetchElement($attachment, 'as:url')];
817 * Fetches data from the object part of an activity
819 * @param array $object
823 private static function processObject($object)
825 if (!JsonLD::fetchElement($object, '@id')) {
830 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
831 $object_data['id'] = JsonLD::fetchElement($object, '@id');
832 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo');
834 // An empty "id" field is translated to "./" by the compactor, so we have to check for this content
835 if (empty($object_data['reply-to-id']) || ($object_data['reply-to-id'] == './')) {
836 $object_data['reply-to-id'] = $object_data['id'];
839 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
840 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
842 if (empty($object_data['updated'])) {
843 $object_data['updated'] = $object_data['published'];
846 if (empty($object_data['published']) && !empty($object_data['updated'])) {
847 $object_data['published'] = $object_data['updated'];
850 $actor = JsonLD::fetchElement($object, 'as:attributedTo');
852 $actor = JsonLD::fetchElement($object, 'as:actor');
855 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid');
856 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment');
857 $object_data['diaspora:like'] = JsonLD::fetchElement($object, 'diaspora:like');
858 $object_data['actor'] = $object_data['author'] = $actor;
859 $object_data['context'] = JsonLD::fetchElement($object, 'as:context');
860 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation');
861 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
862 $object_data['name'] = JsonLD::fetchElement($object, 'as:name');
863 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary');
864 $object_data['content'] = JsonLD::fetchElement($object, 'as:content');
865 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
866 $object_data['start-time'] = JsonLD::fetchElement($object, 'as:startTime', '@value');
867 $object_data['end-time'] = JsonLD::fetchElement($object, 'as:endTime', '@value');
868 $object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
869 $object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
870 $object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
871 $object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
872 $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
873 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
874 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
875 $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', 'toot:Emoji'));
876 $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
877 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
879 // Special treatment for Hubzilla links
880 if (is_array($object_data['alternate-url'])) {
881 $object_data['alternate-url'] = JsonLD::fetchElement($object_data['alternate-url'], 'as:href');
883 if (!is_string($object_data['alternate-url'])) {
884 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href');
888 $object_data['receiver'] = self::getReceivers($object, $object_data['actor'], $object_data['tags']);
890 // Common object data:
893 // @context, type, actor, signature, mediaType, duration, replies, icon
895 // Also missing: (Defined in the standard, but currently unused)
896 // audience, preview, endTime, startTime, image
901 // contentMap, announcement_count, announcements, context_id, likes, like_count
902 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
907 // category, licence, language, commentsEnabled
910 // views, waitTranscoding, state, support, subtitleLanguage
911 // likes, dislikes, shares, comments