summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-13 15:25:52 +0300
committerAndrew Dolgov <[email protected]>2017-02-13 15:25:52 +0300
commitbf6398650a7956a84418c216f0876c0e35d8e56c (patch)
treeb05859dfa9a56958a3f9b87c168dd0ff27390e5d /plugins
parent4a23031fcdb1d0a5e26e6f739088317b10f115c0 (diff)
af_zz_imgproxy: show GD-based (if possible) error message on proxy failure
Diffstat (limited to 'plugins')
-rw-r--r--plugins/af_zz_imgproxy/init.php33
1 files changed, 32 insertions, 1 deletions
diff --git a/plugins/af_zz_imgproxy/init.php b/plugins/af_zz_imgproxy/init.php
index 047f5a211..07177bb7c 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 "<h1>Proxy request failed.</h1>";
+ print "<p>Fetch error $fetch_last_error ($fetch_last_error_code)</p>";
+ print "<p>URL: $url</p>";
+ print "<textarea cols='80' rows='25'>" . htmlspecialchars($fetch_last_error_content) . "</textarea>";
+ }
}
}
}