3 namespace Friendica\Module\Diaspora;
5 use Friendica\BaseModule;
6 use Friendica\Core\Protocol;
7 use Friendica\Model\Item;
8 use Friendica\Model\User;
9 use Friendica\Network\HTTPException;
10 use Friendica\Protocol\Diaspora;
11 use Friendica\Util\Strings;
14 * This module is part of the Diaspora protocol.
15 * It is used for fetching single public posts.
17 class Fetch extends BaseModule
19 public static function rawContent()
21 $app = self::getApp();
23 // @TODO: Replace with parameter from router
24 if (($app->argc != 3) || (!in_array($app->argv[1], ["post", "status_message", "reshare"]))) {
25 throw new HTTPException\NotFoundException();
28 // @TODO: Replace with parameter from router
29 $guid = $app->argv[2];
33 'uid', 'title', 'body', 'guid', 'contact-id', 'private', 'created', 'app', 'location', 'coord', 'network',
34 'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'attach'
36 $condition = ['wall' => true, 'private' => false, 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
37 $item = Item::selectFirst($fields, $condition);
39 $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
40 $item = Item::selectFirst(['author-link'], $condition);
42 $parts = parse_url($item["author-link"]);
43 $host = $parts["scheme"] . "://" . $parts["host"];
45 if (Strings::normaliseLink($host) != Strings::normaliseLink($app->getBaseURL())) {
46 $location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid);
47 $app->redirect($location);
51 throw new HTTPException\NotFoundException();
54 // Fetch some data from the author (We could combine both queries - but I think this is more readable)
55 $user = User::getOwnerDataById($item["uid"]);
57 throw new HTTPException\NotFoundException();
60 $status = Diaspora::buildStatus($item, $user);
61 $xml = Diaspora::buildPostXml($status["type"], $status["message"]);
64 header("Content-Type: application/magic-envelope+xml; charset=utf-8");
65 echo Diaspora::buildMagicEnvelope($xml, $user);