From 8879590cb5fd26fbcb0f9e883d29dfb22efa28ad Mon Sep 17 00:00:00 2001 From: n Date: Sun, 27 Dec 2015 22:40:58 +0100 Subject: [PATCH] open graph support for shaarli --- shaarli_oleg.patch | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 shaarli_oleg.patch diff --git a/shaarli_oleg.patch b/shaarli_oleg.patch new file mode 100644 index 0000000..3fd1aa3 --- /dev/null +++ b/shaarli_oleg.patch @@ -0,0 +1,63 @@ +diff --git index.php index.php +index 40a6fbe..2e1117a 100644 +--- index.php ++++ index.php +@@ -2087,10 +2087,14 @@ function computeThumbnail($url,$href=false) + $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, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation) ++ $thumbname=hash('sha1',$url).'.gif'; ++ $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$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. +@@ -2400,18 +2404,30 @@ function genThumbnail() + 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, $data) = get_http_url($url, 30); +- if (strpos($headers[0], '200 OK') !== false) { +- $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$thumbname; +- file_put_contents($filepath,$data); // Save image to cache. +- if (resizeImage($filepath)) +- { +- header('Content-Type: image/jpeg'); +- echo file_get_contents($filepath); +- return; +- } +- } ++ list($httpstatus,$headers,$data) = get_http_url($url,30); // We allow 30 seconds max to download (and downloads are limited to 4 Mb) ++ // Extract the link to the thumbnail ++ $doc = new DOMDocument(); ++ libxml_use_internal_errors(true); ++ $doc->loadHTML($data); ++ 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($httpstatus,$headers,$data) = get_http_url($imageurl,20); // No control on image size, so wait long enough. ++ if (strpos($httpstatus,'200 OK')!==false) ++ { ++ $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$thumbname; ++ file_put_contents($filepath,$data); // Save image to cache. ++ if (resizeImage($filepath)) ++ { ++ header('Content-Type: image/jpeg'); ++ echo file_get_contents($filepath); ++ return; ++ } ++ } ++ } ++ + } + +