3 * @file src/Module/Objects.php
5 namespace Friendica\Module;
7 use Friendica\BaseModule;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Item;
11 use Friendica\Protocol\ActivityPub;
16 class Objects extends BaseModule
18 public static function rawContent()
22 if (empty($a->argv[1])) {
23 throw new \Friendica\Network\HTTPException\NotFoundException();
26 if (!ActivityPub::isRequest()) {
27 $a->internalRedirect(str_replace('objects/', 'display/', $a->query_string));
30 /// @todo Add Authentication to enable fetching of non public content
31 // $requester = HTTPSignature::getSigner('', $_SERVER);
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();
45 $data = ActivityPub\Transmitter::createObjectFromItemID($item['id']);
47 header('Content-Type: application/activity+json');
48 echo json_encode($data);