aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorEmilien Klein <emilien@klein.st>2011-11-19 13:51:57 +0100
committerEmilien Klein <emilien@klein.st>2011-11-19 13:51:57 +0100
commit05f41b062a76238545ace056fc1cab9acd1deb1a (patch)
treec43463e25140e1f54fc53ea2c27a2aad3285720d /index.php
parent751aaefec215e9e55d0fb4d5e4c25f398c3cc8d3 (diff)
downloadShaarli-05f41b062a76238545ace056fc1cab9acd1deb1a.tar.gz
Shaarli-05f41b062a76238545ace056fc1cab9acd1deb1a.tar.zst
Shaarli-05f41b062a76238545ace056fc1cab9acd1deb1a.zip
Added: Support for TED Talks (ted.com/talks) thumbnails
Diffstat (limited to 'index.php')
-rw-r--r--index.php41
1 files changed, 39 insertions, 2 deletions
diff --git a/index.php b/index.php
index 88be084b..d9692927 100644
--- a/index.php
+++ b/index.php
@@ -1515,13 +1515,21 @@ function thumbnail($url,$href=false)
1515 1515
1516 if (!$GLOBALS['config']['ENABLE_LOCALCACHE']) return ''; // If local cache is disabled, no thumbnails for services which require the use a local cache. 1516 if (!$GLOBALS['config']['ENABLE_LOCALCACHE']) return ''; // If local cache is disabled, no thumbnails for services which require the use a local cache.
1517 1517
1518 if ($domain=='flickr.com' || endsWith($domain,'.flickr.com') || $domain=='vimeo.com') 1518 if ($domain=='flickr.com' || endsWith($domain,'.flickr.com')
1519 || $domain=='vimeo.com'
1520 || $domain=='ted.com' || endsWith($domain,'.ted.com')
1521 )
1519 { 1522 {
1520 if ($domain=='vimeo.com') 1523 if ($domain=='vimeo.com')
1521 { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric) 1524 { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric)
1522 $path = parse_url($url,PHP_URL_PATH); 1525 $path = parse_url($url,PHP_URL_PATH);
1523 if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL. 1526 if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL.
1524 } 1527 }
1528 if ($domain=='ted.com' || endsWith($domain,'.ted.com'))
1529 { // Make sure this TED url points to a video (/talks/...)
1530 $path = parse_url($url,PHP_URL_PATH);
1531 if ("/talks/" !== substr($path,0,7)) return ''; // This is not a single video URL.
1532 }
1525 $sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation) 1533 $sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation)
1526 return '<a href="'.htmlspecialchars($href).'"><img src="?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url).'" width="120" style="height:auto;"></a>'; 1534 return '<a href="'.htmlspecialchars($href).'"><img src="?do=genthumbnail&hmac='.htmlspecialchars($sign).'&url='.urlencode($url).'" width="120" style="height:auto;"></a>';
1527 } 1535 }
@@ -1881,6 +1889,35 @@ function genThumbnail()
1881 } 1889 }
1882 } 1890 }
1883 } 1891 }
1892
1893 if ($domain=='ted.com' || endsWith($domain,'.ted.com'))
1894 {
1895 // The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page
1896 // http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html
1897 // <link rel="image_src" href="http://images.ted.com/images/ted/28bced335898ba54d4441809c5b1112ffaf36781_389x292.jpg" />
1898 list($httpstatus,$headers,$data) = getHTTP($url,5);
1899 if (strpos($httpstatus,'200 OK')!==false)
1900 {
1901 // Extract the link to the thumbnail
1902 preg_match('!link rel="image_src" href="(http://images.ted.com/images/ted/.+_\d+x\d+\.jpg)[^s]!',$data,$matches);
1903 if (!empty($matches[1]))
1904 { // Let's download the image.
1905 $imageurl=$matches[1];
1906 list($httpstatus,$headers,$data) = getHTTP($imageurl,20); // No control on image size, so wait long enough.
1907 if (strpos($httpstatus,'200 OK')!==false)
1908 {
1909 $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$thumbname;
1910 file_put_contents($filepath,$data); // Save image to cache.
1911 if (resizeImage($filepath))
1912 {
1913 header('Content-Type: image/jpeg');
1914 echo file_get_contents($filepath);
1915 return;
1916 }
1917 }
1918 }
1919 }
1920 }
1884 1921
1885 // For all other domains, we try to download the image and make a thumbnail. 1922 // For all other domains, we try to download the image and make a thumbnail.
1886 list($httpstatus,$headers,$data) = getHTTP($url,30); // We allow 30 seconds max to download (and downloads are limited to 4 Mb) 1923 list($httpstatus,$headers,$data) = getHTTP($url,30); // We allow 30 seconds max to download (and downloads are limited to 4 Mb)
@@ -1950,4 +1987,4 @@ if (!isset($_SESSION['LINKS_PER_PAGE'])) $_SESSION['LINKS_PER_PAGE']=$GLOBALS['c
1950if (startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; } 1987if (startswith($_SERVER["QUERY_STRING"],'do=rss')) { showRSS(); exit; }
1951if (startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; } 1988if (startswith($_SERVER["QUERY_STRING"],'do=atom')) { showATOM(); exit; }
1952renderPage(); 1989renderPage();
1953?> \ No newline at end of file 1990?>