]> git.mxchange.org Git - friendica.git/blob - src/Module/Objects.php
Replace deprecated $a->page with DI::page()
[friendica.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\DI;
11 use Friendica\Model\Item;
12 use Friendica\Protocol\ActivityPub;
13
14 /**
15  * ActivityPub Objects
16  */
17 class Objects extends BaseModule
18 {
19         public static function rawContent(array $parameters = [])
20         {
21                 $a = DI::app();
22
23                 if (empty($a->argv[1])) {
24                         throw new \Friendica\Network\HTTPException\NotFoundException();
25                 }
26
27                 if (!ActivityPub::isRequest()) {
28                         DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString()));
29                 }
30
31                 /// @todo Add Authentication to enable fetching of non public content
32                 // $requester = HTTPSignature::getSigner('', $_SERVER);
33
34                 // At first we try the original post with that guid
35                 // @TODO: Replace with parameter from router
36                 $item = Item::selectFirst(['id'], ['guid' => $a->argv[1], 'origin' => true, 'private' => false]);
37                 if (!DBA::isResult($item)) {
38                         // If no original post could be found, it could possibly be a forum post, there we remove the "origin" field.
39                         // @TODO: Replace with parameter from router
40                         $item = Item::selectFirst(['id', 'author-link'], ['guid' => $a->argv[1], 'private' => false]);
41                         if (!DBA::isResult($item) || !strstr($item['author-link'], System::baseUrl())) {
42                                 throw new \Friendica\Network\HTTPException\NotFoundException();
43                         }
44                 }
45
46                 $activity = ActivityPub\Transmitter::createActivityFromItem($item['id'], true);
47                 // Only display "Create" activity objects here, no reshares or anything else
48                 if (!is_array($activity['object']) || ($activity['type'] != 'Create')) {
49                         throw new \Friendica\Network\HTTPException\NotFoundException();
50                 }
51
52                 $data = ['@context' => ActivityPub::CONTEXT];
53                 $data = array_merge($data, $activity['object']);
54
55                 header('Content-Type: application/activity+json');
56                 echo json_encode($data);
57                 exit();
58         }
59 }