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