]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - index.php
Process session filters through Slim controllers
[github/shaarli/Shaarli.git] / index.php
index 04ec0d731358d147eccec5860f9b34eceef4d39a..a31cbeab68106756d929b056d71b3b1377bf17db 100644 (file)
--- a/index.php
+++ b/index.php
@@ -451,91 +451,25 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
 
     // -------- User clicks on a tag in result count: Remove the tag from the list of searched tags (searchtags=...)
     if (isset($_GET['removetag'])) {
-        // Get previous URL (http_referer) and remove the tag from the searchtags parameters in query.
-        if (empty($_SERVER['HTTP_REFERER'])) {
-            header('Location: ?');
-            exit;
-        }
-
-        // In case browser does not send HTTP_REFERER
-        parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $params);
-
-        // Prevent redirection loop
-        if (isset($params['removetag'])) {
-            unset($params['removetag']);
-        }
-
-        if (isset($params['searchtags'])) {
-            $tags = explode(' ', $params['searchtags']);
-            // Remove value from array $tags.
-            $tags = array_diff($tags, array($_GET['removetag']));
-            $params['searchtags'] = implode(' ', $tags);
-
-            if (empty($params['searchtags'])) {
-                unset($params['searchtags']);
-            }
-
-            // We also remove page (keeping the same page has no sense, since
-            // the results are different)
-            unset($params['page']);
-        }
-        header('Location: ?'.http_build_query($params));
+        header('Location: ./remove-tag/'. $_GET['removetag']);
         exit;
     }
 
     // -------- User wants to change the number of bookmarks per page (linksperpage=...)
     if (isset($_GET['linksperpage'])) {
-        if (is_numeric($_GET['linksperpage'])) {
-            $_SESSION['LINKS_PER_PAGE']=abs(intval($_GET['linksperpage']));
-        }
-
-        if (! empty($_SERVER['HTTP_REFERER'])) {
-            $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('linksperpage'));
-        } else {
-            $location = '?';
-        }
-        header('Location: '. $location);
+        header('Location: ./links-per-page?nb='. $_GET['linksperpage']);
         exit;
     }
 
     // -------- User wants to see only private bookmarks (toggle)
     if (isset($_GET['visibility'])) {
-        if ($_GET['visibility'] === 'private') {
-            // Visibility not set or not already private, set private, otherwise reset it
-            if (empty($_SESSION['visibility']) || $_SESSION['visibility'] !== 'private') {
-                // See only private bookmarks
-                $_SESSION['visibility'] = 'private';
-            } else {
-                unset($_SESSION['visibility']);
-            }
-        } elseif ($_GET['visibility'] === 'public') {
-            if (empty($_SESSION['visibility']) || $_SESSION['visibility'] !== 'public') {
-                // See only public bookmarks
-                $_SESSION['visibility'] = 'public';
-            } else {
-                unset($_SESSION['visibility']);
-            }
-        }
-
-        if (! empty($_SERVER['HTTP_REFERER'])) {
-            $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('visibility'));
-        } else {
-            $location = '?';
-        }
-        header('Location: '. $location);
+        header('Location: ./visibility/'. $_GET['visibility']);
         exit;
     }
 
     // -------- User wants to see only untagged bookmarks (toggle)
     if (isset($_GET['untaggedonly'])) {
-        $_SESSION['untaggedonly'] = empty($_SESSION['untaggedonly']);
-
-        if (! empty($_SERVER['HTTP_REFERER'])) {
-            $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('untaggedonly'));
-        } else {
-            $location = '?';
-        }
-        header('Location: '. $location);
+        header('Location: ./untagged-only');
         exit;
     }
 
@@ -1576,6 +1510,20 @@ $app->group('', function () {
     $this->get('/open-search', '\Shaarli\Front\Controller\OpenSearchController:index')->setName('opensearch');
 
     $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\TagController:addTag')->setName('add-tag');
+    $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\TagController:removeTag')->setName('remove-tag');
+
+    $this
+        ->get('/links-per-page', '\Shaarli\Front\Controller\SessionFilterController:linksPerPage')
+        ->setName('filter-links-per-page')
+    ;
+    $this
+        ->get('/visibility/{visibility}', '\Shaarli\Front\Controller\SessionFilterController:visibility')
+        ->setName('visibility')
+    ;
+    $this
+        ->get('/untagged-only', '\Shaarli\Front\Controller\SessionFilterController:untaggedOnly')
+        ->setName('untagged-only')
+    ;
 })->add('\Shaarli\Front\ShaarliMiddleware');
 
 $response = $app->run(true);