]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Merge pull request #3418 from gerhard6380/develop
[friendica.git] / mod / starred.php
1 <?php
2
3 use Friendica\App;
4
5 function starred_init(App $a) {
6
7         require_once("include/threads.php");
8
9         $starred = 0;
10
11         if (! local_user()) {
12                 killme();
13         }
14         if ($a->argc > 1) {
15                 $message_id = intval($a->argv[1]);
16         }
17         if (! $message_id) {
18                 killme();
19         }
20
21         $r = q("SELECT `starred` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
22                 intval(local_user()),
23                 intval($message_id)
24         );
25         if (! dbm::is_result($r)) {
26                 killme();
27         }
28
29         if (! intval($r[0]['starred'])) {
30                 $starred = 1;
31         }
32
33         $r = q("UPDATE `item` SET `starred` = %d WHERE `uid` = %d AND `id` = %d",
34                 intval($starred),
35                 intval(local_user()),
36                 intval($message_id)
37         );
38
39         update_thread($message_id);
40
41         // See if we've been passed a return path to redirect to
42         $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
43         if ($return_path) {
44                 $rand = '_=' . time();
45                 if (strpos($return_path, '?')) {
46                         $rand = "&$rand";
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 }