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