aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-26 11:15:15 +0100
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit485b168a9677d160b0c0426e4f282b9bd0c632c1 (patch)
treec7c21ea01096bfe28622b3a23c5c76d1cb2435fa /application
parentbee33239ed444f9724422fe5234cd79997500519 (diff)
downloadShaarli-485b168a9677d160b0c0426e4f282b9bd0c632c1.tar.gz
Shaarli-485b168a9677d160b0c0426e4f282b9bd0c632c1.tar.zst
Shaarli-485b168a9677d160b0c0426e4f282b9bd0c632c1.zip
Process picwall rendering through Slim controller + UT
Diffstat (limited to 'application')
-rw-r--r--application/bookmark/Bookmark.php2
-rw-r--r--application/container/ContainerBuilder.php5
-rw-r--r--application/container/ShaarliContainer.php2
-rw-r--r--application/front/controllers/PictureWallController.php72
-rw-r--r--application/front/exceptions/ThumbnailsDisabledException.php15
-rw-r--r--application/updater/Updater.php18
6 files changed, 112 insertions, 2 deletions
diff --git a/application/bookmark/Bookmark.php b/application/bookmark/Bookmark.php
index f9b21d3d..83ddab82 100644
--- a/application/bookmark/Bookmark.php
+++ b/application/bookmark/Bookmark.php
@@ -346,7 +346,7 @@ class Bookmark
346 /** 346 /**
347 * Get the Thumbnail. 347 * Get the Thumbnail.
348 * 348 *
349 * @return string|bool 349 * @return string|bool|null
350 */ 350 */
351 public function getThumbnail() 351 public function getThumbnail()
352 { 352 {
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index e2c78ccc..99c12334 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -7,6 +7,7 @@ namespace Shaarli\Container;
7use Shaarli\Bookmark\BookmarkFileService; 7use Shaarli\Bookmark\BookmarkFileService;
8use Shaarli\Bookmark\BookmarkServiceInterface; 8use Shaarli\Bookmark\BookmarkServiceInterface;
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\Formatter\FormatterFactory;
10use Shaarli\History; 11use Shaarli\History;
11use Shaarli\Plugin\PluginManager; 12use Shaarli\Plugin\PluginManager;
12use Shaarli\Render\PageBuilder; 13use Shaarli\Render\PageBuilder;
@@ -76,6 +77,10 @@ class ContainerBuilder
76 return new PluginManager($container->conf); 77 return new PluginManager($container->conf);
77 }; 78 };
78 79
80 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory {
81 return new FormatterFactory($container->conf, $container->loginManager->isLoggedIn());
82 };
83
79 return $container; 84 return $container;
80 } 85 }
81} 86}
diff --git a/application/container/ShaarliContainer.php b/application/container/ShaarliContainer.php
index 3fa9116e..fdf2f77f 100644
--- a/application/container/ShaarliContainer.php
+++ b/application/container/ShaarliContainer.php
@@ -6,6 +6,7 @@ namespace Shaarli\Container;
6 6
7use Shaarli\Bookmark\BookmarkServiceInterface; 7use Shaarli\Bookmark\BookmarkServiceInterface;
8use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
9use Shaarli\Formatter\FormatterFactory;
9use Shaarli\History; 10use Shaarli\History;
10use Shaarli\Plugin\PluginManager; 11use Shaarli\Plugin\PluginManager;
11use Shaarli\Render\PageBuilder; 12use Shaarli\Render\PageBuilder;
@@ -23,6 +24,7 @@ use Slim\Container;
23 * @property BookmarkServiceInterface $bookmarkService 24 * @property BookmarkServiceInterface $bookmarkService
24 * @property PageBuilder $pageBuilder 25 * @property PageBuilder $pageBuilder
25 * @property PluginManager $pluginManager 26 * @property PluginManager $pluginManager
27 * @property FormatterFactory $formatterFactory
26 */ 28 */
27class ShaarliContainer extends Container 29class ShaarliContainer extends Container
28{ 30{
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}
diff --git a/application/updater/Updater.php b/application/updater/Updater.php
index 95654d81..4bbcb9f2 100644
--- a/application/updater/Updater.php
+++ b/application/updater/Updater.php
@@ -2,8 +2,8 @@
2 2
3namespace Shaarli\Updater; 3namespace Shaarli\Updater;
4 4
5use Shaarli\Config\ConfigManager;
6use Shaarli\Bookmark\BookmarkServiceInterface; 5use Shaarli\Bookmark\BookmarkServiceInterface;
6use Shaarli\Config\ConfigManager;
7use Shaarli\Updater\Exception\UpdaterException; 7use Shaarli\Updater\Exception\UpdaterException;
8 8
9/** 9/**
@@ -111,4 +111,20 @@ class Updater
111 { 111 {
112 return $this->doneUpdates; 112 return $this->doneUpdates;
113 } 113 }
114
115 /**
116 * With the Slim routing system, default header link should be `./` instead of `?`.
117 * Otherwise you can not go back to the home page. Example: `/picture-wall` -> `/picture-wall?` instead of `/`.
118 */
119 public function updateMethodRelativeHomeLink(): bool
120 {
121 $link = trim($this->conf->get('general.header_link'));
122 if ($link[0] === '?') {
123 $link = './'. ltrim($link, '?');
124
125 $this->conf->set('general.header_link', $link, true, true);
126 }
127
128 return true;
129 }
114} 130}