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