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