aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-15 11:46:24 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-20 10:15:18 +0200
commit21e72da9ee34cec56b10c83ae0c75b4bf320dfcb (patch)
treeb6c0b8208f004e1b2b37b1af54e8d4c40310d56e /application
parent9b3c1270bcbe4f8e30e0160da8badd43dd94871a (diff)
downloadShaarli-21e72da9ee34cec56b10c83ae0c75b4bf320dfcb.tar.gz
Shaarli-21e72da9ee34cec56b10c83ae0c75b4bf320dfcb.tar.zst
Shaarli-21e72da9ee34cec56b10c83ae0c75b4bf320dfcb.zip
Asynchronous retrieval of bookmark's thumbnails
This feature is based general.enable_async_metadata setting and works with existing metadata.js file. The script is compatible with any template: - the thumbnail div bloc must have attribute - the bookmark bloc must have attribute with the bookmark ID as value Fixes #1564
Diffstat (limited to 'application')
-rw-r--r--application/bookmark/Bookmark.php18
-rw-r--r--application/front/controller/admin/ManageShaareController.php3
-rw-r--r--application/front/controller/visitor/BookmarkListController.php10
3 files changed, 24 insertions, 7 deletions
diff --git a/application/bookmark/Bookmark.php b/application/bookmark/Bookmark.php
index ea565d1f..4810c5e6 100644
--- a/application/bookmark/Bookmark.php
+++ b/application/bookmark/Bookmark.php
@@ -378,6 +378,24 @@ class Bookmark
378 } 378 }
379 379
380 /** 380 /**
381 * Return true if:
382 * - the bookmark's thumbnail is not already set to false (= not found)
383 * - it's not a note
384 * - it's an HTTP(S) link
385 * - the thumbnail has not yet be retrieved (null) or its associated cache file doesn't exist anymore
386 *
387 * @return bool True if the bookmark's thumbnail needs to be retrieved.
388 */
389 public function shouldUpdateThumbnail(): bool
390 {
391 return $this->thumbnail !== false
392 && !$this->isNote()
393 && startsWith(strtolower($this->url), 'http')
394 && (null === $this->thumbnail || !is_file($this->thumbnail))
395 ;
396 }
397
398 /**
381 * Get the Sticky. 399 * Get the Sticky.
382 * 400 *
383 * @return bool 401 * @return bool
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php
index df2f1631..908ebae3 100644
--- a/application/front/controller/admin/ManageShaareController.php
+++ b/application/front/controller/admin/ManageShaareController.php
@@ -129,7 +129,8 @@ class ManageShaareController extends ShaarliAdminController
129 $bookmark->setTagsString($request->getParam('lf_tags')); 129 $bookmark->setTagsString($request->getParam('lf_tags'));
130 130
131 if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE 131 if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
132 && false === $bookmark->isNote() 132 && true !== $this->container->conf->get('general.enable_async_metadata', true)
133 && $bookmark->shouldUpdateThumbnail()
133 ) { 134 ) {
134 $bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl())); 135 $bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl()));
135 } 136 }
diff --git a/application/front/controller/visitor/BookmarkListController.php b/application/front/controller/visitor/BookmarkListController.php
index 18368751..a8019ead 100644
--- a/application/front/controller/visitor/BookmarkListController.php
+++ b/application/front/controller/visitor/BookmarkListController.php
@@ -169,14 +169,11 @@ class BookmarkListController extends ShaarliVisitorController
169 */ 169 */
170 protected function updateThumbnail(Bookmark $bookmark, bool $writeDatastore = true): bool 170 protected function updateThumbnail(Bookmark $bookmark, bool $writeDatastore = true): bool
171 { 171 {
172 // Logged in, thumbnails enabled, not a note, is HTTP 172 // Logged in, not async retrieval, thumbnails enabled, and thumbnail should be updated
173 // and (never retrieved yet or no valid cache file)
174 if ($this->container->loginManager->isLoggedIn() 173 if ($this->container->loginManager->isLoggedIn()
174 && true !== $this->container->conf->get('general.enable_async_metadata', true)
175 && $this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE 175 && $this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
176 && false !== $bookmark->getThumbnail() 176 && $bookmark->shouldUpdateThumbnail()
177 && !$bookmark->isNote()
178 && (null === $bookmark->getThumbnail() || !is_file($bookmark->getThumbnail()))
179 && startsWith(strtolower($bookmark->getUrl()), 'http')
180 ) { 177 ) {
181 $bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl())); 178 $bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl()));
182 $this->container->bookmarkService->set($bookmark, $writeDatastore); 179 $this->container->bookmarkService->set($bookmark, $writeDatastore);
@@ -198,6 +195,7 @@ class BookmarkListController extends ShaarliVisitorController
198 'page_max' => '', 195 'page_max' => '',
199 'search_tags' => '', 196 'search_tags' => '',
200 'result_count' => '', 197 'result_count' => '',
198 'async_metadata' => $this->container->conf->get('general.enable_async_metadata', true)
201 ]; 199 ];
202 } 200 }
203 201