diff --git a/src/Module/Starred.php b/src/Module/Item/Star.php similarity index 60% rename from src/Module/Starred.php rename to src/Module/Item/Star.php index 8bc0fa3e4e..fb1a5d2044 100644 --- a/src/Module/Starred.php +++ b/src/Module/Item/Star.php @@ -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); } } diff --git a/static/routes.config.php b/static/routes.config.php index 6acad3827e..7d1d9a1bfc 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -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]], diff --git a/view/js/main.js b/view/js/main.js index 4921ea94f7..0b9c1da283 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -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(); }); } diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index 7dcdb15a5d..0d2561869f 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -105,7 +105,7 @@ {{/if}} {{if $item.star}} - + {{/if}} {{if $item.tagger}} diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 6e76f23d6a..bcd957396b 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -206,8 +206,8 @@ {{if $item.star}}
  • -  {{$item.star.do}} -  {{$item.star.undo}} +  {{$item.star.do}} +  {{$item.star.undo}}
  • {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index f632b0bba1..34d2a73747 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -358,8 +358,8 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.star}}
  • -  {{$item.star.do}} -  {{$item.star.undo}} +  {{$item.star.do}} +  {{$item.star.undo}}
  • {{/if}} @@ -523,8 +523,8 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.star}}
  • -  {{$item.star.do}} -  {{$item.star.undo}} +  {{$item.star.do}} +  {{$item.star.undo}}
  • {{/if}} diff --git a/view/theme/quattro/templates/photo_item.tpl b/view/theme/quattro/templates/photo_item.tpl index 182607ab35..4a43d2cb81 100644 --- a/view/theme/quattro/templates/photo_item.tpl +++ b/view/theme/quattro/templates/photo_item.tpl @@ -33,8 +33,8 @@
    {{if $star}} - {{$star.do}} - {{$star.undo}} + {{$star.do}} + {{$star.undo}} {{$star.tagger}} {{/if}} diff --git a/view/theme/quattro/templates/search_item.tpl b/view/theme/quattro/templates/search_item.tpl index 70aa2ed863..3793cb1033 100644 --- a/view/theme/quattro/templates/search_item.tpl +++ b/view/theme/quattro/templates/search_item.tpl @@ -52,8 +52,8 @@
    {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{$item.star.tagger}} {{/if}} diff --git a/view/theme/quattro/templates/wall_thread.tpl b/view/theme/quattro/templates/wall_thread.tpl index 671b7643f3..e3ed4f26ca 100644 --- a/view/theme/quattro/templates/wall_thread.tpl +++ b/view/theme/quattro/templates/wall_thread.tpl @@ -102,8 +102,8 @@ {{$item.pin.undo}} {{/if}} {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{/if}} {{if $item.ignore}} {{$item.ignore.do}} diff --git a/view/theme/smoothly/templates/wall_thread.tpl b/view/theme/smoothly/templates/wall_thread.tpl index 4f70ea6d5b..53f918813f 100644 --- a/view/theme/smoothly/templates/wall_thread.tpl +++ b/view/theme/smoothly/templates/wall_thread.tpl @@ -117,7 +117,7 @@ {{/if}} {{if $item.star}} - + {{/if}} {{if $item.tagger}} diff --git a/view/theme/vier/templates/photo_item.tpl b/view/theme/vier/templates/photo_item.tpl index aafadae911..069bd22296 100644 --- a/view/theme/vier/templates/photo_item.tpl +++ b/view/theme/vier/templates/photo_item.tpl @@ -40,8 +40,8 @@
    {{if $star}} - {{$star.do}} - {{$star.undo}} + {{$star.do}} + {{$star.undo}} {{$star.tagger}} {{/if}} diff --git a/view/theme/vier/templates/search_item.tpl b/view/theme/vier/templates/search_item.tpl index 7a4c332d08..063e0e9433 100644 --- a/view/theme/vier/templates/search_item.tpl +++ b/view/theme/vier/templates/search_item.tpl @@ -57,8 +57,8 @@
    {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{$item.star.tagger}} {{/if}} diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl index 1e4806c9e0..73997e7c53 100644 --- a/view/theme/vier/templates/wall_thread.tpl +++ b/view/theme/vier/templates/wall_thread.tpl @@ -140,8 +140,8 @@ {{$item.pin.undo}} {{/if}} {{if $item.star}} - {{$item.star.do}} - {{$item.star.undo}} + {{$item.star.do}} + {{$item.star.undo}} {{/if}} {{if $item.ignore}} {{$item.ignore.do}}