2020-01-26 11:15:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-05-22 13:20:31 +02:00
|
|
|
namespace Shaarli\Front\Controller\Visitor;
|
2020-01-26 11:15:15 +01:00
|
|
|
|
|
|
|
use Shaarli\Front\Exception\ThumbnailsDisabledException;
|
2020-07-06 08:04:35 +02:00
|
|
|
use Shaarli\Render\TemplatePage;
|
2020-01-26 11:15:15 +01:00
|
|
|
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.
|
|
|
|
*/
|
2020-05-22 13:20:31 +02:00
|
|
|
class PictureWallController extends ShaarliVisitorController
|
2020-01-26 11:15:15 +01:00
|
|
|
{
|
|
|
|
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',
|
2020-09-22 20:25:47 +02:00
|
|
|
t('Picture wall') . ' - ' . $this->container->conf->get('general.title', 'Shaarli')
|
2020-01-26 11:15:15 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// Optionally filter the results:
|
|
|
|
$links = $this->container->bookmarkService->search($request->getQueryParams());
|
|
|
|
$linksToDisplay = [];
|
|
|
|
|
|
|
|
// 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 ($links as $key => $link) {
|
|
|
|
if (!empty($link->getThumbnail())) {
|
|
|
|
$linksToDisplay[] = $formatter->format($link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 14:43:10 +02:00
|
|
|
$data = ['linksToDisplay' => $linksToDisplay];
|
|
|
|
$this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);
|
|
|
|
|
2020-01-26 11:15:15 +01:00
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$this->assignView($key, $value);
|
|
|
|
}
|
|
|
|
|
2020-07-06 08:04:35 +02:00
|
|
|
return $response->write($this->render(TemplatePage::PICTURE_WALL));
|
2020-01-26 11:15:15 +01:00
|
|
|
}
|
|
|
|
}
|