diff --git a/mod/display.php b/mod/display.php index 62e180874..175f8da32 100644 --- a/mod/display.php +++ b/mod/display.php @@ -36,7 +36,6 @@ use Friendica\Module\Response; use Friendica\Network\HTTPException; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\DFRN; -use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; function display_init(App $a) @@ -49,8 +48,6 @@ function display_init(App $a) return; } - $nick = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : ''); - $item = null; $item_user = DI::userSession()->getLocalUserId(); @@ -58,14 +55,9 @@ function display_init(App $a) // If there is only one parameter, then check if this parameter could be a guid if (DI::args()->getArgc() == 2) { - $nick = ''; - // Does the local user have this item? if (DI::userSession()->getLocalUserId()) { $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['guid' => DI::args()->getArgv()[1], 'uid' => DI::userSession()->getLocalUserId()]); - if (DBA::isResult($item)) { - $nick = $a->getLoggedInUserNickname(); - } } // Is this item private but could be visible to the remove visitor? @@ -84,22 +76,12 @@ function display_init(App $a) if (!DBA::isResult($item)) { $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['guid' => DI::args()->getArgv()[1], 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); } - } elseif (DI::args()->getArgc() >= 3 && $nick == 'feed-item') { - $uri_id = DI::args()->getArgv()[2]; - if (substr($uri_id, -5) == '.atom') { - $uri_id = substr($uri_id, 0, -5); - } - $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), $fields, ['uri-id' => $uri_id, 'private' => [Item::PUBLIC, Item::UNLISTED], 'uid' => 0]); } if (!DBA::isResult($item)) { return; } - if (DI::args()->getArgc() >= 3 && $nick == 'feed-item') { - displayShowFeed($item['uri-id'], $item['uid'], DI::args()->getArgc() > 3 && DI::args()->getArgv()[3] == 'conversation.atom'); - } - if (!empty($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) { Logger::debug('Directly serving XML', ['uri-id' => $item['uri-id']]); displayShowFeed($item['uri-id'], $item['uid'], false); diff --git a/src/Module/Item/Feed.php b/src/Module/Item/Feed.php new file mode 100644 index 000000000..8830cb0af --- /dev/null +++ b/src/Module/Item/Feed.php @@ -0,0 +1,92 @@ +. + * + * See update_profile.php for documentation + */ + +namespace Friendica\Module\Item; + +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\L10n; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Core\System; +use Friendica\Model\Item; +use Friendica\Model\Post; +use Friendica\Module\Response; +use Friendica\Protocol\DFRN; +use Friendica\Util\Profiler; +use Friendica\Network\HTTPException; +use Psr\Log\LoggerInterface; + +/** + * Controller to display an item (or the whole conversation of an item) as an ATOM Feed + */ +class Feed extends BaseModule +{ + /** @var IManageConfigValues */ + protected $config; + /** @var IHandleUserSessions */ + protected $session; + + public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, IHandleUserSessions $session, array $server, array $parameters = []) + { + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->config = $config; + $this->session = $session; + } + + protected function rawContent(array $request = []) + { + if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) { + throw new HTTPException\UnauthorizedException($this->t('Access denied.')); + } + + $uriId = $this->parameters['uri-id']; + + $item = Post::selectFirstForUser($this->session->getLocalUserId(), [ + 'uri-id', + 'parent-uri-id', + 'author-id', + 'author-link', + 'body', + 'uid', + 'guid', + 'gravity', + ], [ + 'uri-id' => $uriId, + 'private' => [Item::PUBLIC, Item::UNLISTED], + 'uid' => 0, + ]); + + if (empty($item)) { + throw new HTTPException\BadRequestException($this->t('Item not found.', ['uri-id' => $uriId])); + } + + $xml = DFRN::itemFeed($item['uri-id'], $item['uid'], ($this->parameters['mode'] ?? '') === 'conversation'); + + if (empty($xml)) { + throw new HTTPException\InternalServerErrorException($this->t('The feed for this item is unavailable.', ['uri-id' => $uriId])); + } + + System::httpExit($xml, Response::TYPE_ATOM); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index d5bed2756..747cbe700 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -398,6 +398,9 @@ return [ '/dirfind' => [Module\Search\Directory::class, [R::GET]], '/directory' => [Module\Directory::class, [R::GET]], + '/display/feed-item/{uri-id}[.atom]' => [Module\Item\Feed::class, [R::GET]], + '/display/feed-item/{uri-id}/{mode:conversation}[.atom]' => [Module\Item\Feed::class, [R::GET]], + '/featured/{nickname}' => [Module\ActivityPub\Featured::class, [R::GET]], '/feed' => [