3 namespace Friendica\Module\Diaspora;
5 use Friendica\BaseModule;
6 use Friendica\Core\Protocol;
7 use Friendica\Core\System;
9 use Friendica\Model\Item;
10 use Friendica\Model\User;
11 use Friendica\Network\HTTPException;
12 use Friendica\Protocol\Diaspora;
13 use Friendica\Util\Strings;
16 * This module is part of the Diaspora protocol.
17 * It is used for fetching single public posts.
19 class Fetch extends BaseModule
21 public static function rawContent(array $parameters = [])
25 // @TODO: Replace with parameter from router
26 if (($app->argc != 3) || (!in_array($app->argv[1], ["post", "status_message", "reshare"]))) {
27 throw new HTTPException\NotFoundException();
30 // @TODO: Replace with parameter from router
31 $guid = $app->argv[2];
35 'uid', 'title', 'body', 'guid', 'contact-id', 'private', 'created', 'received', 'app', 'location', 'coord', 'network',
36 'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'attach'
38 $condition = ['wall' => true, 'private' => false, 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
39 $item = Item::selectFirst($fields, $condition);
41 $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
42 $item = Item::selectFirst(['author-link'], $condition);
44 $parts = parse_url($item["author-link"]);
45 if (empty($parts["scheme"]) || empty($parts["host"])) {
46 throw new HTTPException\InternalServerErrorException();
48 $host = $parts["scheme"] . "://" . $parts["host"];
50 if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) {
51 $location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid);
52 System::externalRedirect($location, 301);
56 throw new HTTPException\NotFoundException();
59 // Fetch some data from the author (We could combine both queries - but I think this is more readable)
60 $user = User::getOwnerDataById($item["uid"]);
62 throw new HTTPException\NotFoundException();
65 $status = Diaspora::buildStatus($item, $user);
66 $xml = Diaspora::buildPostXml($status["type"], $status["message"]);
69 header("Content-Type: application/magic-envelope+xml; charset=utf-8");
70 echo Diaspora::buildMagicEnvelope($xml, $user);