kopia lustrzana https://github.com/friendica/friendica
Merge pull request #9892 from MrPetovan/task/9872-item-pin
Move GET pinned/{id} to POST item/{id}/pinpull/9894/head
commit
2d687b1052
|
@ -19,42 +19,58 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module;
|
||||
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 Pinned extends BaseModule
|
||||
class Pin extends BaseModule
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
if (!local_user()) {
|
||||
throw new \Friendica\Network\HTTPException\ForbiddenException();
|
||||
$l10n = DI::l10n();
|
||||
|
||||
if (!Session::isAuthenticated()) {
|
||||
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
|
||||
}
|
||||
|
||||
if (empty($parameters['item'])) {
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
if (empty($parameters['id'])) {
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$itemId = intval($parameters['item']);
|
||||
$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
|
||||
$returnPath = $_REQUEST['return'] ?? '';
|
||||
if (!empty($returnPath)) {
|
||||
$rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand';
|
||||
DI::baseUrl()->redirect($returnPath . $rand);
|
||||
$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);
|
||||
}
|
||||
|
||||
// the json doesn't really matter, it will either be 0 or 1
|
||||
echo json_encode((int)$pinned);
|
||||
exit();
|
||||
$return = [
|
||||
'status' => 'ok',
|
||||
'item_id' => $itemId,
|
||||
'verb' => 'pin',
|
||||
'state' => (int)$pinned,
|
||||
];
|
||||
|
||||
System::jsonExit($return);
|
||||
}
|
||||
}
|
|
@ -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]],
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
{{/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>
|
||||
|
|
|
@ -199,8 +199,8 @@
|
|||
|
||||
{{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> {{$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> {{$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> {{$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> {{$item.pin.undo}}</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -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> {{$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> {{$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> {{$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> {{$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> {{$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> {{$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> {{$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> {{$item.pin.undo}}</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
{{/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>
|
||||
|
|
|
@ -136,8 +136,8 @@
|
|||
{{/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>
|
||||
|
|
Ładowanie…
Reference in New Issue