]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notification.php
Merge pull request #8155 from nupplaphil/task/move_notifications
[friendica.git] / src / Module / Notifications / Notification.php
1 <?php
2
3 namespace Friendica\Module\Notifications;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\System;
7 use Friendica\DI;
8 use Friendica\Network\HTTPException;
9
10 /**
11  * Interacting with the /notification command
12  */
13 class Notification extends BaseModule
14 {
15         public static function init(array $parameters = [])
16         {
17                 if (!local_user()) {
18                         throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
19                 }
20         }
21
22         public static function rawContent(array $parameters = [])
23         {
24                 // @TODO: Replace with parameter from router
25                 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
26                         $success = DI::notification()->setAllSeen();
27
28                         header('Content-type: application/json; charset=utf-8');
29                         echo json_encode([
30                                 'result' => ($success) ? 'success' : 'fail',
31                         ]);
32                         exit();
33                 }
34         }
35
36         /**
37          * Redirect to the notifications main page or to the url for the chosen notifications
38          *
39          * @return string|void
40          * @throws HTTPException\InternalServerErrorException
41          */
42         public static function content(array $parameters = [])
43         {
44                 // @TODO: Replace with parameter from router
45                 if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) {
46                         $notificationManager = DI::notification();
47                         // @TODO: Replace with parameter from router
48                         $note = $notificationManager->getByID(DI::args()->get(2));
49                         if (!empty($note)) {
50                                 $notificationManager->setSeen($note);
51                                 if (!empty($note['link'])) {
52                                         System::externalRedirect($note['link']);
53                                 }
54                         }
55
56                         DI::baseUrl()->redirect();
57                 }
58
59                 // @TODO: Replace with parameter from router
60                 DI::baseUrl()->redirect('notifications/system');
61         }
62 }