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