]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notification.php
Merge pull request #8243 from MrPetovan/task/8238-cleanup-yesno
[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 post(array $parameters = [])
23         {
24                 $request_id = $parameters['id'] ?? false;
25
26                 if ($request_id) {
27                         $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
28
29                         switch ($_POST['submit']) {
30                                 case DI::l10n()->t('Discard'):
31                                         $intro->discard();
32                                         break;
33                                 case DI::l10n()->t('Ignore'):
34                                         $intro->ignore();
35                                         break;
36                         }
37
38                         DI::baseUrl()->redirect('notifications/intros');
39                 }
40         }
41
42         public static function rawContent(array $parameters = [])
43         {
44                 // @TODO: Replace with parameter from router
45                 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
46                         try {
47                                 $success = DI::notify()->setSeen();
48                         } catch (\Exception $e) {
49                                 DI::logger()->warning('set all seen failed.', ['exception' => $e]);
50                                 $success = false;
51                         }
52
53                         System::jsonExit(['result' => (($success) ? 'success' : 'fail')]);
54                 }
55         }
56
57         /**
58          * Redirect to the notifications main page or to the url for the chosen notifications
59          *
60          * @return string|void
61          * @throws HTTPException\InternalServerErrorException
62          */
63         public static function content(array $parameters = [])
64         {
65                 $request_id = $parameters['id'] ?? false;
66
67                 if ($request_id) {
68                         try {
69                                 $notify = DI::notify()->getByID($request_id);
70                                 DI::notify()->setSeen(true, $notify);
71
72                                 if (!empty($notify->link)) {
73                                         System::externalRedirect($notify->link);
74                                 }
75
76                         } catch (HTTPException\NotFoundException $e) {
77                                 info(DI::l10n()->t('Invalid notification.'));
78                         }
79
80                         DI::baseUrl()->redirect();
81                 }
82
83                 DI::baseUrl()->redirect('notifications/system');
84         }
85 }