Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use web-thumbnailer to retrieve thumbnails #687

Merged
merged 9 commits into from
Jul 28, 2018

Conversation

ArthurHoaro
Copy link
Member

@ArthurHoaro ArthurHoaro commented Nov 9, 2016

Disclaimer:

Hi guys! I've tried to refactor thumbnails, and then end up writing web-thumbnailer. It goes a bit beyond Shaarli needs but I still think we could use it as a dependency to retrieve thumbnail - see the readme for more info.

This PR shows how to integrate web-thumbnailer within Shaarli. So, what changes:

  • a lot more thumbnails are retrieved
  • use blazy on linklist to lazy load images
  • thumbnails can be disabled
  • thumbs size is now 120x120
  • thumbs are now cropped to fit the expected size
  • again, requires PHP 5.6

Fixes #345 #425 #487 #543 #588 #590

PS: a few things still need to be fixed, like a release on the WT repo.

EDIT: Fixes #712 - all thumbnails are now cached, no more hotlinking.
Fixes #1056

@ArthurHoaro ArthurHoaro added 3rd party interoperability with third-party platforms discussion feedback needed in progress template HTML rendering thumbnail media thumbnails labels Nov 9, 2016
@ArthurHoaro ArthurHoaro added this to the 0.10.0 milestone Nov 9, 2016
@ArthurHoaro ArthurHoaro self-assigned this Nov 9, 2016
@nodiscc
Copy link
Member

nodiscc commented Nov 11, 2016

I have just read the patch comments, had a quick look at the implementation in Shaarli, and at the readme in https://github.com/ArthurHoaro/web-thumbnailer, and I would very much welcome this change. Lacking time to do a full code review though :/

Thanks

@kalvn
Copy link

kalvn commented Nov 2, 2017

May I suggest to add a way for templates to retrieve thumbnails direct URL? Or an array with several useful parameters such as what computeThumbnail() function does.

@ArthurHoaro
Copy link
Member Author

@kalvn What's your use case?

@kalvn
Copy link

kalvn commented Nov 3, 2017

@ArthurHoaro the idea would be to allow more flexibility in the way templates display the thumbnail (with background-image instead of for example). The current way is a bit rigid.

@ArthurHoaro ArthurHoaro force-pushed the web-thumb branch 5 times, most recently from 97db222 to 9b49f9b Compare November 11, 2017 15:42
@ArthurHoaro
Copy link
Member Author

@kalvn Each links will have a thumbnail field containing the thumbnail URL, or false if there isn't any.

PR updated and ready for v0.10!

