]> git.mxchange.org Git - friendica.git/blob - src/Module/Pinned.php
Merge pull request #7848 from annando/mail-hooks
[friendica.git] / src / Module / Pinned.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Model\Item;
7
8 /**
9  * Toggle pinned items
10  */
11 class Pinned extends BaseModule
12 {
13         public static function rawContent(array $parameters = [])
14         {
15                 if (!local_user()) {
16                         throw new \Friendica\Network\HTTPException\ForbiddenException();
17                 }
18
19                 if (empty($parameters['item'])) {
20                         throw new \Friendica\Network\HTTPException\BadRequestException();
21                 }
22
23                 $itemId = intval($parameters['item']);
24
25                 $pinned = !Item::getPinned($itemId, local_user());
26
27                 Item::setPinned($itemId, local_user(), $pinned);
28
29                 // See if we've been passed a return path to redirect to
30                 $returnPath = $_REQUEST['return'] ?? '';
31                 if (!empty($returnPath)) {
32                         $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand';
33                         self::getApp()->internalRedirect($returnPath . $rand);
34                 }
35
36                 // the json doesn't really matter, it will either be 0 or 1
37                 echo json_encode((int)$pinned);
38                 exit();
39         }
40 }