3 namespace Friendica\Module\Item;
6 use Friendica\BaseModule;
7 use Friendica\Core\L10n\L10n;
8 use Friendica\Core\Session;
9 use Friendica\Core\System;
10 use Friendica\Database\Database;
12 use Friendica\Model\Item;
13 use Friendica\Network\HTTPException;
16 * Module for ignoring threads or user items
18 class Ignore extends BaseModule
20 public static function rawContent(array $parameters = [])
22 /** @var L10n $l10n */
23 $l10n = self::getClass(L10n::class);
25 if (!Session::isAuthenticated()) {
26 throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
29 /** @var App\Arguments $args */
30 $args = self::getClass(App\Arguments::class);
31 /** @var Database $dba */
32 $dba = self::getClass(Database::class);
34 $message_id = intval($args->get(2));
36 if (empty($message_id) || !is_int($message_id)) {
37 throw new HTTPException\BadRequestException();
40 $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
41 if (!$dba->isResult($thread)) {
42 throw new HTTPException\BadRequestException();
45 // Numeric values are needed for the json output further below
46 $ignored = !empty($thread['ignored']) ? 0 : 1;
48 switch ($thread['uid'] ?? 0) {
49 // if the thread is from the current user
51 $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
53 // 0 (null will get transformed to 0) => it's a public post
55 $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
57 // Throws a BadRequestException and not a ForbiddenException on purpose
58 // Avoids harvesting existing, but forbidden IIDs (security issue)
60 throw new HTTPException\BadRequestException();
63 // See if we've been passed a return path to redirect to
64 $return_path = $_REQUEST['return'] ?? '';
65 if (!empty($return_path)) {
66 $rand = '_=' . time();
67 if (strpos($return_path, '?')) {
73 DI::app()->internalRedirect($return_path . $rand);
76 // the json doesn't really matter, it will either be 0 or 1
77 System::jsonExit($ignored);