aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-06-27 12:08:26 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit6132d64748dfc6806ed25f71d2e078a5ed29d071 (patch)
tree0b6bdaf5106d7c27daff0cfb2c541dba362e9d1e /application
parent764d34a7d347d653414e5f5c632e02499edaef04 (diff)
downloadShaarli-6132d64748dfc6806ed25f71d2e078a5ed29d071.tar.gz
Shaarli-6132d64748dfc6806ed25f71d2e078a5ed29d071.tar.zst
Shaarli-6132d64748dfc6806ed25f71d2e078a5ed29d071.zip
Process thumbnail synchronize page through Slim controllers
Diffstat (limited to 'application')
-rw-r--r--application/Thumbnailer.php3
-rw-r--r--application/front/controller/admin/ConfigureController.php2
-rw-r--r--application/front/controller/admin/ThumbnailsController.php79
-rw-r--r--application/legacy/LegacyUpdater.php2
4 files changed, 82 insertions, 4 deletions
diff --git a/application/Thumbnailer.php b/application/Thumbnailer.php
index 314baf0d..5aec23c8 100644
--- a/application/Thumbnailer.php
+++ b/application/Thumbnailer.php
@@ -4,7 +4,6 @@ namespace Shaarli;
4 4
5use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6use WebThumbnailer\Application\ConfigManager as WTConfigManager; 6use WebThumbnailer\Application\ConfigManager as WTConfigManager;
7use WebThumbnailer\Exception\WebThumbnailerException;
8use WebThumbnailer\WebThumbnailer; 7use WebThumbnailer\WebThumbnailer;
9 8
10/** 9/**
@@ -90,7 +89,7 @@ class Thumbnailer
90 89
91 try { 90 try {
92 return $this->wt->thumbnail($url); 91 return $this->wt->thumbnail($url);
93 } catch (WebThumbnailerException $e) { 92 } catch (\Throwable $e) {
94 // Exceptions are only thrown in debug mode. 93 // Exceptions are only thrown in debug mode.
95 error_log(get_class($e) . ': ' . $e->getMessage()); 94 error_log(get_class($e) . ': ' . $e->getMessage());
96 } 95 }
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
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Admin;
6
7use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class ToolsController
13 *
14 * Slim controller used to handle thumbnails update.
15 */
16class 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}
diff --git a/application/legacy/LegacyUpdater.php b/application/legacy/LegacyUpdater.php
index 8d5cd071..cbf6890f 100644
--- a/application/legacy/LegacyUpdater.php
+++ b/application/legacy/LegacyUpdater.php
@@ -534,7 +534,7 @@ class LegacyUpdater
534 534
535 if ($thumbnailsEnabled) { 535 if ($thumbnailsEnabled) {
536 $this->session['warnings'][] = t( 536 $this->session['warnings'][] = t(
537 'You have enabled or changed thumbnails mode. <a href="./?do=thumbs_update">Please synchronize them</a>.' 537 'You have enabled or changed thumbnails mode. <a href="./admin/thumbnails">Please synchronize them</a>.'
538 ); 538 );
539 } 539 }
540 540