2019-05-04 10:30:05 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2021-03-29 08:40:20 +02:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-04 10:30:05 +02:00
|
|
|
|
|
|
|
namespace Friendica\Module\Filer;
|
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2021-01-21 21:25:06 +01:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2021-01-21 21:25:06 +01:00
|
|
|
use Friendica\Model\Post;
|
2019-05-04 10:30:05 +02:00
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
use Friendica\Util\XML;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a tag from a file
|
|
|
|
*/
|
|
|
|
class RemoveTag extends BaseModule
|
|
|
|
{
|
2019-11-05 22:48:54 +01:00
|
|
|
public static function content(array $parameters = [])
|
2019-05-04 10:30:05 +02:00
|
|
|
{
|
|
|
|
if (!local_user()) {
|
|
|
|
throw new HTTPException\ForbiddenException();
|
|
|
|
}
|
|
|
|
|
2019-12-15 22:34:11 +01:00
|
|
|
$app = DI::app();
|
2019-12-15 23:46:56 +01:00
|
|
|
$logger = DI::logger();
|
2019-05-04 10:30:05 +02:00
|
|
|
|
|
|
|
$item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0);
|
|
|
|
|
2019-10-15 15:20:32 +02:00
|
|
|
$term = XML::unescape(trim($_GET['term'] ?? ''));
|
|
|
|
$cat = XML::unescape(trim($_GET['cat'] ?? ''));
|
2019-05-04 10:30:05 +02:00
|
|
|
|
2021-01-21 21:25:06 +01:00
|
|
|
if (!empty($cat)) {
|
|
|
|
$type = Post\Category::CATEGORY;
|
2019-05-04 10:30:05 +02:00
|
|
|
$term = $cat;
|
2021-01-21 21:25:06 +01:00
|
|
|
} else {
|
|
|
|
$type = Post\Category::FILE;
|
2019-05-04 10:30:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$logger->info('Filer - Remove Tag', [
|
2021-01-21 21:25:06 +01:00
|
|
|
'term' => $term,
|
|
|
|
'item' => $item_id,
|
|
|
|
'type' => $type
|
2019-05-04 10:30:05 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($item_id && strlen($term)) {
|
2021-01-21 21:25:06 +01:00
|
|
|
$item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
|
|
|
|
if (!DBA::isResult($item)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Post\Category::deleteFileByURIId($item['uri-id'], local_user(), $type, $term)) {
|
2020-07-23 08:11:21 +02:00
|
|
|
notice(DI::l10n()->t('Item was not removed'));
|
2019-05-04 10:30:05 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-23 08:11:21 +02:00
|
|
|
notice(DI::l10n()->t('Item was not deleted'));
|
2019-05-04 10:30:05 +02:00
|
|
|
}
|
|
|
|
|
2021-01-21 21:25:06 +01:00
|
|
|
if ($type == Post\Category::FILE) {
|
|
|
|
DI::baseUrl()->redirect('filed?file=' . rawurlencode($term));
|
|
|
|
}
|
2019-05-04 10:30:05 +02:00
|
|
|
}
|
|
|
|
}
|