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;
|
2018-08-11 16:40:44 -04:00
|
|
|
use Friendica\Core\Protocol;
|
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;
|
2018-11-08 11:28:29 -05:00
|
|
|
use Friendica\Util\Strings;
|
2017-11-10 07:45:33 -05:00
|
|
|
use Friendica\Util\XML;
|
2018-07-21 08:40:21 -04:00
|
|
|
use Friendica\Database\DBA;
|
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-12-02 15:14:53 -05:00
|
|
|
System::httpExit(404);
|
2016-06-29 16:50:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$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',
|
2018-09-13 17:11:52 -04:00
|
|
|
'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'attach'];
|
2018-08-11 16:40:44 -04:00
|
|
|
$condition = ['wall' => true, 'private' => false, 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
2018-06-18 16:36:34 -04:00
|
|
|
$item = Item::selectFirst($fields, $condition);
|
2018-07-21 08:46:04 -04:00
|
|
|
if (!DBA::isResult($item)) {
|
2018-08-11 16:40:44 -04:00
|
|
|
$condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
2018-06-18 16:36:34 -04:00
|
|
|
$item = Item::selectFirst(['author-link'], $condition);
|
2018-07-21 08:46:04 -04:00
|
|
|
if (DBA::isResult($item)) {
|
2018-06-18 16:36:34 -04:00
|
|
|
$parts = parse_url($item["author-link"]);
|
2016-06-30 02:55:26 -04:00
|
|
|
$host = $parts["scheme"]."://".$parts["host"];
|
|
|
|
|
2018-11-08 11:28:29 -05:00
|
|
|
if (Strings::normaliseLink($host) != Strings::normaliseLink(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);
|
2018-12-26 00:40:12 -05:00
|
|
|
exit();
|
2016-06-30 06:02:35 -04:00
|
|
|
}
|
2016-06-30 02:55:26 -04:00
|
|
|
}
|
|
|
|
|
2018-12-02 15:14:53 -05:00
|
|
|
System::httpExit(404);
|
2016-06-29 16:50:30 -04:00
|
|
|
}
|
|
|
|
|
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-12-02 15:14:53 -05:00
|
|
|
System::httpExit(404);
|
2016-06-29 16:50:30 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-12-26 00:40:12 -05:00
|
|
|
exit();
|
2016-06-29 16:50:30 -04:00
|
|
|
}
|