diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-05-22 13:20:31 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 2899ebb5b5e82890c877151f5c02045266ac9973 (patch) | |
tree | 0c4e2684c7f6d161f92a21181bfa4b2f78d6a82f /application/front/controller/visitor/PictureWallController.php | |
parent | af290059d10319e76d1e7d78b592cab99c26d91a (diff) | |
download | Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.gz Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.tar.zst Shaarli-2899ebb5b5e82890c877151f5c02045266ac9973.zip |
Initialize admin Slim controllers
- Reorganize visitor controllers
- Fix redirection with Slim's requests base path
- Fix daily links
Diffstat (limited to 'application/front/controller/visitor/PictureWallController.php')
-rw-r--r-- | application/front/controller/visitor/PictureWallController.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/application/front/controller/visitor/PictureWallController.php b/application/front/controller/visitor/PictureWallController.php new file mode 100644 index 00000000..4e1dce8c --- /dev/null +++ b/application/front/controller/visitor/PictureWallController.php | |||
@@ -0,0 +1,70 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Visitor; | ||
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 | class PictureWallController extends ShaarliVisitorController | ||
19 | { | ||
20 | public function index(Request $request, Response $response): Response | ||
21 | { | ||
22 | if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) === Thumbnailer::MODE_NONE) { | ||
23 | throw new ThumbnailsDisabledException(); | ||
24 | } | ||
25 | |||
26 | $this->assignView( | ||
27 | 'pagetitle', | ||
28 | t('Picture wall') .' - '. $this->container->conf->get('general.title', 'Shaarli') | ||
29 | ); | ||
30 | |||
31 | // Optionally filter the results: | ||
32 | $links = $this->container->bookmarkService->search($request->getQueryParams()); | ||
33 | $linksToDisplay = []; | ||
34 | |||
35 | // Get only bookmarks which have a thumbnail. | ||
36 | // Note: we do not retrieve thumbnails here, the request is too heavy. | ||
37 | $formatter = $this->container->formatterFactory->getFormatter('raw'); | ||
38 | foreach ($links as $key => $link) { | ||
39 | if (!empty($link->getThumbnail())) { | ||
40 | $linksToDisplay[] = $formatter->format($link); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | $data = $this->executeHooks($linksToDisplay); | ||
45 | foreach ($data as $key => $value) { | ||
46 | $this->assignView($key, $value); | ||
47 | } | ||
48 | |||
49 | return $response->write($this->render('picwall')); | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * @param mixed[] $linksToDisplay List of formatted bookmarks | ||
54 | * | ||
55 | * @return mixed[] Template data after active plugins render_picwall hook execution. | ||
56 | */ | ||
57 | protected function executeHooks(array $linksToDisplay): array | ||
58 | { | ||
59 | $data = [ | ||
60 | 'linksToDisplay' => $linksToDisplay, | ||
61 | ]; | ||
62 | $this->container->pluginManager->executeHooks( | ||
63 | 'render_picwall', | ||
64 | $data, | ||
65 | ['loggedin' => $this->container->loginManager->isLoggedIn()] | ||
66 | ); | ||
67 | |||
68 | return $data; | ||
69 | } | ||
70 | } | ||