Frio - bugfix - don't show new event button if the button isn't available
[friendica.git/.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         if (!local_user()) {
11                 killme();
12         }
13
14         if ($a->argc > 1) {
15                 $message_id = intval($a->argv[1]);
16         }
17
18         if (!$message_id) {
19                 killme();
20         }
21
22         $thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
23         if (!DBA::isResult($thread)) {
24                 killme();
25         }
26
27         // Numeric values are needed for the json output further below
28         $ignored = ($thread['ignored'] ? 0 : 1);
29
30         if ($thread['uid'] != 0) {
31                 DBA::update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
32         } else {
33                 DBA::update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
34         }
35
36         // See if we've been passed a return path to redirect to
37         $return_path = defaults($_REQUEST, 'return', '');
38         if ($return_path) {
39                 $rand = '_=' . time();
40                 if (strpos($return_path, '?')) {
41                         $rand = "&$rand";
42                 } else {
43                         $rand = "?$rand";
44                 }
45
46                 goaway(System::baseUrl() . "/" . $return_path . $rand);
47         }
48
49         // the json doesn't really matter, it will either be 0 or 1
50
51         echo json_encode($ignored);
52         killme();
53 }