]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Merge pull request #4400 from zeroadam/feature/Threads
[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         $r = q("UPDATE `item` SET `starred` = %d WHERE `uid` = %d AND `id` = %d",
36                 intval($starred),
37                 intval(local_user()),
38                 intval($message_id)
39         );
40
41         Item::updateThread($message_id);
42
43         // See if we've been passed a return path to redirect to
44         $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
45         if ($return_path) {
46                 $rand = '_=' . time();
47                 if (strpos($return_path, '?')) {
48                         $rand = "&$rand";
49                 } else {
50                         $rand = "?$rand";
51                 }
52
53                 goaway(System::baseUrl() . "/" . $return_path . $rand);
54         }
55
56         // the json doesn't really matter, it will either be 0 or 1
57
58         echo json_encode($starred);
59         killme();
60 }