Issue 7142: Prevent respawn of "remote self" items
[friendica.git/.git] / mod / ignored.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Database\DBA;
5 use Friendica\Model\Item;
6
7 function ignored_init(App $a)
8 {
9         if (!local_user()) {
10                 exit();
11         }
12
13         if ($a->argc > 1) {
14                 $message_id = intval($a->argv[1]);
15         }
16
17         if (empty($message_id)) {
18                 exit();
19         }
20
21         $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
22         if (!DBA::isResult($thread)) {
23                 exit();
24         }
25
26         // Numeric values are needed for the json output further below
27         $ignored = ($thread['ignored'] ? 0 : 1);
28
29         if ($thread['uid'] != 0) {
30                 DBA::update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
31         } else {
32                 DBA::update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
33         }
34
35         // See if we've been passed a return path to redirect to
36         $return_path = defaults($_REQUEST, 'return', '');
37         if ($return_path) {
38                 $rand = '_=' . time();
39                 if (strpos($return_path, '?')) {
40                         $rand = "&$rand";
41                 } else {
42                         $rand = "?$rand";
43                 }
44
45                 $a->internalRedirect($return_path . $rand);
46         }
47
48         // the json doesn't really matter, it will either be 0 or 1
49
50         echo json_encode($ignored);
51         exit();
52 }