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