]> git.mxchange.org Git - friendica.git/blob - src/Module/Feed.php
Merge pull request #8135 from annando/brief
[friendica.git] / src / Module / Feed.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\DI;
7 use Friendica\Protocol\OStatus;
8
9 /**
10  * Provides public Atom feeds
11  *
12  * Currently supported:
13  * - /feed/[nickname]/ => posts
14  * - /feed/[nickname]/posts => posts
15  * - /feed/[nickname]/comments => comments
16  * - /feed/[nickname]/replies => comments
17  * - /feed/[nickname]/activity => activity
18  *
19  * The nocache GET parameter is provided mainly for debug purposes, requires auth
20  *
21  * @author Hypolite Petovan <hypolite@mrpetovan.com>
22  */
23 class Feed extends BaseModule
24 {
25         public static function content(array $parameters = [])
26         {
27                 $a = DI::app();
28
29                 $last_update = $_GET['last_update'] ?? '';
30                 $nocache     = !empty($_GET['nocache']) && local_user();
31
32                 // @TODO: Replace with parameter from router
33                 if ($a->argc < 2) {
34                         throw new \Friendica\Network\HTTPException\BadRequestException();
35                 }
36
37                 $type = null;
38                 // @TODO: Replace with parameter from router
39                 if ($a->argc > 2) {
40                         $type = $a->argv[2];
41                 }
42
43                 switch ($type) {
44                         case 'posts':
45                         case 'comments':
46                         case 'activity':
47                                 // Correct type names, no change needed
48                                 break;
49                         case 'replies':
50                                 $type = 'comments';
51                                 break;
52                         default:
53                                 $type = 'posts';
54                 }
55
56                 // @TODO: Replace with parameter from router
57                 $nickname = $a->argv[1];
58                 header("Content-type: application/atom+xml; charset=utf-8");
59                 echo OStatus::feed($nickname, $last_update, 10, $type, $nocache, true);
60                 exit();
61         }
62 }