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
This commit is contained in:
parent
9b3c1270bc
commit
21e72da9ee
10 changed files with 279 additions and 42 deletions
application/front/controller
|
@ -129,7 +129,8 @@ class ManageShaareController extends ShaarliAdminController
|
|||
$bookmark->setTagsString($request->getParam('lf_tags'));
|
||||
|
||||
if ($this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
|
||||
&& false === $bookmark->isNote()
|
||||
&& true !== $this->container->conf->get('general.enable_async_metadata', true)
|
||||
&& $bookmark->shouldUpdateThumbnail()
|
||||
) {
|
||||
$bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl()));
|
||||
}
|
||||
|
|
|
@ -169,14 +169,11 @@ class BookmarkListController extends ShaarliVisitorController
|
|||
*/
|
||||
protected function updateThumbnail(Bookmark $bookmark, bool $writeDatastore = true): bool
|
||||
{
|
||||
// Logged in, thumbnails enabled, not a note, is HTTP
|
||||
// and (never retrieved yet or no valid cache file)
|
||||
// Logged in, not async retrieval, thumbnails enabled, and thumbnail should be updated
|
||||
if ($this->container->loginManager->isLoggedIn()
|
||||
&& true !== $this->container->conf->get('general.enable_async_metadata', true)
|
||||
&& $this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
|
||||
&& false !== $bookmark->getThumbnail()
|
||||
&& !$bookmark->isNote()
|
||||
&& (null === $bookmark->getThumbnail() || !is_file($bookmark->getThumbnail()))
|
||||
&& startsWith(strtolower($bookmark->getUrl()), 'http')
|
||||
&& $bookmark->shouldUpdateThumbnail()
|
||||
) {
|
||||
$bookmark->setThumbnail($this->container->thumbnailer->get($bookmark->getUrl()));
|
||||
$this->container->bookmarkService->set($bookmark, $writeDatastore);
|
||||
|
@ -198,6 +195,7 @@ class BookmarkListController extends ShaarliVisitorController
|
|||
'page_max' => '',
|
||||
'search_tags' => '',
|
||||
'result_count' => '',
|
||||
'async_metadata' => $this->container->conf->get('general.enable_async_metadata', true)
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue