]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notification.php
Improvements:
[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                         try {
27                                 $success = DI::notification()->setAllSeen();
28                         }catch (\Exception $e) {
29                                 $success = false;
30                         }
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 notifications
42          *
43          * @return string|void
44          * @throws HTTPException\InternalServerErrorException
45          */
46         public static function content(array $parameters = [])
47         {
48                 // @TODO: Replace with parameter from router
49                 if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) {
50                         try {
51                                 $notification = DI::notification()->getByID(DI::args()->get(2));
52                                 $notification->setSeen();
53
54                                 if (!empty($notification->link)) {
55                                         System::externalRedirect($notification->link);
56                                 }
57
58                         } catch (HTTPException\NotFoundException $e) {
59                                 info(DI::l10n()->t('Invalid notification.'));
60                         }
61
62                         DI::baseUrl()->redirect();
63                 }
64
65                 // @TODO: Replace with parameter from router
66                 DI::baseUrl()->redirect('notifications/system');
67         }
68 }