3 * @copyright Copyright (C) 2010-2023, 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;
25 use Friendica\BaseModule;
26 use Friendica\Content\Nav;
27 use Friendica\Core\L10n;
28 use Friendica\Core\Protocol;
29 use Friendica\Core\Renderer;
30 use Friendica\Database\Database;
33 use Friendica\Module\Contact;
34 use Friendica\Module\Response;
35 use Friendica\Module\Security\Login;
36 use Friendica\Network\HTTPException;
37 use Friendica\Util\Profiler;
38 use Psr\Log\LoggerInterface;
40 class Revoke extends BaseModule
43 * User-specific contact (uid != 0) array
51 public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Database $dba, Response $response, array $server, array $parameters = [])
53 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
57 if (!DI::userSession()->getLocalUserId()) {
61 $data = Model\Contact::getPublicAndUserContactID($this->parameters['id'], DI::userSession()->getLocalUserId());
62 if (!$this->dba->isResult($data)) {
63 throw new HTTPException\NotFoundException($this->t('Unknown contact.'));
66 if (empty($data['user'])) {
67 throw new HTTPException\ForbiddenException();
70 $this->contact = Model\Contact::getById($data['user']);
72 if ($this->contact['deleted']) {
73 throw new HTTPException\NotFoundException($this->t('Contact is deleted.'));
76 if (!empty($this->contact['network']) && $this->contact['network'] == Protocol::PHANTOM) {
77 throw new HTTPException\NotFoundException($this->t('Contact is being deleted.'));
81 protected function post(array $request = [])
83 if (!DI::userSession()->getLocalUserId()) {
84 throw new HTTPException\UnauthorizedException();
87 self::checkFormSecurityTokenRedirectOnError('contact/' . $this->parameters['id'], 'contact_revoke');
89 Model\Contact::revokeFollow($this->contact);
91 DI::sysmsg()->addNotice($this->t('Follow was successfully revoked.'));
93 $this->baseUrl->redirect('contact/' . $this->parameters['id']);
96 protected function content(array $request = []): string
98 if (!DI::userSession()->getLocalUserId()) {
99 return Login::form($_SERVER['REQUEST_URI']);
102 Nav::setSelected('contact');
104 return Renderer::replaceMacros(Renderer::getMarkupTemplate('contact_drop_confirm.tpl'), [
106 'header' => $this->t('Revoke Follow'),
107 'message' => $this->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.'),
108 'confirm' => $this->t('Yes'),
109 'cancel' => $this->t('Cancel'),
111 '$contact' => Contact::getContactTemplateVars($this->contact),
113 '$confirm_url' => $this->args->getCommand(),
114 '$confirm_name' => 'form_security_token',
115 '$confirm_value' => BaseModule::getFormSecurityToken('contact_revoke'),