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