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;
11 use Friendica\Model\Item;
12 use Friendica\Network\HTTPException;
15 * Module for ignoring threads or user items
17 class Ignore extends BaseModule
19 public static function rawContent(array $parameters = [])
21 /** @var L10n $l10n */
22 $l10n = self::getClass(L10n::class);
24 if (!Session::isAuthenticated()) {
25 throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
28 /** @var App\Arguments $args */
29 $args = self::getClass(App\Arguments::class);
30 /** @var Database $dba */
31 $dba = self::getClass(Database::class);
33 $message_id = intval($args->get(2));
35 if (empty($message_id) || !is_int($message_id)) {
36 throw new HTTPException\BadRequestException();
39 $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
40 if (!$dba->isResult($thread)) {
41 throw new HTTPException\BadRequestException();
44 // Numeric values are needed for the json output further below
45 $ignored = !empty($thread['ignored']) ? 0 : 1;
47 switch ($thread['uid'] ?? 0) {
48 // if the thread is from the current user
50 $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
52 // 0 (null will get transformed to 0) => it's a public post
54 $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
56 // Throws a BadRequestException and not a ForbiddenException on purpose
57 // Avoids harvesting existing, but forbidden IIDs (security issue)
59 throw new HTTPException\BadRequestException();
62 // See if we've been passed a return path to redirect to
63 $return_path = $_REQUEST['return'] ?? '';
64 if (!empty($return_path)) {
65 $rand = '_=' . time();
66 if (strpos($return_path, '?')) {
72 self::getApp()->internalRedirect($return_path . $rand);
75 // the json doesn't really matter, it will either be 0 or 1
76 System::jsonExit($ignored);