]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #9892 from MrPetovan/task/9872-item-pin
authorMichael Vogel <icarus@dabo.de>
Sun, 31 Jan 2021 10:35:40 +0000 (11:35 +0100)
committerGitHub <noreply@github.com>
Sun, 31 Jan 2021 10:35:40 +0000 (11:35 +0100)
Move GET pinned/{id} to POST item/{id}/pin

src/Module/Item/Pin.php [new file with mode: 0644]
src/Module/Pinned.php [deleted file]
static/routes.config.php
view/js/main.js
view/templates/wall_thread.tpl
view/theme/frio/templates/search_item.tpl
view/theme/frio/templates/wall_thread.tpl
view/theme/quattro/templates/wall_thread.tpl
view/theme/smoothly/templates/wall_thread.tpl
view/theme/vier/templates/wall_thread.tpl

diff --git a/src/Module/Item/Pin.php b/src/Module/Item/Pin.php
new file mode 100644 (file)
index 0000000..d99b1a3
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Item;
+
+use Friendica\BaseModule;
+use Friendica\Core\Session;
+use Friendica\Core\System;
+use Friendica\DI;
+use Friendica\Model\Item;
+use Friendica\Network\HTTPException;
+
+/**
+ * Toggle pinned items
+ */
+class Pin extends BaseModule
+{
+       public static function rawContent(array $parameters = [])
+       {
+               $l10n = DI::l10n();
+
+               if (!Session::isAuthenticated()) {
+                       throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
+               }
+
+               if (empty($parameters['id'])) {
+                       throw new HTTPException\BadRequestException();
+               }
+
+               $itemId = intval($parameters['id']);
+
+               $pinned = !Item::getPinned($itemId, local_user());
+
+               Item::setPinned($itemId, local_user(), $pinned);
+
+               // See if we've been passed a return path to redirect to
+               $return_path = $_REQUEST['return'] ?? '';
+               if (!empty($return_path)) {
+                       $rand = '_=' . time();
+                       if (strpos($return_path, '?')) {
+                               $rand = "&$rand";
+                       } else {
+                               $rand = "?$rand";
+                       }
+
+                       DI::baseUrl()->redirect($return_path . $rand);
+               }
+
+               $return = [
+                       'status'  => 'ok',
+                       'item_id' => $itemId,
+                       'verb'    => 'pin',
+                       'state'   => (int)$pinned,
+               ];
+
+               System::jsonExit($return);
+       }
+}
diff --git a/src/Module/Pinned.php b/src/Module/Pinned.php
deleted file mode 100644 (file)
index 97364ce..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2020, Friendica
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\DI;
-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';
-                       DI::baseUrl()->redirect($returnPath . $rand);
-               }
-
-               // the json doesn't really matter, it will either be 0 or 1
-               echo json_encode((int)$pinned);
-               exit();
-       }
-}
index 8108c24cdceffba1eb0e69c86a88fc441e9b6564..5a2ee2ffd1885578f5f01bc5d2b52de42be8e9e4 100644 (file)
@@ -292,6 +292,7 @@ return [
 
        '/item'            => [
                '/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]],
+               '/{id:\d+}/pin' => [Module\Item\Pin::class,       [        R::POST]],
        ],
 
        '/like/{item:\d+}'    => [Module\Like::class,            [R::GET]],
@@ -351,7 +352,6 @@ return [
                '/{type}/{customize}/{name}' => [Module\Photo::class, [R::GET]],
        ],
 
-       '/pinned/{item:\d+}' => [Module\Pinned::class,       [R::GET]],
        '/pretheme'          => [Module\ThemeDetails::class, [R::GET]],
        '/probe'             => [Module\Debug\Probe::class,  [R::GET]],
 
index a0ffea3718222a8aef9664f0f18eb9a13b92e86d..1503529d1fef06940834f2ef08cf511c7f2c3990 100644 (file)
@@ -701,21 +701,26 @@ function dostar(ident) {
        });
 }
 
