scripts/shaarli_OleG.0.8.3.patch

67 lines
2.9 KiB
Diff

--- Shaarli/index.php 2017-01-20 16:47:36.000000000 +0100
+++ /home/www/beta/Shaarli/index.php 2017-02-11 23:27:22.510042000 +0100
@@ -1821,11 +1821,14 @@
$path = parse_url($url,PHP_URL_PATH);
if ("/talks/" !== substr($path,0,7)) return array(); // This is not a single video URL.
}
+ }
$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),
+ $thumbname=hash('sha1',$url).'.gif';
+ $filepath = $conf->get('resource.thumbnails_cache').'/'.$thumbname;
+ if (sha1_file($filepath) != '48d45d7ada69f9f858849bbd6e459f66c9694ee7')
+ return array('src'=>index_url($_SERVER).'?do=genthumbnail&hmac='.$sign.'&url='.urlencode($url),
'href'=>$href,'width'=>'120','style'=>'height:auto;','alt'=>'thumbnail');
- }
-
+
// 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.
// But using the extension will do.
@@ -2154,19 +2157,33 @@
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)
- list($headers, $content) = get_http_response($url, 30);
- if (strpos($headers[0], '200 OK') !== false) {
- $filepath = $cacheDir .'/'.$thumbname;
- // Save image to cache.
- file_put_contents($filepath, $content);
- if (resizeImage($filepath))
- {
- header('Content-Type: image/jpeg');
- echo file_get_contents($filepath);
- return;
- }
- }
+ 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);
+ $doc->loadHTML($content);
+ 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;
+ }
+ }
+ }
+ }
}