]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Just some more fixed notice
[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         $starred = 0;
12         $message_id = null;
13
14         if (!local_user()) {
15                 killme();
16         }
17         if ($a->argc > 1) {
18                 $message_id = intval($a->argv[1]);
19         }
20         if (!$message_id) {
21                 killme();
22         }
23
24         $item = Item::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
25         if (!DBM::is_result($item)) {
26                 killme();
27         }
28
29         if (!intval($item['starred'])) {
30                 $starred = 1;
31         }
32
33         Item::update(['starred' => $starred], ['id' => $message_id]);
34
35         // See if we've been passed a return path to redirect to
36         $return_path = (x($_REQUEST,'return') ? $_REQUEST['return'] : '');
37         if ($return_path) {
38                 $rand = '_=' . time();
39                 if (strpos($return_path, '?')) {
40                         $rand = "&$rand";
41                 } else {
42                         $rand = "?$rand";
43                 }
44
45                 goaway(System::baseUrl() . "/" . $return_path . $rand);
46         }
47
48         // the json doesn't really matter, it will either be 0 or 1
49
50         echo json_encode($starred);
51         killme();
52 }