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