]> git.mxchange.org Git - friendica.git/blob - mod/ignored.php
Ops, one more left ...
[friendica.git] / mod / ignored.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5 use Friendica\Database\DBA;
6 use Friendica\Model\Item;
7
8 function ignored_init(App $a)
9 {
10         $ignored = 0;
11
12         if (!local_user()) {
13                 killme();
14         }
15
16         if ($a->argc > 1) {
17                 $message_id = intval($a->argv[1]);
18         }
19
20         if (!$message_id) {
21                 killme();
22         }
23
24         $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
25         if (!DBA::isResult($thread)) {
26                 killme();
27         }
28
29         if (!$thread['ignored']) {
30                 $ignored = true;
31         }
32
33         if ($thread['uid'] != 0) {
34                 DBA::update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
35         } else {
36                 DBA::update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
37         }
38
39         // See if we've been passed a return path to redirect to
40         $return_path = defaults($_REQUEST, 'return', '');
41         if ($return_path) {
42                 $rand = '_=' . time();
43                 if (strpos($return_path, '?')) {
44                         $rand = "&$rand";
45                 } else {
46                         $rand = "?$rand";
47                 }
48
49                 goaway(System::baseUrl() . "/" . $return_path . $rand);
50         }
51
52         // the json doesn't really matter, it will either be 0 or 1
53
54         echo json_encode($ignored);
55         killme();
56 }