]> git.mxchange.org Git - friendica.git/commitdiff
Pinning: Missing file added
authorMichael <heluecht@pirati.ca>
Sat, 9 Nov 2019 03:17:18 +0000 (03:17 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 9 Nov 2019 03:17:18 +0000 (03:17 +0000)
src/Module/Pinned.php [new file with mode: 0644]

diff --git a/src/Module/Pinned.php b/src/Module/Pinned.php
new file mode 100644 (file)
index 0000000..e4c0d2b
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Model\Item;
+
+/**
+ * Toggle pinned items
+ */
+class Pinned extends BaseModule
+{
+       public static function rawContent(array $parameters = [])
+       {
+               if (!local_user()) {
+                       throw new \Friendica\Network\HTTPException\ForbiddenException();
+               }
+
+               if (empty($parameters['item'])) {
+                       throw new \Friendica\Network\HTTPException\BadRequestException();
+               }
+
+               $itemId = intval($parameters['item']);
+
+               $pinned = !Item::getPinned($itemId, local_user());
+
+               Item::setPinned($itemId, local_user(), $pinned);
+
+               // See if we've been passed a return path to redirect to
+               $returnPath = $_REQUEST['return'] ?? '';
+               if (!empty($returnPath)) {
+                       $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand';
+                       self::getApp()->internalRedirect($returnPath . $rand);
+               }
+
+               // the json doesn't really matter, it will either be 0 or 1
+               echo json_encode((int)$pinned);
+               exit();
+       }
+}