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