@@ -321,8 +321,8 @@ window.onload = function () {
/**
* bLazy trigger
*/
var picwall = document.getElementById('picwall_container');
if (picwall != null) {
var blazyElements = document.getElementsByClassName('.b-lazy');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know... I've used it multiple times in this file.


$this->thumbnailer = new Thumbnailer($conf);
// cache files in the sandbox
\WebThumbnailer\Application\ConfigManager::addFile('tests/utils/config/wt.json');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should use a use keyword? like you do in ConfigManager

@nodiscc
Copy link
Member

nodiscc commented Nov 13, 2017

Each links will have a thumbnail field containing the thumbnail URL, or false if there isn't any.

Very nice.

created (??)
description (string)
id (integer)
private (boolean)
shorturl (string, 6-char long)
tags (array of strings)
title (string)
updated (???)
url (string)

add thumbnails to that.

@ArthurHoaro
Copy link
Member Author

@nodiscc Good idea, I'll add that. And dates are now stored as DateTime objects.

index.php Outdated
@@ -768,22 +769,51 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager)
// -------- Picture wall
if ($targetPage == Router::$PAGE_PICWALL)
{
if (! $conf->get('thumbnails.enabled')) {
header('Location: ?');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe display a warning message to the user Picture wall unavailable (thumbnails are disabled). Or even better, hide the Picture wall button from the toolbar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I did both.

@ArthurHoaro
Copy link
Member Author

ArthurHoaro commented Jul 5, 2018

I think I'm good here. I've:

  • Fixed the issue with Apache userdir
  • Auto-generate a .htaccess file in thumbs/ cache folder which grants direct access
  • Move the sync to a dedicated page through AJAX requests (the picwall no longer trigger retrieval)
  • Added a common mode which only retrieve thumbs from a list of websites
  • Rebased the branch

As usual, clear the cache folder to test it. Regarding the milestone, since we didn't released v0.10 yet, maybe we can merge it before (depending on the feedback review of course).

EDIT: if you already ran the updater with previous commits, you might need to remove thumbnails section from the config file also.

@virtualtam
Copy link
Member

Neat, I'll test it to(day|morrow) :)

@virtualtam
Copy link
Member

virtualtam commented Jul 10, 2018

Currently testing :)

  • thumbs are correctly displayed when serving in a user-specific path (http://domain.tld/~user/shaarli)
  • the new option to define which thumbnails are fetched is convenient, maybe it should default to "Only common media hosts" to stay consistent with the current behaviour
  • the thumbnail update page is a nice addition, that should appear more prominently:
    • as a button in the Tools page (I actually missed it in its current form :p )
    • as a button in the Picture Wall page if the picture cache is empty
  • the thumbnails seem to be fetched only when browsing the linklist; browsing the picture wall has no effect

The following is most likely due to removing the thumbnails section under data/config.json.php:

  • the Picture Wall looks nicer with square thumbnails
  • on the linklist, the thumbnail div does not respect its parent container's geometry, see screenshot below:
    thumb-size

Here is the resulting configuration section, I think it misses the width/height settings:

    "thumbnails": {
        "mode": "common"
    }

@ArthurHoaro
Copy link
Member Author

the new option to define which thumbnails are fetched is convenient, maybe it should default to "Only common media hosts" to stay consistent with the current behaviour

I'm not sure. The goal behind this PR, beside having a cleaner solution, is to provide a more complete feature. I feel like this option is nice to have for people who want a lighter solution, but displaying thumbnails for any website which provides an OpenGraph image is a good default option.

I don't really know what users would prefer, and this can easily be changed though, so any other opinion is welcome here.

the thumbnail update page is a nice addition, that should appear more prominently

It should display a big pure-alert warning when you run the update or change the setting.

as a button in the Tools page (I actually missed it in its current form :p )
as a button in the Picture Wall page if the picture cache is empty

Sure, I'll add those.

For the last part:

  • I'll check the size settings update. I believe I never reset them after the update. And you probably already ran the update during your previous tests.
  • I'll fix the CSS issue if the thumb is too high.

Thanks again for the quick test 👍

index.php Outdated
$thumbnailsMode = extension_loaded('gd') ? $_POST['enableThumbnails'] : Thumbnailer::MODE_NONE;
if ($conf->get('thumbnails.enabled', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE) {
$_SESSION['warnings'][] = t(
'You have enabled or changed thumbnails mode. <a href="?do=thumbs_update">Please synchonize them</a>.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/synchonize/synchronize

{
"settings": {
"default": {
"download_mode": "HOTLINK",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not set the download mode to DOWNLOAD ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, there was actually an issue with WT where this setting would be ignored.

  - add a default thumb size value (125x90px)
  - improve private vertical bar visual, especially with thumbnails
  - translations
  - add a sync thumbs button in tool and empty picwall page
  - fixes WT download mode in JSON config
@ArthurHoaro
Copy link
Member Author

Bunch of improvements for thumbnails integration:

  • add a default thumb size value (125x90px)
  • improve private vertical bar visual, especially with thumbnails
  • translations
  • add a sync thumbs button in tool and empty picwall page
  • fixes WT download mode in JSON config

I've changed a bit the way the orange bar for private links is displayed, mostly because it was truncated with floating thumbnails and no description. I went for an easier solution, and IMO it looks better. Example:

Copy link
Member

@virtualtam virtualtam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @ArthurHoaro 🎉

Thumbnail generation and display went smoothly, I think we can merge this PR and handle improvements in future issues/PRs

@ArthurHoaro
Copy link
Member Author

Thank you @virtualtam and everyone for your time and reviews on this looong PR. Let's merge it! 🎉

@nicolasdanelon
Copy link

nicolasdanelon commented Jul 30, 2018

hi, I have a problem with thumbnails..

my list of links and the detail of a link refers to public_html/links/cache/thumb/14dd5266c70789bdc806364df4586335/3a9726225cd4ed259458afa90126bb1509eea4a01259010.jpg

the link should be links/cache/thumb/14dd5266c70789bdc806364df4586335/3a9726225cd4ed259458afa90126bb1509eea4a01259010.jpg

my shaarli is updated like this

$ cd /home/username/public_html/links
$ git checkout master
$ git pull --prune
$ composer install --no-dev --prefer-dist
$ yarn install
$ yarn run build

nginx  1.12.1
php-fpm 5.6.36-1

$ node -v
v6.14.2
$ yarn -v
1.9.2
$ npm -v
3.10.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party interoperability with third-party platforms documentation in review template HTML rendering thumbnail media thumbnails
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More options for theming picwall page Option to block non-https thumbnails Refactor thumbnail functions
5 participants