Replace System::httpExit() by HTTPException throwing
[friendica.git/.git] / src / Module / Objects.php
1 <?php
2 /**
3  * @file src/Module/Objects.php
4  */
5 namespace Friendica\Module;
6
7 use Friendica\BaseModule;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Item;
11 use Friendica\Protocol\ActivityPub;
12
13 /**
14  * ActivityPub Objects
15  */
16 class Objects extends BaseModule
17 {
18         public static function rawContent()
19         {
20                 $a = self::getApp();
21
22                 if (empty($a->argv[1])) {
23                         throw new \Friendica\Network\HTTPException\NotFoundException();
24                 }
25
26                 if (!ActivityPub::isRequest()) {
27                         $a->internalRedirect(str_replace('objects/', 'display/', $a->query_string));
28                 }
29
30                 /// @todo Add Authentication to enable fetching of non public content
31                 // $requester = HTTPSignature::getSigner('', $_SERVER);
32
33                 // At first we try the original post with that guid
34                 // @TODO: Replace with parameter from router
35                 $item = Item::selectFirst(['id'], ['guid' => $a->argv[1], 'origin' => true, 'private' => false]);
36                 if (!DBA::isResult($item)) {
37                         // If no original post could be found, it could possibly be a forum post, there we remove the "origin" field.
38                         // @TODO: Replace with parameter from router
39                         $item = Item::selectFirst(['id', 'author-link'], ['guid' => $a->argv[1], 'private' => false]);
40                         if (!DBA::isResult($item) || !strstr($item['author-link'], System::baseUrl())) {
41                                 throw new \Friendica\Network\HTTPException\NotFoundException();
42                         }
43                 }
44
45                 $data = ActivityPub\Transmitter::createObjectFromItemID($item['id']);
46
47                 header('Content-Type: application/activity+json');
48                 echo json_encode($data);
49                 exit();
50         }
51 }