From 7609cbcccf4648b1545c9f23702dadbc3fc6bf68 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 19 May 2014 09:24:15 +0200 Subject: [PATCH] Merged mass tag and post list redirection --- src/Controllers/PostController.php | 19 ++++++++++++++++--- src/Controllers/TagController.php | 24 ------------------------ src/Views/tag/tag-mass-tag.phtml | 4 +++- src/routes.php | 3 +-- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index f980fa10..97995fa7 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -43,7 +43,15 @@ class PostController extends AbstractController public function listRedirectAction($source = 'posts') { $context = Core::getContext(); + + if ($source == 'mass-tag') + Access::assert(new Privilege(Privilege::MassTag)); + + $oldPage = intval(InputHelper::get('old-page')); + $oldQuery = trim(InputHelper::get('old-query')); $query = trim(InputHelper::get('query')); + $additionalInfo = trim(InputHelper::get('tag')); + $context->transport->searchQuery = $query; $context->transport->lastSearchQuery = $query; if (strpos($query, '/') !== false) @@ -53,9 +61,14 @@ class PostController extends AbstractController $params['source'] = $source; if ($query) $params['query'] = $query; - #if ($additionalInfo) - # $params['additionalInfo'] = $additionalInfo; - $params['page'] = 1; + if ($additionalInfo) + $params['additionalInfo'] = $additionalInfo; + + if ($oldPage != 0 and $oldQuery == $query) + $params['page'] = $oldPage; + else + $params['page'] = 1; + $url = \Chibi\Router::linkTo(['PostController', 'listView'], $params); $this->redirect($url); diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 5868c84d..eff9672e 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -131,30 +131,6 @@ class TagController extends AbstractController $this->renderViewWithSource('tag-list-wrapper', 'mass-tag'); } - public function massTagRedirectAction() - { - Access::assert(new Privilege(Privilege::MassTag)); - $suppliedOldPage = intval(InputHelper::get('old-page')); - $suppliedOldQuery = InputHelper::get('old-query'); - $suppliedQuery = InputHelper::get('query'); - $suppliedTag = InputHelper::get('tag'); - - $params = - [ - 'source' => 'mass-tag', - 'query' => trim($suppliedQuery ?: ''), - 'additionalInfo' => $suppliedTag ? $suppliedTag : '', - ]; - - if ($suppliedOldPage != 0 and $suppliedOldQuery == $suppliedQuery) - $params['page'] = $suppliedOldPage; - else - $params['page'] = 1; - - $url = \Chibi\Router::linkTo(['PostController', 'listView'], $params); - $this->redirect($url); - } - private function renderViewWithSource($viewName, $source) { diff --git a/src/Views/tag/tag-mass-tag.phtml b/src/Views/tag/tag-mass-tag.phtml index 3f6f959e..cf28eb79 100644 --- a/src/Views/tag/tag-mass-tag.phtml +++ b/src/Views/tag/tag-mass-tag.phtml @@ -1,5 +1,7 @@
-
+

mass tag

diff --git a/src/routes.php b/src/routes.php index 60469db3..941b2e44 100644 --- a/src/routes.php +++ b/src/routes.php @@ -40,7 +40,7 @@ $postValidation = \Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{page}', $postValidation); \Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}/{page}', $postValidation); \Chibi\Router::register(['PostController', 'listView'], 'GET', '/{source}/{query}/{additionalInfo}/{page}', $postValidation); -\Chibi\Router::register(['PostController', 'listRedirectAction'], 'POST', '/posts-redirect', $postValidation); +\Chibi\Router::register(['PostController', 'listRedirectAction'], 'POST', '/{source}-redirect', $postValidation); \Chibi\Router::register(['PostController', 'randomView'], 'GET', '/random', $postValidation); \Chibi\Router::register(['PostController', 'randomView'], 'GET', '/random/{page}', $postValidation); @@ -91,7 +91,6 @@ $tagValidation = \Chibi\Router::register(['TagController', 'mergeView'], 'GET', '/tags-merge', $tagValidation); \Chibi\Router::register(['TagController', 'mergeAction'], 'POST', '/tags-merge', $tagValidation); \Chibi\Router::register(['TagController', 'massTagRedirectView'], 'GET', '/mass-tag-redirect', $tagValidation); -\Chibi\Router::register(['TagController', 'massTagRedirectAction'], 'POST', '/mass-tag-redirect', $tagValidation); $userValidation = [