X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fnetwork.php;h=c6379e407bcc79aae4a3ed852c3409d9225a1f09;hb=df312402e46cc3cdc788c73d0c41874b6c71fcb3;hp=02b2d7c2aed1c25325754b154a8677d6dcf6e8d7;hpb=e839e3e1ec4b4a56ecf9886d8e29e07d6e5a798c;p=friendica.git diff --git a/include/network.php b/include/network.php index 02b2d7c2ae..c6379e407b 100644 --- a/include/network.php +++ b/include/network.php @@ -42,6 +42,7 @@ if(!function_exists('z_fetch_url')){ * @return array an assoziative array with: * * \e int \b return_code => HTTP return code or 0 if timeout or failure * * \e boolean \b success => boolean true (if HTTP 2xx result) or false + * * \e string \b redirect_url => in case of redirect, content was finally retrieved from this URL * * \e string \b header => HTTP headers * * \e string \b body => fetched content */ @@ -86,10 +87,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { if(x($opts,'nobody')){ @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); } - if(intval($timeout)) { - @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - } - else { + if(x($opts,'timeout')){ + @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); + } else { $curl_time = intval(get_config('system','curl_timeout')); @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } @@ -117,6 +117,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { // if it throws any errors. $s = @curl_exec($ch); + if (curl_errno($ch) !== CURLE_OK) { + logger('fetch_url error fetching '.$url.': '.curl_error($ch), LOGGER_NORMAL); + } $base = $s; $curl_info = @curl_getinfo($ch); @@ -134,6 +137,10 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $base = substr($base,strlen($chunk)); } + $a->set_curl_code($http_code); + $a->set_curl_content_type($curl_info['content_type']); + $a->set_curl_headers($header); + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { $new_location_info = @parse_url($curl_info["redirect_url"]); $old_location_info = @parse_url($curl_info["url"]); @@ -161,13 +168,13 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $a->set_curl_content_type($curl_info['content_type']); $body = substr($s,strlen($header)); - $a->set_curl_headers($header); $rc = intval($http_code); $ret['return_code'] = $rc; $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); + $ret['redirect_url'] = $url; if(! $ret['success']) { $ret['error'] = curl_error($ch); $ret['debug'] = $curl_info; @@ -309,16 +316,25 @@ function xml_status($st, $message = '') { if(! function_exists('http_status_exit')) { -function http_status_exit($val) { - +function http_status_exit($val, $description = array()) { $err = ''; - if($val >= 400) + if($val >= 400) { $err = 'Error'; + if (!isset($description["title"])) + $description["title"] = $err." ".$val; + } if($val >= 200 && $val < 300) $err = 'OK'; logger('http_status_exit ' . $val); header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); + + if (isset($description["title"])) { + $tpl = get_markup_template('http_status.tpl'); + echo replace_macros($tpl, array('$title' => $description["title"], + '$description' => $description["description"])); + } + killme(); }} @@ -579,7 +595,7 @@ function lrdd($uri, $debug = false) { $lines = explode("\n",$headers); if(count($lines)) { foreach($lines as $line) { - // TODO alter the following regex to support multiple relations (space separated) + /// @TODO Alter the following regex to support multiple relations (space separated) if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) { $pagelink = $matches[1]; break; @@ -1238,6 +1254,9 @@ function original_url($url, $depth=1, $fetchbody = false) { $a->save_timestamp($stamp1, "network"); + if ($http_code == 0) + return($url); + if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302")) AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) { if ($curl_info['redirect_url'] != "")