From: Andrew Dolgov Date: Mon, 13 Feb 2017 12:25:52 +0000 (+0300) Subject: af_zz_imgproxy: show GD-based (if possible) error message on proxy failure X-Git-Tag: 17.4~35 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=bf6398650a7956a84418c216f0876c0e35d8e56c;p=tt-rss.git af_zz_imgproxy: show GD-based (if possible) error message on proxy failure --- diff --git a/plugins/af_zz_imgproxy/init.php b/plugins/af_zz_imgproxy/init.php index 047f5a21..07177bb7 100644 --- a/plugins/af_zz_imgproxy/init.php +++ b/plugins/af_zz_imgproxy/init.php @@ -63,7 +63,7 @@ class Af_Zz_ImgProxy extends Plugin { readfile($local_filename); } else { - $data = fetch_file_contents(array("url" => $url)); + $data = fetch_file_contents(array("url" => $url, "useragent" => "Mozilla/5.0")); if ($data) { if (file_put_contents($local_filename, $data)) { @@ -72,6 +72,37 @@ class Af_Zz_ImgProxy extends Plugin { } print $data; + } else { + global $fetch_last_error; + global $fetch_last_error_code; + global $fetch_last_error_content; + + if (function_exists("imagecreate")) { + $img = imagecreate(400, 75); + + $bg = imagecolorallocate($img, 255, 255, 255); + $textcolor = imagecolorallocate($img, 255, 0, 0); + + imagerectangle($img, 0, 0, 400-1, 75-1, $textcolor); + + imagestring($img, 5, 5, 5, "Proxy request failed", $textcolor); + imagestring($img, 5, 5, 30, $url, $textcolor); + imagestring($img, 5, 5, 55, "HTTP Code: $fetch_last_error_code", $textcolor); + + header("Content-type: image/png"); + print imagepng($img); + imagedestroy($img); + + } else { + header("Content-type: text/html"); + + http_response_code(400); + + print "

Proxy request failed.

"; + print "

Fetch error $fetch_last_error ($fetch_last_error_code)

"; + print "

URL: $url

"; + print ""; + } } } }