]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Merge pull request #2148 from annando/issue-1871
[friendica.git] / mod / starred.php
1 <?php
2
3
4 function starred_init(&$a) {
5
6         require_once("include/threads.php");
7
8         $starred = 0;
9
10         if(! local_user())
11                 killme();
12         if($a->argc > 1)
13                 $message_id = intval($a->argv[1]);
14         if(! $message_id)
15                 killme();
16
17         $r = q("SELECT starred FROM item WHERE uid = %d AND id = %d LIMIT 1",
18                 intval(local_user()),
19                 intval($message_id)
20         );
21         if(! count($r))
22                 killme();
23
24         if(! intval($r[0]['starred']))
25                 $starred = 1;
26
27         $r = q("UPDATE item SET starred = %d WHERE uid = %d and id = %d",
28                 intval($starred),
29                 intval(local_user()),
30                 intval($message_id)
31         );
32
33         update_thread($message_id);
34
35         // See if we've been passed a return path to redirect to
36         $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
37         if($return_path) {
38                 $rand = '_=' . time();
39                 if(strpos($return_path, '?')) $rand = "&$rand";
40                 else $rand = "?$rand";
41
42                 goaway($a->get_baseurl() . "/" . $return_path . $rand);
43         }
44
45         // the json doesn't really matter, it will either be 0 or 1
46
47         echo json_encode($starred);
48         killme();
49 }