2017-02-11 18:32:39 +01:00
--- Shaarli/index.php 2017-01-20 16:47:36.000000000 +0100
2017-05-08 11:54:45 +02:00
+++ index.php 2017-02-11 23:27:22.510042000 +0100
2017-02-11 23:29:37 +01:00
@@ -1821,11 +1821,14 @@
2015-12-27 22:40:58 +01:00
$path = parse_url($url,PHP_URL_PATH);
if ("/talks/" !== substr($path,0,7)) return array(); // This is not a single video URL.
}
+ }
2017-02-11 15:42:02 +01:00
$sign = hash_hmac('sha256', $url, $conf->get('credentials.salt')); // We use the salt to sign data (it's random, secret, and specific to each installation)
- return array('src'=>index_url($_SERVER).'?do=genthumbnail&hmac='.$sign.'&url='.urlencode($url),
2015-12-27 22:40:58 +01:00
+ $thumbname=hash('sha1',$url).'.gif';
2017-02-11 15:42:02 +01:00
+ $filepath = $conf->get('resource.thumbnails_cache').'/'.$thumbname;
2015-12-27 22:40:58 +01:00
+ if (sha1_file($filepath) != '48d45d7ada69f9f858849bbd6e459f66c9694ee7')
2017-02-11 15:42:02 +01:00
+ return array('src'=>index_url($_SERVER).'?do=genthumbnail&hmac='.$sign.'&url='.urlencode($url),
2015-12-27 22:40:58 +01:00
'href'=>$href,'width'=>'120','style'=>'height:auto;','alt'=>'thumbnail');
- }
2017-02-11 18:20:18 +01:00
-
+
2015-12-27 22:40:58 +01:00
// For all other, we try to make a thumbnail of links ending with .jpg/jpeg/png/gif
// Technically speaking, we should download ALL links and check their Content-Type to see if they are images.
2017-02-11 18:20:18 +01:00
// But using the extension will do.
2017-02-11 23:29:37 +01:00
@@ -2154,19 +2157,33 @@
2015-12-27 22:40:58 +01:00
else
{
// For all other domains, we try to download the image and make a thumbnail.
- // We allow 30 seconds max to download (and downloads are limited to 4 Mb)
2017-02-11 15:42:02 +01:00
- list($headers, $content) = get_http_response($url, 30);
2015-12-27 22:40:58 +01:00
- if (strpos($headers[0], '200 OK') !== false) {
2017-02-11 15:42:02 +01:00
- $filepath = $cacheDir .'/'.$thumbname;
- // Save image to cache.
- file_put_contents($filepath, $content);
2015-12-27 22:40:58 +01:00
- if (resizeImage($filepath))
- {
- header('Content-Type: image/jpeg');
- echo file_get_contents($filepath);
- return;
- }
2017-02-11 18:20:18 +01:00
- }
+ list($headers, $content) = get_http_response($url,30); // We allow 30 seconds max to download (and downloads are limited to 4 Mb)
+ if (strpos($headers[0], '200 OK') !== false)
+ {
+ // Extract the link to the thumbnail
+ $doc = new DOMDocument();
+ libxml_use_internal_errors(true);
2017-02-11 18:32:39 +01:00
+ $doc->loadHTML($content);
2017-02-11 18:20:18 +01:00
+ foreach( $doc->getElementsByTagName('meta') as $meta )
+ if ($meta->getAttribute('property') == 'og:image')
+ $imageurl=$meta->getAttribute('content');
+
+ if (!empty($imageurl))
+ { // Let's download the image.
+ list($headers, $content) = get_http_response($imageurl, 20);
+ if (strpos($headers[0], '200 OK') !== false)
+ {
+ $filepath = $conf->get('resource.thumbnails_cache').'/'.$thumbname;
+ file_put_contents($filepath,$content); // Save image to cache.
+ if (resizeImage($filepath))
+ {
+ header('Content-Type: image/jpeg');
+ echo file_get_contents($filepath);
+ return;
+ }
+ }
+ }
+ }
2015-12-27 22:40:58 +01:00
}
2017-02-11 18:20:18 +01:00