diff options
author | Emilien Klein <emilien@klein.st> | 2011-11-19 13:53:55 +0100 |
---|---|---|
committer | Emilien Klein <emilien@klein.st> | 2011-11-19 13:53:55 +0100 |
commit | c4c9c4140d16e7e88ddc64c5c3b8fd6e17b74a05 (patch) | |
tree | 45d1af9a495fba882bad2e4e7bf3bcd93d9b5cd8 /index.php | |
parent | 05f41b062a76238545ace056fc1cab9acd1deb1a (diff) | |
download | Shaarli-c4c9c4140d16e7e88ddc64c5c3b8fd6e17b74a05.tar.gz Shaarli-c4c9c4140d16e7e88ddc64c5c3b8fd6e17b74a05.tar.zst Shaarli-c4c9c4140d16e7e88ddc64c5c3b8fd6e17b74a05.zip |
Corrected: Better error handling in thumbnail generation
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -1868,7 +1868,7 @@ function genThumbnail() | |||
1868 | } | 1868 | } |
1869 | } | 1869 | } |
1870 | 1870 | ||
1871 | if ($domain=='vimeo.com' ) | 1871 | elseif ($domain=='vimeo.com' ) |
1872 | { | 1872 | { |
1873 | // This is more complex: we have to perform a HTTP request, then parse the result. | 1873 | // This is more complex: we have to perform a HTTP request, then parse the result. |
1874 | // Maybe we should deport this to javascript ? Example: http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo/4285098#4285098 | 1874 | // Maybe we should deport this to javascript ? Example: http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo/4285098#4285098 |
@@ -1890,7 +1890,7 @@ function genThumbnail() | |||
1890 | } | 1890 | } |
1891 | } | 1891 | } |
1892 | 1892 | ||
1893 | if ($domain=='ted.com' || endsWith($domain,'.ted.com')) | 1893 | elseif ($domain=='ted.com' || endsWith($domain,'.ted.com')) |
1894 | { | 1894 | { |
1895 | // The thumbnail for TED talks is located in the <link rel="image_src" [...]> tag on that page | 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 | 1896 | // http://www.ted.com/talks/mikko_hypponen_fighting_viruses_defending_the_net.html |
@@ -1919,19 +1919,22 @@ function genThumbnail() | |||
1919 | } | 1919 | } |
1920 | } | 1920 | } |
1921 | 1921 | ||
1922 | // For all other domains, we try to download the image and make a thumbnail. | 1922 | else |
1923 | list($httpstatus,$headers,$data) = getHTTP($url,30); // We allow 30 seconds max to download (and downloads are limited to 4 Mb) | ||
1924 | if (strpos($httpstatus,'200 OK')!==false) | ||
1925 | { | 1923 | { |
1926 | $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$thumbname; | 1924 | // For all other domains, we try to download the image and make a thumbnail. |
1927 | file_put_contents($filepath,$data); // Save image to cache. | 1925 | list($httpstatus,$headers,$data) = getHTTP($url,30); // We allow 30 seconds max to download (and downloads are limited to 4 Mb) |
1928 | if (resizeImage($filepath)) | 1926 | if (strpos($httpstatus,'200 OK')!==false) |
1929 | { | 1927 | { |
1930 | header('Content-Type: image/jpeg'); | 1928 | $filepath=$GLOBALS['config']['CACHEDIR'].'/'.$thumbname; |
1931 | echo file_get_contents($filepath); | 1929 | file_put_contents($filepath,$data); // Save image to cache. |
1932 | return; | 1930 | if (resizeImage($filepath)) |
1931 | { | ||
1932 | header('Content-Type: image/jpeg'); | ||
1933 | echo file_get_contents($filepath); | ||
1934 | return; | ||
1935 | } | ||
1933 | } | 1936 | } |
1934 | } | 1937 | } |
1935 | 1938 | ||
1936 | 1939 | ||
1937 | // Otherwise, return an empty image (8x8 transparent gif) | 1940 | // Otherwise, return an empty image (8x8 transparent gif) |