Index: functions.php
===================================================================
--- functions.php	(revision 5173)
+++ functions.php	(working copy)
@@ -552,12 +552,19 @@
 
 	$head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
 
-	$fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
-	if ( !$fp )
-		return false;
-
+	if (WP_USEPROXY) {
+		$fp = fsockopen(WP_PROXYHOST, WP_PROXYPORT);
+		if (!$fp)
+			return false;
+		fputs($fp, $head);
+		fputs($fp, "Proxy-Authentication: Basic " . base64_encode(WP_PROXYUSER . ":" . WP_PROXYPASS) . "\r\n\r\n");
+	} else {
+		$fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
+		if ( !$fp )
+			return false;
+		fputs( $fp, $head );
+	}
 	$response = '';
-	fputs( $fp, $head );
 	while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
 		$response .= fgets( $fp, 2048 );
 	fclose( $fp );
@@ -871,22 +878,37 @@
 		$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;
-		fclose($fp);
-		return $linea;
+		if (WP_USEPROXY) {
+			$proxy_fp = fsockopen(WP_PROXYHOST, WP_PROXYPORT);
+			if ( !$proxy_fp )
+				return false;
+			fputs($proxy_fp, "GET $uri HTTP/1.0\r\nHost: ".WP_PROXYHOST." \r\n");
+			fputs($proxy_fp, "Proxy-Authentication: Basic " . base64_encode(WP_PROXYUSER . ":" . WP_PROXYPASS) . "\r\n\r\n");
+			while(!feof($proxy_fp))
+				$proxy_cont .= fread($proxy_fp,4096);
+			fclose($proxy_fp);
+			$proxy_cont = substr($proxy_cont, strpos($proxy_cont, "\r\n\r\n")+4);
+			return $proxy_cont;
+		} else {
+			$fp = fopen( $uri, 'r' );
+			if ( !$fp )
+					return false;
+			$linea = '';
+			while( $remote_read = fread($fp, 4096) )
+					$linea .= $remote_read;
+			fclose($fp);
+			return $linea;
+		}
 	} else if ( function_exists('curl_init') ) {
 		$handle = curl_init();
 		curl_setopt ($handle, CURLOPT_URL, $uri);
 		curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
 		curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
 		curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
+		if (WP_USEPROXY) {
+			curl_setopt ($handle, CURLOPT_PROXY, WP_PROXYHOST . ":" . WP_PROXYPORT);
+			curl_setopt ($handle, CURLOPT_PROXYUSERPWD, WP_PROXYUSER . ":".  WP_PROXYPASS);
+		}
 		$buffer = curl_exec($handle);
 		curl_close($handle);
 		return $buffer;

