Merge pull request #9891 from MrPetovan/task/9782-item-star
Move GET starred/{id} to POST item/{id}/star
This commit is contained in:
commit
ee6699e641
13 changed files with 64 additions and 43 deletions
|
@ -19,33 +19,38 @@
|
|||
*
|
||||
*/
|
||||
|
||||
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\Model\Post;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* Toggle starred items
|
||||
*/
|
||||
class Starred extends BaseModule
|
||||
class Star 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']);
|
||||
|
||||
$item = Post::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]);
|
||||
if (empty($item)) {
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException();
|
||||
throw new HTTPException\NotFoundException();
|
||||
}
|
||||
|
||||
$starred = !(bool)$item['starred'];
|
||||
|
@ -53,14 +58,25 @@ class Starred extends BaseModule
|
|||
Item::update(['starred' => $starred], ['id' => $itemId]);
|
||||
|
||||
// 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)$starred);
|
||||
exit();
|
||||
$return = [
|
||||
'status' => 'ok',
|
||||
'item_id' => $itemId,
|
||||
'verb' => 'star',
|
||||
'state' => (int)$starred,
|
||||
];
|
||||
|
||||
System::jsonExit($return);
|
||||
}
|
||||
}
|
|
@ -294,6 +294,7 @@ return [
|
|||
'/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]],
|
||||
'/{id:\d+}/ignore' => [Module\Item\Ignore::class, [ R::POST]],
|
||||
'/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]],
|
||||
'/{id:\d+}/star' => [Module\Item\Star::class, [ R::POST]],
|
||||
],
|
||||
|
||||
'/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]],
|
||||
|
@ -412,7 +413,6 @@ return [
|
|||
'/rsd.xml' => [Module\ReallySimpleDiscovery::class, [R::GET]],
|
||||
'/smilies[/json]' => [Module\Smilies::class, [R::GET]],
|
||||
'/statistics.json' => [Module\Statistics::class, [R::GET]],
|
||||
'/starred/{item:\d+}' => [Module\Starred::class, [R::GET]],
|
||||
'/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]],
|
||||
'/tos' => [Module\Tos::class, [R::GET]],
|
||||
|
||||
|
|
|
@ -682,21 +682,26 @@ function dosubthread(ident) {
|
|||
liking = 1;
|
||||
}
|
||||
|
||||
function dostar(ident) {
|
||||
function doStar(ident) {
|
||||
ident = ident.toString();
|
||||
$('#like-rotator-' + ident).show();
|
||||
$.get('starred/' + ident, function(data) {
|
||||
if (data.match(/1/)) {
|
||||
$('#starred-' + ident).addClass('starred');
|
||||
$('#starred-' + ident).removeClass('unstarred');
|
||||
$.post('item/' + ident + '/star')
|
||||
.then(function(data) {
|
||||
if (data.state === 1) {
|
||||
$('#starred-' + ident)
|
||||
.addClass('starred')
|
||||
.removeClass('unstarred');
|
||||
$('#star-' + ident).addClass('hidden');
|
||||
$('#unstar-' + ident).removeClass('hidden');
|
||||
} else {
|
||||
$('#starred-' + ident).addClass('unstarred');
|
||||
$('#starred-' + ident).removeClass('starred');
|
||||
$('#starred-' + ident)
|
||||
.addClass('unstarred')
|
||||
.removeClass('starred');
|
||||
$('#star-' + ident).removeClass('hidden');
|
||||
$('#unstar-' + ident).addClass('hidden');
|
||||
}
|
||||
})
|
||||
.always(function () {
|
||||
$('#like-rotator-' + ident).hide();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
<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>
|
||||
<a href="#" id="starred-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
|
||||
{{/if}}
|
||||
{{if $item.tagger}}
|
||||
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="tag-item icon tagged" title="{{$item.tagger.add}}"></a>
|
||||
|
|
|
@ -206,8 +206,8 @@
|
|||
|
||||
{{if $item.star}}
|
||||
<li role="menuitem">
|
||||
<a id="star-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i> {{$item.star.do}}</a>
|
||||
<a id="unstar-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i> {{$item.star.undo}}</a>
|
||||
<a id="star-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i> {{$item.star.do}}</a>
|
||||
<a id="unstar-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i> {{$item.star.undo}}</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -358,8 +358,8 @@ as the value of $top_child_total (this is done at the end of this file)
|
|||
|
||||
{{if $item.star}}
|
||||
<li role="menuitem">
|
||||
<a id="star-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i> {{$item.star.do}}</a>
|
||||
<a id="unstar-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i> {{$item.star.undo}}</a>
|
||||
<a id="star-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i> {{$item.star.do}}</a>
|
||||
<a id="unstar-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i> {{$item.star.undo}}</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
|
@ -523,8 +523,8 @@ as the value of $top_child_total (this is done at the end of this file)
|
|||
|
||||
{{if $item.star}}
|
||||
<li role="menuitem">
|
||||
<a id="star-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i> {{$item.star.do}}</a>
|
||||
<a id="unstar-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i> {{$item.star.undo}}</a>
|
||||
<a id="star-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i> {{$item.star.do}}</a>
|
||||
<a id="unstar-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i> {{$item.star.undo}}</a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
|
||||
<div class="wall-item-actions-social">
|
||||
{{if $star}}
|
||||
<a href="#" id="star-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a>
|
||||
<a href="#" id="unstar-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a>
|
||||
<a href="#" id="star-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a>
|
||||
<a href="#" id="unstar-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a>
|
||||
<a href="#" id="tagger-{{$id}}" onclick="itemTag({{$id}}); return false;" class="{{$star.classtagger}}" title="{{$star.tagger}}">{{$star.tagger}}</a>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@
|
|||
|
||||
<div class="wall-item-actions-social">
|
||||
{{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="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</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>
|
||||
<a href="#" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>
|
||||
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.star.classtagger}}" title="{{$item.star.tagger}}">{{$item.star.tagger}}</a>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -102,8 +102,8 @@
|
|||
<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>
|
||||
<a href="#" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</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>
|
||||
<a href="#" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>
|
||||
{{/if}}
|
||||
{{if $item.ignore}}
|
||||
<a href="#" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}">{{$item.ignore.do}}</a>
|
||||
|
|
|
@ -117,7 +117,7 @@
|
|||
<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>
|
||||
<a href="#" id="starred-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
|
||||
{{/if}}
|
||||
{{if $item.tagger}}
|
||||
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="tag-item icon tagged" title="{{$item.tagger.add}}"></a>
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
|
||||
<div class="wall-item-actions-social">
|
||||
{{if $star}}
|
||||
<a href="#" id="star-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a>
|
||||
<a href="#" id="unstar-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a>
|
||||
<a href="#" id="star-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a>
|
||||
<a href="#" id="unstar-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a>
|
||||
<a href="#" id="tagger-{{$id}}" onclick="itemTag({{$id}}); return false;" class="{{$star.classtagger}}" title="{{$star.tagger}}">{{$star.tagger}}</a>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
|
||||
<div class="wall-item-actions-social">
|
||||
{{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="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</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>
|
||||
<a href="#" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>
|
||||
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.star.classtagger}}" title="{{$item.star.tagger}}">{{$item.star.tagger}}</a>
|
||||
{{/if}}
|
||||
|
||||
|
|
|
@ -140,8 +140,8 @@
|
|||
<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>
|
||||
<a role="button" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="icon-star-empty icon-large"><span class="sr-only">{{$item.star.undo}}</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>
|
||||
<a role="button" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="icon-star-empty icon-large"><span class="sr-only">{{$item.star.undo}}</span></i></a>
|
||||
{{/if}}
|
||||
{{if $item.ignore}}
|
||||
<a role="button" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="icon-bell-slash icon-large"><span class="sr-only">{{$item.ignore.do}}</span></i></a>
|
||||
|
|
Loading…
Reference in a new issue