]> git.mxchange.org Git - friendica.git/blob - src/Module/Feed.php
Unified output via the "httpExit" function
[friendica.git] / src / Module / 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  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\System;
26 use Friendica\DI;
27 use Friendica\Protocol\Feed as ProtocolFeed;
28
29 /**
30  * Provides public Atom feeds
31  *
32  * Currently supported:
33  * - /feed/[nickname]/ => posts
34  * - /feed/[nickname]/posts => posts
35  * - /feed/[nickname]/comments => comments
36  * - /feed/[nickname]/replies => comments
37  * - /feed/[nickname]/activity => activity
38  *
39  * The nocache GET parameter is provided mainly for debug purposes, requires auth
40  *
41  * @author Hypolite Petovan <hypolite@mrpetovan.com>
42  */
43 class Feed extends BaseModule
44 {
45         protected function content(array $request = []): string
46         {
47                 $last_update = $request['last_update'] ?? '';
48                 $nocache     = !empty($request['nocache']) && local_user();
49
50                 $type = null;
51                 // @TODO: Replace with parameter from router
52                 if (DI::args()->getArgc() > 2) {
53                         $type = DI::args()->getArgv()[2];
54                 }
55
56                 switch ($type) {
57                         case 'posts':
58                         case 'comments':
59                         case 'activity':
60                                 // Correct type names, no change needed
61                                 break;
62                         case 'replies':
63                                 $type = 'comments';
64                                 break;
65                         default:
66                                 $type = 'posts';
67                 }
68
69                 System::httpExit(ProtocolFeed::atom($this->parameters['nickname'], $last_update, 10, $type, $nocache, true), Response::TYPE_ATOM);
70         }
71 }