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