]> git.wh0rd.org - tt-rss.git/commitdiff
fix SELF_USER_AGENT defined with blank VERSION
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 23 Feb 2013 14:37:40 +0000 (18:37 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 23 Feb 2013 14:37:40 +0000 (18:37 +0400)
better error reporting in fetch_file_contents()

include/functions.php

index a2b2c1c9ae6cfb5fa53a7894525cfb19bf2bed01..d07288a910126a0a7de3337ac83026a9f73f92f3 100644 (file)
@@ -1,7 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
        define('SCHEMA_VERSION', 103);
-       define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)');
 
        $fetch_last_error = false;
        $pluginhost = false;
        require_once 'ccache.php';
        require_once 'labels.php';
 
+       define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)');
        ini_set('user_agent', SELF_USER_AGENT);
 
        require_once 'lib/pubsubhubbub/publisher.php';
                }
        }
 
-       function fetch_file_contents($url, $type = false, $login = false, $pass = false, $post_query = false) {
+       function fetch_file_contents($url, $type = false, $login = false, $pass = false, $post_query = false, $timeout = false) {
                $login = urlencode($login);
                $pass = urlencode($pass);
 
                if (function_exists('curl_init') && !ini_get("open_basedir")) {
                        $ch = curl_init($url);
 
-                       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
-                       curl_setopt($ch, CURLOPT_TIMEOUT, 45);
+                       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : 15);
+                       curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : 45);
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                        curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
                        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
                        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
                        curl_setopt($ch, CURLOPT_USERAGENT, SELF_USER_AGENT);
                        curl_setopt($ch, CURLOPT_ENCODING , "gzip");
+                       curl_setopt($fp, CURLOPT_REFERER, $url);
 
                        if ($post_query) {
                                curl_setopt($ch, CURLOPT_POST, true);
 
                        $contents = @curl_exec($ch);
 
+                       if (curl_errno($fp) === 23 || curl_errno($fp) === 61) {
+                               curl_setopt($fp, CURLOPT_ENCODING, 'none');
+                               $contents = @curl_exec($fp);
+                       }
+
                        if ($contents === false) {
-                               $fetch_last_error = curl_error($ch);
+                               $fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
                                curl_close($ch);
                                return false;
                        }
 
                        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                        $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
-                       curl_close($ch);
 
                        if ($http_code != 200 || $type && strpos($content_type, "$type") === false) {
+                               if (curl_errno($ch) != 0) {
+                                       $fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
+                               } else {
+                                       $fetch_last_error = "HTTP Code: $http_code";
+                               }
+                               curl_close($ch);
                                return false;
                        }
 
+                       curl_close($ch);
+
                        return $contents;
                } else {
                        if ($login && $pass ){