Ticket #4011: 4011.6.diff
File 4011.6.diff, 23.7 KB (added by , 16 years ago) |
---|
-
wp-includes/http.php
118 118 } 119 119 } 120 120 121 if ( has_filter('http_transport_get_debug') )121 if ( has_filter('http_transport_get_debug') ) 122 122 do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport); 123 123 124 124 if ( isset($args['blocking']) && !$args['blocking'] ) … … 166 166 } 167 167 } 168 168 169 if ( has_filter('http_transport_post_debug') )169 if ( has_filter('http_transport_post_debug') ) 170 170 do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport); 171 171 172 172 if ( isset($args['blocking']) && !$args['blocking'] ) … … 243 243 244 244 // Determine if this is a https call and pass that on to the transport functions 245 245 // so that we can blacklist the transports that do not support ssl verification 246 if ( $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl' ) 247 $r['ssl'] = true; 248 else 249 $r['ssl'] = false; 246 $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; 250 247 251 // Determine if this request is to OUR install of WordPress 252 if ( stristr(get_bloginfo('url'), $arrURL['host']) ) 253 $r['local'] = true; 254 else 255 $r['local'] = false; 248 // Determine if this request is to OUR install of WordPress 249 $homeURL = parse_url(get_bloginfo('url')); 250 $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host']; 251 unset($homeURL); 256 252 257 253 if ( is_null( $r['headers'] ) ) 258 254 $r['headers'] = array(); … … 275 271 // Construct Cookie: header if any cookies are set 276 272 WP_Http::buildCookieHeader( $r ); 277 273 278 if ( WP_Http_Encoding::is_available() )274 if ( WP_Http_Encoding::is_available() ) 279 275 $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding(); 280 276 281 277 if ( is_null($r['body']) ) { … … 296 292 $transports = WP_Http::_postTransport($r); 297 293 } 298 294 299 if ( has_action('http_api_debug') )295 if ( has_action('http_api_debug') ) 300 296 do_action('http_api_debug', $transports, 'transports_list'); 301 297 302 298 $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); 303 foreach ( (array) $transports as $transport ) {299 foreach ( (array) $transports as $transport ) { 304 300 $response = $transport->request($url, $r); 305 301 306 if ( has_action('http_api_debug') )302 if ( has_action('http_api_debug') ) 307 303 do_action( 'http_api_debug', $response, 'response', get_class($transport) ); 308 304 309 if ( ! is_wp_error($response) )305 if ( ! is_wp_error($response) ) 310 306 return $response; 311 307 } 312 308 … … 419 415 420 416 if ( !empty( $value ) ) { 421 417 $key = strtolower( $key ); 422 if ( isset( $newheaders[$key] ) ) { 418 419 if ( isset( $newheaders[$key] ) ) 423 420 $newheaders[$key] = array( $newheaders[$key], trim( $value ) ); 424 } else {421 else 425 422 $newheaders[$key] = trim( $value ); 426 } 423 427 424 if ( 'set-cookie' == strtolower( $key ) ) 428 425 $cookies[] = new WP_Http_Cookie( $value ); 429 426 } … … 448 445 function buildCookieHeader( &$r ) { 449 446 if ( ! empty($r['cookies']) ) { 450 447 $cookies_header = ''; 451 foreach ( (array) $r['cookies'] as $cookie ) {448 foreach ( (array) $r['cookies'] as $cookie ) 452 449 $cookies_header .= $cookie->getHeaderValue() . '; '; 453 }454 450 $cookies_header = substr( $cookies_header, 0, -2 ); 455 451 $r['headers']['cookie'] = $cookies_header; 456 452 } … … 494 490 495 491 $body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n"); 496 492 497 if ( "0" == trim($body) )493 if ( "0" == trim($body) ) 498 494 return $parsedBody; // Ignore footer headers. 499 495 } else { 500 496 return $body; … … 510 506 * 511 507 * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL in your wp-config.php file 512 508 * and this will only allow localhost and your blog to make requests. The constant 513 * WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests. 509 * WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests. The format of the 510 * WP_ACCESSABLE_HOSTS constant is a comma separated list of hostnames to allow. 514 511 * 515 512 * @since 2.8.0 516 513 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests. … … 537 534 if ( $check === false ) 538 535 return false; 539 536 540 $home = parse_url( get_ bloginfo('site_url') );537 $home = parse_url( get_option('siteurl') ); 541 538 542 539 // Don't block requests back to ourselves by default 543 if ( $ uri == 'localhost' || $uri== $home['host'] )540 if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] ) 544 541 return apply_filters('block_local_requests', false); 545 542 546 if ( defined('WP_ACCESSABLE_HOSTS') && is_array( WP_ACCESSABLE_HOSTS ) && in_array( $check['host'], WP_ACCESSABLE_HOSTS ) ) { 547 return false; 548 } 543 if ( !defined('WP_ACCESSABLE_HOSTS') ) 544 return true; 549 545 550 return true; 546 static $accessable_hosts; 547 if ( null == $accessable_hosts ) 548 $accessable_hosts = preg_split('|,\s*|', WP_ACCESSABLE_HOSTS); 549 550 return !in_array( $check['host'], $accessable_hosts ); //Inverse logic, If its in the array, then we can't access it. 551 551 } 552 552 } 553 553 … … 606 606 if ( ! isset($arrURL['port']) ) { 607 607 if ( ($arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https') && extension_loaded('openssl') ) { 608 608 $arrURL['host'] = 'ssl://' . $arrURL['host']; 609 $arrURL['port'] = apply_filters('http_request_port', 443);609 $arrURL['port'] = 443; 610 610 $secure_transport = true; 611 611 } else { 612 $arrURL['port'] = apply_filters('http_request_default_port', 80);612 $arrURL['port'] = 80; 613 613 } 614 } else {615 $arrURL['port'] = apply_filters('http_request_port', $arrURL['port'], $arrURL['host']);616 614 } 617 615 618 616 // There are issues with the HTTPS and SSL protocols that cause errors that can be safely … … 625 623 $proxy = new WP_HTTP_Proxy(); 626 624 627 625 if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) { 628 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )626 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 629 627 $handle = @fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] ); 630 628 else 631 629 $handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); 632 } 633 else { 634 if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 630 } else { 631 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 635 632 $handle = fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] ); 636 633 else 637 634 $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); … … 648 645 if ( false === $handle ) 649 646 return new WP_Error('http_request_failed', $iError . ': ' . $strError); 650 647 651 // WordPress supports PHP 4.3, which has this function. Removed sanity checking for652 // performance reasons.653 648 stream_set_timeout($handle, $r['timeout'] ); 654 649 655 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); 656 $requestPath = empty($requestPath) ? '/' : $requestPath; 650 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field. 651 $requestPath = $url; 652 else 653 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); 657 654 658 $strHeaders = '';659 $strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";655 if ( empty($requestPath) ) 656 $requestPath .= '/'; 660 657 661 if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 662 $strHeaders .= 'Host: ' . $arrURL['host'] .':'. $arrURL['port'] . "\r\n"; 658 $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; 659 660 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 661 $strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n"; 663 662 else 664 663 $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; 665 664 666 if ( isset($r['user-agent']) )665 if ( isset($r['user-agent']) ) 667 666 $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; 668 667 669 668 if ( is_array($r['headers']) ) { … … 673 672 $strHeaders .= $r['headers']; 674 673 } 675 674 676 if ( $proxy->use_authentication() ) {675 if ( $proxy->use_authentication() ) 677 676 $strHeaders .= $proxy->authentication_header() . "\r\n"; 678 }679 677 680 678 $strHeaders .= "\r\n"; 681 679 … … 731 729 * @static 732 730 * @return boolean False means this class can not be used, true means it can. 733 731 */ 734 function test( $args = array()) {732 function test( $args = array() ) { 735 733 if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours 736 734 return false; 737 735 738 if ( function_exists( 'fsockopen' ) && ( isset($args['ssl']) && !$args['ssl'] ) ) 739 return apply_filters('use_fsockopen_transport', true); 736 $is_ssl = isset($args['ssl']) && $args['ssl']; 740 737 741 return false; 738 if ( ! $is_ssl && function_exists( 'fsockopen' ) ) 739 $use = true; 740 elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) ) 741 $use = true; 742 else 743 $use = false; 744 745 return apply_filters('use_fsockopen_transport', $use, $args); 742 746 } 743 747 } 744 748 … … 772 776 * @return array 'headers', 'body', 'cookies' and 'response' keys. 773 777 */ 774 778 function request($url, $args = array()) { 775 global $http_response_header;776 777 779 $defaults = array( 778 780 'method' => 'GET', 'timeout' => 5, 779 781 'redirection' => 5, 'httpversion' => '1.0', … … 799 801 if (! $handle) 800 802 return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); 801 803 802 // WordPress supports PHP 4.3, which has this function. Removed sanity803 // checking for performance reasons.804 804 stream_set_timeout($handle, $r['timeout'] ); 805 805 806 806 if ( ! $r['blocking'] ) { … … 812 812 while ( ! feof($handle) ) 813 813 $strResponse .= fread($handle, 4096); 814 814 815 $theHeaders = '';816 815 if ( function_exists('stream_get_meta_data') ) { 817 816 $meta = stream_get_meta_data($handle); 818 817 $theHeaders = $meta['wrapper_data']; 819 if ( isset( $meta['wrapper_data']['headers'] ) )818 if ( isset( $meta['wrapper_data']['headers'] ) ) 820 819 $theHeaders = $meta['wrapper_data']['headers']; 821 820 } else { 822 if( ! isset( $http_response_header ) )823 global $http_response_header;821 //$http_response_header is a PHP reserved variable which is set in the current-scope when using the HTTP Wrapper 822 //see http://php.oregonstate.edu/manual/en/reserved.variables.httpresponseheader.php 824 823 $theHeaders = $http_response_header; 825 824 } 826 825 … … 844 843 * @static 845 844 * @return boolean False means this class can not be used, true means it can. 846 845 */ 847 function test( ) {846 function test($args = array()) { 848 847 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) ) 849 848 return false; 850 849 851 if ( 852 ( isset($args['ssl']) && !$args['ssl'] ) || 853 ( isset($args['local']) && $args['local'] == true && apply_filters('https_local_ssl_verify', true) != true ) || 854 ( isset($args['local']) && $args['local'] == false && apply_filters('https_ssl_verify', true) != true ) || 855 ( isset($args['sslverify']) && !$args['sslverify'] ) 856 ) 857 return apply_filters('use_fopen_transport', true); 850 $use = true; 858 851 859 return false; 852 //PHP does not verify SSL certs, We can only make a request via this transports if SSL Verification is turned off. 853 $is_ssl = isset($args['ssl']) && $args['ssl']; 854 if ( $is_ssl ) { 855 $is_local = isset($args['local']) && $args['local']; 856 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 857 if ( $is_local && true != apply_filters('https_local_ssl_verify', true) ) 858 $use = true; 859 elseif ( !$is_local && true != apply_filters('https_ssl_verify', true) ) 860 $use = true; 861 elseif ( !$ssl_verify ) 862 $use = true; 863 else 864 $use = false; 865 } 866 867 return apply_filters('use_fopen_transport', $use, $args); 860 868 } 861 869 } 862 870 … … 910 918 return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url)); 911 919 912 920 if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] ) 913 $url = str_replace($arrURL['scheme'], 'http', $url);921 $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url); 914 922 915 923 // Convert Header array to string. 916 924 $strHeaders = ''; 917 925 if ( is_array( $r['headers'] ) ) 918 foreach ( $r['headers'] as $name => $value )926 foreach ( $r['headers'] as $name => $value ) 919 927 $strHeaders .= "{$name}: $value\r\n"; 920 928 else if ( is_string( $r['headers'] ) ) 921 929 $strHeaders = $r['headers']; 922 930 931 $is_local = isset($args['local']) && $args['local']; 932 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 933 if ( $is_local ) 934 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 935 elseif ( ! $is_local ) 936 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 937 923 938 $arrContext = array('http' => 924 939 array( 925 940 'method' => strtoupper($r['method']), … … 929 944 'header' => $strHeaders, 930 945 'timeout' => $r['timeout'], 931 946 'ssl' => array( 932 'verify_peer' => apply_filters('https_ssl_verify', $r['sslverify']),933 'verify_host' => apply_filters('https_ssl_verify', $r['sslverify'])947 'verify_peer' => $ssl_verify, 948 'verify_host' => $ssl_verify 934 949 ) 935 950 ) 936 951 ); … … 938 953 $proxy = new WP_HTTP_Proxy(); 939 954 940 955 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 941 $arrContext['http']['proxy'] = 'tcp://'.$proxy->host().':'.$proxy->port(); 956 $arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port(); 957 $arrContext['http']['request_fulluri'] = true; 942 958 943 959 // We only support Basic authentication so this will only work if that is what your proxy supports. 944 if ( $proxy->use_authentication() ) {960 if ( $proxy->use_authentication() ) 945 961 $arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n"; 946 }947 962 } 948 963 949 964 if ( ! is_null($r['body']) && ! empty($r['body'] ) ) … … 975 990 fclose($handle); 976 991 977 992 $processedHeaders = array(); 978 if ( isset( $meta['wrapper_data']['headers'] ) )993 if ( isset( $meta['wrapper_data']['headers'] ) ) 979 994 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']); 980 995 else 981 996 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']); … … 1005 1020 if ( version_compare(PHP_VERSION, '5.0', '<') ) 1006 1021 return false; 1007 1022 1008 return apply_filters('use_streams_transport', true); 1023 //HTTPS via Proxy was added in 5.1.0 1024 $is_ssl = isset($args['ssl']) && $args['ssl']; 1025 if ( $is_ssl && version_compare(PHP_VERSION, '5.1.0', '<') ) { 1026 $proxy = new WP_HTTP_Proxy(); 1027 /** 1028 * No URL check, as its not currently passed to the ::test() function 1029 * In the case where a Proxy is in use, Just bypass this transport for HTTPS. 1030 */ 1031 if ( $proxy->is_enabled() ) 1032 return false; 1033 } 1034 1035 return apply_filters('use_streams_transport', true, $args); 1009 1036 } 1010 1037 } 1011 1038 … … 1069 1096 $arrURL = parse_url($url); 1070 1097 1071 1098 if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] ) 1072 $url = str_replace($arrURL['scheme'], 'http', $url);1099 $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url); 1073 1100 1101 $is_local = isset($args['local']) && $args['local']; 1102 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 1103 if ( $is_local ) 1104 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 1105 elseif ( ! $is_local ) 1106 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 1107 1074 1108 $options = array( 1075 1109 'timeout' => $r['timeout'], 1076 1110 'connecttimeout' => $r['timeout'], … … 1078 1112 'useragent' => $r['user-agent'], 1079 1113 'headers' => $r['headers'], 1080 1114 'ssl' => array( 1081 'verifypeer' => apply_filters('https_ssl_verify', $r['sslverify']),1082 'verifyhost' => apply_filters('https_ssl_verify', $r['sslverify'])1115 'verifypeer' => $ssl_verify, 1116 'verifyhost' => $ssl_verify 1083 1117 ) 1084 1118 ); 1085 1119 … … 1139 1173 * @return boolean False means this class can not be used, true means it can. 1140 1174 */ 1141 1175 function test($args = array()) { 1142 if ( function_exists('http_request') ) 1143 return apply_filters('use_http_extension_transport', true); 1144 1145 return false; 1176 return apply_filters('use_http_extension_transport', function_exists('http_request'), $args ); 1146 1177 } 1147 1178 } 1148 1179 … … 1199 1230 $proxy = new WP_HTTP_Proxy(); 1200 1231 1201 1232 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 1202 curl_setopt( $handle, CURLOPT_HTTPPROXYTUNNEL, true );1203 1233 1204 1234 $isPHP5 = version_compare(PHP_VERSION, '5.0.0', '>='); 1205 1235 … … 1218 1248 curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() ); 1219 1249 } 1220 1250 } 1251 1252 $is_local = isset($args['local']) && $args['local']; 1253 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 1254 if ( $is_local ) 1255 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 1256 elseif ( ! $is_local ) 1257 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 1221 1258 1222 1259 curl_setopt( $handle, CURLOPT_URL, $url); 1223 1260 curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); 1224 curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, apply_filters('https_ssl_verify', $r['sslverify']));1225 curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, apply_filters('https_ssl_verify', $r['sslverify']));1261 curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify ); 1262 curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify ); 1226 1263 curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] ); 1227 1264 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] ); 1228 1265 curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] ); … … 1250 1287 if ( !empty( $r['headers'] ) ) { 1251 1288 // cURL expects full header strings in each element 1252 1289 $headers = array(); 1253 foreach ( $r['headers'] as $name => $value ) {1290 foreach ( $r['headers'] as $name => $value ) 1254 1291 $headers[] = "{$name}: $value"; 1255 }1256 1292 curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); 1257 1293 } 1258 1294 … … 1317 1353 */ 1318 1354 function test($args = array()) { 1319 1355 if ( function_exists('curl_init') && function_exists('curl_exec') ) 1320 return apply_filters('use_curl_transport', true);1356 return apply_filters('use_curl_transport', true, $args); 1321 1357 1322 1358 return false; 1323 1359 } … … 1338 1374 * <li>WP_PROXY_PASSWORD - Proxy password, if it requires authentication.</li> 1339 1375 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy. 1340 1376 * You do not need to have localhost and the blog host in this list, because they will not be passed 1341 * through the proxy. </li>1377 * through the proxy. The list should be presented in a comma separated list</li> 1342 1378 * </ol> 1343 1379 * 1344 1380 * An example can be as seen below. 1345 1381 * <code> 1346 1382 * define('WP_PROXY_HOST', '192.168.84.101'); 1347 1383 * define('WP_PROXY_PORT', '8080'); 1348 * define('WP_PROXY_BYPASS_HOSTS', array('localhost', 'www.example.com'));1384 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com'); 1349 1385 * </code> 1350 1386 * 1351 1387 * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress. … … 1353 1389 */ 1354 1390 class WP_HTTP_Proxy { 1355 1391 1356 function WP_HTTP_Proxy() {1357 $this->__construct();1358 }1359 1360 function __construct() {1361 1362 }1363 1364 1392 /** 1365 1393 * Whether proxy connection should be used. 1366 1394 * … … 1371 1399 * @return bool 1372 1400 */ 1373 1401 function is_enabled() { 1374 return ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT'));1402 return defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT'); 1375 1403 } 1376 1404 1377 1405 /** … … 1384 1412 * @return bool 1385 1413 */ 1386 1414 function use_authentication() { 1387 return ( defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'));1415 return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'); 1388 1416 } 1389 1417 1390 1418 /** … … 1395 1423 * @return string 1396 1424 */ 1397 1425 function host() { 1398 if ( defined('WP_PROXY_HOST') )1426 if ( defined('WP_PROXY_HOST') ) 1399 1427 return WP_PROXY_HOST; 1400 1428 1401 1429 return ''; … … 1409 1437 * @return string 1410 1438 */ 1411 1439 function port() { 1412 if ( defined('WP_PROXY_PORT') )1440 if ( defined('WP_PROXY_PORT') ) 1413 1441 return WP_PROXY_PORT; 1414 1442 1415 1443 return ''; … … 1423 1451 * @return string 1424 1452 */ 1425 1453 function username() { 1426 if ( defined('WP_PROXY_USERNAME') )1454 if ( defined('WP_PROXY_USERNAME') ) 1427 1455 return WP_PROXY_USERNAME; 1428 1456 1429 1457 return ''; … … 1437 1465 * @return string 1438 1466 */ 1439 1467 function password() { 1440 if ( defined('WP_PROXY_PASSWORD') )1468 if ( defined('WP_PROXY_PASSWORD') ) 1441 1469 return WP_PROXY_PASSWORD; 1442 1470 1443 1471 return ''; … … 1451 1479 * @return string 1452 1480 */ 1453 1481 function authentication() { 1454 return $this->username() . ':'. $this->password();1482 return $this->username() . ':' . $this->password(); 1455 1483 } 1456 1484 1457 1485 /** … … 1462 1490 * @return string 1463 1491 */ 1464 1492 function authentication_header() { 1465 return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() );1493 return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() ); 1466 1494 } 1467 1495 1468 1496 /** … … 1484 1512 $check = @parse_url($uri); 1485 1513 1486 1514 // Malformed URL, can not process, but this could mean ssl, so let through anyway. 1487 if ( $check === false )1515 if ( $check === false ) 1488 1516 return true; 1489 1517 1490 $home = parse_url( get_ bloginfo('site_url') );1518 $home = parse_url( get_option('siteurl') ); 1491 1519 1492 if ( $ uri == 'localhost' || $uri== $home['host'] )1520 if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] ) 1493 1521 return false; 1494 1522 1495 if ( defined('WP_PROXY_BYPASS_HOSTS') && is_array( WP_PROXY_BYPASS_HOSTS ) && in_array( $check['host'], WP_PROXY_BYPASS_HOSTS ) ) { 1496 return false; 1497 } 1498 1499 return true; 1523 if ( !defined('WP_PROXY_BYPASS_HOSTS') ) 1524 return true; 1525 1526 static $bypass_hosts; 1527 if ( null == $bypass_hosts ) 1528 $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS); 1529 1530 return !in_array( $check['host'], $bypass_hosts ); 1500 1531 } 1501 1532 } 1502 1503 1504 1533 /** 1505 1534 * Internal representation of a single cookie. 1506 1535 * … … 1744 1773 function decompress( $compressed, $length = null ) { 1745 1774 $decompressed = gzinflate( $compressed ); 1746 1775 1747 if ( false !== $decompressed )1776 if ( false !== $decompressed ) 1748 1777 return $decompressed; 1749 1778 1750 1779 $decompressed = gzuncompress( $compressed ); 1751 1780 1752 if ( false !== $decompressed )1781 if ( false !== $decompressed ) 1753 1782 return $decompressed; 1754 1783 1755 1784 $decompressed = gzdecode( $compressed ); 1756 1785 1757 if ( false !== $decompressed )1786 if ( false !== $decompressed ) 1758 1787 return $decompressed; 1759 1788 1760 1789 return $compressed; … … 1769 1798 */ 1770 1799 function accept_encoding() { 1771 1800 $type = array(); 1772 if ( function_exists( 'gzinflate' ) )1801 if ( function_exists( 'gzinflate' ) ) 1773 1802 $type[] = 'deflate;q=1.0'; 1774 1803 1775 if ( function_exists( 'gzuncompress' ) )1804 if ( function_exists( 'gzuncompress' ) ) 1776 1805 $type[] = 'compress;q=0.5'; 1777 1806 1778 if ( function_exists( 'gzdecode' ) )1807 if ( function_exists( 'gzdecode' ) ) 1779 1808 $type[] = 'gzip;q=0.5'; 1780 1809 1781 1810 return implode(', ', $type); … … 1801 1830 * @return bool 1802 1831 */ 1803 1832 function should_decode($headers) { 1804 if ( is_array( $headers ) ) {1805 if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )1833 if ( is_array( $headers ) ) { 1834 if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) 1806 1835 return true; 1807 1836 } else if( is_string( $headers ) ) { 1808 1837 return ( stripos($headers, 'content-encoding:') !== false ); … … 1823 1852 * @return bool 1824 1853 */ 1825 1854 function is_available() { 1826 return ( function_exists('gzuncompress') || function_exists('gzdeflate') || 1827 function_exists('gzinflate') ); 1855 return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') ); 1828 1856 } 1829 1857 } 1830 1858 … … 1890 1918 */ 1891 1919 function wp_remote_get($url, $args = array()) { 1892 1920 $objFetchSite = _wp_http_get_object(); 1893 1894 1921 return $objFetchSite->get($url, $args); 1895 1922 } 1896 1923