Merge pull request #7288 from annando/fix-search
[friendica.git/.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\Protocol\ActivityPub;
14 use Friendica\Util\HTTPSignature;
15
16 /**
17  * ActivityPub Inbox
18  */
19 class Inbox extends BaseModule
20 {
21         public static function rawContent()
22         {
23                 $a = self::getApp();
24
25                 $postdata = file_get_contents('php://input');
26
27                 if (empty($postdata)) {
28                         throw new \Friendica\Network\HTTPException\BadRequestException();
29                 }
30
31                 if (Config::get('debug', 'ap_inbox_log')) {
32                         if (HTTPSignature::getSigner($postdata, $_SERVER)) {
33                                 $filename = 'signed-activitypub';
34                         } else {
35                                 $filename = 'failed-activitypub';
36                         }
37                         $tempfile = tempnam(get_temppath(), $filename);
38                         file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
39                         Logger::log('Incoming message stored under ' . $tempfile);
40                 }
41
42                 // @TODO: Replace with parameter from router
43                 if (!empty($a->argv[1])) {
44                         $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
45                         if (!DBA::isResult($user)) {
46                                 throw new \Friendica\Network\HTTPException\NotFoundException();
47                         }
48                         $uid = $user['uid'];
49                 } else {
50                         $uid = 0;
51                 }
52
53                 ActivityPub\Receiver::processInbox($postdata, $_SERVER, $uid);
54
55                 throw new \Friendica\Network\HTTPException\AcceptedException();
56         }
57 }