diff --git a/lib/chibi-core b/lib/chibi-core index 3c70aa33..19bb5ee3 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit 3c70aa336c0571d83557d5fe66ff1b5cc0f3478f +Subproject commit 19bb5ee3901cf6402d7507c30b8fc183c3fc0bcc diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 1ca0ffb2..9487a97d 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -49,7 +49,7 @@ $context->layoutName $context->viewName = ''; $context->transport = new StdClass; -session_start(); +SessionHelper::init(); if (!Auth::isLoggedIn()) Auth::tryAutoLogin(); diff --git a/public_html/media/js/post-list.js b/public_html/media/js/post-list.js index 96f9f5f7..dcef3ac9 100644 --- a/public_html/media/js/post-list.js +++ b/public_html/media/js/post-list.js @@ -13,7 +13,7 @@ $(function() var enable = !aDom.parents('.post').hasClass('tagged'); var url = $(this).attr('href'); - url = url.replace('_enable_', enable ? '1' : '0'); + url = url.replace(/\/[01]\/?$/, '/' + (enable ? '1' : '0')); postJSON({ url: url }).success(function(data) { aDom.removeClass('inactive'); diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 28b96ea5..829cb8e6 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -36,6 +36,7 @@ class CommentController JobArgs::ARG_NEW_TEXT => InputHelper::get('text') ]); } + $this->redirectToLastVisitedUrl(); } public function editView($id) @@ -65,6 +66,7 @@ class CommentController JobArgs::ARG_NEW_TEXT => InputHelper::get('text') ]); } + $this->redirectToLastVisitedUrl(); } public function deleteAction($id) @@ -74,5 +76,14 @@ class CommentController [ JobArgs::ARG_COMMENT_ID => $id, ]); + $this->redirectToLastVisitedUrl(); + } + + private function redirectToLastVisitedUrl() + { + $lastUrl = SessionHelper::getLastVisitedUrl(); + if ($lastUrl) + \Chibi\Util\Url::forward($lastUrl); + exit; } } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index ee8e4c35..99dbf96f 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -78,6 +78,8 @@ class PostController JobArgs::ARG_TAG_NAME => $tag, JobArgs::ARG_NEW_STATE => $enable, ]); + + $this->redirectToLastVisitedUrl(); } public function uploadView() @@ -161,11 +163,13 @@ class PostController } Api::run(new EditPostJob(), $jobArgs); + $this->redirectToGenericView($id); } public function flagAction($id) { Api::run(new FlagPostJob(), [JobArgs::ARG_POST_ID => $id]); + $this->redirectToGenericView($id); } public function hideAction($id) @@ -173,6 +177,7 @@ class PostController Api::run(new TogglePostVisibilityJob(), [ JobArgs::ARG_POST_ID => $id, JobArgs::ARG_NEW_STATE => false]); + $this->redirectToGenericView($id); } public function unhideAction($id) @@ -180,12 +185,14 @@ class PostController Api::run(new TogglePostVisibilityJob(), [ JobArgs::ARG_POST_ID => $id, JobArgs::ARG_NEW_STATE => true]); + $this->redirectToGenericView($id); } public function deleteAction($id) { Api::run(new DeletePostJob(), [ JobArgs::ARG_POST_ID => $id]); + $this->redirectToGenericView($id); } public function addFavoriteAction($id) @@ -193,6 +200,7 @@ class PostController Api::run(new TogglePostFavoriteJob(), [ JobArgs::ARG_POST_ID => $id, JobArgs::ARG_NEW_STATE => true]); + $this->redirectToGenericView($id); } public function removeFavoriteAction($id) @@ -200,6 +208,7 @@ class PostController Api::run(new TogglePostFavoriteJob(), [ JobArgs::ARG_POST_ID => $id, JobArgs::ARG_NEW_STATE => false]); + $this->redirectToGenericView($id); } public function scoreAction($id, $score) @@ -207,12 +216,14 @@ class PostController Api::run(new ScorePostJob(), [ JobArgs::ARG_POST_ID => $id, JobArgs::ARG_NEW_POST_SCORE => $score]); + $this->redirectToGenericView($id); } public function featureAction($id) { Api::run(new FeaturePostJob(), [ JobArgs::ARG_POST_ID => $id]); + $this->redirectToGenericView($id); } public function genericView($id) @@ -281,7 +292,7 @@ class PostController $context->layoutName = 'layout-file'; } - protected function splitPostIds($string) + private function splitPostIds($string) { $ids = preg_split('/\D/', trim($string)); $ids = array_filter($ids, function($x) { return $x != ''; }); @@ -290,11 +301,27 @@ class PostController return $ids; } - protected function splitTags($string) + private function splitTags($string) { $tags = preg_split('/[,;\s]+/', trim($string)); $tags = array_filter($tags, function($x) { return $x != ''; }); $tags = array_unique($tags); return $tags; } + + private function redirectToLastVisitedUrl() + { + $lastUrl = SessionHelper::getLastVisitedUrl(); + if ($lastUrl) + \Chibi\Util\Url::forward($lastUrl); + exit; + } + + private function redirectToGenericView($id) + { + \Chibi\Util\Url::forward(\Chibi\Router::linkTo( + ['PostController', 'genericView'], + ['id' => $id])); + exit; + } } diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index f89a6608..7c43adcc 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -94,25 +94,6 @@ class UserController Messenger::message('Browsing settings updated!'); } - public function toggleSafetyAction($safety) - { - $safety = new PostSafety($safety); - $safety->validate(); - - $user = Auth::getCurrentUser(); - $user->getSettings()->enableSafety($safety, !$user->getSettings()->hasEnabledSafety($safety)); - $desiredSafety = $user->getSettings()->get(UserSettings::SETTING_SAFETY); - - $user = Api::run( - new EditUserSettingsJob(), - [ - JobArgs::ARG_USER_ENTITY => Auth::getCurrentUser(), - JobArgs::ARG_NEW_SETTINGS => [UserSettings::SETTING_SAFETY => $desiredSafety], - ]); - - Auth::setCurrentUser($user); - } - public function editAction($identifier) { $this->genericView($identifier, 'edit'); @@ -143,6 +124,26 @@ class UserController Messenger::message($message); } + public function toggleSafetyAction($safety) + { + $safety = new PostSafety($safety); + $safety->validate(); + + $user = Auth::getCurrentUser(); + $user->getSettings()->enableSafety($safety, !$user->getSettings()->hasEnabledSafety($safety)); + $desiredSafety = $user->getSettings()->get(UserSettings::SETTING_SAFETY); + + $user = Api::run( + new EditUserSettingsJob(), + [ + JobArgs::ARG_USER_ENTITY => Auth::getCurrentUser(), + JobArgs::ARG_NEW_SETTINGS => [UserSettings::SETTING_SAFETY => $desiredSafety], + ]); + + Auth::setCurrentUser($user); + $this->redirectToLastVisitedUrl(); + } + public function deleteAction($identifier) { $this->genericView($identifier, 'delete'); @@ -165,6 +166,7 @@ class UserController Api::run( new FlagUserJob(), $this->appendUserIdentifierArgument([], $identifier)); + $this->redirectToGenericView($identifier); } public function banAction($identifier) @@ -174,6 +176,7 @@ class UserController $this->appendUserIdentifierArgument([ JobArgs::ARG_NEW_STATE => true ], $identifier)); + $this->redirectToGenericView($identifier); } public function unbanAction($identifier) @@ -183,6 +186,7 @@ class UserController $this->appendUserIdentifierArgument([ JobArgs::ARG_NEW_STATE => true ], $identifier)); + $this->redirectToGenericView($identifier); } public function acceptRegistrationAction($identifier) @@ -190,6 +194,7 @@ class UserController Api::run( new AcceptUserRegistrationJob(), $this->appendUserIdentifierArgument([], $identifier)); + $this->redirectToGenericView($identifier); } public function registrationView() @@ -328,4 +333,20 @@ class UserController $arguments[JobArgs::ARG_USER_NAME] = $userIdentifier; return $arguments; } + + private function redirectToLastVisitedUrl() + { + $lastUrl = SessionHelper::getLastVisitedUrl(); + if ($lastUrl) + \Chibi\Util\Url::forward($lastUrl); + exit; + } + + private function redirectToGenericView($identifier) + { + \Chibi\Util\Url::forward(\Chibi\Router::linkTo( + ['UserController', 'genericView'], + ['identifier' => $identifier])); + exit; + } } diff --git a/src/Helpers/SessionHelper.php b/src/Helpers/SessionHelper.php index 3a2858cd..599d2c81 100644 --- a/src/Helpers/SessionHelper.php +++ b/src/Helpers/SessionHelper.php @@ -1,6 +1,16 @@ query; + }); + } + public static function get($key, $default = null) { if (!isset($_SESSION[$key])) @@ -12,4 +22,11 @@ class SessionHelper { $_SESSION[$key] = $value; } + + public static function getLastVisitedUrl() + { + if (!isset($_SESSION['last-visited-url'])) + return ''; + return \Chibi\Util\Url::makeAbsolute($_SESSION['last-visited-url']); + } } diff --git a/src/Views/post/post-small.phtml b/src/Views/post/post-small.phtml index bc041f2f..d0ddc277 100644 --- a/src/Views/post/post-small.phtml +++ b/src/Views/post/post-small.phtml @@ -32,7 +32,7 @@ if ($masstag) href="= \Chibi\Router::linkTo(['PostController', 'toggleTagAction'], [ 'id' => $this->context->post->getId(), 'tag' => $this->context->additionalInfo, - 'enable' => '_enable_']) ?>" + 'enable' => in_array('tagged', $classNames) ? '0' : '1']) ?>" data-text-tagged="Tagged" data-text-untagged="Untagged"> diff --git a/src/Views/post/post-view.phtml b/src/Views/post/post-view.phtml index 2aef0a58..78de73b1 100644 --- a/src/Views/post/post-view.phtml +++ b/src/Views/post/post-view.phtml @@ -229,7 +229,9 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;