aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front
diff options
context:
space:
mode:
Diffstat (limited to 'application/front')
-rw-r--r--application/front/controllers/PictureWallController.php72
-rw-r--r--application/front/exceptions/ThumbnailsDisabledException.php15
2 files changed, 87 insertions, 0 deletions
diff --git a/application/front/controllers/PictureWallController.php b/application/front/controllers/PictureWallController.php
new file mode 100644
index 00000000..08d31b29
--- /dev/null
+++ b/application/front/controllers/PictureWallController.php
@@ -0,0 +1,72 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller;
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.
17 *
18 * @package Front\Controller
19 */
20class 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}
diff --git a/application/front/exceptions/ThumbnailsDisabledException.php b/application/front/exceptions/ThumbnailsDisabledException.php
new file mode 100644
index 00000000..1b9cf5b7
--- /dev/null
+++ b/application/front/exceptions/ThumbnailsDisabledException.php
@@ -0,0 +1,15 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Exception;
6
7class ThumbnailsDisabledException extends ShaarliException
8{
9 public function __construct()
10 {
11 $message = t('Picture wall unavailable (thumbnails are disabled).');
12
13 parent::__construct($message, 400);
14 }
15}