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