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