]> git.wh0rd.org - tt-rss.git/commitdiff
subscribe dialog: do not report errors via alert()
authorAndrew Dolgov <noreply@fakecake.org>
Sat, 28 Jan 2017 09:45:49 +0000 (12:45 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Sat, 28 Jan 2017 09:45:49 +0000 (12:45 +0300)
fetch_file_contents: reset all globals on start, return error message body when not using curl
subscribe_to_feed: report if cloudflare is in the error message

classes/feeds.php
include/functions.php
js/functions.js

index 4a34945cd713c5a40ff678f8c9f4e4dd975270a8..1375f0c376dafdaf1a75d159cd058dbe4395dfa8 100755 (executable)
@@ -1030,6 +1030,8 @@ class Feeds extends Handler_Protected {
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">";
                print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">";
 
+               print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>";
+
                print "<div id='fadd_multiple_notify' style='display : none'>";
                print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
                print "<p></div>";
index 46f55d4e2068fa9ca1d510d0f3e9e4924033eafc..72cf695f3f2061744fc90b83d43140b16372f681 100644 (file)
                global $fetch_last_content_type;
                global $fetch_curl_used;
 
+               $fetch_last_error = false;
+               $fetch_last_error_code = -1;
+               $fetch_last_error_content = "";
+               $fetch_last_content_type = "";
+               $fetch_curl_used = false;
+
                if (!is_array($options)) {
 
                        // falling back on compatibility shim
                                 $context = stream_context_create(array(
                                          'http' => array(
                                                        'method' => 'GET',
+                                                   'ignore_errors' => true,
                                                    'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
                                                        'protocol_version'=> 1.1,
                                                        'header' => "If-Modified-Since: ".gmdate("D, d M Y H:i:s \\G\\M\\T\r\n", $timestamp)
                                 $context = stream_context_create(array(
                                          'http' => array(
                                                        'method' => 'GET',
+                                                   'ignore_errors' => true,
                                                    'timeout' => $timeout ? $timeout : FILE_FETCH_TIMEOUT,
                                                        'protocol_version'=> 1.1
                                          )));
 
                        $data = @file_get_contents($url, false, $context);
 
-                       $fetch_last_content_type = false;  // reset if no type was sent from server
                        if (isset($http_response_header) && is_array($http_response_header)) {
                                foreach ($http_response_header as $h) {
                                        if (substr(strtolower($h), 0, 13) == 'content-type:') {
                                }
                        }
 
-                       if (!$data) {
+                       if ($fetch_last_error_code != 200) {
                                $error = error_get_last();
 
                                if ($error['message'] != $old_error['message']) {
                                } else {
                                        $fetch_last_error = "HTTP Code: $fetch_last_error_code";
                                }
+
+                               $fetch_last_error_content = $data;
+
+                               return false;
                        }
                        return $data;
                }
                        $auth_login = '', $auth_pass = '') {
 
                global $fetch_last_error;
+               global $fetch_last_error_content;
+               global $fetch_last_error_code;
 
                require_once "include/rssfuncs.php";
 
                $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
 
                if (!$contents) {
+                       if (preg_match("/cloudflare\.com/", $fetch_last_error_content)) {
+                               $fetch_last_error .= " (feed behind Cloudflare)";
+                       }
+
                        return array("code" => 5, "message" => $fetch_last_error);
                }
 
index 63ff4121bb8c8fa56b326bd2794d5ebfb2aede20..db18ac6dd9d8d49bdb15a6c813ce00bd0c4b3af4 100755 (executable)
@@ -804,6 +804,15 @@ function quickAddFeed() {
                        id: "feedAddDlg",
                        title: __("Subscribe to Feed"),
                        style: "width: 600px",
+                       show_error: function(msg) {
+                               var elem = $("fadd_error_message");
+
+                               elem.innerHTML = msg;
+
+                               if (!Element.visible(elem))
+                                       new Effect.Appear(elem);
+
+                       },
                        execute: function() {
                                if (this.validate()) {
                                        console.log(dojo.objectToQuery(this.attr('value')));
@@ -811,6 +820,7 @@ function quickAddFeed() {
                                        var feed_url = this.attr('value').feed;
 
                                        Element.show("feed_add_spinner");
+                                       Element.hide("fadd_error_message");
 
                                        new Ajax.Request("backend.php", {
                                                parameters: dojo.objectToQuery(this.attr('value')),
@@ -841,10 +851,10 @@ function quickAddFeed() {
                                                                        updateFeedList();
                                                                        break;
                                                                case 2:
-                                                                       alert(__("Specified URL seems to be invalid."));
+                                                                       dialog.show_error(__("Specified URL seems to be invalid."));
                                                                        break;
                                                                case 3:
-                                                                       alert(__("Specified URL doesn't seem to contain any feeds."));
+                                                                       dialog.show_error(__("Specified URL doesn't seem to contain any feeds."));
                                                                        break;
                                                                case 4:
                                                                        feeds = rc['feeds'];
@@ -868,16 +878,16 @@ function quickAddFeed() {
 
                                                                        break;
                                                                case 5:
-                                                                       alert(__("Couldn't download the specified URL: %s").
+                                                                       dialog.show_error(__("Couldn't download the specified URL: %s").
                                                                                        replace("%s", rc['message']));
                                                                        break;
                                                                case 6:
-                                                                       alert(__("XML validation failed: %s").
+                                                                       dialog.show_error(__("XML validation failed: %s").
                                                                                        replace("%s", rc['message']));
                                                                        break;
                                                                        break;
                                                                case 0:
-                                                                       alert(__("You are already subscribed to this feed."));
+                                                                       dialog.show_error(__("You are already subscribed to this feed."));
                                                                        break;
                                                                }