]> git.mxchange.org Git - friendica.git/blob - src/Protocol/ActivityPub/Receiver.php
Merge pull request #5921 from annando/ap-video
[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                                         $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
423                                                 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false];
424                                         $contacts = DBA::select('contact', ['uid'], $condition);
425                                         while ($contact = DBA::fetch($contacts)) {
426                                                 if ($contact['uid'] != 0) {
427                                                         $receivers['uid:' . $contact['uid']] = $contact['uid'];
428                                                 }
429                                         }
430                                         DBA::close($contacts);
431                                         continue;
432                                 }
433
434                                 $condition = ['self' => true, 'nurl' => normalise_link($receiver)];
435                                 $contact = DBA::selectFirst('contact', ['uid'], $condition);
436                                 if (!DBA::isResult($contact)) {
437                                         continue;
438                                 }
439                                 $receivers['uid:' . $contact['uid']] = $contact['uid'];
440                         }
441                 }
442
443                 self::switchContacts($receivers, $actor);
444
445                 return $receivers;
446         }
447
448         /**
449          * Switches existing contacts to ActivityPub
450          *
451          * @param integer $cid Contact ID
452          * @param integer $uid User ID
453          * @param string $url Profile URL
454          */
455         public static function switchContact($cid, $uid, $url)
456         {
457                 $profile = ActivityPub::probeProfile($url);
458                 if (empty($profile)) {
459                         return;
460                 }
461
462                 logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' to ActivityPub');
463
464                 $photo = $profile['photo'];
465                 unset($profile['photo']);
466                 unset($profile['baseurl']);
467
468                 $profile['nurl'] = normalise_link($profile['url']);
469                 DBA::update('contact', $profile, ['id' => $cid]);
470
471                 Contact::updateAvatar($photo, $uid, $cid);
472
473                 // Send a new follow request to be sure that the connection still exists
474                 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND]])) {
475                         ActivityPub\Transmitter::sendActivity('Follow', $profile['url'], $uid);
476                         logger('Send a new follow request to ' . $profile['url'] . ' for user ' . $uid, LOGGER_DEBUG);
477                 }
478         }
479
480         /**
481          * 
482          *
483          * @param $receivers
484          * @param $actor
485          */
486         private static function switchContacts($receivers, $actor)
487         {
488                 if (empty($actor)) {
489                         return;
490                 }
491
492                 foreach ($receivers as $receiver) {
493                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => normalise_link($actor)]);
494                         if (DBA::isResult($contact)) {
495                                 self::switchContact($contact['id'], $receiver, $actor);
496                         }
497
498                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [normalise_link($actor), $actor]]);
499                         if (DBA::isResult($contact)) {
500                                 self::switchContact($contact['id'], $receiver, $actor);
501                         }
502                 }
503         }
504
505         /**
506          * 
507          *
508          * @param $object_data
509          * @param array $activity
510          *
511          * @return 
512          */
513         private static function addActivityFields($object_data, $activity)
514         {
515                 if (!empty($activity['published']) && empty($object_data['published'])) {
516                         $object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
517                 }
518
519                 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
520                         $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
521                 }
522
523                 $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
524
525                 return $object_data;
526         }
527
528         /**
529          * Fetches the object data from external ressources if needed
530          *
531          * @param string  $object_id    Object ID of the the provided object
532          * @param array   $object       The provided object array
533          * @param boolean $trust_source Do we trust the provided object?
534          *
535          * @return array with trusted and valid object data
536          */
537         private static function fetchObject($object_id, $object = [], $trust_source = false)
538         {
539                 // By fetching the type we check if the object is complete.
540                 $type = JsonLD::fetchElement($object, '@type');
541
542                 if (!$trust_source || empty($type)) {
543                         $data = ActivityPub::fetchContent($object_id);
544                         if (!empty($data)) {
545                                 $object = JsonLD::compact($data);
546                                 logger('Fetched content for ' . $object_id, LOGGER_DEBUG);
547                         } else {
548                                 logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
549
550                                 $item = Item::selectFirst([], ['uri' => $object_id]);
551                                 if (!DBA::isResult($item)) {
552                                         logger('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
553                                         return false;
554                                 }
555                                 logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
556                                 $data = ActivityPub\Transmitter::createNote($item);
557                                 $object = JsonLD::compact($data);
558                         }
559                 } else {
560                         logger('Using original object for url ' . $object_id, LOGGER_DEBUG);
561                 }
562
563                 $type = JsonLD::fetchElement($object, '@type');
564
565                 if (empty($type)) {
566                         logger('Empty type', LOGGER_DEBUG);
567                         return false;
568                 }
569
570                 if (in_array($type, self::CONTENT_TYPES)) {
571                         return self::processObject($object);
572                 }
573
574                 if ($type == 'as:Announce') {
575                         $object_id = JsonLD::fetchElement($object, 'object');
576                         if (empty($object_id)) {
577                                 return false;
578                         }
579                         return self::fetchObject($object_id);
580                 }
581
582                 logger('Unhandled object type: ' . $type, LOGGER_DEBUG);
583         }
584
585         /**
586          * Convert tags from JSON-LD format into a simplified format
587          *
588          * @param array $tags Tags in JSON-LD format
589          *
590          * @return array with tags in a simplified format
591          */
592         private static function processTags($tags)
593         {
594                 $taglist = [];
595
596                 if (empty($tags)) {
597                         return [];
598                 }
599
600                 foreach ($tags as $tag) {
601                         if (empty($tag)) {
602                                 continue;
603                         }
604
605                         $taglist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
606                                 'href' => JsonLD::fetchElement($tag, 'as:href'),
607                                 'name' => JsonLD::fetchElement($tag, 'as:name')];
608                 }
609                 return $taglist;
610         }
611
612         /**
613          * Convert attachments from JSON-LD format into a simplified format
614          *
615          * @param array $attachments Attachments in JSON-LD format
616          *
617          * @return array with attachmants in a simplified format
618          */
619         private static function processAttachments($attachments)
620         {
621                 $attachlist = [];
622
623                 if (empty($attachments)) {
624                         return [];
625                 }
626
627                 foreach ($attachments as $attachment) {
628                         if (empty($attachment)) {
629                                 continue;
630                         }
631
632                         $attachlist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
633                                 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType'),
634                                 'name' => JsonLD::fetchElement($attachment, 'as:name'),
635                                 'url' => JsonLD::fetchElement($attachment, 'as:url')];
636                 }
637                 return $attachlist;
638         }
639
640         /**
641          * Fetches data from the object part of an activity
642          *
643          * @param array $object
644          *
645          * @return array
646          */
647         private static function processObject($object)
648         {
649                 if (!JsonLD::fetchElement($object, '@id')) {
650                         return false;
651                 }
652
653                 $object_data = [];
654                 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
655                 $object_data['id'] = JsonLD::fetchElement($object, '@id');
656
657                 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo');
658
659                 if (empty($object_data['reply-to-id'])) {
660                         $object_data['reply-to-id'] = $object_data['id'];
661                 }
662
663                 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
664                 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
665
666                 if (empty($object_data['updated'])) {
667                         $object_data['updated'] = $object_data['published'];
668                 }
669
670                 if (empty($object_data['published']) && !empty($object_data['updated'])) {
671                         $object_data['published'] = $object_data['updated'];
672                 }
673
674                 $actor = JsonLD::fetchElement($object, 'as:attributedTo');
675                 if (empty($actor)) {
676                         $actor = JsonLD::fetchElement($object, 'as:actor');
677                 }
678
679                 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid');
680                 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment');
681                 $object_data['actor'] = $object_data['author'] = $actor;
682                 $object_data['context'] = JsonLD::fetchElement($object, 'as:context');
683                 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation');
684                 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
685                 $object_data['name'] = JsonLD::fetchElement($object, 'as:name');
686                 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary');
687                 $object_data['content'] = JsonLD::fetchElement($object, 'as:content');
688                 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
689                 $object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
690                 $object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
691                 $object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
692                 $object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
693                 $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
694                 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
695                 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
696                 $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
697                 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
698
699                 // Special treatment for Hubzilla links
700                 if (is_array($object_data['alternate-url'])) {
701                         $object_data['alternate-url'] = JsonLD::fetchElement($object_data['alternate-url'], 'as:href');
702
703                         if (!is_string($object_data['alternate-url'])) {
704                                 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href');
705                         }
706                 }
707
708                 $object_data['receiver'] = self::getReceivers($object, $object_data['actor']);
709
710                 // Common object data:
711
712                 // Unhandled
713                 // @context, type, actor, signature, mediaType, duration, replies, icon
714
715                 // Also missing: (Defined in the standard, but currently unused)
716                 // audience, preview, endTime, startTime, image
717
718                 // Data in Notes:
719
720                 // Unhandled
721                 // contentMap, announcement_count, announcements, context_id, likes, like_count
722                 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
723
724                 // Data in video:
725
726                 // To-Do?
727                 // category, licence, language, commentsEnabled
728
729                 // Unhandled
730                 // views, waitTranscoding, state, support, subtitleLanguage
731                 // likes, dislikes, shares, comments
732
733                 return $object_data;
734         }
735 }