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\Contact;
24 use Friendica\BaseModule;
25 use Friendica\Content\Nav;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Database\DBA;
31 use Friendica\Module\Contact;
32 use Friendica\Module\Security\Login;
33 use Friendica\Network\HTTPException;
35 class Revoke extends BaseModule
38 private static $contact;
40 public static function init(array $parameters = [])
46 $data = Model\Contact::getPublicAndUserContactID($parameters['id'], local_user());
47 if (!DBA::isResult($data)) {
48 throw new HTTPException\NotFoundException(DI::l10n()->t('Unknown contact.'));
51 if (empty($data['user'])) {
52 throw new HTTPException\ForbiddenException();
55 self::$contact = Model\Contact::getById($data['user']);
57 if (self::$contact['deleted']) {
58 throw new HTTPException\NotFoundException(DI::l10n()->t('Contact is deleted.'));
61 if (!empty(self::$contact['network']) && self::$contact['network'] == Protocol::PHANTOM) {
62 throw new HTTPException\NotFoundException(DI::l10n()->t('Contact is being deleted.'));
66 public static function post(array $parameters = [])
69 throw new HTTPException\UnauthorizedException();
72 self::checkFormSecurityTokenRedirectOnError('contact/' . $parameters['id'], 'contact_revoke');
74 $result = Model\Contact::revokeFollow(self::$contact);
75 if ($result === true) {
76 notice(DI::l10n()->t('Follow was successfully revoked.'));
77 } elseif ($result === null) {
78 notice(DI::l10n()->t('Follow was successfully revoked, however the remote contact won\'t be aware of this revokation.'));
80 notice(DI::l10n()->t('Unable to revoke follow, please try again later or contact the administrator.'));
83 DI::baseUrl()->redirect('contact/' . $parameters['id']);
86 public static function content(array $parameters = []): string
89 return Login::form($_SERVER['REQUEST_URI']);
92 Nav::setSelected('contact');
94 return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
96 'header' => DI::l10n()->t('Revoke Follow'),
97 'message' => DI::l10n()->t('Do you really want to revoke this contact\'s follow? This cannot be undone and they will have to manually follow you back again.'),
98 'confirm' => DI::l10n()->t('Yes'),
99 'cancel' => DI::l10n()->t('Cancel'),
101 '$contact' => Contact::getContactTemplateVars(self::$contact),
103 '$confirm_url' => DI::args()->getCommand(),
104 '$confirm_name' => 'form_security_token',
105 '$confirm_value' => BaseModule::getFormSecurityToken('contact_revoke'),