aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/visitor/PictureWallController.php
blob: 9c8f07d7a18e07990c1a488224563e1ec199d104 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

declare(strict_types=1);

namespace Shaarli\Front\Controller\Visitor;

use Shaarli\Front\Exception\ThumbnailsDisabledException;
use Shaarli\Render\TemplatePage;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;

/**
 * Class PicturesWallController
 *
 * Slim controller used to render the pictures wall page.
 * If thumbnails mode is set to NONE, we just render the template without any image.
 */
class PictureWallController extends ShaarliVisitorController
{
    public function index(Request $request, Response $response): Response
    {
        if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) === Thumbnailer::MODE_NONE) {
            throw new ThumbnailsDisabledException();
        }

        $this->assignView(
            'pagetitle',
            t('Picture wall') . ' - ' . $this->container->conf->get('general.title', 'Shaarli')
        );

        // Optionally filter the results:
        $bookmarks = $this->container->bookmarkService->search($request->getQueryParams())->getBookmarks();
        $links = [];

        // Get only bookmarks which have a thumbnail.
        // Note: we do not retrieve thumbnails here, the request is too heavy.
        $formatter = $this->container->formatterFactory->getFormatter('raw');
        foreach ($bookmarks as $key => $bookmark) {
            if (!empty($bookmark->getThumbnail())) {
                $links[] = $formatter->format($bookmark);
            }
        }

        $data = ['linksToDisplay' => $links];
        $this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);

        foreach ($data as $key => $value) {
            $this->assignView($key, $value);
        }

        return $response->write($this->render(TemplatePage::PICTURE_WALL));
    }
}