3 This file is part of the Diaspora protocol. It is used for fetching single public posts.
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Protocol\Diaspora;
10 use Friendica\Util\XML;
12 function fetch_init(App $a)
15 if (($a->argc != 3) || (!in_array($a->argv[1], ["post", "status_message", "reshare"]))) {
16 header($_SERVER["SERVER_PROTOCOL"].' 404 '.L10n::t('Not Found'));
24 "SELECT `uid`, `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app`, `location`, `coord`
25 FROM `item` WHERE `wall` AND NOT `private` AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
33 FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') AND `id` = `parent` LIMIT 1",
40 $parts = parse_url($r[0]["author-link"]);
41 $host = $parts["scheme"]."://".$parts["host"];
43 if (normalise_link($host) != normalise_link(System::baseUrl())) {
44 $location = $host."/fetch/".$a->argv[1]."/".urlencode($guid);
46 header("HTTP/1.1 301 Moved Permanently");
47 header("Location:".$location);
52 header($_SERVER["SERVER_PROTOCOL"].' 404 '.L10n::t('Not Found'));
56 // Fetch some data from the author (We could combine both queries - but I think this is more readable)
58 "SELECT `user`.`prvkey`, `contact`.`addr`, `user`.`nickname`, `contact`.`nick` FROM `user`
59 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
60 WHERE `user`.`uid` = %d",
61 intval($item[0]["uid"])
65 header($_SERVER["SERVER_PROTOCOL"].' 404 '.L10n::t('Not Found'));
70 $status = Diaspora::buildStatus($item[0], $user);
71 $xml = Diaspora::buildPostXml($status["type"], $status["message"]);
74 header("Content-Type: application/magic-envelope+xml; charset=utf-8");
75 echo Diaspora::buildMagicEnvelope($xml, $user);