]> git.mxchange.org Git - friendica.git/blob - src/Module/Like.php
Merge pull request #7451 from annando/ap-contact-id
[friendica.git] / src / Module / Like.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Model\Item;
7 use Friendica\Network\HTTPException;
8 use Friendica\Util\Strings;
9
10 /**
11  * Performs a like and optionally redirects to a return path
12  */
13 class Like extends BaseModule
14 {
15         public static function rawContent()
16         {
17                 if (!local_user() && !remote_user()) {
18                         throw new HTTPException\ForbiddenException();
19                 }
20
21                 $verb = Strings::escapeTags(trim($_GET['verb']));
22
23                 if (!$verb) {
24                         $verb = 'like';
25                 }
26
27                 $app = self::getApp();
28
29                 // @TODO: Replace with parameter from router
30                 $itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0);
31
32                 if (!Item::performLike($itemId, $verb)) {
33                         throw new HTTPException\BadRequestException();
34                 }
35
36                 // Decide how to return. If we were called with a 'return' argument,
37                 // then redirect back to the calling page. If not, just quietly end
38                 $returnPath = defaults($_REQUEST, 'return', '');
39
40                 if (!empty($returnPath)) {
41                         $rand = '_=' . time();
42                         if (strpos($returnPath, '?')) {
43                                 $rand = "&$rand";
44                         } else {
45                                 $rand = "?$rand";
46                         }
47
48                         $app->internalRedirect($returnPath . $rand);
49                 }
50         }
51 }