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