]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Merge branch 'develop' into rewrites/dbm_is_result
[friendica.git] / mod / starred.php
1 <?php
2
3
4 function starred_init(App &$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 (! dbm::is_result($r)) {
22                 killme();
23         }
24
25         if(! intval($r[0]['starred']))
26                 $starred = 1;
27
28         $r = q("UPDATE item SET starred = %d WHERE uid = %d and id = %d",
29                 intval($starred),
30                 intval(local_user()),
31                 intval($message_id)
32         );
33
34         update_thread($message_id);
35
36         // See if we've been passed a return path to redirect to
37         $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
38         if($return_path) {
39                 $rand = '_=' . time();
40                 if(strpos($return_path, '?')) $rand = "&$rand";
41                 else $rand = "?$rand";
42
43                 goaway(App::get_baseurl() . "/" . $return_path . $rand);
44         }
45
46         // the json doesn't really matter, it will either be 0 or 1
47
48         echo json_encode($starred);
49         killme();
50 }