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