]> git.mxchange.org Git - friendica.git/blob - mod/starred.php
Merge pull request #7101 from nupplaphil/task/mod_viewsrc
[friendica.git] / mod / starred.php
1 <?php
2 /**
3  * @file mod/starred.php
4  */
5 use Friendica\App;
6 use Friendica\Database\DBA;
7 use Friendica\Model\Item;
8
9 function starred_init(App $a) {
10         $starred = 0;
11         $message_id = null;
12
13         if (!local_user()) {
14                 exit();
15         }
16         if ($a->argc > 1) {
17                 $message_id = intval($a->argv[1]);
18         }
19         if (!$message_id) {
20                 exit();
21         }
22
23         $item = Item::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
24         if (!DBA::isResult($item)) {
25                 exit();
26         }
27
28         if (!intval($item['starred'])) {
29                 $starred = 1;
30         }
31
32         Item::update(['starred' => $starred], ['id' => $message_id]);
33
34         // See if we've been passed a return path to redirect to
35         $return_path = defaults($_REQUEST, 'return', '');
36         if ($return_path) {
37                 $rand = '_=' . time();
38                 if (strpos($return_path, '?')) {
39                         $rand = "&$rand";
40                 } else {
41                         $rand = "?$rand";
42                 }
43
44                 $a->internalRedirect($return_path . $rand);
45         }
46
47         // the json doesn't really matter, it will either be 0 or 1
48
49         echo json_encode($starred);
50         exit();
51 }