3 * @copyright Copyright (C) 2010-2021, the Friendica project
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 DI::dba()->update('notification', ['seen' => true], ['uid' => local_user()]);
82 $success = DI::notify()->setAllSeenForUser(local_user());
83 } catch (\Exception $e) {
84 DI::logger()->warning('set all seen failed.', ['exception' => $e]);
88 System::jsonExit(['result' => (($success) ? 'success' : 'fail')]);
95 * Redirect to the notifications main page or to the url for the chosen notifications
97 * @throws HTTPException\NotFoundException In case the notification is either not existing or is not for this user
98 * @throws HTTPException\InternalServerErrorException
101 public static function content(array $parameters = []): string
104 notice(DI::l10n()->t('You must be logged in to show this page.'));
105 return Login::form();
108 $request_id = $parameters['id'] ?? false;
111 $Notify = DI::notify()->selectOneById($request_id);
112 if ($Notify->uid !== local_user()) {
113 throw new HTTPException\ForbiddenException();
116 if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
118 DI::notify()->save($Notify);
120 if ($Notify->uriId) {
121 DI::dba()->update('notification', ['seen' => true], ['uid' => $Notify->uid, 'target-uri-id' => $Notify->uriId]);
124 DI::notify()->setAllSeenForRelatedNotify($Notify);
128 System::externalRedirect($Notify->link);
131 DI::baseUrl()->redirect();
134 DI::baseUrl()->redirect('notifications/system');