diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-01-26 11:15:15 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 485b168a9677d160b0c0426e4f282b9bd0c632c1 (patch) | |
tree | c7c21ea01096bfe28622b3a23c5c76d1cb2435fa /application | |
parent | bee33239ed444f9724422fe5234cd79997500519 (diff) | |
download | Shaarli-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.php | 2 | ||||
-rw-r--r-- | application/container/ContainerBuilder.php | 5 | ||||
-rw-r--r-- | application/container/ShaarliContainer.php | 2 | ||||
-rw-r--r-- | application/front/controllers/PictureWallController.php | 72 | ||||
-rw-r--r-- | application/front/exceptions/ThumbnailsDisabledException.php | 15 | ||||
-rw-r--r-- | application/updater/Updater.php | 18 |
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; | |||
7 | use Shaarli\Bookmark\BookmarkFileService; | 7 | use Shaarli\Bookmark\BookmarkFileService; |
8 | use Shaarli\Bookmark\BookmarkServiceInterface; | 8 | use Shaarli\Bookmark\BookmarkServiceInterface; |
9 | use Shaarli\Config\ConfigManager; | 9 | use Shaarli\Config\ConfigManager; |
10 | use Shaarli\Formatter\FormatterFactory; | ||
10 | use Shaarli\History; | 11 | use Shaarli\History; |
11 | use Shaarli\Plugin\PluginManager; | 12 | use Shaarli\Plugin\PluginManager; |
12 | use Shaarli\Render\PageBuilder; | 13 | use 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 | ||
7 | use Shaarli\Bookmark\BookmarkServiceInterface; | 7 | use Shaarli\Bookmark\BookmarkServiceInterface; |
8 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
9 | use Shaarli\Formatter\FormatterFactory; | ||
9 | use Shaarli\History; | 10 | use Shaarli\History; |
10 | use Shaarli\Plugin\PluginManager; | 11 | use Shaarli\Plugin\PluginManager; |
11 | use Shaarli\Render\PageBuilder; | 12 | use 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 | */ |
27 | class ShaarliContainer extends Container | 29 | class 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 | |||
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 | } | ||
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 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Exception; | ||
6 | |||
7 | class 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 | ||
3 | namespace Shaarli\Updater; | 3 | namespace Shaarli\Updater; |
4 | 4 | ||
5 | use Shaarli\Config\ConfigManager; | ||
6 | use Shaarli\Bookmark\BookmarkServiceInterface; | 5 | use Shaarli\Bookmark\BookmarkServiceInterface; |
6 | use Shaarli\Config\ConfigManager; | ||
7 | use Shaarli\Updater\Exception\UpdaterException; | 7 | use 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 | } |