Skip to content

Commit

Permalink
Use web-thumbnailer to retrieve thumbnails
Browse files Browse the repository at this point in the history
  * requires PHP 5.6
  * use blazy on linklist since a lot more thumbs are retrieved
  * thumbnails can be disabled
  * thumbs size is now 120x120
  * thumbs are now cropped to fit the expected size

Fixes shaarli#345 shaarli#425 shaarli#487 shaarli#543 shaarli#588 shaarli#590
  • Loading branch information
ArthurHoaro committed Nov 17, 2017
1 parent 844be5d commit 9ef1d57
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 432 deletions.
5 changes: 5 additions & 0 deletions application/PageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ private function initialize()
if ($this->linkDB !== null) {
$this->tpl->assign('tags', $this->linkDB->linksCountPerTag());
}

$this->tpl->assign('thumbnails_enabled', $this->conf->get('thumbnails.enabled'));
$this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width'));
$this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height'));

// To be removed with a proper theme configuration.
$this->tpl->assign('conf', $this->conf);
}
Expand Down
49 changes: 49 additions & 0 deletions application/Thumbnailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

use WebThumbnailer\WebThumbnailer;

/**
* Class Thumbnailer
*
* Utility class used to retrieve thumbnails using web-thumbnailer dependency.
*/
class Thumbnailer
{
/**
* @var WebThumbnailer instance.
*/
protected $wt;

/**
* @var ConfigManager instance.
*/
protected $conf;

/**
* Thumbnailer constructor.
*
* @param ConfigManager $conf instance.
*/
public function __construct($conf)
{
$this->conf = $conf;
$this->wt = new WebThumbnailer();
\WebThumbnailer\Application\ConfigManager::addFile('inc/web-thumbnailer.json');
$this->wt->maxWidth($this->conf->get('thumbnails.width'))
->maxHeight($this->conf->get('thumbnails.height'))
->crop(true)
->debug($this->conf->get('dev.debug', false));
}

/**
* Retrieve a thumbnail for given URL
*
* @param string $url where to look for a thumbnail.
*
* @return bool|string The thumbnail relative cache file path, or false if none has been found.
*/
public function get($url)
{
return $this->wt->thumbnail($url);
}
}
4 changes: 4 additions & 0 deletions application/config/ConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ protected function setDefaultValues()
$this->setEmpty('general.enabled_plugins', self::$DEFAULT_PLUGINS);
$this->setEmpty('general.default_note_title', 'Note: ');

$this->setEmpty('thumbnails.enabled', true);
$this->setEmpty('thumbnails.width', 120);
$this->setEmpty('thumbnails.height', 120);

$this->setEmpty('updates.check_updates', false);
$this->setEmpty('updates.check_updates_branch', 'stable');
$this->setEmpty('updates.check_updates_interval', 86400);
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"keywords": ["bookmark", "link", "share", "web"],
"config": {
"platform": {
"php": "5.5.38"
"php": "5.6.32"
}
},
"require": {
"php": ">=5.5",
"php": ">=5.6",
"shaarli/netscape-bookmark-parser": "^2.0",
"erusev/parsedown": "1.6",
"slim/slim": "^3.0",
"arthurhoaro/web-thumbnailer": "dev-master",
"pubsubhubbub/publisher": "dev-master",
"gettext/gettext": "^4.4"
},
Expand Down
9 changes: 9 additions & 0 deletions inc/web-thumbnailer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"settings": {
"default": {
"_comment": "infinite cache",
"cache_duration": -1,
"timeout": 60
}
}
}
Loading

0 comments on commit 9ef1d57

Please sign in to comment.