]> git.wh0rd.org - tt-rss.git/commitdiff
af_zz_imgproxy: show GD-based (if possible) error message on proxy failure
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Mon, 13 Feb 2017 12:25:52 +0000 (15:25 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Mon, 13 Feb 2017 12:25:52 +0000 (15:25 +0300)
plugins/af_zz_imgproxy/init.php

index 047f5a211ae57070d38b5068c660c88413f6ed88..07177bb7c14e5c67987b493fd51b5686f1f8806a 100644 (file)
@@ -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>";
+                               }
                        }
                }
        }