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 self::storeConversation($object_data, $body);
337 // Internal flag for thread completion. See Processor.php
338 if (!empty($activity['thread-completion'])) {
339 $object_data['thread-completion'] = $activity['thread-completion'];
345 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
346 ActivityPub\Processor::createItem($object_data);
351 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
352 ActivityPub\Processor::createActivity($object_data, ACTIVITY_LIKE);
357 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
358 ActivityPub\Processor::createActivity($object_data, ACTIVITY_DISLIKE);
362 case 'as:TentativeAccept':
363 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
364 ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDMAYBE);
369 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
370 ActivityPub\Processor::updateItem($object_data);
371 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
372 ActivityPub\Processor::updatePerson($object_data, $body);
377 if ($object_data['object_type'] == 'as:Tombstone') {
378 ActivityPub\Processor::deleteItem($object_data, $body);
379 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
380 ActivityPub\Processor::deletePerson($object_data, $body);
385 if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
386 ActivityPub\Processor::followUser($object_data);
391 if ($object_data['object_type'] == 'as:Follow') {
392 ActivityPub\Processor::acceptFollowUser($object_data);
393 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
394 ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTEND);
399 if ($object_data['object_type'] == 'as:Follow') {
400 ActivityPub\Processor::rejectFollowUser($object_data);
401 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
402 ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDNO);
407 if (($object_data['object_type'] == 'as:Follow') &&
408 in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
409 ActivityPub\Processor::undoFollowUser($object_data);
410 } elseif (($object_data['object_type'] == 'as:Accept') &&
411 in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
412 ActivityPub\Processor::rejectFollowUser($object_data);
413 } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES) &&
414 in_array($object_data['object_object_type'], self::CONTENT_TYPES)) {
415 ActivityPub\Processor::undoActivity($object_data);
420 Logger::log('Unknown activity: ' . $type . ' ' . $object_data['object_type'], Logger::DEBUG);
426 * Fetch the receiver list from an activity array
428 * @param array $activity
429 * @param string $actor
432 * @return array with receivers (user id)
434 private static function getReceivers($activity, $actor, $tags = [])
438 // When it is an answer, we inherite the receivers from the parent
439 $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo');
440 if (!empty($replyto)) {
441 $parents = Item::select(['uid'], ['uri' => $replyto]);
442 while ($parent = Item::fetch($parents)) {
443 $receivers['uid:' . $parent['uid']] = $parent['uid'];
447 if (!empty($actor)) {
448 $profile = APContact::getByURL($actor);
449 $followers = defaults($profile, 'followers', '');
451 Logger::log('Actor: ' . $actor . ' - Followers: ' . $followers, Logger::DEBUG);
453 Logger::log('Empty actor', Logger::DEBUG);
457 foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
458 $receiver_list = JsonLD::fetchElementArray($activity, $element);
459 if (empty($receiver_list)) {
463 foreach ($receiver_list as $receiver) {
464 if ($receiver == self::PUBLIC_COLLECTION) {
465 $receivers['uid:0'] = 0;
468 if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
469 // This will most likely catch all OStatus connections to Mastodon
470 $condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
471 , 'archive' => false, 'pending' => false];
472 $contacts = DBA::select('contact', ['uid'], $condition);
473 while ($contact = DBA::fetch($contacts)) {
474 if ($contact['uid'] != 0) {
475 $receivers['uid:' . $contact['uid']] = $contact['uid'];
478 DBA::close($contacts);
481 if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
482 $receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags));
486 // Fetching all directly addressed receivers
487 $condition = ['self' => true, 'nurl' => Strings::normaliseLink($receiver)];
488 $contact = DBA::selectFirst('contact', ['uid', 'contact-type'], $condition);
489 if (!DBA::isResult($contact)) {
493 // Check if the potential receiver is following the actor
494 // Exception: The receiver is targetted via "to" or this is a comment
495 if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY)) {
496 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
497 $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
498 'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
500 // Forum posts are only accepted from forum contacts
501 if ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) {
502 $condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
505 if (!DBA::exists('contact', $condition)) {
510 $receivers['uid:' . $contact['uid']] = $contact['uid'];
514 self::switchContacts($receivers, $actor);
520 * Fetch the receiver list of a given actor
522 * @param string $actor
525 * @return array with receivers (user id)
527 public static function getReceiverForActor($actor, $tags)
530 $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
531 $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
532 'network' => $networks, 'archive' => false, 'pending' => false];
533 $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
534 while ($contact = DBA::fetch($contacts)) {
535 if (self::isValidReceiverForActor($contact, $actor, $tags)) {
536 $receivers['uid:' . $contact['uid']] = $contact['uid'];
539 DBA::close($contacts);
544 * Tests if the contact is a valid receiver for this actor
546 * @param array $contact
547 * @param string $actor
550 * @return array with receivers (user id)
552 private static function isValidReceiverForActor($contact, $actor, $tags)
554 // Public contacts are no valid receiver
555 if ($contact['uid'] == 0) {
559 // Are we following the contact? Then this is a valid receiver
560 if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
564 // When the possible receiver isn't a community, then it is no valid receiver
565 $owner = User::getOwnerDataById($contact['uid']);
566 if (empty($owner) || ($owner['contact-type'] != Contact::ACCOUNT_TYPE_COMMUNITY)) {
570 // Is the community account tagged?
571 foreach ($tags as $tag) {
572 if ($tag['type'] != 'Mention') {
576 if ($tag['href'] == $owner['url']) {
585 * Switches existing contacts to ActivityPub
587 * @param integer $cid Contact ID
588 * @param integer $uid User ID
589 * @param string $url Profile URL
591 public static function switchContact($cid, $uid, $url)
593 $profile = ActivityPub::probeProfile($url);
594 if (empty($profile)) {
598 Logger::log('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
600 $photo = defaults($profile, 'photo', null);
601 unset($profile['photo']);
602 unset($profile['baseurl']);
603 unset($profile['guid']);
605 $profile['nurl'] = Strings::normaliseLink($profile['url']);
606 DBA::update('contact', $profile, ['id' => $cid]);
608 Contact::updateAvatar($photo, $uid, $cid);
610 // Send a new follow request to be sure that the connection still exists
611 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
612 ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
613 Logger::log('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, Logger::DEBUG);
623 private static function switchContacts($receivers, $actor)
629 foreach ($receivers as $receiver) {
630 $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => Strings::normaliseLink($actor)]);
631 if (DBA::isResult($contact)) {
632 self::switchContact($contact['id'], $receiver, $actor);
635 $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [Strings::normaliseLink($actor), $actor]]);
636 if (DBA::isResult($contact)) {
637 self::switchContact($contact['id'], $receiver, $actor);
645 * @param $object_data
646 * @param array $activity
650 private static function addActivityFields($object_data, $activity)
652 if (!empty($activity['published']) && empty($object_data['published'])) {
653 $object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
656 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
657 $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
660 $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
666 * Fetches the object data from external ressources if needed
668 * @param string $object_id Object ID of the the provided object
669 * @param array $object The provided object array
670 * @param boolean $trust_source Do we trust the provided object?
671 * @param integer $uid User ID for the signature that we use to fetch data
673 * @return array with trusted and valid object data
675 private static function fetchObject($object_id, $object = [], $trust_source = false, $uid = 0)
677 // By fetching the type we check if the object is complete.
678 $type = JsonLD::fetchElement($object, '@type');
680 if (!$trust_source || empty($type)) {
681 $data = ActivityPub::fetchContent($object_id, $uid);
683 $object = JsonLD::compact($data);
684 Logger::log('Fetched content for ' . $object_id, Logger::DEBUG);
686 Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
688 $item = Item::selectFirst([], ['uri' => $object_id]);
689 if (!DBA::isResult($item)) {
690 Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
693 Logger::log('Using already stored item for url ' . $object_id, Logger::DEBUG);
694 $data = ActivityPub\Transmitter::createNote($item);
695 $object = JsonLD::compact($data);
698 Logger::log('Using original object for url ' . $object_id, Logger::DEBUG);
701 $type = JsonLD::fetchElement($object, '@type');
704 Logger::log('Empty type', Logger::DEBUG);
708 if (in_array($type, self::CONTENT_TYPES)) {
709 return self::processObject($object);
712 if ($type == 'as:Announce') {
713 $object_id = JsonLD::fetchElement($object, 'object');
714 if (empty($object_id)) {
717 return self::fetchObject($object_id, [], false, $uid);
720 Logger::log('Unhandled object type: ' . $type, Logger::DEBUG);
724 * Convert tags from JSON-LD format into a simplified format
726 * @param array $tags Tags in JSON-LD format
728 * @return array with tags in a simplified format
730 private static function processTags($tags)
738 foreach ($tags as $tag) {
743 $element = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
744 'href' => JsonLD::fetchElement($tag, 'as:href'),
745 'name' => JsonLD::fetchElement($tag, 'as:name')];
747 if (empty($element['type'])) {
751 $taglist[] = $element;
757 * Convert emojis from JSON-LD format into a simplified format
759 * @param array $tags Tags in JSON-LD format
761 * @return array with emojis in a simplified format
763 private static function processEmojis($emojis)
767 if (empty($emojis)) {
771 foreach ($emojis as $emoji) {
772 if (empty($emoji) || (JsonLD::fetchElement($emoji, '@type') != 'toot:Emoji') || empty($emoji['as:icon'])) {
776 $url = JsonLD::fetchElement($emoji['as:icon'], 'as:url');
777 $element = ['name' => JsonLD::fetchElement($emoji, 'as:name'),
780 $emojilist[] = $element;
786 * Convert attachments from JSON-LD format into a simplified format
788 * @param array $attachments Attachments in JSON-LD format
790 * @return array with attachmants in a simplified format
792 private static function processAttachments($attachments)
796 if (empty($attachments)) {
800 foreach ($attachments as $attachment) {
801 if (empty($attachment)) {
805 $attachlist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
806 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType'),
807 'name' => JsonLD::fetchElement($attachment, 'as:name'),
808 'url' => JsonLD::fetchElement($attachment, 'as:url')];
814 * Fetches data from the object part of an activity
816 * @param array $object
820 private static function processObject($object)
822 if (!JsonLD::fetchElement($object, '@id')) {
827 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
828 $object_data['id'] = JsonLD::fetchElement($object, '@id');
830 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo');
832 if (empty($object_data['reply-to-id'])) {
833 $object_data['reply-to-id'] = $object_data['id'];
836 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
837 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
839 if (empty($object_data['updated'])) {
840 $object_data['updated'] = $object_data['published'];
843 if (empty($object_data['published']) && !empty($object_data['updated'])) {
844 $object_data['published'] = $object_data['updated'];
847 $actor = JsonLD::fetchElement($object, 'as:attributedTo');
849 $actor = JsonLD::fetchElement($object, 'as:actor');
852 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid');
853 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment');
854 $object_data['diaspora:like'] = JsonLD::fetchElement($object, 'diaspora:like');
855 $object_data['actor'] = $object_data['author'] = $actor;
856 $object_data['context'] = JsonLD::fetchElement($object, 'as:context');
857 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation');
858 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
859 $object_data['name'] = JsonLD::fetchElement($object, 'as:name');
860 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary');
861 $object_data['content'] = JsonLD::fetchElement($object, 'as:content');
862 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
863 $object_data['start-time'] = JsonLD::fetchElement($object, 'as:startTime', '@value');
864 $object_data['end-time'] = JsonLD::fetchElement($object, 'as:endTime', '@value');
865 $object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
866 $object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
867 $object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
868 $object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
869 $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
870 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
871 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
872 $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', 'toot:Emoji'));
873 $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
874 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
876 // Special treatment for Hubzilla links
877 if (is_array($object_data['alternate-url'])) {
878 $object_data['alternate-url'] = JsonLD::fetchElement($object_data['alternate-url'], 'as:href');
880 if (!is_string($object_data['alternate-url'])) {
881 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href');
885 $object_data['receiver'] = self::getReceivers($object, $object_data['actor'], $object_data['tags']);
887 // Common object data:
890 // @context, type, actor, signature, mediaType, duration, replies, icon
892 // Also missing: (Defined in the standard, but currently unused)
893 // audience, preview, endTime, startTime, image
898 // contentMap, announcement_count, announcements, context_id, likes, like_count
899 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
904 // category, licence, language, commentsEnabled
907 // views, waitTranscoding, state, support, subtitleLanguage
908 // likes, dislikes, shares, comments