3 * @copyright Copyright (C) 2010-2022, 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\Filer;
25 use Friendica\BaseModule;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Session;
28 use Friendica\Core\System;
29 use Friendica\Database\DBA;
30 use Friendica\Model\Post;
31 use Friendica\Module\Response;
32 use Friendica\Navigation\SystemMessages;
33 use Friendica\Network\HTTPException;
34 use Friendica\Util\Profiler;
35 use Psr\Log\LoggerInterface;
38 * Remove a tag from a file
40 class RemoveTag extends BaseModule
42 /** @var SystemMessages */
43 private $systemMessages;
45 public function __construct(SystemMessages $systemMessages, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
47 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
49 $this->systemMessages = $systemMessages;
52 protected function post(array $request = [])
54 System::httpError($this->removeTag($request));
57 protected function content(array $request = []): string
59 if (!Session::getLocalUser()) {
60 throw new HTTPException\ForbiddenException();
63 $this->removeTag($request, $type, $term);
65 if ($type == Post\Category::FILE) {
66 $this->baseUrl->redirect('filed?file=' . rawurlencode($term));
73 * @param array $request The $_REQUEST array
74 * @param string|null $type Output parameter with the computed type
75 * @param string|null $term Output parameter with the computed term
77 * @return int The relevant HTTP code
81 private function removeTag(array $request, string &$type = null, string &$term = null): int
83 $item_id = $this->parameters['id'] ?? 0;
85 $term = trim($request['term'] ?? '');
86 $cat = trim($request['cat'] ?? '');
89 $type = Post\Category::CATEGORY;
92 $type = Post\Category::FILE;
95 $this->logger->info('Filer - Remove Tag', [
101 if (!$item_id || !strlen($term)) {
102 $this->systemMessages->addNotice($this->l10n->t('Item was not deleted'));
106 $item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
107 if (!DBA::isResult($item)) {
111 if (!Post\Category::deleteFileByURIId($item['uri-id'], Session::getLocalUser(), $type, $term)) {
112 $this->systemMessages->addNotice($this->l10n->t('Item was not removed'));