3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Notifications;
24 use Friendica\BaseModule;
25 use Friendica\Core\System;
27 use Friendica\Module\Security\Login;
28 use Friendica\Network\HTTPException;
31 * Interacting with the /notification command
33 class Notification extends BaseModule
38 * @throws HTTPException\InternalServerErrorException
39 * @throws HTTPException\NotFoundException
40 * @throws HTTPException\UnauthorizedException
41 * @throws \ImagickException
44 public static function post(array $parameters = [])
47 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
50 $request_id = $parameters['id'] ?? false;
53 $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
55 switch ($_POST['submit']) {
56 case DI::l10n()->t('Discard'):
59 case DI::l10n()->t('Ignore'):
64 DI::baseUrl()->redirect('notifications/intros');
71 * @throws HTTPException\UnauthorizedException
73 public static function rawContent(array $parameters = [])
76 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
79 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
81 $success = DI::notify()->setSeen();
82 } catch (\Exception $e) {
83 DI::logger()->warning('set all seen failed.', ['exception' => $e]);
87 System::jsonExit(['result' => (($success) ? 'success' : 'fail')]);
94 * Redirect to the notifications main page or to the url for the chosen notifications
96 * @throws HTTPException\NotFoundException In case the notification is either not existing or is not for this user
97 * @throws HTTPException\InternalServerErrorException
100 public static function content(array $parameters = [])
103 notice(DI::l10n()->t('You must be logged in to show this page.'));
104 return Login::form();
107 $request_id = $parameters['id'] ?? false;
110 $notify = DI::notify()->getByID($request_id, local_user());
112 if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
113 $notify->seen = true;
114 DI::notify()->update($notify);
116 DI::notify()->setSeen(true, $notify);
119 if (!empty($notify->link)) {
120 System::externalRedirect($notify->link);
123 DI::baseUrl()->redirect();
126 DI::baseUrl()->redirect('notifications/system');
128 throw new HTTPException\InternalServerErrorException('Invalid situation.');