i modified the urlgrabber method in functions.lib.php, but only the fsockopen part. My problem is, that i don't have a host with curl support to test and debug this. So i need your help.
What is happening on a guild update?
Roster fetches the following url (eu example):
- Code: Select all
http://eu.wowarmory.com/guild-info.xml?r=[realm_name]&n=[guild_name]&p=1&locale=[locale]
The armory returns a 302 Moved temporarily. So with fsockopen it returns a header with a location line in it. I parse the answers header for a line containing Localtion: http://.... and call the urlgrabber method again with the url provided in the Location header.
Here is the code doing it. See the preg_match line for parsing and the if ( isset($redirect[1]) ) line for calling urlgrabber once again:
- Code: Select all
$file = fsockopen($host, $port, $errno, $errstr, $timeout);
if( !$file )
{
trigger_error("UrlGrabber Error [fsock]: $errstr ($errno)", E_USER_WARNING);
return false;
}
else
{
$header = "GET $page$page_params HTTP/1.0\r\n"
. "Host: $host\r\n"
. "User-Agent: $user_agent\r\n"
. "Connection: Close\r\n\r\n";
fwrite($file, $header);
stream_set_timeout($file, $timeout);
$inHeader = true;
$redirect = false;
while( !feof($file) )
{
$chunk = fgets($file, 256);
if( $inHeader )
{
$pos = strpos($chunk, '<');
if( $pos !== false )
{
$contents .= substr( $chunk, $pos, strlen($chunk) );
$inHeader = false;
}
if( preg_match ( '/^(?:Location:\s)(.+)/', $chunk, $redirect ) )
{
break;
}
continue;
}
$contents .= $chunk;
}
fclose($file);
if ( isset($redirect[1]) )
{
return urlgrabber( $redirect[1], $timeout, $user_agent );
}
else
{
return $contents;
}
}
So what needs to be done with the curl part?
I don't know. Lets have a look at the code:
- Code: Select all
if( function_exists('curl_init') )
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if( $user_agent )
{
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
}
$contents = curl_exec($ch);
// If there were errors
if( curl_errno($ch) )
{
trigger_error('UrlGrabber Error [CURL]: ' . curl_error($ch), E_USER_WARNING);
return false;
}
curl_close($ch);
return $contents;
}
I would expect that the error curl_errno($ch) should contain something useful the recognize that the site is redirected. If not, there must at least something in the content.
Can anyone debug this function and post the content of curl_errno($ch), curl_error($ch) and $contents? There should be a way to get into this.
Thx for your help.