]> git.mxchange.org Git - friendica.git/blob - src/Protocol/ActivityPub/Receiver.php
Add support for multiple Link as urls of Images in ActivityPub\Receiver
[friendica.git] / src / Protocol / ActivityPub / Receiver.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Protocol\ActivityPub;
23
24 use Friendica\Content\Text\BBCode;
25 use Friendica\Database\DBA;
26 use Friendica\Content\Text\HTML;
27 use Friendica\Content\Text\Markdown;
28 use Friendica\Core\Logger;
29 use Friendica\Core\Protocol;
30 use Friendica\Model\Contact;
31 use Friendica\Model\APContact;
32 use Friendica\Model\Item;
33 use Friendica\Model\User;
34 use Friendica\Protocol\Activity;
35 use Friendica\Protocol\ActivityPub;
36 use Friendica\Util\DateTimeFormat;
37 use Friendica\Util\HTTPSignature;
38 use Friendica\Util\JsonLD;
39 use Friendica\Util\LDSignature;
40 use Friendica\Util\Strings;
41
42 /**
43  * ActivityPub Receiver Protocol class
44  *
45  * To-Do:
46  * @todo Undo Announce
47  *
48  * Check what this is meant to do:
49  * - Add
50  * - Block
51  * - Flag
52  * - Remove
53  * - Undo Block
54  */
55 class Receiver
56 {
57         const PUBLIC_COLLECTION = 'as:Public';
58         const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
59         const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event', 'as:Audio'];
60         const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept'];
61
62         /**
63          * Checks if the web request is done for the AP protocol
64          *
65          * @return bool is it AP?
66          */
67         public static function isRequest()
68         {
69                 return stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') ||
70                         stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json');
71         }
72
73         /**
74          * Checks incoming message from the inbox
75          *
76          * @param         $body
77          * @param         $header
78          * @param integer $uid User ID
79          * @throws \Exception
80          */
81         public static function processInbox($body, $header, $uid)
82         {
83                 $http_signer = HTTPSignature::getSigner($body, $header);
84                 if (empty($http_signer)) {
85                         Logger::warning('Invalid HTTP signature, message will be discarded.');
86                         return;
87                 } else {
88                         Logger::info('Valid HTTP signature', ['signer' => $http_signer]);
89                 }
90
91                 $activity = json_decode($body, true);
92
93                 if (empty($activity)) {
94                         Logger::warning('Invalid body.');
95                         return;
96                 }
97
98                 $ldactivity = JsonLD::compact($activity);
99
100                 $actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id');
101
102                 Logger::info('Message for user ' . $uid . ' is from actor ' . $actor);
103
104                 if (LDSignature::isSigned($activity)) {
105                         $ld_signer = LDSignature::getSigner($activity);
106                         if (empty($ld_signer)) {
107                                 Logger::log('Invalid JSON-LD signature from ' . $actor, Logger::DEBUG);
108                         }
109                         if (!empty($ld_signer && ($actor == $http_signer))) {
110                                 Logger::log('The HTTP and the JSON-LD signature belong to ' . $ld_signer, Logger::DEBUG);
111                                 $trust_source = true;
112                         } elseif (!empty($ld_signer)) {
113                                 Logger::log('JSON-LD signature is signed by ' . $ld_signer, Logger::DEBUG);
114                                 $trust_source = true;
115                         } elseif ($actor == $http_signer) {
116                                 Logger::log('Bad JSON-LD signature, but HTTP signer fits the actor.', Logger::DEBUG);
117                                 $trust_source = true;
118                         } else {
119                                 Logger::log('Invalid JSON-LD signature and the HTTP signer is different.', Logger::DEBUG);
120                                 $trust_source = false;
121                         }
122                 } elseif ($actor == $http_signer) {
123                         Logger::log('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', Logger::DEBUG);
124                         $trust_source = true;
125                 } else {
126                         Logger::log('No JSON-LD signature, different actor.', Logger::DEBUG);
127                         $trust_source = false;
128                 }
129
130                 self::processActivity($ldactivity, $body, $uid, $trust_source, true);
131         }
132
133         /**
134          * Fetches the object type for a given object id
135          *
136          * @param array   $activity
137          * @param string  $object_id Object ID of the the provided object
138          * @param integer $uid       User ID
139          *
140          * @return string with object type
141          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
142          * @throws \ImagickException
143          */
144         private static function fetchObjectType($activity, $object_id, $uid = 0)
145         {
146                 if (!empty($activity['as:object'])) {
147                         $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
148                         if (!empty($object_type)) {
149                                 return $object_type;
150                         }
151                 }
152
153                 if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
154                         // We just assume "note" since it doesn't make a difference for the further processing
155                         return 'as:Note';
156                 }
157
158                 $profile = APContact::getByURL($object_id);
159                 if (!empty($profile['type'])) {
160                         return 'as:' . $profile['type'];
161                 }
162
163                 $data = ActivityPub::fetchContent($object_id, $uid);
164                 if (!empty($data)) {
165                         $object = JsonLD::compact($data);
166                         $type = JsonLD::fetchElement($object, '@type');
167                         if (!empty($type)) {
168                                 return $type;
169                         }
170                 }
171
172                 return null;
173         }
174
175         /**
176          * Prepare the object array
177          *
178          * @param array   $activity     Array with activity data
179          * @param integer $uid          User ID
180          * @param boolean $push         Message had been pushed to our system
181          * @param boolean $trust_source Do we trust the source?
182          *
183          * @return array with object data
184          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
185          * @throws \ImagickException
186          */
187         private static function prepareObjectData($activity, $uid, $push, &$trust_source)
188         {
189                 $actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
190                 if (empty($actor)) {
191                         Logger::log('Empty actor', Logger::DEBUG);
192                         return [];
193                 }
194
195                 $type = JsonLD::fetchElement($activity, '@type');
196
197                 // Fetch all receivers from to, cc, bto and bcc
198                 $receivers = self::getReceivers($activity, $actor);
199
200                 // When it is a delivery to a personal inbox we add that user to the receivers
201                 if (!empty($uid)) {
202                         $additional = ['uid:' . $uid => $uid];
203                         $receivers = array_merge($receivers, $additional);
204                 } else {
205                         // We possibly need some user to fetch private content,
206                         // so we fetch the first out ot the list.
207                         $uid = self::getFirstUserFromReceivers($receivers);
208                 }
209
210                 Logger::log('Receivers: ' . $uid . ' - ' . json_encode($receivers), Logger::DEBUG);
211
212                 $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
213                 if (empty($object_id)) {
214                         Logger::log('No object found', Logger::DEBUG);
215                         return [];
216                 }
217
218                 if (!is_string($object_id)) {
219                         Logger::info('Invalid object id', ['object' => $object_id]);
220                         return [];
221                 }
222
223                 $object_type = self::fetchObjectType($activity, $object_id, $uid);
224
225                 // Fetch the content only on activities where this matters
226                 if (in_array($type, ['as:Create', 'as:Update', 'as:Announce'])) {
227                         if ($type == 'as:Announce') {
228                                 $trust_source = false;
229                         }
230                         $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source, $uid);
231                         if (empty($object_data)) {
232                                 Logger::log("Object data couldn't be processed", Logger::DEBUG);
233                                 return [];
234                         }
235
236                         $object_data['object_id'] = $object_id;
237
238                         if ($type == 'as:Announce') {
239                                 $object_data['push'] = false;
240                         } else {
241                                 $object_data['push'] = $push;
242                         }
243
244                         // Test if it is an answer to a mail
245                         if (DBA::exists('mail', ['uri' => $object_data['reply-to-id']])) {
246                                 $object_data['directmessage'] = true;
247                         } else {
248                                 $object_data['directmessage'] = JsonLD::fetchElement($activity, 'litepub:directMessage');
249                         }
250
251                         // We had been able to retrieve the object data - so we can trust the source
252                         $trust_source = true;
253                 } elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) {
254                         // Create a mostly empty array out of the activity data (instead of the object).
255                         // This way we later don't have to check for the existence of ech individual array element.
256                         $object_data = self::processObject($activity);
257                         $object_data['name'] = $type;
258                         $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
259                         $object_data['object_id'] = $object_id;
260                         $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
261                 } elseif (in_array($type, ['as:Add'])) {
262                         $object_data = [];
263                         $object_data['id'] = JsonLD::fetchElement($activity, '@id');
264                         $object_data['target_id'] = JsonLD::fetchElement($activity, 'as:target', '@id');
265                         $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
266                         $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
267                         $object_data['object_content'] = JsonLD::fetchElement($activity['as:object'], 'as:content', '@type');
268                 } else {
269                         $object_data = [];
270                         $object_data['id'] = JsonLD::fetchElement($activity, '@id');
271                         $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
272                         $object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor', '@id');
273                         $object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
274                         $object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
275
276                         // An Undo is done on the object of an object, so we need that type as well
277                         if (($type == 'as:Undo') && !empty($object_data['object_object'])) {
278                                 $object_data['object_object_type'] = self::fetchObjectType([], $object_data['object_object'], $uid);
279                         }
280                 }
281
282                 $object_data = self::addActivityFields($object_data, $activity);
283
284                 if (empty($object_data['object_type'])) {
285                         $object_data['object_type'] = $object_type;
286                 }
287
288                 $object_data['type'] = $type;
289                 $object_data['actor'] = $actor;
290                 $object_data['item_receiver'] = $receivers;
291                 $object_data['receiver'] = array_merge($object_data['receiver'] ?? [], $receivers);
292
293                 Logger::log('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], Logger::DEBUG);
294
295                 return $object_data;
296         }
297
298         /**
299          * Fetches the first user id from the receiver array
300          *
301          * @param array $receivers Array with receivers
302          * @return integer user id;
303          */
304         public static function getFirstUserFromReceivers($receivers)
305         {
306                 foreach ($receivers as $receiver) {
307                         if (!empty($receiver)) {
308                                 return $receiver;
309                         }
310                 }
311                 return 0;
312         }
313
314         /**
315          * Processes the activity object
316          *
317          * @param array   $activity     Array with activity data
318          * @param string  $body
319          * @param integer $uid          User ID
320          * @param boolean $trust_source Do we trust the source?
321          * @param boolean $push         Message had been pushed to our system
322          * @throws \Exception
323          */
324         public static function processActivity($activity, $body = '', $uid = null, $trust_source = false, $push = false)
325         {
326                 $type = JsonLD::fetchElement($activity, '@type');
327                 if (!$type) {
328                         Logger::log('Empty type', Logger::DEBUG);
329                         return;
330                 }
331
332                 if (!JsonLD::fetchElement($activity, 'as:object', '@id')) {
333                         Logger::log('Empty object', Logger::DEBUG);
334                         return;
335                 }
336
337                 if (!JsonLD::fetchElement($activity, 'as:actor', '@id')) {
338                         Logger::log('Empty actor', Logger::DEBUG);
339                         return;
340
341                 }
342
343                 // Don't trust the source if "actor" differs from "attributedTo". The content could be forged.
344                 if ($trust_source && ($type == 'as:Create') && is_array($activity['as:object'])) {
345                         $actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
346                         $attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
347                         $trust_source = ($actor == $attributed_to);
348                         if (!$trust_source) {
349                                 Logger::log('Not trusting actor: ' . $actor . '. It differs from attributedTo: ' . $attributed_to, Logger::DEBUG);
350                         }
351                 }
352
353                 // $trust_source is called by reference and is set to true if the content was retrieved successfully
354                 $object_data = self::prepareObjectData($activity, $uid, $push, $trust_source);
355                 if (empty($object_data)) {
356                         Logger::log('No object data found', Logger::DEBUG);
357                         return;
358                 }
359
360                 if (!$trust_source) {
361                         Logger::log('No trust for activity type "' . $type . '", so we quit now.', Logger::DEBUG);
362                         return;
363                 }
364
365                 if (!empty($body) && empty($object_data['raw'])) {
366                         $object_data['raw'] = $body;
367                 }
368
369                 // Internal flag for thread completion. See Processor.php
370                 if (!empty($activity['thread-completion'])) {
371                         $object_data['thread-completion'] = $activity['thread-completion'];
372                 }
373
374                 switch ($type) {
375                         case 'as:Create':
376                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
377                                         ActivityPub\Processor::createItem($object_data);
378                                 }
379                                 break;
380
381                         case 'as:Add':
382                                 if ($object_data['object_type'] == 'as:tag') {
383                                         ActivityPub\Processor::addTag($object_data);
384                                 }
385                                 break;
386
387                         case 'as:Announce':
388                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
389                                         $profile = APContact::getByURL($object_data['actor']);
390                                         // Reshared posts from persons appear as summary at the bottom
391                                         // If this isn't set, then a single reshare appears on top. This is used for groups.
392                                         $object_data['thread-completion'] = ($profile['type'] != 'Group');
393
394                                         ActivityPub\Processor::createItem($object_data);
395
396                                         // Add the bottom reshare information only for persons
397                                         if ($profile['type'] != 'Group') {
398                                                 $announce_object_data = self::processObject($activity);
399                                                 $announce_object_data['name'] = $type;
400                                                 $announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
401                                                 $announce_object_data['object_id'] = $object_data['object_id'];
402                                                 $announce_object_data['object_type'] = $object_data['object_type'];
403                                                 $announce_object_data['push'] = $push;
404
405                                                 if (!empty($body)) {
406                                                         $announce_object_data['raw'] = $body;
407                                                 }
408
409                                                 ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
410                                         }
411                                 }
412                                 break;
413
414                         case 'as:Like':
415                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
416                                         ActivityPub\Processor::createActivity($object_data, Activity::LIKE);
417                                 }
418                                 break;
419
420                         case 'as:Dislike':
421                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
422                                         ActivityPub\Processor::createActivity($object_data, Activity::DISLIKE);
423                                 }
424                                 break;
425
426                         case 'as:TentativeAccept':
427                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
428                                         ActivityPub\Processor::createActivity($object_data, Activity::ATTENDMAYBE);
429                                 }
430                                 break;
431
432                         case 'as:Update':
433                                 if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
434                                         ActivityPub\Processor::updateItem($object_data);
435                                 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
436                                         ActivityPub\Processor::updatePerson($object_data);
437                                 }
438                                 break;
439
440                         case 'as:Delete':
441                                 if ($object_data['object_type'] == 'as:Tombstone') {
442                                         ActivityPub\Processor::deleteItem($object_data);
443                                 } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
444                                         ActivityPub\Processor::deletePerson($object_data);
445                                 }
446                                 break;
447
448                         case 'as:Follow':
449                                 if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
450                                         ActivityPub\Processor::followUser($object_data);
451                                 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
452                                         $object_data['reply-to-id'] = $object_data['object_id'];
453                                         ActivityPub\Processor::createActivity($object_data, Activity::FOLLOW);
454                                 }
455                                 break;
456
457                         case 'as:Accept':
458                                 if ($object_data['object_type'] == 'as:Follow') {
459                                         ActivityPub\Processor::acceptFollowUser($object_data);
460                                 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
461                                         ActivityPub\Processor::createActivity($object_data, Activity::ATTEND);
462                                 }
463                                 break;
464
465                         case 'as:Reject':
466                                 if ($object_data['object_type'] == 'as:Follow') {
467                                         ActivityPub\Processor::rejectFollowUser($object_data);
468                                 } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
469                                         ActivityPub\Processor::createActivity($object_data, Activity::ATTENDNO);
470                                 }
471                                 break;
472
473                         case 'as:Undo':
474                                 if (($object_data['object_type'] == 'as:Follow') &&
475                                         in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
476                                         ActivityPub\Processor::undoFollowUser($object_data);
477                                 } elseif (($object_data['object_type'] == 'as:Accept') &&
478                                         in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
479                                         ActivityPub\Processor::rejectFollowUser($object_data);
480                                 } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES) &&
481                                         in_array($object_data['object_object_type'], self::CONTENT_TYPES)) {
482                                         ActivityPub\Processor::undoActivity($object_data);
483                                 }
484                                 break;
485
486                         default:
487                                 Logger::log('Unknown activity: ' . $type . ' ' . $object_data['object_type'], Logger::DEBUG);
488                                 break;
489                 }
490         }
491
492         /**
493          * Fetch the receiver list from an activity array
494          *
495          * @param array   $activity
496          * @param string  $actor
497          * @param array   $tags
498          * @param boolean $fetch_unlisted 
499          *
500          * @return array with receivers (user id)
501          * @throws \Exception
502          */
503         private static function getReceivers($activity, $actor, $tags = [], $fetch_unlisted = false)
504         {
505                 $receivers = [];
506
507                 // When it is an answer, we inherite the receivers from the parent
508                 $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo', '@id');
509                 if (!empty($replyto)) {
510                         // Fix possibly wrong item URI (could be an answer to a plink uri)
511                         $fixedReplyTo = Item::getURIByLink($replyto);
512                         $replyto = $fixedReplyTo ?: $replyto;
513
514                         $parents = Item::select(['uid'], ['uri' => $replyto]);
515                         while ($parent = Item::fetch($parents)) {
516                                 $receivers['uid:' . $parent['uid']] = $parent['uid'];
517                         }
518                 }
519
520                 if (!empty($actor)) {
521                         $profile = APContact::getByURL($actor);
522                         $followers = $profile['followers'] ?? '';
523
524                         Logger::log('Actor: ' . $actor . ' - Followers: ' . $followers, Logger::DEBUG);
525                 } else {
526                         Logger::log('Empty actor', Logger::DEBUG);
527                         $followers = '';
528                 }
529
530                 foreach (['as:to', 'as:cc', 'as:bto', 'as:bcc'] as $element) {
531                         $receiver_list = JsonLD::fetchElementArray($activity, $element, '@id');
532                         if (empty($receiver_list)) {
533                                 continue;
534                         }
535
536                         foreach ($receiver_list as $receiver) {
537                                 if ($receiver == self::PUBLIC_COLLECTION) {
538                                         $receivers['uid:0'] = 0;
539                                 }
540
541                                 // Add receiver "-1" for unlisted posts 
542                                 if ($fetch_unlisted && ($receiver == self::PUBLIC_COLLECTION) && ($element == 'as:cc')) {
543                                         $receivers['uid:-1'] = -1;
544                                 }
545
546                                 if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
547                                         // This will most likely catch all OStatus connections to Mastodon
548                                         $condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]
549                                                 , 'archive' => false, 'pending' => false];
550                                         $contacts = DBA::select('contact', ['uid'], $condition);
551                                         while ($contact = DBA::fetch($contacts)) {
552                                                 if ($contact['uid'] != 0) {
553                                                         $receivers['uid:' . $contact['uid']] = $contact['uid'];
554                                                 }
555                                         }
556                                         DBA::close($contacts);
557                                 }
558
559                                 if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) {
560                                         $receivers = array_merge($receivers, self::getReceiverForActor($actor, $tags));
561                                         continue;
562                                 }
563
564                                 // Fetching all directly addressed receivers
565                                 $condition = ['self' => true, 'nurl' => Strings::normaliseLink($receiver)];
566                                 $contact = DBA::selectFirst('contact', ['uid', 'contact-type'], $condition);
567                                 if (!DBA::isResult($contact)) {
568                                         continue;
569                                 }
570
571                                 // Check if the potential receiver is following the actor
572                                 // Exception: The receiver is targetted via "to" or this is a comment
573                                 if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
574                                         $networks = Protocol::FEDERATED;
575                                         $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
576                                                 'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
577
578                                         // Forum posts are only accepted from forum contacts
579                                         if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
580                                                 $condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
581                                         }
582
583                                         if (!DBA::exists('contact', $condition)) {
584                                                 continue;
585                                         }
586                                 }
587
588                                 $receivers['uid:' . $contact['uid']] = $contact['uid'];
589                         }
590                 }
591
592                 self::switchContacts($receivers, $actor);
593
594                 return $receivers;
595         }
596
597         /**
598          * Fetch the receiver list of a given actor
599          *
600          * @param string $actor
601          * @param array  $tags
602          *
603          * @return array with receivers (user id)
604          * @throws \Exception
605          */
606         public static function getReceiverForActor($actor, $tags)
607         {
608                 $receivers = [];
609                 $networks = Protocol::FEDERATED;
610                 $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
611                         'network' => $networks, 'archive' => false, 'pending' => false];
612                 $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
613                 while ($contact = DBA::fetch($contacts)) {
614                         if (self::isValidReceiverForActor($contact, $actor, $tags)) {
615                                 $receivers['uid:' . $contact['uid']] = $contact['uid'];
616                         }
617                 }
618                 DBA::close($contacts);
619                 return $receivers;
620         }
621
622         /**
623          * Tests if the contact is a valid receiver for this actor
624          *
625          * @param array  $contact
626          * @param string $actor
627          * @param array  $tags
628          *
629          * @return bool with receivers (user id)
630          * @throws \Exception
631          */
632         private static function isValidReceiverForActor($contact, $actor, $tags)
633         {
634                 // Public contacts are no valid receiver
635                 if ($contact['uid'] == 0) {
636                         return false;
637                 }
638
639                 // Are we following the contact? Then this is a valid receiver
640                 if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
641                         return true;
642                 }
643
644                 // When the possible receiver isn't a community, then it is no valid receiver
645                 $owner = User::getOwnerDataById($contact['uid']);
646                 if (empty($owner) || ($owner['contact-type'] != Contact::TYPE_COMMUNITY)) {
647                         return false;
648                 }
649
650                 // Is the community account tagged?
651                 foreach ($tags as $tag) {
652                         if ($tag['type'] != 'Mention') {
653                                 continue;
654                         }
655
656                         if ($tag['href'] == $owner['url']) {
657                                 return true;
658                         }
659                 }
660
661                 return false;
662         }
663
664         /**
665          * Switches existing contacts to ActivityPub
666          *
667          * @param integer $cid Contact ID
668          * @param integer $uid User ID
669          * @param string  $url Profile URL
670          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
671          * @throws \ImagickException
672          */
673         public static function switchContact($cid, $uid, $url)
674         {
675                 if (DBA::exists('contact', ['id' => $cid, 'network' => Protocol::ACTIVITYPUB])) {
676                         Logger::info('Contact is already ActivityPub', ['id' => $cid, 'uid' => $uid, 'url' => $url]);
677                         return;
678                 }
679
680                 if (Contact::updateFromProbe($cid, '', true)) {
681                         Logger::info('Update was successful', ['id' => $cid, 'uid' => $uid, 'url' => $url]);
682                 }
683
684                 // Send a new follow request to be sure that the connection still exists
685                 if (($uid != 0) && DBA::exists('contact', ['id' => $cid, 'rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB])) {
686                         Logger::info('Contact had been switched to ActivityPub. Sending a new follow request.', ['uid' => $uid, 'url' => $url]);
687                         ActivityPub\Transmitter::sendActivity('Follow', $url, $uid);
688                 }
689         }
690
691         /**
692          *
693          *
694          * @param $receivers
695          * @param $actor
696          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
697          * @throws \ImagickException
698          */
699         private static function switchContacts($receivers, $actor)
700         {
701                 if (empty($actor)) {
702                         return;
703                 }
704
705                 foreach ($receivers as $receiver) {
706                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => Strings::normaliseLink($actor)]);
707                         if (DBA::isResult($contact)) {
708                                 self::switchContact($contact['id'], $receiver, $actor);
709                         }
710
711                         $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [Strings::normaliseLink($actor), $actor]]);
712                         if (DBA::isResult($contact)) {
713                                 self::switchContact($contact['id'], $receiver, $actor);
714                         }
715                 }
716         }
717
718         /**
719          *
720          *
721          * @param       $object_data
722          * @param array $activity
723          *
724          * @return mixed
725          */
726         private static function addActivityFields($object_data, $activity)
727         {
728                 if (!empty($activity['published']) && empty($object_data['published'])) {
729                         $object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
730                 }
731
732                 if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
733                         $object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid', '@value');
734                 }
735
736                 $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
737                 $object_data['service'] = JsonLD::fetchElement($object_data, 'service', '@value');
738
739                 if (!empty($object_data['object_id'])) {
740                         // Some systems (e.g. GNU Social) don't reply to the "id" field but the "uri" field.
741                         $objectId = Item::getURIByLink($object_data['object_id']);
742                         if (!empty($objectId) && ($object_data['object_id'] != $objectId)) {
743                                 Logger::notice('Fix wrong object-id', ['received' => $object_data['object_id'], 'correct' => $objectId]);
744                                 $object_data['object_id'] = $objectId;
745                         }
746                 }
747
748                 return $object_data;
749         }
750
751         /**
752          * Fetches the object data from external ressources if needed
753          *
754          * @param string  $object_id    Object ID of the the provided object
755          * @param array   $object       The provided object array
756          * @param boolean $trust_source Do we trust the provided object?
757          * @param integer $uid          User ID for the signature that we use to fetch data
758          *
759          * @return array|false with trusted and valid object data
760          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
761          * @throws \ImagickException
762          */
763         private static function fetchObject(string $object_id, array $object = [], bool $trust_source = false, int $uid = 0)
764         {
765                 // By fetching the type we check if the object is complete.
766                 $type = JsonLD::fetchElement($object, '@type');
767
768                 if (!$trust_source || empty($type)) {
769                         $data = ActivityPub::fetchContent($object_id, $uid);
770                         if (!empty($data)) {
771                                 $object = JsonLD::compact($data);
772                                 Logger::log('Fetched content for ' . $object_id, Logger::DEBUG);
773                         } else {
774                                 Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
775
776                                 $item = Item::selectFirst([], ['uri' => $object_id]);
777                                 if (!DBA::isResult($item)) {
778                                         Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
779                                         return false;
780                                 }
781                                 Logger::log('Using already stored item for url ' . $object_id, Logger::DEBUG);
782                                 $data = ActivityPub\Transmitter::createNote($item);
783                                 $object = JsonLD::compact($data);
784                         }
785                 } else {
786                         Logger::log('Using original object for url ' . $object_id, Logger::DEBUG);
787                 }
788
789                 $type = JsonLD::fetchElement($object, '@type');
790
791                 if (empty($type)) {
792                         Logger::log('Empty type', Logger::DEBUG);
793                         return false;
794                 }
795
796                 if (in_array($type, self::CONTENT_TYPES)) {
797                         $object_data = self::processObject($object);
798
799                         if (!empty($data)) {
800                                 $object_data['raw'] = json_encode($data);
801                         }
802                         return $object_data;
803                 }
804
805                 if ($type == 'as:Announce') {
806                         $object_id = JsonLD::fetchElement($object, 'object', '@id');
807                         if (empty($object_id) || !is_string($object_id)) {
808                                 return false;
809                         }
810                         return self::fetchObject($object_id, [], false, $uid);
811                 }
812
813                 Logger::log('Unhandled object type: ' . $type, Logger::DEBUG);
814                 return false;
815         }
816
817         /**
818          * Convert tags from JSON-LD format into a simplified format
819          *
820          * @param array $tags Tags in JSON-LD format
821          *
822          * @return array with tags in a simplified format
823          */
824         private static function processTags(array $tags)
825         {
826                 $taglist = [];
827
828                 foreach ($tags as $tag) {
829                         if (empty($tag)) {
830                                 continue;
831                         }
832
833                         $element = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
834                                 'href' => JsonLD::fetchElement($tag, 'as:href', '@id'),
835                                 'name' => JsonLD::fetchElement($tag, 'as:name', '@value')];
836
837                         if (empty($element['type'])) {
838                                 continue;
839                         }
840
841                         if (empty($element['href'])) {
842                                 $element['href'] = $element['name'];
843                         }
844
845                         $taglist[] = $element;
846                 }
847                 return $taglist;
848         }
849
850         /**
851          * Convert emojis from JSON-LD format into a simplified format
852          *
853          * @param array $emojis
854          * @return array with emojis in a simplified format
855          */
856         private static function processEmojis(array $emojis)
857         {
858                 $emojilist = [];
859
860                 foreach ($emojis as $emoji) {
861                         if (empty($emoji) || (JsonLD::fetchElement($emoji, '@type') != 'toot:Emoji') || empty($emoji['as:icon'])) {
862                                 continue;
863                         }
864
865                         $url = JsonLD::fetchElement($emoji['as:icon'], 'as:url', '@id');
866                         $element = ['name' => JsonLD::fetchElement($emoji, 'as:name', '@value'),
867                                 'href' => $url];
868
869                         $emojilist[] = $element;
870                 }
871
872                 return $emojilist;
873         }
874
875         /**
876          * Convert attachments from JSON-LD format into a simplified format
877          *
878          * @param array $attachments Attachments in JSON-LD format
879          *
880          * @return array Attachments in a simplified format
881          */
882         private static function processAttachments(array $attachments)
883         {
884                 $attachlist = [];
885
886                 // Removes empty values
887                 $attachments = array_filter($attachments);
888
889                 foreach ($attachments as $attachment) {
890                         switch (JsonLD::fetchElement($attachment, '@type')) {
891                                 case 'as:Page':
892                                         $pageUrl = null;
893                                         $pageImage = null;
894
895                                         $urls = JsonLD::fetchElementArray($attachment, 'as:url');
896                                         foreach ($urls as $url) {
897                                                 // Single scalar URL case
898                                                 if (is_string($url)) {
899                                                         $pageUrl = $url;
900                                                         continue;
901                                                 }
902
903                                                 $href = JsonLD::fetchElement($url, 'as:href', '@id');
904                                                 $mediaType = JsonLD::fetchElement($url, 'as:mediaType', '@value');
905                                                 if (Strings::startsWith($mediaType, 'image')) {
906                                                         $pageImage = $href;
907                                                 } else {
908                                                         $pageUrl = $href;
909                                                 }
910                                         }
911
912                                         $attachlist[] = [
913                                                 'type'  => 'link',
914                                                 'title' => JsonLD::fetchElement($attachment, 'as:name', '@value'),
915                                                 'desc'  => JsonLD::fetchElement($attachment, 'as:summary', '@value'),
916                                                 'url'   => $pageUrl,
917                                                 'image' => $pageImage,
918                                         ];
919                                         break;
920                                 case 'as:Link':
921                                         $attachlist[] = [
922                                                 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
923                                                 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType', '@value'),
924                                                 'name' => JsonLD::fetchElement($attachment, 'as:name', '@value'),
925                                                 'url' => JsonLD::fetchElement($attachment, 'as:href', '@id')
926                                         ];
927                                         break;
928                                 case 'as:Image':
929                                         $mediaType = JsonLD::fetchElement($attachment, 'as:mediaType', '@value');
930                                         $imageFullUrl = JsonLD::fetchElement($attachment, 'as:url', '@id');
931                                         $imagePreviewUrl = null;
932                                         // Multiple URLs?
933                                         if (!$imageFullUrl && ($urls = JsonLD::fetchElementArray($attachment, 'as:url'))) {
934                                                 $imageVariants = [];
935                                                 $previewVariants = [];
936                                                 foreach ($urls as $url) {
937                                                         // Scalar URL, no discrimination possible
938                                                         if (is_string($url)) {
939                                                                 $imageFullUrl = $url;
940                                                                 continue;
941                                                         }
942
943                                                         // Not sure what to do with a different Link media type than the base Image, we skip
944                                                         if ($mediaType != JsonLD::fetchElement($url, 'as:mediaType', '@value')) {
945                                                                 continue;
946                                                         }
947
948                                                         $href = JsonLD::fetchElement($url, 'as:href', '@id');
949
950                                                         // Default URL choice if no discriminating width is provided
951                                                         $imageFullUrl = $href ?? $imageFullUrl;
952
953                                                         $width = intval(JsonLD::fetchElement($url, 'as:width', '@value') ?? 1);
954
955                                                         if ($href && $width) {
956                                                                 $imageVariants[$width] = $href;
957                                                                 // 632 is the ideal width for full screen frio posts, we compute the absolute distance to it
958                                                                 $previewVariants[abs(632 - $width)] = $href;
959                                                         }
960                                                 }
961
962                                                 if ($imageVariants) {
963                                                         // Taking the maximum size image
964                                                         ksort($imageVariants);
965                                                         $imageFullUrl = array_pop($imageVariants);
966
967                                                         // Taking the minimum number distance to the target distance
968                                                         ksort($previewVariants);
969                                                         $imagePreviewUrl = array_shift($previewVariants);
970                                                 }
971
972                                                 unset($imageVariants);
973                                                 unset($previewVariants);
974                                         }
975
976                                         $attachlist[] = [
977                                                 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
978                                                 'mediaType' => $mediaType,
979                                                 'name'  => JsonLD::fetchElement($attachment, 'as:name', '@value'),
980                                                 'url'   => $imageFullUrl,
981                                                 'image' => $imagePreviewUrl !== $imageFullUrl ? $imagePreviewUrl : null,
982                                         ];
983                                         break;
984                                 default:
985                                         $attachlist[] = [
986                                                 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
987                                                 'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType', '@value'),
988                                                 'name' => JsonLD::fetchElement($attachment, 'as:name', '@value'),
989                                                 'url' => JsonLD::fetchElement($attachment, 'as:url', '@id')
990                                         ];
991                         }
992                 }
993
994                 return $attachlist;
995         }
996
997         /**
998          * Fetch the original source or content with the "language" Markdown or HTML
999          *
1000          * @param array $object
1001          * @param array $object_data
1002          *
1003          * @return array
1004          * @throws \Exception
1005          */
1006         private static function getSource($object, $object_data)
1007         {
1008                 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
1009                 $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value');
1010                 if (!empty($object_data['source'])) {
1011                         return $object_data;
1012                 }
1013
1014                 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/markdown');
1015                 $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value');
1016                 if (!empty($object_data['source'])) {
1017                         $object_data['source'] = Markdown::toBBCode($object_data['source']);
1018                         return $object_data;
1019                 }
1020
1021                 $object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/html');
1022                 $object_data['source'] = JsonLD::fetchElement($object_data, 'source', '@value');
1023                 if (!empty($object_data['source'])) {
1024                         $object_data['source'] = HTML::toBBCode($object_data['source']);
1025                         return $object_data;
1026                 }
1027
1028                 return $object_data;
1029         }
1030
1031         /**
1032          * Check if the "as:url" element is an array with multiple links
1033          * This is the case with audio and video posts.
1034          * Then the links are added as attachments
1035          *
1036          * @param array $object      The raw object
1037          * @param array $object_data The parsed object data for later processing
1038          * @return array the object data
1039          */
1040         private static function processAttachmentUrls(array $object, array $object_data) {
1041                 // Check if this is some url with multiple links
1042                 if (empty($object['as:url'])) {
1043                         return $object_data;
1044                 }
1045                 
1046                 $urls = $object['as:url'];
1047                 $keys = array_keys($urls);
1048                 if (!is_numeric(array_pop($keys))) {
1049                         return $object_data;
1050                 }
1051
1052                 $attachments = [];
1053
1054                 foreach ($urls as $url) {
1055                         if (empty($url['@type']) || ($url['@type'] != 'as:Link')) {
1056                                 continue;
1057                         }
1058
1059                         $href = JsonLD::fetchElement($url, 'as:href', '@id');
1060                         if (empty($href)) {
1061                                 continue;
1062                         }
1063
1064                         $mediatype = JsonLD::fetchElement($url, 'as:mediaType');
1065                         if (empty($mediatype)) {
1066                                 continue;
1067                         }
1068
1069                         if ($mediatype == 'text/html') {
1070                                 $object_data['alternate-url'] = $href;
1071                         }
1072
1073                         $filetype = strtolower(substr($mediatype, 0, strpos($mediatype, '/')));
1074
1075                         if ($filetype == 'audio') {
1076                                 $attachments[$filetype] = ['type' => $mediatype, 'url' => $href];
1077                         } elseif ($filetype == 'video') {
1078                                 $height = (int)JsonLD::fetchElement($url, 'as:height', '@value');
1079
1080                                 // We save bandwidth by using a moderate height
1081                                 // Peertube normally uses these heights: 240, 360, 480, 720, 1080
1082                                 if (!empty($attachments[$filetype]['height']) &&
1083                                         (($height > 480) || $height < $attachments[$filetype]['height'])) {
1084                                         continue;
1085                                 }
1086
1087                                 $attachments[$filetype] = ['type' => $mediatype, 'url' => $href, 'height' => $height];
1088                         }
1089                 }
1090
1091                 foreach ($attachments as $type => $attachment) {
1092                         $object_data['attachments'][] = ['type' => $type,
1093                                 'mediaType' => $attachment['type'],
1094                                 'name' => '',
1095                                 'url' => $attachment['url']];
1096                 }
1097                 return $object_data;
1098         }
1099
1100         /**
1101          * Fetches data from the object part of an activity
1102          *
1103          * @param array $object
1104          *
1105          * @return array
1106          * @throws \Exception
1107          */
1108         private static function processObject($object)
1109         {
1110                 if (!JsonLD::fetchElement($object, '@id')) {
1111                         return false;
1112                 }
1113
1114                 $object_data = [];
1115                 $object_data['object_type'] = JsonLD::fetchElement($object, '@type');
1116                 $object_data['id'] = JsonLD::fetchElement($object, '@id');
1117                 $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo', '@id');
1118
1119                 // An empty "id" field is translated to "./" by the compactor, so we have to check for this content
1120                 if (empty($object_data['reply-to-id']) || ($object_data['reply-to-id'] == './')) {
1121                         $object_data['reply-to-id'] = $object_data['id'];
1122                 } else {
1123                         // Some systems (e.g. GNU Social) don't reply to the "id" field but the "uri" field.
1124                         $replyToId = Item::getURIByLink($object_data['reply-to-id']);
1125                         if (!empty($replyToId) && ($object_data['reply-to-id'] != $replyToId)) {
1126                                 Logger::notice('Fix wrong reply-to', ['received' => $object_data['reply-to-id'], 'correct' => $replyToId]);
1127                                 $object_data['reply-to-id'] = $replyToId;
1128                         }
1129                 }
1130
1131                 $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');
1132                 $object_data['updated'] = JsonLD::fetchElement($object, 'as:updated', '@value');
1133
1134                 if (empty($object_data['updated'])) {
1135                         $object_data['updated'] = $object_data['published'];
1136                 }
1137
1138                 if (empty($object_data['published']) && !empty($object_data['updated'])) {
1139                         $object_data['published'] = $object_data['updated'];
1140                 }
1141
1142                 $actor = JsonLD::fetchElement($object, 'as:attributedTo', '@id');
1143                 if (empty($actor)) {
1144                         $actor = JsonLD::fetchElement($object, 'as:actor', '@id');
1145                 }
1146
1147                 $location = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
1148                 $location = JsonLD::fetchElement($location, 'location', '@value');
1149                 if ($location) {
1150                         // Some AP software allow formatted text in post location, so we run all the text converters we have to boil
1151                         // down to HTML and then finally format to plaintext.
1152                         $location = Markdown::convert($location);
1153                         $location = BBCode::convert($location);
1154                         $location = HTML::toPlaintext($location);
1155                 }
1156
1157                 $object_data['sc:identifier'] = JsonLD::fetchElement($object, 'sc:identifier', '@value');
1158                 $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid', '@value');
1159                 $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment', '@value');
1160                 $object_data['diaspora:like'] = JsonLD::fetchElement($object, 'diaspora:like', '@value');
1161                 $object_data['actor'] = $object_data['author'] = $actor;
1162                 $object_data['context'] = JsonLD::fetchElement($object, 'as:context', '@id');
1163                 $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation', '@id');
1164                 $object_data['sensitive'] = JsonLD::fetchElement($object, 'as:sensitive');
1165                 $object_data['name'] = JsonLD::fetchElement($object, 'as:name', '@value');
1166                 $object_data['summary'] = JsonLD::fetchElement($object, 'as:summary', '@value');
1167                 $object_data['content'] = JsonLD::fetchElement($object, 'as:content', '@value');
1168                 $object_data = self::getSource($object, $object_data);
1169                 $object_data['start-time'] = JsonLD::fetchElement($object, 'as:startTime', '@value');
1170                 $object_data['end-time'] = JsonLD::fetchElement($object, 'as:endTime', '@value');
1171                 $object_data['location'] = $location;
1172                 $object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
1173                 $object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
1174                 $object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
1175                 $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
1176                 $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment') ?? []);
1177                 $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag') ?? []);
1178                 $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', 'toot:Emoji') ?? []);
1179                 $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
1180                 $object_data['generator'] = JsonLD::fetchElement($object_data, 'generator', '@value');
1181                 $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url', '@id');
1182
1183                 // Special treatment for Hubzilla links
1184                 if (is_array($object_data['alternate-url'])) {
1185                         $object_data['alternate-url'] = JsonLD::fetchElement($object_data['alternate-url'], 'as:href', '@id');
1186
1187                         if (!is_string($object_data['alternate-url'])) {
1188                                 $object_data['alternate-url'] = JsonLD::fetchElement($object['as:url'], 'as:href', '@id');
1189                         }
1190                 }
1191
1192                 if (in_array($object_data['object_type'], ['as:Audio', 'as:Video'])) {
1193                         $object_data = self::processAttachmentUrls($object, $object_data);
1194                 }
1195
1196                 $object_data['receiver'] = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
1197                 $object_data['unlisted'] = in_array(-1, $object_data['receiver']);
1198                 unset($object_data['receiver']['uid:-1']);
1199
1200                 // Common object data:
1201
1202                 // Unhandled
1203                 // @context, type, actor, signature, mediaType, duration, replies, icon
1204
1205                 // Also missing: (Defined in the standard, but currently unused)
1206                 // audience, preview, endTime, startTime, image
1207
1208                 // Data in Notes:
1209
1210                 // Unhandled
1211                 // contentMap, announcement_count, announcements, context_id, likes, like_count
1212                 // inReplyToStatusId, shares, quoteUrl, statusnetConversationId
1213
1214                 // Data in video:
1215
1216                 // To-Do?
1217                 // category, licence, language, commentsEnabled
1218
1219                 // Unhandled
1220                 // views, waitTranscoding, state, support, subtitleLanguage
1221                 // likes, dislikes, shares, comments
1222
1223                 return $object_data;
1224         }
1225 }