]> git.mxchange.org Git - friendica.git/blob - src/Module/Item/Feed.php
Make PHP-CS happy
[friendica.git] / src / Module / Item / Feed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * See update_profile.php for documentation
21  */
22
23 namespace Friendica\Module\Item;
24
25 use Friendica\App;
26 use Friendica\BaseModule;
27 use Friendica\Core\Config\Capability\IManageConfigValues;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Session\Capability\IHandleUserSessions;
30 use Friendica\Core\System;
31 use Friendica\Model\Item;
32 use Friendica\Model\Post;
33 use Friendica\Module\Response;
34 use Friendica\Protocol\DFRN;
35 use Friendica\Util\Profiler;
36 use Friendica\Network\HTTPException;
37 use Psr\Log\LoggerInterface;
38
39 /**
40  * Controller to display an item (or the whole conversation of an item) as an ATOM Feed
41  */
42 class Feed extends BaseModule
43 {
44         /** @var IManageConfigValues */
45         protected $config;
46         /** @var IHandleUserSessions */
47         protected $session;
48
49         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 = [])
50         {
51                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
52
53                 $this->config  = $config;
54                 $this->session = $session;
55         }
56
57         protected function rawContent(array $request = [])
58         {
59                 if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
60                         throw new HTTPException\UnauthorizedException($this->t('Access denied.'));
61                 }
62
63                 $uriId = $this->parameters['uri-id'];
64
65                 $item = Post::selectFirstForUser($this->session->getLocalUserId(), [
66                         'uri-id',
67                         'parent-uri-id',
68                         'author-id',
69                         'author-link',
70                         'body',
71                         'uid',
72                         'guid',
73                         'gravity',
74                 ], [
75                         'uri-id'  => $uriId,
76                         'private' => [Item::PUBLIC, Item::UNLISTED],
77                         'uid'     => 0,
78                 ]);
79
80                 if (empty($item)) {
81                         throw new HTTPException\BadRequestException($this->t('Item not found.', ['uri-id' => $uriId]));
82                 }
83
84                 $xml = DFRN::itemFeed($item['uri-id'], $item['uid'], ($this->parameters['mode'] ?? '') === 'conversation');
85
86                 if (empty($xml)) {
87                         throw new HTTPException\InternalServerErrorException($this->t('The feed for this item is unavailable.', ['uri-id' => $uriId]));
88                 }
89
90                 System::httpExit($xml, Response::TYPE_ATOM);
91         }
92 }