]> git.mxchange.org Git - friendica.git/blob - src/Module/Inbox.php
Merge pull request #8048 from MrPetovan/bug/fix-bbcode-scaleexternalimage
[friendica.git] / src / Module / Inbox.php
1 <?php
2 /**
3  * @file src/Module/Inbox.php
4  */
5
6 namespace Friendica\Module;
7
8 use Friendica\BaseModule;
9 use Friendica\Core\Config;
10 use Friendica\Core\Logger;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\DI;
14 use Friendica\Protocol\ActivityPub;
15 use Friendica\Util\HTTPSignature;
16 use Friendica\Util\Network;
17
18 /**
19  * ActivityPub Inbox
20  */
21 class Inbox extends BaseModule
22 {
23         public static function rawContent(array $parameters = [])
24         {
25                 $a = DI::app();
26
27                 $postdata = Network::postdata();
28
29                 if (empty($postdata)) {
30                         throw new \Friendica\Network\HTTPException\BadRequestException();
31                 }
32
33                 if (Config::get('debug', 'ap_inbox_log')) {
34                         if (HTTPSignature::getSigner($postdata, $_SERVER)) {
35                                 $filename = 'signed-activitypub';
36                         } else {
37                                 $filename = 'failed-activitypub';
38                         }
39                         $tempfile = tempnam(get_temppath(), $filename);
40                         file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
41                         Logger::log('Incoming message stored under ' . $tempfile);
42                 }
43
44                 // @TODO: Replace with parameter from router
45                 if (!empty($a->argv[1])) {
46                         $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
47                         if (!DBA::isResult($user)) {
48                                 throw new \Friendica\Network\HTTPException\NotFoundException();
49                         }
50                         $uid = $user['uid'];
51                 } else {
52                         $uid = 0;
53                 }
54
55                 ActivityPub\Receiver::processInbox($postdata, $_SERVER, $uid);
56
57                 throw new \Friendica\Network\HTTPException\AcceptedException();
58         }
59 }