diff --git a/plugins/Favourite/Controller/Favourite.php b/plugins/Favourite/Controller/Favourite.php index ffde83e3b6..2e81ceb462 100644 --- a/plugins/Favourite/Controller/Favourite.php +++ b/plugins/Favourite/Controller/Favourite.php @@ -27,6 +27,7 @@ use App\Core\Controller; use App\Core\DB\DB; use App\Core\Event; use App\Core\Form; +use App\Core\Router\Router; use App\Util\Common; use App\Util\Exception\InvalidFormException; use App\Util\Exception\NoLoggedInUser; @@ -72,8 +73,12 @@ class Favourite extends Controller $opts = ['note_id' => $id, 'actor_id' => $user->getId()]; DB::persist(FavouriteEntity::create($opts)); DB::flush(); - // TODO: proper redirect from where the user came from - throw new RedirectException(); + + if ($redirect_back_exists = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1] )[0]) { + $redirect_back_exists = substr($redirect_back_exists, 5); + # TODO anchor on element id + throw new RedirectException($redirect_back_exists); + } } return [ @@ -114,8 +119,12 @@ class Favourite extends Controller if ($form_remove_favourite->isSubmitted()) { DB::remove($remove_favourite_note); DB::flush(); - // TODO: proper redirect from where the user came from - throw new RedirectException(); + + if ($redirect_back_exists = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1] )[0]) { + $redirect_back_exists = substr($redirect_back_exists, 5); + # TODO anchor on element id + throw new RedirectException($redirect_back_exists); + } } $note = DB::find('note', ['id' => $id]); diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 1ea514dd52..c8f5fb06a1 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -34,6 +34,7 @@ use App\Util\Exception\InvalidFormException; use App\Util\Exception\NoSuchNoteException; use App\Util\Exception\RedirectException; use App\Util\Nickname; +use phpDocumentor\Reflection\PseudoTypes\NumericString; use Symfony\Component\HttpFoundation\Request; class Favourite extends NoteHandlerPlugin @@ -54,7 +55,7 @@ class Favourite extends NoteHandlerPlugin return Event::next; } - // If note is favourite, "is_set" is 1 + // If note is favourite, "is_favourite" is 1 $opts = ['note_id' => $note->getId(), 'actor_id' => $user->getId()]; $is_favourite = DB::find('favourite', $opts) !== null; @@ -65,10 +66,14 @@ class Favourite extends NoteHandlerPlugin Router::url('note_remove_favourite', $args, $type) : Router::url('note_add_favourite', $args, $type); + // Concatenating get parameter to redirect the user to where he came from + $favourite_action_url .= '?from=' . urlencode(Common::route()); + $extra_classes = $is_favourite ? "note-actions-set" : "note-actions-unset"; $favourite_action = [ "url" => $favourite_action_url, - "classes" => "button-container favourite-button-container $extra_classes" + "classes" => "button-container favourite-button-container $extra_classes", + "id" => "favourite-button-container-" . $note->getId() ]; $actions[] = $favourite_action; diff --git a/plugins/Favourite/templates/favourite/add_to_favourites.html.twig b/plugins/Favourite/templates/favourite/add_to_favourites.html.twig index 4f406bfe20..f6b23ece00 100644 --- a/plugins/Favourite/templates/favourite/add_to_favourites.html.twig +++ b/plugins/Favourite/templates/favourite/add_to_favourites.html.twig @@ -1,24 +1,17 @@ {% extends 'stdgrid.html.twig' %} -{% block meta %} - {{ parent() }} -{% endblock %} - {% block title %}{{ 'Favourite ' | trans }}{{ note.getActorNickname() }}{{ '\'s note.' | trans }}{% endblock %} -{% block header %} +{% block stylesheets %} {{ parent() }} -{% endblock %} - -{% block left %} - {{ parent() }} -{% endblock %} + +{% endblock stylesheets %} {% block body %} {{ parent() }}