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