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