]>
Commit | Line | Data |
---|---|---|
485b168a A |
1 | <?php |
2 | ||
3 | declare(strict_types=1); | |
4 | ||
2899ebb5 | 5 | namespace Shaarli\Front\Controller\Visitor; |
485b168a A |
6 | |
7 | use Shaarli\Front\Exception\ThumbnailsDisabledException; | |
1a8ac737 | 8 | use Shaarli\Render\TemplatePage; |
485b168a A |
9 | use Shaarli\Thumbnailer; |
10 | use Slim\Http\Request; | |
11 | use Slim\Http\Response; | |
12 | ||
13 | /** | |
14 | * Class PicturesWallController | |
15 | * | |
16 | * Slim controller used to render the pictures wall page. | |
17 | * If thumbnails mode is set to NONE, we just render the template without any image. | |
485b168a | 18 | */ |
2899ebb5 | 19 | class PictureWallController extends ShaarliVisitorController |
485b168a A |
20 | { |
21 | public function index(Request $request, Response $response): Response | |
22 | { | |
23 | if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) === Thumbnailer::MODE_NONE) { | |
24 | throw new ThumbnailsDisabledException(); | |
25 | } | |
26 | ||
27 | $this->assignView( | |
28 | 'pagetitle', | |
29 | t('Picture wall') .' - '. $this->container->conf->get('general.title', 'Shaarli') | |
30 | ); | |
31 | ||
32 | // Optionally filter the results: | |
33 | $links = $this->container->bookmarkService->search($request->getQueryParams()); | |
34 | $linksToDisplay = []; | |
35 | ||
36 | // Get only bookmarks which have a thumbnail. | |
37 | // Note: we do not retrieve thumbnails here, the request is too heavy. | |
38 | $formatter = $this->container->formatterFactory->getFormatter('raw'); | |
39 | foreach ($links as $key => $link) { | |
40 | if (!empty($link->getThumbnail())) { | |
41 | $linksToDisplay[] = $formatter->format($link); | |
42 | } | |
43 | } | |
44 | ||
45 | $data = $this->executeHooks($linksToDisplay); | |
46 | foreach ($data as $key => $value) { | |
47 | $this->assignView($key, $value); | |
48 | } | |
49 | ||
1a8ac737 | 50 | return $response->write($this->render(TemplatePage::PICTURE_WALL)); |
485b168a A |
51 | } |
52 | ||
53 | /** | |
54 | * @param mixed[] $linksToDisplay List of formatted bookmarks | |
55 | * | |
56 | * @return mixed[] Template data after active plugins render_picwall hook execution. | |
57 | */ | |
58 | protected function executeHooks(array $linksToDisplay): array | |
59 | { | |
60 | $data = [ | |
61 | 'linksToDisplay' => $linksToDisplay, | |
62 | ]; | |
63 | $this->container->pluginManager->executeHooks( | |
64 | 'render_picwall', | |
65 | $data, | |
66 | ['loggedin' => $this->container->loginManager->isLoggedIn()] | |
67 | ); | |
68 | ||
69 | return $data; | |
70 | } | |
71 | } |