+ elseif ($domain=='xkcd.com' || endsWith($domain,'.xkcd.com'))
+ {
+ // There is no thumbnail available for xkcd comics, so download the whole image and resize it.
+ // http://xkcd.com/327/
+ // <img src="http://imgs.xkcd.com/comics/exploits_of_a_mom.png" title="<BLABLA>" alt="<BLABLA>" />
+ list($httpstatus,$headers,$data) = getHTTP($url,5);
+ if (strpos($httpstatus,'200 OK')!==false)
+ {
+ // Extract the link to the thumbnail
+ preg_match('!<img src="(http://imgs.xkcd.com/comics/.*)" title="[^s]!',$data,$matches);
+ if (!empty($matches[1]))
+ { // Let's download the image.
+ $imageurl=$matches[1];
+ list($httpstatus,$headers,$data) = getHTTP($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;
+ }
+ }
+ }
+ }
+ }
+