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