relative link redirects

This commit is contained in:
friendica 2012-02-26 14:34:01 -08:00
parent 5f7858a688
commit bdb14d5aad
3 changed files with 26 additions and 14 deletions

View file

@ -9,7 +9,7 @@ require_once('include/nav.php');
require_once('include/cache.php'); require_once('include/cache.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_VERSION', '2.3.1263' ); define ( 'FRIENDICA_VERSION', '2.3.1264' );
define ( 'DFRN_PROTOCOL_VERSION', '2.22' ); define ( 'DFRN_PROTOCOL_VERSION', '2.22' );
define ( 'DB_UPDATE_VERSION', 1126 ); define ( 'DB_UPDATE_VERSION', 1126 );

View file

@ -230,11 +230,16 @@ function scrape_feed($url) {
$ret = array(); $ret = array();
$s = fetch_url($url); $s = fetch_url($url);
if(! $s)
return $ret;
$headers = $a->get_curl_headers(); $headers = $a->get_curl_headers();
logger('scrape_feed: headers=' . $headers, LOGGER_DEBUG); $code = $a->get_curl_code();
logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG);
if(! $s) {
logger('scrape_feed: no data returned for ' . $url);
return $ret;
}
$lines = explode("\n",$headers); $lines = explode("\n",$headers);
if(count($lines)) { if(count($lines)) {
@ -258,8 +263,10 @@ function scrape_feed($url) {
logger('scrape_feed: parse error: ' . $e); logger('scrape_feed: parse error: ' . $e);
} }
if(! $dom) if(! $dom) {
logger('scrape_feed: failed to parse.');
return $ret; return $ret;
}
$head = $dom->getElementsByTagName('base'); $head = $dom->getElementsByTagName('base');
@ -556,7 +563,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if($check_feed) { if($check_feed) {
$feedret = scrape_feed(($poll) ? $poll : $url); $feedret = scrape_feed(($poll) ? $poll : $url);
logger('probe_url: scrape_feed returns: ' . print_r($feedret,true), LOGGER_DATA); logger('probe_url: scrape_feed ' . (($poll)? $poll : $url) . ' returns: ' . print_r($feedret,true), LOGGER_DATA);
if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) { if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
$poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss'])); $poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']));
if(! x($vcard)) if(! x($vcard))

View file

@ -17,7 +17,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
if (!is_null($accept_content)){ if (!is_null($accept_content)){
curl_setopt($ch,CURLOPT_HTTPHEADER, array ( curl_setopt($ch,CURLOPT_HTTPHEADER, array (
"Accept: "+$accept_content "Accept: " . $accept_content
)); ));
} }
@ -60,6 +60,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
$curl_info = @curl_getinfo($ch); $curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code']; $http_code = $curl_info['http_code'];
// logger('fetch_url:' . $http_code . ' data: ' . $s);
$header = ''; $header = '';
// Pull out multiple headers, e.g. proxy and continuation headers // Pull out multiple headers, e.g. proxy and continuation headers
@ -74,11 +75,13 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
$matches = array(); $matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$url = trim(array_pop($matches)); $newurl = trim(array_pop($matches));
$url_parsed = @parse_url($url); if(strpos($newurl,'/') === 0)
$newurl = $url . $newurl;
$url_parsed = @parse_url($newurl);
if (isset($url_parsed)) { if (isset($url_parsed)) {
$redirects++; $redirects++;
return fetch_url($url,$binary,$redirects,$timeout); return fetch_url($newurl,$binary,$redirects,$timeout);
} }
} }
@ -163,11 +166,13 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
if($http_code == 301 || $http_code == 302 || $http_code == 303) { if($http_code == 301 || $http_code == 302 || $http_code == 303) {
$matches = array(); $matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$url = trim(array_pop($matches)); $newurl = trim(array_pop($matches));
$url_parsed = @parse_url($url); if(strpos($newurl,'/') === 0)
$newurl = $url . $newurl;
$url_parsed = @parse_url($newurl);
if (isset($url_parsed)) { if (isset($url_parsed)) {
$redirects++; $redirects++;
return post_url($url,$params,$headers,$redirects,$timeout); return fetch_url($newurl,$binary,$redirects,$timeout);
} }
} }
$a->set_curl_code($http_code); $a->set_curl_code($http_code);