]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
af_zz_imgproxy: add optional setting to proxy all remote images
[tt-rss.git] / include / functions.php
index 46f55d4e2068fa9ca1d510d0f3e9e4924033eafc..072779615ec1f07c5ebc1c3ba1d379aa625e583b 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;
                }
                print "</select>";
        }
 
+       function print_hidden($name, $value) {
+               print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
+       }
+
+       function print_checkbox($id, $checked, $attributes = "") {
+               $checked_str = $checked ? "checked" : "";
+
+               print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $checked_str $attributes name=\"$id\">";
+       }
+
+       function print_button($type, $value, $attributes = "") {
+               print "<p><button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">$value</button>";
+       }
+
        function print_radio($id, $default, $true_is, $values, $attributes = "") {
                foreach ($values as $v) {
 
                        $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);
                }