rearrange rawContent / content
[friendica.git/.git] / src / Module / Notifications / Notify.php
1 <?php
2
3 namespace Friendica\Module\Notifications;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\L10n;
7 use Friendica\Core\NotificationsManager;
8 use Friendica\Core\System;
9 use Friendica\Network\HTTPException;
10
11 /**
12  * Interacting with the /notify command
13  */
14 class Notify extends BaseModule
15 {
16         public static function init()
17         {
18                 if (!local_user()) {
19                         throw new HTTPException\UnauthorizedException(L10n::t('Permission denied.'));
20                 }
21
22                 $a = self::getApp();
23
24                 // @TODO: Replace with parameter from router
25                 if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
26                         $notificationsManager = new NotificationsManager();
27                         // @TODO: Replace with parameter from router
28                         $note = $notificationsManager->getByID($a->argv[2]);
29                         if (!empty($note)) {
30                                 $notificationsManager->setSeen($note);
31                                 if (!empty($note['link'])) {
32                                         System::externalRedirect($note['link']);
33                                 }
34                         }
35
36                         $a->internalRedirect();
37                 }
38         }
39
40         public static function rawContent()
41         {
42                 $a = self::getApp();
43
44                 // @TODO: Replace with parameter from router
45                 if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
46                         $notificationsManager = new NotificationsManager();
47                         $success              = $notificationsManager->setAllSeen();
48
49                         header('Content-type: application/json; charset=utf-8');
50                         echo json_encode([
51                                 'result' => ($success) ? 'success' : 'fail',
52                         ]);
53                         exit();
54                 }
55         }
56
57         /**
58          * Redirect to the notifications main page
59          *
60          * @return string|void
61          * @throws HTTPException\InternalServerErrorException
62          */
63         public static function content()
64         {
65                 $a = self::getApp();
66
67                 // @TODO: Replace with parameter from router
68                 $a->internalRedirect('notifications/system');
69         }
70 }