Merge pull request #6703 from tobiasd/2019.03-CHANGELOG
[friendica.git/.git] / mod / like.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Model\Item;
5 use Friendica\Util\Strings;
6
7 function like_content(App $a) {
8         if (!local_user() && !remote_user()) {
9                 return false;
10         }
11
12
13         $verb = Strings::escapeTags(trim($_GET['verb']));
14
15         if (!$verb) {
16                 $verb = 'like';
17         }
18
19         $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
20
21         $r = Item::performLike($item_id, $verb);
22         if (!$r) {
23                 return;
24         }
25
26         // See if we've been passed a return path to redirect to
27         $return_path = defaults($_REQUEST, 'return', '');
28
29         like_content_return($a, $return_path);
30         exit();
31 }
32
33
34 // Decide how to return. If we were called with a 'return' argument,
35 // then redirect back to the calling page. If not, just quietly end
36
37 function like_content_return(App $a, $return_path) {
38         if ($return_path) {
39                 $rand = '_=' . time();
40                 if (strpos($return_path, '?')) {
41                         $rand = "&$rand";
42                 } else {
43                         $rand = "?$rand";
44                 }
45
46                 $a->internalRedirect($return_path . $rand);
47         }
48 }