]> git.mxchange.org Git - friendica.git/blob - src/Module/Item/Ignore.php
Added parameter to rawContent
[friendica.git] / src / Module / Item / Ignore.php
1 <?php
2
3 namespace Friendica\Module\Item;
4
5 use Friendica\App;
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;
13
14 /**
15  * Module for ignoring threads or user items
16  */
17 class Ignore extends BaseModule
18 {
19         public static function rawContent($parameters)
20         {
21                 /** @var L10n $l10n */
22                 $l10n = self::getClass(L10n::class);
23
24                 if (!Session::isAuthenticated()) {
25                         throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
26                 }
27
28                 /** @var App\Arguments $args */
29                 $args = self::getClass(App\Arguments::class);
30                 /** @var Database $dba */
31                 $dba = self::getClass(Database::class);
32
33                 $message_id = intval($args->get(2));
34
35                 if (empty($message_id) || !is_int($message_id)) {
36                         throw new HTTPException\BadRequestException();
37                 }
38
39                 $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
40                 if (!$dba->isResult($thread)) {
41                         throw new HTTPException\BadRequestException();
42                 }
43
44                 // Numeric values are needed for the json output further below
45                 $ignored = !empty($thread['ignored']) ? 0 : 1;
46
47                 switch ($thread['uid'] ?? 0) {
48                         // if the thread is from the current user
49                         case local_user():
50                                 $dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
51                                 break;
52                         // 0 (null will get transformed to 0) => it's a public post
53                         case 0:
54                                 $dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
55                                 break;
56                         // Throws a BadRequestException and not a ForbiddenException on purpose
57                         // Avoids harvesting existing, but forbidden IIDs (security issue)
58                         default:
59                                 throw new HTTPException\BadRequestException();
60                 }
61
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, '?')) {
67                                 $rand = "&$rand";
68                         } else {
69                                 $rand = "?$rand";
70                         }
71
72                         self::getApp()->internalRedirect($return_path . $rand);
73                 }
74
75                 // the json doesn't really matter, it will either be 0 or 1
76                 System::jsonExit([$ignored]);
77         }
78 }