aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmilien Klein <emilien@klein.st>2012-01-18 21:31:12 +0100
committerEmilien Klein <emilien@klein.st>2012-01-18 21:31:12 +0100
commitc2f6c2680330ad40f80a4cfe68388ece8dd313ec (patch)
treef9c6a66c13a6234563041fb8e7b3964ac2c30496
parent45e88576b3e9658c9f4987d20e2241538b2b5185 (diff)
downloadShaarli-c2f6c2680330ad40f80a4cfe68388ece8dd313ec.tar.gz
Shaarli-c2f6c2680330ad40f80a4cfe68388ece8dd313ec.tar.zst
Shaarli-c2f6c2680330ad40f80a4cfe68388ece8dd313ec.zip
Added: Support for xkcd thumbnails
-rw-r--r--index.php37
1 files changed, 34 insertions, 3 deletions
diff --git a/index.php b/index.php
index 011aeed9..ba3d9c34 100644
--- a/index.php
+++ b/index.php
@@ -1484,12 +1484,14 @@ function thumbnail($url,$href=false)
1484 if ($domain=='flickr.com' || endsWith($domain,'.flickr.com') 1484 if ($domain=='flickr.com' || endsWith($domain,'.flickr.com')
1485 || $domain=='vimeo.com' 1485 || $domain=='vimeo.com'
1486 || $domain=='ted.com' || endsWith($domain,'.ted.com') 1486 || $domain=='ted.com' || endsWith($domain,'.ted.com')
1487 || $domain=='xkcd.com' || endsWith($domain,'.xkcd.com')
1487 ) 1488 )
1488 { 1489 {
1489 if ($domain=='vimeo.com') 1490 if ($domain=='vimeo.com' || $domain=='xkcd.com' || endsWith($domain,'.xkcd.com'))
1490 { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric) 1491 { // Make sure the url is of the form /xxx... where xxx is numeric
1492 // For Vimeo's videos and xkcd's comics
1491 $path = parse_url($url,PHP_URL_PATH); 1493 $path = parse_url($url,PHP_URL_PATH);
1492 if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL. 1494 if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video/comic URL.
1493 } 1495 }
1494 if ($domain=='ted.com' || endsWith($domain,'.ted.com')) 1496 if ($domain=='ted.com' || endsWith($domain,'.ted.com'))
1495 { // Make sure this TED url points to a video (/talks/...) 1497 { // Make sure this TED url points to a video (/talks/...)
@@ -1797,6 +1799,35 @@ function genThumbnail()
1797 } 1799 }
1798 } 1800 }
1799 1801
1802 elseif ($domain=='xkcd.com' || endsWith($domain,'.xkcd.com'))
1803 {
1804 // There is no thumbnail available for xkcd comics, so download the whole image and resize it.
1805 // http://xkcd.com/327/
1806 // <img src="http://imgs.xkcd.com/comics/exploits_of_a_mom.png" title="<BLABLA>" alt="<BLABLA>" />
1807 list($httpstatus,$headers,$data) = getHTTP($url,5);
1808 if (strpos($httpstatus,'200 OK')!==false)
1809 {
1810 // Extract the link to the thumbnail
1811 preg_match('!<img src="(http://imgs.xkcd.com/comics/.*)" title="[^s]!',$data,$matches);
1812 if (!empty($matches[1]))
1813 { // Let's download the image.
1814 $imageurl=$matches[1];
1815 list($httpstatus,$headers,$data) = getHTTP($imageurl,20); // No control on image size, so wait long enough.
1816 if (strpos($httpstatus,'200 OK')!==false)
1817 {
1818 $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$thumbname;
1819 file_put_contents($filepath,$data); // Save image to cache.
1820 if (resizeImage($filepath))
1821 {
1822 header('Content-Type: image/jpeg');
1823 echo file_get_contents($filepath);
1824 return;
1825 }
1826 }
1827 }
1828 }
1829 }
1830
1800 else 1831 else
1801 { 1832 {
1802 // For all other domains, we try to download the image and make a thumbnail. 1833 // For all other domains, we try to download the image and make a thumbnail.