3 * @file src/Module/Objects.php
5 namespace Friendica\Module;
7 use Friendica\BaseModule;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
11 use Friendica\Model\Item;
12 use Friendica\Protocol\ActivityPub;
17 class Objects extends BaseModule
19 public static function rawContent(array $parameters = [])
23 if (empty($a->argv[1])) {
24 throw new \Friendica\Network\HTTPException\NotFoundException();
27 if (!ActivityPub::isRequest()) {
28 DI::baseUrl()->redirect(str_replace('objects/', 'display/', DI::args()->getQueryString()));
31 /// @todo Add Authentication to enable fetching of non public content
32 // $requester = HTTPSignature::getSigner('', $_SERVER);
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();
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();
52 $data = ['@context' => ActivityPub::CONTEXT];
53 $data = array_merge($data, $activity['object']);
55 header('Content-Type: application/activity+json');
56 echo json_encode($data);