]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notification.php
Merge pull request #8261 from MrPetovan/task/8251-use-about-for-pdesc
[friendica.git] / src / Module / Notifications / Notification.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Notifications;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\System;
26 use Friendica\DI;
27 use Friendica\Network\HTTPException;
28
29 /**
30  * Interacting with the /notification command
31  */
32 class Notification extends BaseModule
33 {
34         public static function init(array $parameters = [])
35         {
36                 if (!local_user()) {
37                         throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
38                 }
39         }
40
41         public static function post(array $parameters = [])
42         {
43                 $request_id = $parameters['id'] ?? false;
44
45                 if ($request_id) {
46                         $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
47
48                         switch ($_POST['submit']) {
49                                 case DI::l10n()->t('Discard'):
50                                         $intro->discard();
51                                         break;
52                                 case DI::l10n()->t('Ignore'):
53                                         $intro->ignore();
54                                         break;
55                         }
56
57                         DI::baseUrl()->redirect('notifications/intros');
58                 }
59         }
60
61         public static function rawContent(array $parameters = [])
62         {
63                 // @TODO: Replace with parameter from router
64                 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
65                         try {
66                                 $success = DI::notify()->setSeen();
67                         } catch (\Exception $e) {
68                                 DI::logger()->warning('set all seen failed.', ['exception' => $e]);
69                                 $success = false;
70                         }
71
72                         System::jsonExit(['result' => (($success) ? 'success' : 'fail')]);
73                 }
74         }
75
76         /**
77          * Redirect to the notifications main page or to the url for the chosen notifications
78          *
79          * @return string|void
80          * @throws HTTPException\InternalServerErrorException
81          */
82         public static function content(array $parameters = [])
83         {
84                 $request_id = $parameters['id'] ?? false;
85
86                 if ($request_id) {
87                         try {
88                                 $notify = DI::notify()->getByID($request_id);
89                                 DI::notify()->setSeen(true, $notify);
90
91                                 if (!empty($notify->link)) {
92                                         System::externalRedirect($notify->link);
93                                 }
94
95                         } catch (HTTPException\NotFoundException $e) {
96                                 info(DI::l10n()->t('Invalid notification.'));
97                         }
98
99                         DI::baseUrl()->redirect();
100                 }
101
102                 DI::baseUrl()->redirect('notifications/system');
103         }
104 }