estrict wp_remote_fopen to remote files.

git-svn-id: http://svn.automattic.com/wordpress/branches/2.0@4827 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-01-28 22:31:22 +00:00
parent 817335ed16
commit 81bf2a7ad7

View File

@ -2187,10 +2187,21 @@ function add_magic_quotes($array) {
}
function wp_remote_fopen( $uri ) {
$timeout = 10;
$parsed_url = @parse_url($uri);
if ( !$parsed_url || !is_array($parsed_url) )
return false;
if ( !isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], array('http','https')) )
$uri = 'http://' . $uri;
if ( ini_get('allow_url_fopen') ) {
$fp = @fopen( $uri, 'r' );
if ( !$fp )
return false;
//stream_set_timeout($fp, $timeout); // Requires php 4.3
$linea = '';
while( $remote_read = fread($fp, 4096) )
$linea .= $remote_read;
@ -2201,6 +2212,7 @@ function wp_remote_fopen( $uri ) {
curl_setopt ($handle, CURLOPT_URL, $uri);
curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
$buffer = curl_exec($handle);
curl_close($handle);
return $buffer;