diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-06-27 12:08:26 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 6132d64748dfc6806ed25f71d2e078a5ed29d071 (patch) | |
tree | 0b6bdaf5106d7c27daff0cfb2c541dba362e9d1e /application/front/controller/admin | |
parent | 764d34a7d347d653414e5f5c632e02499edaef04 (diff) | |
download | Shaarli-6132d64748dfc6806ed25f71d2e078a5ed29d071.tar.gz Shaarli-6132d64748dfc6806ed25f71d2e078a5ed29d071.tar.zst Shaarli-6132d64748dfc6806ed25f71d2e078a5ed29d071.zip |
Process thumbnail synchronize page through Slim controllers
Diffstat (limited to 'application/front/controller/admin')
-rw-r--r-- | application/front/controller/admin/ConfigureController.php | 2 | ||||
-rw-r--r-- | application/front/controller/admin/ThumbnailsController.php | 79 |
2 files changed, 80 insertions, 1 deletions
diff --git a/application/front/controller/admin/ConfigureController.php b/application/front/controller/admin/ConfigureController.php index 44971c43..201a859b 100644 --- a/application/front/controller/admin/ConfigureController.php +++ b/application/front/controller/admin/ConfigureController.php | |||
@@ -99,7 +99,7 @@ class ConfigureController extends ShaarliAdminController | |||
99 | ) { | 99 | ) { |
100 | $this->saveWarningMessage(t( | 100 | $this->saveWarningMessage(t( |
101 | 'You have enabled or changed thumbnails mode. ' | 101 | 'You have enabled or changed thumbnails mode. ' |
102 | .'<a href="./?do=thumbs_update">Please synchronize them</a>.' | 102 | .'<a href="'. $this->container->basePath .'/admin/thumbnails">Please synchronize them</a>.' |
103 | )); | 103 | )); |
104 | } | 104 | } |
105 | $this->container->conf->set('thumbnails.mode', $thumbnailsMode); | 105 | $this->container->conf->set('thumbnails.mode', $thumbnailsMode); |
diff --git a/application/front/controller/admin/ThumbnailsController.php b/application/front/controller/admin/ThumbnailsController.php new file mode 100644 index 00000000..e5308510 --- /dev/null +++ b/application/front/controller/admin/ThumbnailsController.php | |||
@@ -0,0 +1,79 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Admin; | ||
6 | |||
7 | use Shaarli\Bookmark\Exception\BookmarkNotFoundException; | ||
8 | use Slim\Http\Request; | ||
9 | use Slim\Http\Response; | ||
10 | |||
11 | /** | ||
12 | * Class ToolsController | ||
13 | * | ||
14 | * Slim controller used to handle thumbnails update. | ||
15 | */ | ||
16 | class ThumbnailsController extends ShaarliAdminController | ||
17 | { | ||
18 | /** | ||
19 | * GET /admin/thumbnails - Display thumbnails update page | ||
20 | */ | ||
21 | public function index(Request $request, Response $response): Response | ||
22 | { | ||
23 | $ids = []; | ||
24 | foreach ($this->container->bookmarkService->search() as $bookmark) { | ||
25 | // A note or not HTTP(S) | ||
26 | if ($bookmark->isNote() || !startsWith(strtolower($bookmark->getUrl()), 'http')) { | ||
27 | continue; | ||
28 | } | ||
29 | |||
30 | $ids[] = $bookmark->getId(); | ||
31 | } | ||
32 | |||
33 | $this->assignView('ids', $ids); | ||
34 | $this->assignView( | ||
35 | 'pagetitle', | ||
36 | t('Thumbnails update') .' - '. $this->container->conf->get('general.title', 'Shaarli') | ||
37 | ); | ||
38 | |||
39 | return $response->write($this->render('thumbnails')); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * PATCH /admin/shaare/{id}/thumbnail-update - Route for AJAX calls | ||
44 | */ | ||
45 | public function ajaxUpdate(Request $request, Response $response, array $args): Response | ||
46 | { | ||
47 | $id = $args['id'] ?? null; | ||
48 | |||
49 | if (false === ctype_digit($id)) { | ||
50 | return $response->withStatus(400); | ||
51 | } | ||
52 | |||
53 | try { | ||
54 | $bookmark = $this->container->bookmarkService->get($id); | ||
55 | } catch (BookmarkNotFoundException $e) { | ||
56 | return $response->withStatus(404); | ||
57 | } | ||
58 | |||
59 | $bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl())); | ||
60 | $this->container->bookmarkService->set($bookmark); | ||
61 | |||
62 | return $response->withJson($this->container->formatterFactory->getFormatter('raw')->format($bookmark)); | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * @param mixed[] $data Variables passed to the template engine | ||
67 | * | ||
68 | * @return mixed[] Template data after active plugins render_picwall hook execution. | ||
69 | */ | ||
70 | protected function executeHooks(array $data): array | ||
71 | { | ||
72 | $this->container->pluginManager->executeHooks( | ||
73 | 'render_tools', | ||
74 | $data | ||
75 | ); | ||
76 | |||
77 | return $data; | ||
78 | } | ||
79 | } | ||