2016-06-29 16:50:30 -04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
This file is part of the Diaspora protocol. It is used for fetching single public posts.
|
|
|
|
*/
|
2017-04-30 00:07:00 -04:00
|
|
|
|
|
|
|
use Friendica\App;
|
2018-01-22 16:59:31 -05:00
|
|
|
use Friendica\Core\L10n;
|
2017-08-26 02:04:21 -04:00
|
|
|
use Friendica\Core\System;
|
2017-11-07 19:37:53 -05:00
|
|
|
use Friendica\Protocol\Diaspora;
|
2018-06-18 16:36:34 -04:00
|
|
|
use Friendica\Model\Item;
|
|
|
|
use Friendica\Model\User;
|
2017-11-10 07:45:33 -05:00
|
|
|
use Friendica\Util\XML;
|
2018-06-18 16:36:34 -04:00
|
|
|
use Friendica\Database\DBM;
|
2017-04-30 00:07:00 -04:00
|
|
|
|
2017-11-10 00:00:50 -05:00
|
|
|
function fetch_init(App $a)
|
|
|
|
{
|
2016-06-29 16:50:30 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
if (($a->argc != 3) || (!in_array($a->argv[1], ["post", "status_message", "reshare"]))) {
|
2018-01-22 16:59:31 -05:00
|
|
|
header($_SERVER["SERVER_PROTOCOL"].' 404 '.L10n::t('Not Found'));
|
2016-06-29 16:50:30 -04:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
$guid = $a->argv[2];
|
|
|
|
|
2016-06-30 01:32:07 -04:00
|
|
|
// Fetch the item
|
2018-07-10 08:27:56 -04:00
|
|
|
$fields = ['uid', 'title', 'body', 'guid', 'contact-id', 'private', 'created', 'app', 'location', 'coord', 'network',
|
|
|
|
'event-id', 'resource-id', 'author-link', 'owner-link', 'attach'];
|
2018-06-18 16:36:34 -04:00
|
|
|
$condition = ['wall' => true, 'private' => false, 'guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]];
|
|
|
|
$item = Item::selectFirst($fields, $condition);
|
|
|
|
if (!DBM::is_result($item)) {
|
|
|
|
$condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]];
|
|
|
|
$item = Item::selectFirst(['author-link'], $condition);
|
|
|
|
if (DBM::is_result($item)) {
|
|
|
|
$parts = parse_url($item["author-link"]);
|
2016-06-30 02:55:26 -04:00
|
|
|
$host = $parts["scheme"]."://".$parts["host"];
|
|
|
|
|
2017-08-26 03:32:10 -04:00
|
|
|
if (normalise_link($host) != normalise_link(System::baseUrl())) {
|
2016-06-30 06:02:35 -04:00
|
|
|
$location = $host."/fetch/".$a->argv[1]."/".urlencode($guid);
|
2016-06-30 02:55:26 -04:00
|
|
|
|
2016-06-30 06:02:35 -04:00
|
|
|
header("HTTP/1.1 301 Moved Permanently");
|
|
|
|
header("Location:".$location);
|
|
|
|
killme();
|
|
|
|
}
|
2016-06-30 02:55:26 -04:00
|
|
|
}
|
|
|
|
|
2018-01-22 16:59:31 -05:00
|
|
|
header($_SERVER["SERVER_PROTOCOL"].' 404 '.L10n::t('Not Found'));
|
2016-06-29 16:50:30 -04:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2016-06-30 01:32:07 -04:00
|
|
|
// Fetch some data from the author (We could combine both queries - but I think this is more readable)
|
2018-06-18 16:36:34 -04:00
|
|
|
$user = User::getOwnerDataById($item["uid"]);
|
|
|
|
if (!$user) {
|
2018-01-22 16:59:31 -05:00
|
|
|
header($_SERVER["SERVER_PROTOCOL"].' 404 '.L10n::t('Not Found'));
|
2016-06-29 16:50:30 -04:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2018-06-18 16:36:34 -04:00
|
|
|
$status = Diaspora::buildStatus($item, $user);
|
2017-11-23 14:01:58 -05:00
|
|
|
$xml = Diaspora::buildPostXml($status["type"], $status["message"]);
|
2016-06-29 16:50:30 -04:00
|
|
|
|
2016-06-30 01:32:07 -04:00
|
|
|
// Send the envelope
|
|
|
|
header("Content-Type: application/magic-envelope+xml; charset=utf-8");
|
2017-11-23 14:01:58 -05:00
|
|
|
echo Diaspora::buildMagicEnvelope($xml, $user);
|
2016-06-29 16:50:30 -04:00
|
|
|
|
|
|
|
killme();
|
|
|
|
}
|