]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notify.php
Merge pull request #8019 from nupplaphil/task/replace_getClass
[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\System;
8 use Friendica\DI;
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(array $parameters = [])
17         {
18                 if (!local_user()) {
19                         throw new HTTPException\UnauthorizedException(L10n::t('Permission denied.'));
20                 }
21         }
22
23         public static function rawContent(array $parameters = [])
24         {
25                 $a = DI::app();
26
27                 // @TODO: Replace with parameter from router
28                 if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
29                         $success              = DI::notify()->setAllSeen();
30
31                         header('Content-type: application/json; charset=utf-8');
32                         echo json_encode([
33                                 'result' => ($success) ? 'success' : 'fail',
34                         ]);
35                         exit();
36                 }
37         }
38
39         /**
40          * Redirect to the notifications main page or to the url for the chosen notify
41          *
42          * @return string|void
43          * @throws HTTPException\InternalServerErrorException
44          */
45         public static function content(array $parameters = [])
46         {
47                 $a = DI::app();
48
49                 // @TODO: Replace with parameter from router
50                 if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
51                         $notificationsManager = DI::notify();
52                         // @TODO: Replace with parameter from router
53                         $note = $notificationsManager->getByID($a->argv[2]);
54                         if (!empty($note)) {
55                                 $notificationsManager->setSeen($note);
56                                 if (!empty($note['link'])) {
57                                         System::externalRedirect($note['link']);
58                                 }
59                         }
60
61                         DI::baseUrl()->redirect();
62                 }
63
64                 // @TODO: Replace with parameter from router
65                 DI::baseUrl()->redirect('notifications/system');
66         }
67 }