427 lines
14 KiB
PHP
427 lines
14 KiB
PHP
<?php
|
|
/**
|
|
* @file mod/display.php
|
|
*/
|
|
|
|
use Friendica\App;
|
|
use Friendica\Content\Pager;
|
|
use Friendica\Content\Text\BBCode;
|
|
use Friendica\Content\Text\HTML;
|
|
use Friendica\Core\ACL;
|
|
use Friendica\Core\Config;
|
|
use Friendica\Core\L10n;
|
|
use Friendica\Core\Logger;
|
|
use Friendica\Core\Protocol;
|
|
use Friendica\Core\Renderer;
|
|
use Friendica\Core\System;
|
|
use Friendica\Database\DBA;
|
|
use Friendica\Model\Contact;
|
|
use Friendica\Model\Group;
|
|
use Friendica\Model\Item;
|
|
use Friendica\Model\Profile;
|
|
use Friendica\Protocol\ActivityPub;
|
|
use Friendica\Protocol\DFRN;
|
|
use Friendica\Util\Strings;
|
|
use Friendica\Module\Objects;
|
|
|
|
function display_init(App $a)
|
|
{
|
|
if (ActivityPub::isRequest()) {
|
|
Objects::rawContent();
|
|
}
|
|
|
|
if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
|
|
return;
|
|
}
|
|
|
|
$nick = (($a->argc > 1) ? $a->argv[1] : '');
|
|
|
|
if ($a->argc == 3) {
|
|
if (substr($a->argv[2], -5) == '.atom') {
|
|
$item_id = substr($a->argv[2], 0, -5);
|
|
displayShowFeed($item_id, false);
|
|
}
|
|
}
|
|
|
|
if ($a->argc == 4) {
|
|
if ($a->argv[3] == 'conversation.atom') {
|
|
$item_id = $a->argv[2];
|
|
displayShowFeed($item_id, true);
|
|
}
|
|
}
|
|
|
|
$item = null;
|
|
$item_user = local_user();
|
|
|
|
$fields = ['id', 'parent', 'author-id', 'body', 'uid', 'guid'];
|
|
|
|
// If there is only one parameter, then check if this parameter could be a guid
|
|
if ($a->argc == 2) {
|
|
$nick = "";
|
|
|
|
// Does the local user have this item?
|
|
if (local_user()) {
|
|
$item = Item::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'uid' => local_user()]);
|
|
if (DBA::isResult($item)) {
|
|
$nick = $a->user["nickname"];
|
|
}
|
|
// Is this item private but could be visible to the remove visitor?
|
|
} elseif (remote_user()) {
|
|
$item = Item::selectFirst($fields, ['guid' => $a->argv[1], 'private' => 1]);
|
|
if (DBA::isResult($item)) {
|
|
if (!Contact::isFollower(remote_user(), $item['uid'])) {
|
|
$item = null;
|
|
} else {
|
|
$item_user = $item['uid'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Is it an item with uid=0?
|
|
if (!DBA::isResult($item)) {
|
|
$item = Item::selectFirstForUser(local_user(), $fields, ['guid' => $a->argv[1], 'private' => [0, 2], 'uid' => 0]);
|
|
}
|
|
} elseif (($a->argc == 3) && ($nick == 'feed-item')) {
|
|
$item = Item::selectFirstForUser(local_user(), $fields, ['id' => $a->argv[2], 'private' => [0, 2], 'uid' => 0]);
|
|
}
|
|
|
|
if (!DBA::isResult($item)) {
|
|
System::httpExit(404);
|
|
}
|
|
|
|
if (!empty($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) {
|
|
Logger::log('Directly serving XML for id '.$item["id"], Logger::DEBUG);
|
|
displayShowFeed($item["id"], false);
|
|
}
|
|
|
|
if ($item["id"] != $item["parent"]) {
|
|
$item = Item::selectFirstForUser($item_user, $fields, ['id' => $item["parent"]]);
|
|
}
|
|
|
|
$profiledata = display_fetchauthor($a, $item);
|
|
|
|
if (strstr(Strings::normaliseLink($profiledata["url"]), Strings::normaliseLink(System::baseUrl()))) {
|
|
$nickname = str_replace(Strings::normaliseLink(System::baseUrl())."/profile/", "", Strings::normaliseLink($profiledata["url"]));
|
|
|
|
if (($nickname != $a->user["nickname"])) {
|
|
$profile = DBA::fetchFirst("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
|
|
INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
|
WHERE `user`.`nickname` = ? AND `profile`.`is-default` AND `contact`.`self` LIMIT 1",
|
|
$nickname
|
|
);
|
|
if (DBA::isResult($profile)) {
|
|
$profiledata = $profile;
|
|
}
|
|
$profiledata["network"] = Protocol::DFRN;
|
|
} else {
|
|
$profiledata = [];
|
|
}
|
|
}
|
|
|
|
Profile::load($a, $nick, 0, $profiledata);
|
|
}
|
|
|
|
function display_fetchauthor($a, $item)
|
|
{
|
|
$author = DBA::selectFirst('contact', ['name', 'nick', 'photo', 'network', 'url'], ['id' => $item['author-id']]);
|
|
|
|
$profiledata = [];
|
|
$profiledata['uid'] = -1;
|
|
$profiledata['nickname'] = $author['nick'];
|
|
$profiledata['name'] = $author['name'];
|
|
$profiledata['picdate'] = '';
|
|