]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Merge pull request #4404 from annando/item-isolation
[friendica.git] / mod / starred.php
1 <?php
2 /**
3  * @file mod/starred.php
4  */
5 use Friendica\App;
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Item;
9
10 function starred_init(App $a) {
11         $starred = 0;
12
13         if (! local_user()) {
14                 killme();
15         }
16         if ($a->argc > 1) {
17                 $message_id = intval($a->argv[1]);
18         }
19         if (! $message_id) {
20                 killme();
21         }
22
23         $r = q("SELECT `starred` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
24                 intval(local_user()),
25                 intval($message_id)
26         );
27         if (! DBM::is_result($r)) {
28                 killme();
29         }
30
31         if (! intval($r[0]['starred'])) {
32                 $starred = 1;
33         }
34
35         Item::update(['starred' => $starred], ['id' => $message_id]);
36
37         // See if we've been passed a return path to redirect to
38         $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
39         if ($return_path) {
40                 $rand = '_=' . time();
41                 if (strpos($return_path, '?')) {
42                         $rand = "&$rand";
43                 } else {
44                         $rand = "?$rand";
45                 }
46
47                 goaway(System::baseUrl() . "/" . $return_path . $rand);
48         }
49
50         // the json doesn't really matter, it will either be 0 or 1
51
52         echo json_encode($starred);
53         killme();
54 }