]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notify.php
Use correct entry list in Module\Directory
[friendica.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
23         public static function rawContent()
24         {
25                 $a = self::getApp();
26
27                 // @TODO: Replace with parameter from router
28                 if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
29                         $notificationsManager = new NotificationsManager();
30                         $success              = $notificationsManager->setAllSeen();
31
32                         header('Content-type: application/json; charset=utf-8');
33                         echo json_encode([
34                                 'result' => ($success) ? 'success' : 'fail',
35                         ]);
36                         exit();
37                 }
38         }
39
40         /**
41          * Redirect to the notifications main page or to the url for the chosen notify
42          *
43          * @return string|void
44          * @throws HTTPException\InternalServerErrorException
45          */
46         public static function content()
47         {
48                 $a = self::getApp();
49
50                 // @TODO: Replace with parameter from router
51                 if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
52                         $notificationsManager = new NotificationsManager();
53                         // @TODO: Replace with parameter from router
54                         $note = $notificationsManager->getByID($a->argv[2]);
55                         if (!empty($note)) {
56                                 $notificationsManager->setSeen($note);
57                                 if (!empty($note['link'])) {
58                                         System::externalRedirect($note['link']);
59                                 }
60                         }
61
62                         $a->internalRedirect();
63                 }
64
65                 // @TODO: Replace with parameter from router
66                 $a->internalRedirect('notifications/system');
67         }
68 }