]>
Commit | Line | Data |
---|---|---|
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, etc. | |
16 | */ | |
17 | class SessionFilterController extends ShaarliAdminController | |
18 | { | |
19 | /** | |
20 | * GET /admin/visibility: allows to display only public or only private bookmarks in linklist | |
21 | */ | |
22 | public function visibility(Request $request, Response $response, array $args): Response | |
23 | { | |
24 | if (false === $this->container->loginManager->isLoggedIn()) { | |
25 | return $this->redirectFromReferer($request, $response, ['visibility']); | |
26 | } | |
27 | ||
28 | $newVisibility = $args['visibility'] ?? null; | |
29 | if (false === in_array($newVisibility, [BookmarkFilter::$PRIVATE, BookmarkFilter::$PUBLIC], true)) { | |
30 | $newVisibility = null; | |
31 | } | |
32 | ||
33 | $currentVisibility = $this->container->sessionManager->getSessionParameter(SessionManager::KEY_VISIBILITY); | |
34 | ||
35 | // Visibility not set or not already expected value, set expected value, otherwise reset it | |
36 | if ($newVisibility !== null && (null === $currentVisibility || $currentVisibility !== $newVisibility)) { | |
37 | // See only public bookmarks | |
38 | $this->container->sessionManager->setSessionParameter( | |
39 | SessionManager::KEY_VISIBILITY, | |
40 | $newVisibility | |
41 | ); | |
42 | } else { | |
43 | $this->container->sessionManager->deleteSessionParameter(SessionManager::KEY_VISIBILITY); | |
44 | } | |
45 | ||
46 | return $this->redirectFromReferer($request, $response, ['visibility']); | |
47 | } | |
48 | } |