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