Merge pull request #9892 from MrPetovan/task/9872-item-pin

Move GET pinned/{id} to POST item/{id}/pin
This commit is contained in:
Michael Vogel 2021-01-31 11:35:40 +01:00 committed by GitHub
commit 2d687b1052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 34 deletions

View file

@ -19,42 +19,58 @@
* *
*/ */
namespace Friendica\Module; namespace Friendica\Module\Item;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Network\HTTPException;
/** /**
* Toggle pinned items * Toggle pinned items
*/ */
class Pinned extends BaseModule class Pin extends BaseModule
{ {
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
if (!local_user()) { $l10n = DI::l10n();
throw new \Friendica\Network\HTTPException\ForbiddenException();
if (!Session::isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
} }
if (empty($parameters['item'])) { if (empty($parameters['id'])) {
throw new \Friendica\Network\HTTPException\BadRequestException(); throw new HTTPException\BadRequestException();
} }
$itemId = intval($parameters['item']); $itemId = intval($parameters['id']);
$pinned = !Item::getPinned($itemId, local_user()); $pinned = !Item::getPinned($itemId, local_user());
Item::setPinned($itemId, local_user(), $pinned); Item::setPinned($itemId, local_user(), $pinned);
// See if we've been passed a return path to redirect to // See if we've been passed a return path to redirect to
$returnPath = $_REQUEST['return'] ?? ''; $return_path = $_REQUEST['return'] ?? '';
if (!empty($returnPath)) { if (!empty($return_path)) {
$rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; $rand = '_=' . time();
DI::baseUrl()->redirect($returnPath . $rand); if (strpos($return_path, '?')) {
$rand = "&$rand";
} else {
$rand = "?$rand";
}
DI::baseUrl()->redirect($return_path . $rand);
} }
// the json doesn't really matter, it will either be 0 or 1 $return = [
echo json_encode((int)$pinned); 'status' => 'ok',
exit(); 'item_id' => $itemId,
'verb' => 'pin',
'state' => (int)$pinned,
];
System::jsonExit($return);
} }
} }

View file

@ -292,6 +292,7 @@ return [
'/item' => [ '/item' => [
'/ignore/{id}' => [Module\Item\Ignore::class, [R::GET]], '/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]], '/like/{item:\d+}' => [Module\Like::class, [R::GET]],
@ -351,7 +352,6 @@ return [
'/{type}/{customize}/{name}' => [Module\Photo::class, [R::GET]], '/{type}/{customize}/{name}' => [Module\Photo::class, [R::GET]],
], ],
'/pinned/{item:\d+}' => [Module\Pinned::class, [R::GET]],
'/pretheme' => [Module\ThemeDetails::class, [R::GET]], '/pretheme' => [Module\ThemeDetails::class, [R::GET]],
'/probe' => [Module\Debug\Probe::class, [R::GET]], '/probe' => [Module\Debug\Probe::class, [R::GET]],

View file

@ -701,21 +701,26 @@ function dostar(ident) {
}); });
} }
function dopin(ident) { function doPin(ident) {
ident = ident.toString(); ident = ident.toString();
$('#like-rotator-' + ident).show(); $('#like-rotator-' + ident).show();
$.get('pinned/' + ident, function(data) { $.post('item/' + ident + '/pin')
if (data.match(/1/)) { .then(function(data) {
$('#pinned-' + ident).addClass('pinned'); if (data.state === 1) {
$('#pinned-' + ident).removeClass('unpinned'); $('#pinned-' + ident)
.addClass('pinned')
.removeClass('unpinned');
$('#pin-' + ident).addClass('hidden'); $('#pin-' + ident).addClass('hidden');
$('#unpin-' + ident).removeClass('hidden'); $('#unpin-' + ident).removeClass('hidden');
} else { } else {
$('#pinned-' + ident).addClass('unpinned'); $('#pinned-' + ident)
$('#pinned-' + ident).removeClass('pinned'); .addClass('unpinned')
.removeClass('pinned');
$('#pin-' + ident).removeClass('hidden'); $('#pin-' + ident).removeClass('hidden');
$('#unpin-' + ident).addClass('hidden'); $('#unpin-' + ident).addClass('hidden');
} }
})
.always(function () {
$('#like-rotator-' + ident).hide(); $('#like-rotator-' + ident).hide();
}); });
} }

View file

@ -102,7 +102,7 @@
{{/if}} {{/if}}
{{if $item.pin}} {{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}}
{{if $item.star}} {{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> <a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>

View file

@ -199,8 +199,8 @@
{{if $item.pin}} {{if $item.pin}}
<li role="menuitem"> <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="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="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> </li>
{{/if}} {{/if}}

View file

@ -351,8 +351,8 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.pin}} {{if $item.pin}}
<li role="menuitem"> <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="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="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> </li>
{{/if}} {{/if}}
@ -516,8 +516,8 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.pin}} {{if $item.pin}}
<li role="menuitem"> <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="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="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> </li>
{{/if}} {{/if}}

View file

@ -98,8 +98,8 @@
<div class="wall-item-actions-social"> <div class="wall-item-actions-social">
{{if $item.pin}} {{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="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="unpin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}">{{$item.pin.undo}}</a>
{{/if}} {{/if}}
{{if $item.star}} {{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> <a href="#" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classdo}}" title="{{$item.star.do}}">{{$item.star.do}}</a>

View file

@ -114,7 +114,7 @@
{{/if}} {{/if}}
{{if $item.pin}} {{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}}
{{if $item.star}} {{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> <a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>

View file

@ -136,8 +136,8 @@
{{/if}} {{/if}}
{{if $item.pin}} {{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="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="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}}
{{if $item.star}} {{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> <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>