]> git.wh0rd.org Git - tt-rss.git/commitdiff
Pass error code along if geturl fails
authorRob Hoelz <rob@hoelz.ro>
Wed, 29 May 2013 18:50:27 +0000 (20:50 +0200)
committerRob Hoelz <rob@hoelz.ro>
Wed, 29 May 2013 18:50:27 +0000 (20:50 +0200)
include/functions.php

index bad01eb96777643dc387bb5ac68b1cb365676c15..2b7f9ac5913bb5fc509dafed18013ca74465829e 100644 (file)
                        $fetch_curl_used = true;
 
                        if (ini_get("safe_mode") || ini_get("open_basedir")) {
-                               $ch = curl_init(geturl($url));
+                               $new_url = geturl($url);
+                               if (!$new_url) {
+                                   // geturl has already populated $fetch_last_error
+                                   return false;
+                               }
+                               $ch = curl_init($new_url);
                        } else {
                                $ch = curl_init($url);
                        }
                $html = curl_exec($curl);
 
                $status = curl_getinfo($curl);
-               curl_close($curl);
 
                if($status['http_code']!=200){
                        if($status['http_code'] == 301 || $status['http_code'] == 302) {
+                               curl_close($curl);
                                list($header) = explode("\r\n\r\n", $html, 2);
                                $matches = array();
                                preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
                                $url_parsed = parse_url($url);
                                return (isset($url_parsed))? geturl($url):'';
                        }
+
+                       global $fetch_last_error;
+
+                       $fetch_last_error = curl_errno($curl) . " " . curl_error($curl);
+                       curl_close($curl);
+
                        $oline='';
                        foreach($status as $key=>$eline){$oline.='['.$key.']'.$eline.' ';}
                        $line =$oline." \r\n ".$url."\r\n-----------------\r\n";
 #                      fwrite($handle, $line);
                        return FALSE;
                }
+               curl_close($curl);
                return $url;
        }