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