diff options
Diffstat (limited to 'application/front/controller/admin/SessionFilterController.php')
-rw-r--r-- | application/front/controller/admin/SessionFilterController.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/application/front/controller/admin/SessionFilterController.php b/application/front/controller/admin/SessionFilterController.php new file mode 100644 index 00000000..69a16ec3 --- /dev/null +++ b/application/front/controller/admin/SessionFilterController.php | |||
@@ -0,0 +1,79 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Admin; | ||
6 | |||
7 | use Shaarli\Bookmark\BookmarkFilter; | ||
8 | use Shaarli\Security\SessionManager; | ||
9 | use Slim\Http\Request; | ||
10 | use Slim\Http\Response; | ||
11 | |||
12 | /** | ||
13 | * Class SessionFilterController | ||
14 | * | ||
15 | * Slim controller used to handle filters stored in the user session, such as visibility, links per page, etc. | ||
16 | */ | ||
17 | class SessionFilterController extends ShaarliAdminController | ||
18 | { | ||
19 | /** | ||
20 | * GET /links-per-page: set the number of bookmarks to display per page in homepage | ||
21 | */ | ||
22 | public function linksPerPage(Request $request, Response $response): Response | ||
23 | { | ||
24 | $linksPerPage = $request->getParam('nb') ?? null; | ||
25 | if (null === $linksPerPage || false === is_numeric($linksPerPage)) { | ||
26 | $linksPerPage = $this->container->conf->get('general.links_per_page', 20); | ||
27 | } | ||
28 | |||
29 | $this->container->sessionManager->setSessionParameter( | ||
30 | SessionManager::KEY_LINKS_PER_PAGE, | ||
31 | abs(intval($linksPerPage)) | ||
32 | ); | ||
33 | |||
34 | return $this->redirectFromReferer($request, $response, ['linksperpage'], ['nb']); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * GET /visibility: allows to display only public or only private bookmarks in linklist | ||
39 | */ | ||
40 | public function visibility(Request $request, Response $response, array $args): Response | ||
41 | { | ||
42 | if (false === $this->container->loginManager->isLoggedIn()) { | ||
43 | return $this->redirectFromReferer($request, $response, ['visibility']); | ||
44 | } | ||
45 | |||
46 | $newVisibility = $args['visibility'] ?? null; | ||
47 | if (false === in_array($newVisibility, [BookmarkFilter::$PRIVATE, BookmarkFilter::$PUBLIC], true)) { | ||
48 | $newVisibility = null; | ||
49 | } | ||
50 | |||
51 | $currentVisibility = $this->container->sessionManager->getSessionParameter(SessionManager::KEY_VISIBILITY); | ||
52 | |||
53 | // Visibility not set or not already expected value, set expected value, otherwise reset it | ||
54 | if ($newVisibility !== null && (null === $currentVisibility || $currentVisibility !== $newVisibility)) { | ||
55 | // See only public bookmarks | ||
56 | $this->container->sessionManager->setSessionParameter( | ||
57 | SessionManager::KEY_VISIBILITY, | ||
58 | $newVisibility | ||
59 | ); | ||
60 | } else { | ||
61 | $this->container->sessionManager->deleteSessionParameter(SessionManager::KEY_VISIBILITY); | ||
62 | } | ||
63 | |||
64 | return $this->redirectFromReferer($request, $response, ['visibility']); | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * GET /untagged-only: allows to display only bookmarks without any tag | ||
69 | */ | ||
70 | public function untaggedOnly(Request $request, Response $response): Response | ||
71 | { | ||
72 | $this->container->sessionManager->setSessionParameter( | ||
73 | SessionManager::KEY_UNTAGGED_ONLY, | ||
74 | empty($this->container->sessionManager->getSessionParameter(SessionManager::KEY_UNTAGGED_ONLY)) | ||
75 | ); | ||
76 | |||
77 | return $this->redirectFromReferer($request, $response, ['untaggedonly', 'untagged-only']); | ||
78 | } | ||
79 | } | ||