]> git.mxchange.org Git - friendica.git/blob - src/Protocol/ActivityPub/Receiver.php
4341c14a3f42b544e927229f6090fd83945d72b1
[friendica.git] / src / Protocol / ActivityPub / Receiver.php
1 <?php
2 /**
3  * @file src/Protocol/ActivityPub/Receiver.php
4  */
5 namespace Friendica\Protocol\ActivityPub;
6
7 use Friendica\Database\DBA;
8 use Friendica\Util\HTTPSignature;
9 use Friendica\Core\Protocol;
10 use Friendica\Model\Contact;
11 use Friendica\Model\APContact;
12 use Friendica\Model\Item;
13 use Friendica\Model\User;
14 use Friendica\Util\JsonLD;
15 use Friendica\Util\LDSignature;
16 use Friendica\Protocol\ActivityPub;
17 use Friendica\Model\Conversation;
18 use Friendica\Util\DateTimeFormat;
19
20 /**
21  * @brief ActivityPub Receiver Protocol class
22  *
23  * To-Do:
24  * - Update (Image, Video, Article, Note)
25  * - Event
26  * - Undo Announce
27  *
28  * Check what this is meant to do:
29  * - Add
30  * - Block
31  * - Flag
32  * - Remove
33  * - Undo Block
34  * - Undo Accept (Problem: This could invert a contact accept or an event accept)
35  */
36 class Receiver
37 {
38         const PUBLIC_COLLECTION = 'as:Public';
39         const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
40         const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image'];
41         const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept'];
42
43         /**
44          * Checks if the web request is done for the AP protocol
45          *
46          * @return is it AP?
47          */
48         public static function isRequest()
49         {
50                 return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') ||
51                         stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json');
52         }
53
54         /**
55          * Checks incoming message from the inbox
56          *
57          * @param $body
58          * @param $header
59          * @param integer $uid User ID
60          */
61         public static function processInbox($body, $header, $uid)
62         {
63                 $http_signer = HTTPSignature::getSigner($body, $header);
64                 if (empty($http_signer)) {
65                         logger('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG);
66                         return;
67                 } else {
68                         logger('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG);
69                 }
70
71                 $activity = json_decode($body, true);
72
73                 if (empty($activity)) {
74                         logger('Invalid body.', LOGGER_DEBUG);
75                         return;
76                 }
77
78                 $ldactivity = JsonLD::compact($activity);
79
80                 $actor = JsonLD::fetchElement($ldactivity, 'as:actor');
81
82                 logger('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG);
83
84                 if (LDSignature::isSigned($activity)) {
85                         $ld_signer = LDSignature::getSigner($activity);
86                         if (empty($ld_signer)) {
87                                 logger('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG);
88                         }
89                         if (!empty($ld_signer && ($actor == $http_signer))) {
90                                 logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
91                                 $trust_source = true;
92                         } elseif (!empty($ld_signer)) {
93                                 logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
94                                 $trust_source = true;
95                         } elseif ($actor == $http_signer) {
96                                 logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
97                                 $trust_source = true;
98                         } else {
99                                 logger('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
100                                 $trust_source = false;
101                         }
102                 } elseif ($actor == $http_signer) {
103                         logger('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG);
104                         $trust_source = true;
105                 } else {
106                         logger('No JSON-LD signature, different actor.', LOGGER_DEBUG);
107                         $trust_source = false;
108                 }
109
110                 self::processActivity($ldactivity, $body, $uid, $trust_source);
111         }
112
113         /**
114          * Fetches the object type for a given object id
115          *
116          * @param array  $activity
117          * @param string $object_id Object ID of the the provided object
118          *
119          * @return string with object type
120          */
121         private static function fetchObjectType($activity, $object_id)
122         {
123
124                 $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
125                 if (!empty($object_type)) {
126                         return $object_type;
127                 }
128
129                 if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
130                         // We just assume "note" since it doesn't make a difference for the further processing
131                         return 'as:Note';
132                 }
133
134                 $profile = APContact::getByURL($object_id);
135                 if (!empty($profile['type'])) {
136                         return 'as:' . $profile['type'];
137                 }
138
139                 $data = ActivityPub::fetchContent($object_id);
140                 if (!empty($data)) {
141                         $object = JsonLD::compact($data);
142                         $type = JsonLD::fetchElement($object, '@type');
143                         if (!empty($type)) {
144                                 return $type;
145                         }
146                 }
147
148                 return null;
149         }
150
151         /**
152          * Prepare the object array
153          *
154          * @param array $activity
155          * @param integer $uid User ID
156          * @param $trust_source
157          *
158          * @return array with object data
159          */
160         private static function prepareObjectData($activity, $uid, &$trust_source)
161         {
162                 $actor = JsonLD::fetchElement($activity, 'as:actor');
163                 if (empty($actor)) {
164                         logger('Empty actor', LOGGER_DEBUG);
165                         return [];
166                 }
167
168                 $type = JsonLD::fetchElement($activity, '@type');
169
170                 // Fetch all receivers from to, cc, bto and bcc
171                 $receivers = self::getReceivers($activity, $actor);
172
173                 // When it is a delivery to a personal inbox we add that user to the receivers
174                 if (!empty($uid)) {
175                         $owner = User::getOwnerDataById($uid);
176                         $additional = ['uid:' . $uid => $uid];
177                         $receivers = array_merge($receivers, $additional);
178                 }
179
180                 logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
181
182                 $object_id = JsonLD::fetchElement($activity, 'as:object');
183                 if (empty($object_id)) {
184                         logger('No object found', LOGGER_DEBUG);
185                         return [];
186                 }
187
188                 $object_type = self::fetchObjectType($activity, $object_id);
189
190                 // Fetch the content only on activities where this matters
191                 if (in_array($type, ['as:Create', 'as:Announce'])) {
192                         if ($type == 'as:Announce') {
193                                 $trust_source = false;
194                         }
195                         $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source);
196                         if (empty($object_data)) {
197                                 logger("Object data couldn't be processed", LOGGER_DEBUG);
198                                 return [];
199                         }
200                         // We had been able to retrieve the object data - so we can trust the source
201                         $trust_source = true;
202                 } elseif (in_array($type, ['as:Like', 'as:Dislike'])) {
203                         // Create a mostly empty array out of the activity data (instead of the object).
204                         // This way we later don't have to check for the existence of ech individual array element.
205                         $object_data = self::processObject($activity);
206                         $object_data['name'] = $type;
207                         $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor');
208                         $object_data['object_id'] = $object_id;
209                         $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
210                 } else {
211                         $object_data = [];
212                         $object_data['id'] = JsonLD::fetchElement($activity, '@id');
213                         $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object');
214                         $object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor');
215                         $object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
216                         $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
217                 }
218
219                 $object_data = self::addActivityFields($object_data, $activity);
220
221                 if (empty($object_data['object_type'])) {
222                         $object_data['object_type'] = $object_type;
223                 }
224
225                 $object_data['type'] = $type;
226                 $object_data['actor'] = $actor;
227                 $object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers);
228
229                 logger('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG);
230
231                 return $object_data;
232         }
233
234         /**
235          * Store the unprocessed data into the conversation table
236          * This has to be done outside the regular function,
237          * since we store everything - not only item posts.
238          *
239          * @param array  $activity Array with activity data
240          * @param string $body     The raw message
241          */
242         private static function storeConversation($activity, $body)
243         {
244                 if (empty($body) || empty($activity['id'])) {
245                         return;
246                 }
247
248                 $conversation = [
249                         'protocol' => Conversation::PARCEL_ACTIVITYPUB,
250                         'item-uri' => $activity['id'],
251                         'reply-to-uri' => defaults($activity, 'reply-to-id', ''),
252                         'conversation-href' => defaults($activity, 'context', ''),
253                         'conversation-uri' => defaults($activity, 'conversation', ''),
254                         'source' => $body,
255                         'received' => DateTimeFormat::utcNow()];
256
257                 DBA::insert('conversation', $conversation, true);
258         }
259
260         /**
261          * Processes the activity object
262          *
263          * @param array   $activity     Array with activity data
264          * @param string  $body
265          * @param integer $uid          User ID
266          * @param boolean $trust_source Do we trust the source?
267          */
268         public static function processActivity($activity, $body = '', $uid = null, $trust_source = false)
269         {
270                 $type = JsonLD::fetchElement($activity, '@type');
271                 if (!$type) {
272                         logger('Empty type', LOGGER_DEBUG);
273                         return;
274                 }
275
276                 if (!JsonLD::fetchElement($activity, 'as:object')) {
277                         logger('Empty object', LOGGER_DEBUG);
278                         return;
279                 }
280
281                 if (!JsonLD::fetchElement($activity, 'as:actor')) {
282                         logger('Empty actor', LOGGER_DEBUG);
283                         return;
284
285                 }
286
287                 // $trust_source is called by reference and is set to true if the content was retrieved successfully
288                 $object_data = self::prepareObjectData($activity, $uid, $trust_source);
289                 if (empty($object_data)) {
290                         logger('No object data found', LOGGER_DEBUG);
291                         return;
292                 }
293
294                 if (!$trust_source) {
295                         logger('No trust for activity type "' . $type . '", so we quit now.', LOGGER_DEBUG);
296                         return;
297                 }
298
299                 self::storeConversation($object_data, $body);
300
301                 // Internal flag for thread completion. See Processor.php
302                 if (!empty($activity['thread-completion'])) {
303                         $object_data['thread-completion'] = $activity['thread-completion'];
304                 }
305
306                 switch ($type) {
307                         case 'as:Create':
308                         case 'as:Announce':
309                                 ActivityPub\Processor::createItem($object_data);
310                                 break;
311
312                         case 'as:Like':
313                                 ActivityPub\Processor::likeItem($object_data);
314                                 break;
315
316                         case 'as:Dislike':
317                                 ActivityPub\Processor::dislikeItem($object_data);
318                                 break;
319
320                         case 'as:Update':
321                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
322                                         /// @todo
323                                 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
324                                         ActivityPub\Processor::updatePerson($object_data, $body);
325                                 }
326                                 break;
327
328                         case 'as:Delete':
329                                 if ($object_data['object_type'] == 'as:Tombstone') {
330                                         ActivityPub\Processor::deleteItem($object_data, $body);
331                                 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
332                                         ActivityPub\Processor::deletePerson($object_data, $body);
333                                 }
334                                 break;
335
336                         case 'as:Follow':
337                                 ActivityPub\Processor::followUser($object_data);
338                                 break;
339
340                         case 'as:Accept':
341                                 if ($object_data['object_type'] == 'as:Follow') {
342                                         ActivityPub\Processor::acceptFollowUser($object_data);
343                                 }
344                                 break;
345
346                         case 'as:Reject':
347                                 if ($object_data['object_type'] == 'as:Follow') {
348                                         ActivityPub\Processor::rejectFollowUser($object_data);
349                                 }
350                                 break;
351
352                         case 'as:Undo':
353                                 if ($object_data['object_type'] == 'as:Follow') {
354                                         ActivityPub\Processor::undoFollowUser($object_data);
355                                 } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES)) {
356                                         ActivityPub\Processor::undoActivity($object_data);
357                                 }
358                                 break;
359
360                         default:
361                                 logger('Unknown activity: ' . $type, LOGGER_DEBUG);
362                                 break;
363                 }
364         }
365
366         /**
367          * Fetch the receiver list from an activity array
368          *
369          * @param array $activity
370          * @param string $actor
371          *
372          * @return array with receivers (user id)
373          */
374         private static function getReceivers($activity, $actor)
375         {
376                 $receivers = [];
377
378                 // When it is an answer, we inherite the receivers from the parent
379                 $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo');
380                 if (!empty($replyto)) {
381                         $parents = Item::select(['uid'], ['uri' => $replyto]);
382                         while ($parent = Item::fetch($parents)) {
383                                 $receivers['uid:' . $parent['uid']] = $parent['uid'];
384                         }
385                 }
386
387                 if (!empty($actor)) {
388                         $profile = APContact::getByURL($actor);
389                         $followers = defaults($profile, 'followers', '');
390
391                         logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG);
392                 } else {
393                         logger('Empty actor', LOGGER_DEBUG);
394                         $followers = '';
395                 }
396
397                 foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
398                         $receiver_list = JsonLD::fetchElementArray($activity, $element);
399                         if (empty($receiver_list)) {
400                                 continue;
401                         }
402
403                         foreach ($receiver_list as $receiver) {
404                                 if ($receiver == self::PUBLIC_COLLECTION) {
405                                         $receivers['uid:0'] = 0;
406                                 }
407
408                                 if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
409                                         // This will most likely catch all OStatus connections to Mastodon
410                                         $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
411                                                 , 'archive' => false, 'pending' => false];
412                                         $contacts = DBA::select('contact', ['uid'], $condition);
413                                         while ($contact = DBA::fetch($contacts)) {
414                                                 if ($contact['uid'] != 0) {
415                                                         $receivers['uid:' . $contact['uid']] = $contact['uid'];
416                                                 }
417                                         }
418                                         DBA::close($contacts);
419                                 }
420
421                                 if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
422                                         $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS];
423                                         $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
424                                                 'network' => $networks, 'archive' => false, 'pending' => false];
425                                         $contacts = DBA::select('contact', ['uid'], $condition);
426                                         while ($contact = DBA::fetch($contacts)) {
427                                                 if ($contact['uid'] != 0) {
428                                                         $receivers['uid:' . $contact['uid']] = $contact['uid'];
429                                                 }
430                                         }
431                                         DBA::close($contacts);
432                                         continue;
433                                 }
434
435                                 $condition = ['self' => true, 'nurl' => normalise_link($receiver)];
436                                 $contact = DBA::selectFirst('contact', ['uid'], $condition);
437                                 if (!DBA::isResult($contact)) {
438                                         continue;
439                                 }
440                                 $receivers['uid:' . $contact['uid']] = $contact['uid'];
441                         }
442                 }
443
444                 self::switchContacts($receivers, $actor);
445
446                 return $receivers;
447         }
448
449         /**
450          * Switches existing contacts to ActivityPub
451          *
452          * @param integer $cid Contact ID
453          * @param integer $uid User ID
454          * @param string $url Profile URL
455          */
456         public static function switchContact($cid, $uid, $url)
457         {
458                 $profile = ActivityPub::probeProfile($url);
459                 if (empty($profile)) {
460                         return;
461                 }
462
463                 logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
464
465                 $photo = defaults($profile, 'photo', null);
466                 unset($profile['photo']);
467                 unset($profile['baseurl']);
468
469                 $profile['nurl'] = normalise_link($profile['url']);
470                 DBA::update('contact', $profile, ['id' => $cid]);
471
472                 Contact::updateAvatar($photo, $uid, $cid);
473
474                 // Send a new follow request to be sure that the connection still exists
475                 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
476                         ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
477                         logger('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
478                 }
479         }
480
481         /**
482          *
483          *
484          * @param $receivers
485          * @param $actor
486          */
487         private static function switchContacts($receivers, $actor)
488         {
489                 if (empty($actor)) {
490                         return;
491                 }
492
493                 foreach ($receivers as $receiver) {
494                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => normalise_link($actor)]);
495                         if (DBA::isResult($contact)) {
496                                 self::switchContact($contact['id'], $receiver, $actor);
497                         }
498
499                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [normalise_link($actor), $actor]]);
500                         if (DBA::isResult($contact)) {
501                                 self::switchContact($contact['id'], $receiver, $actor);
502                         }
503                 }
504         }
505
506         /**
507          *
508          *
509          * @param $object_data
510          * @param array $activity
511          *
512          * @return
513          */
514         private static function addActivityFields($object_data, $activity)
515         {
516                 if (!empty($activity['published']) && empty($object_data['published'])) {
517                         $object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
518                 }
519
520                 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
521                         $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
522                 }
523
524                 $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
525
526                 return $object_data;
527         }
528
529         /**
530          * Fetches the object data from external ressources if needed
531          *
532          * @param string  $object_id    Object ID of the the provided object
533          * @param array   $object       The provided object array
534          * @param boolean $trust_source Do we trust the provided object?
535          *
536          * @return array with trusted and valid object data
537          */
538         private static function fetchObject($object_id, $object = [], $trust_source = false)
539         {
540                 // By fetching the type we check if the object is complete.
541                 $type = JsonLD::fetchElement($object, '@type');
542
543                 if (!$trust_source || empty($type)) {
544                         $data = ActivityPub::fetchContent($object_id);
545                         if (!empty($data)) {
546                                 $object = JsonLD::compact($data);
547                                 logger('Fetched content for ' . $object_id, LOGGER_DEBUG);
548                         } else {
549                                 logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
550
551                                 $item = Item::selectFirst([], ['uri' => $object_id]);
552                                 if (!DBA::isResult($item)) {
553                                         logger('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
554                                         return false;
555                                 }
556                                 logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
557                                 $data = ActivityPub\Transmitter::createNote($item);
558                                 $object = JsonLD::compact($data);
559                         }
560                 } else {
561                         logger('Using original object for url ' . $object_id, LOGGER_DEBUG);
562                 }
563
564                 $type = JsonLD::fetchElement($object, '@type');
565
566                 if (empty($type)) {
567                         logger('Empty type', LOGGER_DEBUG);
568                         return false;
569                 }
570
571                 if (in_array($type, self::CONTENT_TYPES)) {
572                         return self::processObject($object);
573                 }
574
575                 if ($type == 'as:Announce') {
576                         $object_id = JsonLD::fetchElement($object, 'object');
577                         if (empty($object_id)) {
578                                 return false;
579                         }
580                         return self::fetchObject($object_id);
581                 }
582
583                 logger('Unhandled object type: ' . $type, LOGGER_DEBUG);
584         }
585
586         /**
587          * Convert tags from JSON-LD format into a simplified format
588          *
589          * @param array $tags Tags in JSON-LD format
590          *
591          * @return array with tags in a simplified format
592          */
593         private static function processTags($tags)
594         {
595                 $taglist = [];
596
597                 if (empty($tags)) {
598                         return [];
599                 }
600
601                 foreach ($tags as $tag) {
602                         if (empty($tag)) {
603                                 continue;
604                         }
605
606                         $taglist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
607                                 'href' => JsonLD::fetchElement($tag, 'as:href'),
608                                 'name' => JsonLD::fetchElement($tag, 'as:name')];
609                 }
610                 return $taglist;
611         }
612
613         /**
614          * Convert attachments from JSON-LD format into a simplified format
615          *
616          * @param array $attachments Attachments in JSON-LD format
617          *
618          * @return array with attachmants in a simplified format
619          */
620         private static function processAttachments($attachments)
621         {
622                 $attachlist = [];
623
624                 if (empty($attachments)) {
625                         return [];
626                 }
627
628                 foreach ($attachments as $attachment) {
629                         if (empty($attachment)) {
630                                 continue;
631                         }
632
633                         $attachlist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
634                                 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType'),
635                                 'name' => JsonLD::fetchElement($attachment, 'as:name'),
636                                 'url' => JsonLD::fetchElement($attachment, 'as:url')];
637                 }
638                 return $attachlist;
639         }
640
641         /**
642          * Fetches data from the object part of an activity
643          *
644          * @param array $object
645          *
646          * @return array
647          */
648         private static function processObject($object)
649         {
650                 if (!JsonLD::fetchElement($object, '@id')) {
651                         return false;
652                 }
653
654                 $object_data = [];
655                 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
656                 $object_data['id'] = JsonLD::fetchElement($object, '@id');
657
658                 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo');
659
660                 if (empty($object_data['reply-to-id'])) {
661                         $object_data['reply-to-id'] = $object_data['id'];
662                 }
663
664                 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
665                 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
666
667                 if (empty($object_data['updated'])) {
668                         $object_data['updated'] = $object_data['published'];
669                 }
670
671                 if (empty($object_data['published']) && !empty($object_data['updated'])) {
672                         $object_data['published'] = $object_data['updated'];
673                 }
674
675                 $actor = JsonLD::fetchElement($object, 'as:attributedTo');
676                 if (empty($actor)) {
677                         $actor = JsonLD::fetchElement($object, 'as:actor');
678                 }
679
680                 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid');
681                 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment');
682                 $object_data['actor'] = $object_data['author'] = $actor;
683                 $object_data['context'] = JsonLD::fetchElement($object, 'as:context');
684                 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation');
685                 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
686                 $object_data['name'] = JsonLD::fetchElement($object, 'as:name');
687                 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary');
688                 $object_data['content'] = JsonLD::fetchElement($object, 'as:content');
689                 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
690                 $object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
691                 $object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
692                 $object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
693                 $object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
694                 $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
695                 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
696                 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
697                 $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
698                 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
699
700                 // Special treatment for Hubzilla links
701                 if (is_array($object_data['alternate-url'])) {
702                         $object_data['alternate-url'] = JsonLD::fetchElement($object_data['alternate-url'], 'as:href');
703
704                         if (!is_string($object_data['alternate-url'])) {
705                                 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href');
706                         }
707                 }
708
709                 $object_data['receiver'] = self::getReceivers($object, $object_data['actor']);
710
711                 // Common object data:
712
713                 // Unhandled
714                 // @context, type, actor, signature, mediaType, duration, replies, icon
715
716                 // Also missing: (Defined in the standard, but currently unused)
717                 // audience, preview, endTime, startTime, image
718
719                 // Data in Notes:
720
721                 // Unhandled
722                 // contentMap, announcement_count, announcements, context_id, likes, like_count
723                 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
724
725                 // Data in video:
726
727                 // To-Do?
728                 // category, licence, language, commentsEnabled
729
730                 // Unhandled
731                 // views, waitTranscoding, state, support, subtitleLanguage
732                 // likes, dislikes, shares, comments
733
734                 return $object_data;
735         }
736 }