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