]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - application/front/controller/admin/SessionFilterController.php
Initialize admin Slim controllers
[github/shaarli/Shaarli.git] / application / front / controller / admin / SessionFilterController.php
CommitLineData
af290059
A
1<?php
2
3declare(strict_types=1);
4
2899ebb5 5namespace Shaarli\Front\Controller\Admin;
af290059
A
6
7use Shaarli\Bookmark\BookmarkFilter;
8use Shaarli\Security\SessionManager;
9use Slim\Http\Request;
10use 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.
af290059 16 */
2899ebb5 17class SessionFilterController extends ShaarliAdminController
af290059
A
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
2899ebb5 34 return $this->redirectFromReferer($request, $response, ['linksperpage'], ['nb']);
af290059
A
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()) {
2899ebb5 43 return $this->redirectFromReferer($request, $response, ['visibility']);
af290059
A
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
2899ebb5 64 return $this->redirectFromReferer($request, $response, ['visibility']);
af290059
A
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
2899ebb5 77 return $this->redirectFromReferer($request, $response, ['untaggedonly', 'untagged-only']);
af290059
A
78 }
79}