-function dopin(ident) {
+function doPin(ident) {
        ident = ident.toString();
        $('#like-rotator-' + ident).show();
-       $.get('pinned/' + ident, function(data) {
-               if (data.match(/1/)) {
-                       $('#pinned-' + ident).addClass('pinned');
-                       $('#pinned-' + ident).removeClass('unpinned');
+       $.post('item/' + ident + '/pin')
+       .then(function(data) {
+               if (data.state === 1) {
+                       $('#pinned-' + ident)
+                               .addClass('pinned')
+                               .removeClass('unpinned');
                        $('#pin-' + ident).addClass('hidden');
                        $('#unpin-' + ident).removeClass('hidden');
                } else {
-                       $('#pinned-' + ident).addClass('unpinned');
-                       $('#pinned-' + ident).removeClass('pinned');
+                       $('#pinned-' + ident)
+                               .addClass('unpinned')
+                               .removeClass('pinned');
                        $('#pin-' + ident).removeClass('hidden');
                        $('#unpin-' + ident).addClass('hidden');
                }
+       })
+       .always(function () {
                $('#like-rotator-' + ident).hide();
        });
 }
index 893bd7291aea1a430b474c2b092294b93b6334fd..4b1a42785924f4ad60f7cd93aa4b3c3ec3ea93c3 100644 (file)
                        {{/if}}
 
                        {{if $item.pin}}
-                       <a href="#" id="pinned-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
+                       <a href="#" id="pinned-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
                        {{/if}}
                        {{if $item.star}}
                        <a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
index 717340b8b330dc260a7cafa30e03cfccfe28a21c..835b3d667778940e3a696b19087b5397700e2ea8 100644 (file)
 
                                                {{if $item.pin}}
                                                        <li role="menuitem">
-                                                               <a id="pin-{{$item.id}}" href="javascript:dopin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</a>
-                                                               <a id="unpin-{{$item.id}}" href="javascript:dopin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-dot-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</a>
+                                                               <a id="pin-{{$item.id}}" href="javascript:doPin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</a>
+                                                               <a id="unpin-{{$item.id}}" href="javascript:doPin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-dot-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</a>
                                                        </li>
                                                {{/if}}
 
index 25d6885fc8c23180ecd0422d23013715afc1761e..b98cefb9c9d358aee73a258d1c4fd2cb84c81684 100644 (file)
@@ -351,8 +351,8 @@ as the value of $top_child_total (this is done at the end of this file)
 
                                                {{if $item.pin}}
                                                <li role="menuitem">
-                                                       <a id="pin-{{$item.id}}" href="javascript:dopin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</a>
-                                                       <a id="unpin-{{$item.id}}" href="javascript:dopin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-dot-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</a>
+                                                       <a id="pin-{{$item.id}}" href="javascript:doPin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</a>
+                                                       <a id="unpin-{{$item.id}}" href="javascript:doPin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-dot-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</a>
                                                </li>
                                                {{/if}}
 
@@ -516,8 +516,8 @@ as the value of $top_child_total (this is done at the end of this file)
 
                                                {{if $item.pin}}
                                                        <li role="menuitem">
-                                                       <a id="pin-{{$item.id}}" href="javascript:dopin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</a>
-                                                       <a id="unpin-{{$item.id}}" href="javascript:dopin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-dot-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</a>
+                                                       <a id="pin-{{$item.id}}" href="javascript:doPin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</a>
+                                                       <a id="unpin-{{$item.id}}" href="javascript:doPin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-dot-circle-o" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</a>
                                                </li>
                                                {{/if}}
 
index f7d4b0f8c8d747438ce274f1c4ade178abe487db..5f682dd3e288ed0e0dc506e247231280f03075af 100644 (file)
@@ -98,8 +98,8 @@
 
                        <div class="wall-item-actions-social">
                        {{if $item.pin}}
-                               <a href="#" id="pin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classdo}}"  title="{{$item.pin.do}}">{{$item.pin.do}}</a>
-                               <a href="#" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classundo}}"  title="{{$item.pin.undo}}">{{$item.pin.undo}}</a>
+                               <a href="#" id="pin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classdo}}" title="{{$item.pin.do}}">{{$item.pin.do}}</a>
+                               <a href="#" id="unpin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}">{{$item.pin.undo}}</a>
                        {{/if}}
                        {{if $item.star}}
                                <a href="#" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classdo}}"  title="{{$item.star.do}}">{{$item.star.do}}</a>
index 6fd787afee0a98c643601a23140df16935ad4212..817d4d5ed05f42540a2e619f80281a5040c9f34d 100644 (file)
                        {{/if}}
 
                        {{if $item.pin}}
-                       <a href="#" id="pinned-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
+                       <a href="#" id="pinned-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
                        {{/if}}
                        {{if $item.star}}
                        <a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
index 7a04b5efede418960fc068a7701dd20fc49586d7..6963fd411af26b5deea13c76b676bf37615c6121 100644 (file)
                        {{/if}}
 
                        {{if $item.pin}}
-                               <a role="button" id="pin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="icon-circle icon-large"><span class="sr-only">{{$item.pin.do}}</span></i></a>
-                               <a role="button" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;"  class="{{$item.pin.classundo}}"  title="{{$item.pin.undo}}"><i class="icon-remove-circle icon-large"><span class="sr-only">{{$item.pin.undo}}</span></i></a>
+                               <a role="button" id="pin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="icon-circle icon-large"><span class="sr-only">{{$item.pin.do}}</span></i></a>
+                               <a role="button" id="unpin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="icon-remove-circle icon-large"><span class="sr-only">{{$item.pin.undo}}</span></i></a>
                        {{/if}}
                        {{if $item.star}}
                                <a role="button" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;"  class="{{$item.star.classdo}}" title="{{$item.star.do}}"><i class="icon-star icon-large"><span class="sr-only">{{$item.star.do}}</span></i></a>