Make WordPress Core

Ticket #4011: functions.php.diff

File functions.php.diff, 2.5 KB (added by tmountjr, 18 years ago)

updated to include support in get_headers and curl libraries

  • functions.php

     
    552552
    553553        $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
    554554
    555         $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
    556         if ( !$fp )
    557                 return false;
    558 
     555        if (WP_USEPROXY) {
     556                $fp = fsockopen(WP_PROXYHOST, WP_PROXYPORT);
     557                if (!$fp)
     558                        return false;
     559                fputs($fp, $head);
     560                fputs($fp, "Proxy-Authentication: Basic " . base64_encode(WP_PROXYUSER . ":" . WP_PROXYPASS) . "\r\n\r\n");
     561        } else {
     562                $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
     563                if ( !$fp )
     564                        return false;
     565                fputs( $fp, $head );
     566        }
    559567        $response = '';
    560         fputs( $fp, $head );
    561568        while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
    562569                $response .= fgets( $fp, 2048 );
    563570        fclose( $fp );
     
    871878                $uri = 'http://' . $uri;
    872879
    873880        if ( ini_get('allow_url_fopen') ) {
    874                 $fp = @fopen( $uri, 'r' );
    875                 if ( !$fp )
    876                         return false;
    877 
    878                 //stream_set_timeout($fp, $timeout); // Requires php 4.3
    879                 $linea = '';
    880                 while( $remote_read = fread($fp, 4096) )
    881                         $linea .= $remote_read;
    882                 fclose($fp);
    883                 return $linea;
     881                if (WP_USEPROXY) {
     882                        $proxy_fp = fsockopen(WP_PROXYHOST, WP_PROXYPORT);
     883                        if ( !$proxy_fp )
     884                                return false;
     885                        fputs($proxy_fp, "GET $uri HTTP/1.0\r\nHost: ".WP_PROXYHOST." \r\n");
     886                        fputs($proxy_fp, "Proxy-Authentication: Basic " . base64_encode(WP_PROXYUSER . ":" . WP_PROXYPASS) . "\r\n\r\n");
     887                        while(!feof($proxy_fp))
     888                                $proxy_cont .= fread($proxy_fp,4096);
     889                        fclose($proxy_fp);
     890                        $proxy_cont = substr($proxy_cont, strpos($proxy_cont, "\r\n\r\n")+4);
     891                        return $proxy_cont;
     892                } else {
     893                        $fp = fopen( $uri, 'r' );
     894                        if ( !$fp )
     895                                        return false;
     896                        $linea = '';
     897                        while( $remote_read = fread($fp, 4096) )
     898                                        $linea .= $remote_read;
     899                        fclose($fp);
     900                        return $linea;
     901                }
    884902        } else if ( function_exists('curl_init') ) {
    885903                $handle = curl_init();
    886904                curl_setopt ($handle, CURLOPT_URL, $uri);
    887905                curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
    888906                curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
    889907                curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
     908                if (WP_USEPROXY) {
     909                        curl_setopt ($handle, CURLOPT_PROXY, WP_PROXYHOST . ":" . WP_PROXYPORT);
     910                        curl_setopt ($handle, CURLOPT_PROXYUSERPWD, WP_PROXYUSER . ":".  WP_PROXYPASS);
     911                }
    890912                $buffer = curl_exec($handle);
    891913                curl_close($handle);
    892914                return $buffer;