Changeset 8630
- Timestamp:
- 08/12/2008 09:21:11 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/plugin-install.php
r8600 r8630 11 11 12 12 if ( ! $res ) { 13 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( ), array(), array('action' => $action, 'request' => serialize($args)) );13 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) ); 14 14 $res = unserialize($request['body']); 15 15 if ( ! $res ) -
trunk/wp-includes/http.php
r8600 r8630 138 138 * Send a HTTP request to a URI. 139 139 * 140 * The body and headers are part of the arguments. The 'body' argument is 141 * for the body and will accept either a string or an array. The 'headers' 142 * argument should be an array, but a string is acceptable. If the 'body' 143 * argument is an array, then it will automatically be escaped using 144 * http_build_query(). 145 * 140 146 * The only URI that are supported in the HTTP Transport implementation are 141 147 * the HTTP and HTTPS protocols. HTTP and HTTPS are assumed so the server … … 172 178 * @param string $url URI resource. 173 179 * @param str|array $args Optional. Override the defaults. 174 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.175 * @param string $body Optional. The body that should be sent. Will be automatically escaped and processed.176 180 * @return boolean 177 181 */ 178 function request( $url, $args = array(), $headers = null, $body = null) {182 function request( $url, $args = array() ) { 179 183 global $wp_version; 180 184 … … 183 187 'redirection' => 5, 'httpversion' => '1.0', 184 188 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version ), 185 'blocking' => true 189 'blocking' => true, 190 'headers' => array(), 'body' => null 186 191 ); 187 192 188 193 $r = wp_parse_args( $args, $defaults ); 189 194 190 if ( is_null($headers) ) 191 $headers = array(); 192 193 if ( ! is_array($headers) ) { 194 $processedHeaders = WP_Http::processHeaders($headers); 195 $headers = $processedHeaders['headers']; 196 } 197 198 if ( isset($headers['User-Agent']) ) { 199 $headers['user-agent'] = $headers['User-Agent']; 200 unset($headers['User-Agent']); 201 } 202 203 if ( ! isset($headers['user-agent']) ) 204 $headers['user-agent'] = $r['user-agent']; 205 206 if ( is_null($body) ) { 195 if ( is_null( $r['headers'] ) ) 196 $r['headers'] = array(); 197 198 if ( ! is_array($r['headers']) ) { 199 $processedHeaders = WP_Http::processHeaders($r['headers']); 200 $r['headers'] = $processedHeaders['headers']; 201 } 202 203 if ( isset($r['headers']['User-Agent']) ) { 204 $r['user-agent'] = $headers['User-Agent']; 205 unset($r['headers']['User-Agent']); 206 } 207 208 if ( isset($r['headers']['user-agent']) ) { 209 $r['user-agent'] = $r['headers']['user-agent']; 210 unset($r['headers']['user-agent']); 211 } 212 213 if ( is_null($r['body']) ) { 207 214 $transports = WP_Http::_getTransport(); 208 215 } else { 209 if ( is_array($body) || is_object($body) ) 210 $body = http_build_query($body); 216 if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { 217 $r['body'] = http_build_query($r['body']); 218 $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'); 219 $r['headers']['Content-Length'] = strlen($r['body']); 220 } 211 221 212 222 $transports = WP_Http::_postTransport(); … … 215 225 $response = array( 'headers' => array(), 'body' => '', 'response' => array('code', 'message') ); 216 226 foreach( (array) $transports as $transport ) { 217 $response = $transport->request($url, $r , $headers, $body);227 $response = $transport->request($url, $r); 218 228 219 229 if( !is_wp_error($response) ) … … 234 244 * @param string $url URI resource. 235 245 * @param str|array $args Optional. Override the defaults. 236 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.237 * @param string $body Optional. The body that should be sent. Expected to be already processed.238 246 * @return boolean 239 247 */ 240 function post($url, $args = array() , $headers = null, $body = null) {248 function post($url, $args = array()) { 241 249 $defaults = array('method' => 'POST'); 242 250 $r = wp_parse_args( $args, $defaults ); 243 return $this->request($url, $r , $headers, $body);251 return $this->request($url, $r); 244 252 } 245 253 … … 254 262 * @param string $url URI resource. 255 263 * @param str|array $args Optional. Override the defaults. 256 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.257 * @param string $body Optional. The body that should be sent. Expected to be already processed.258 264 * @return boolean 259 265 */ 260 function get($url, $args = array() , $headers = null, $body = null) {266 function get($url, $args = array()) { 261 267 $defaults = array('method' => 'GET'); 262 268 $r = wp_parse_args( $args, $defaults ); 263 return $this->request($url, $r , $headers, $body);269 return $this->request($url, $r); 264 270 } 265 271 … … 274 280 * @param string $url URI resource. 275 281 * @param str|array $args Optional. Override the defaults. 276 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.277 * @param string $body Optional. The body that should be sent. Expected to be already processed.278 282 * @return boolean 279 283 */ 280 function head($url, $args = array() , $headers = null, $body = null) {284 function head($url, $args = array()) { 281 285 $defaults = array('method' => 'HEAD'); 282 286 $r = wp_parse_args( $args, $defaults ); 283 return $this->request($url, $r , $headers, $body);287 return $this->request($url, $r); 284 288 } 285 289 … … 297 301 list($theHeaders, $theBody) = explode("\r\n\r\n", $strResponse, 2); 298 302 return array('headers' => $theHeaders, 'body' => $theBody); 299 }300 301 /**302 * Whether response code is in the 400 range.303 *304 * @access public305 * @static306 * @since 2.7307 *308 * @param array $response Array with code and message keys309 * @return bool True if 40x Response, false if something else.310 */311 function is400Response($response) {312 if ( (int) substr($response, 0, 1) == 4 )313 return true;314 return false;315 }316 317 /**318 * Whether the headers returned a redirect location.319 *320 * Actually just checks whether the location header exists.321 *322 * @access public323 * @static324 * @since 2.7325 *326 * @param array $headers Array with headers327 * @return bool True if Location header is found.328 */329 function isRedirect($headers) {330 if ( isset($headers['location']) )331 return true;332 return false;333 303 } 334 304 … … 357 327 if ( empty($tempheader) ) 358 328 continue; 359 360 329 361 330 if ( false === strpos($tempheader, ':') ) { … … 374 343 return array('response' => $response, 'headers' => $newheaders); 375 344 } 345 346 /** 347 * Decodes chunk transfer-encoding, based off the HTTP 1.1 specification. 348 * 349 * Based off the HTTP http_encoding_dechunk function. Does not support 350 * UTF-8. Does not support returning footer headers. Shouldn't be too 351 * difficult to support it though. 352 * 353 * @todo Add support for footer chunked headers. 354 * 355 * @static 356 * @param string $body Body content 357 * @return bool|string|WP_Error False if not chunked encoded. WP_Error on failure. Chunked decoded body on success. 358 */ 359 function chunkTransferDecode($body) { 360 $body = str_replace(array("\r\n", "\r"), "\n", $body); 361 // The body is not chunked encoding or is malformed. 362 if ( ! preg_match( '/^[0-9a-f]+(\s|\n)+/mi', trim($body) ) ) 363 return false; 364 365 $hex = ''; 366 $dec = 0; 367 $parsedBody = ''; 368 $parsedHeaders = array(); 369 370 $done = false; 371 372 do { 373 $hasChunk = (bool) preg_match( '/^([0-9a-f]+)(\s|\n)+/mi', $body, $match ); 374 375 if ( $hasChunk ) { 376 if ( empty($match[1]) ) { 377 return new WP_Error('http_chunked_decode', __('Does not appear to be chunked encoded or body is malformed.') ); 378 } 379 380 $length = hexdec( $match[1] ); 381 $chunkLength = strlen( $match[0] ); 382 383 if( $body{$length+$chunkLength} == "\n" ) 384 $length++; 385 386 $strBody = substr($body, strlen( $match[0] ), $length); 387 $parsedBody .= $strBody; 388 $body = str_replace(array($match[0], $strBody), '', $body); 389 390 if( "0" == $body ) { 391 $done = true; 392 return $parsedBody; // Ignore footer headers. 393 break; 394 } 395 } else { 396 return new WP_Error('http_chunked_decode', __('Does not appear to be chunked encoded or body is malformed.') ); 397 } 398 } while ( false === $done ); 399 } 376 400 } 377 401 … … 392 416 * Does not support non-blocking mode. 393 417 * 394 * @see WP_Http::re trieveFor default options descriptions.418 * @see WP_Http::request For default options descriptions. 395 419 * 396 420 * @since 2.7 … … 398 422 * @param string $url URI resource. 399 423 * @param str|array $args Optional. Override the defaults. 400 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.401 * @param string $body Optional. The body that should be sent. Expected to be already processed.402 424 * @return array 'headers', 'body', and 'response' keys. 403 425 */ 404 function request($url, $args = array() , $headers = null, $body = null) {426 function request($url, $args = array()) { 405 427 $defaults = array( 406 428 'method' => 'GET', 'timeout' => 3, 407 429 'redirection' => 5, 'httpversion' => '1.0', 408 'blocking' => true 430 'blocking' => true, 431 'headers' => array(), 'body' => null 409 432 ); 410 433 411 434 $r = wp_parse_args( $args, $defaults ); 435 436 if ( isset($r['headers']['User-Agent']) ) { 437 $r['user-agent'] = $r['headers']['User-Agent']; 438 unset($r['headers']['User-Agent']); 439 } else if( isset($r['headers']['user-agent']) ) { 440 $r['user-agent'] = $r['headers']['user-agent']; 441 unset($r['headers']['user-agent']); 442 } 412 443 413 444 $iError = null; // Store error number … … 446 477 $strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; 447 478 $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; 448 if ( ! is_null($body) ) { 449 $strHeaders .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n"; 450 $strHeaders .= 'Content-Length: ' . strlen($body) . "\r\n"; 451 } 452 453 if ( is_array($headers) ) { 454 foreach ( (array) $headers as $header => $headerValue ) 479 480 if( isset($r['user-agent']) ) 481 $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; 482 483 if ( is_array($r['headers']) ) { 484 foreach ( (array) $r['headers'] as $header => $headerValue ) 455 485 $strHeaders .= $header . ': ' . $headerValue . "\r\n"; 456 486 } else { 457 $strHeaders .= $ headers;487 $strHeaders .= $r['headers']; 458 488 } 459 489 460 490 $strHeaders .= "\r\n"; 461 491 462 if ( ! is_null($ body) )463 $strHeaders .= $ body;492 if ( ! is_null($r['body']) ) 493 $strHeaders .= $r['body']; 464 494 465 495 fwrite($handle, $strHeaders); … … 482 512 $arrHeaders = WP_Http::processHeaders($process['headers']); 483 513 484 if ( WP_Http ::is400Response($arrHeaders['response']) )514 if ( WP_Http_Fsockopen::is400Response($arrHeaders['response']['code']) ) 485 515 return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']); 486 516 517 // If location is found, then assume redirect and redirect to location. 487 518 if ( isset($arrHeaders['headers']['location']) ) { 488 if ( $r['redirection']-- > 0 ) 489 return $this->request($arrHeaders['headers']['location'], $r, $headers, $body); 519 if ( $r['redirection']-- > 0 ) { 520 return $this->request($arrHeaders['headers']['location'], $r); 521 } 490 522 else 491 523 return new WP_Error('http_request_failed', __('Too many redirects.')); … … 508 540 return false; 509 541 } 542 543 /** 544 * Whether response code is in the 400 range. 545 * 546 * @access public 547 * @static 548 * @since 2.7 549 * 550 * @param string $response Response code. 551 * @return bool True if 40x Response, false if something else. 552 */ 553 function is400Response($response) { 554 if ( is_numeric($response) && (int) substr($response, 0, 1) == 4 ) 555 return true; 556 return false; 557 } 510 558 } 511 559 … … 537 585 * @param string $url URI resource. 538 586 * @param str|array $args Optional. Override the defaults. 539 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.540 * @param string $body Optional. The body that should be sent. Expected to be already processed.541 587 * @return array 'headers', 'body', and 'response' keys. 542 588 */ 543 function request($url, $args = array() , $headers = null, $body = null) {589 function request($url, $args = array()) { 544 590 global $http_response_header; 545 591 … … 547 593 'method' => 'GET', 'timeout' => 3, 548 594 'redirection' => 5, 'httpversion' => '1.0', 549 'blocking' => true 595 'blocking' => true, 596 'headers' => array(), 'body' => null 550 597 ); 551 598 … … 592 639 $processedHeaders = WP_Http::processHeaders($theHeaders); 593 640 641 if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 642 $theBody = WP_Http::chunkTransferDecode($strResponse); 643 594 644 return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response']); 595 645 } … … 630 680 * @param string $url 631 681 * @param str|array $args Optional. Override the defaults. 632 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.633 * @param string $body Optional. The body that should be sent. Expected to be already processed.634 682 * @return array 'headers', 'body', and 'response' keys. 635 683 */ 636 function request($url, $args = array() , $headers = null, $body = null) {684 function request($url, $args = array()) { 637 685 $defaults = array( 638 686 'method' => 'GET', 'timeout' => 3, 639 687 'redirection' => 5, 'httpversion' => '1.0', 640 'blocking' => true 688 'blocking' => true, 689 'headers' => array(), 'body' => null 641 690 ); 642 691 643 692 $r = wp_parse_args( $args, $defaults ); 644 693 645 if ( isset($headers['User-Agent']) ) { 646 $r['user-agent'] = $headers['User-Agent']; 647 unset($headers['User-Agent']); 648 } else if( isset($headers['user-agent']) ) { 649 $r['user-agent'] = $headers['user-agent']; 650 unset($headers['user-agent']); 651 } else { 652 $r['user-agent'] = apply_filters('http_headers_useragent', 'WordPress/' . $wp_version ); 694 if ( isset($r['headers']['User-Agent']) ) { 695 $r['user-agent'] = $r['headers']['User-Agent']; 696 unset($r['headers']['User-Agent']); 697 } else if( isset($r['headers']['user-agent']) ) { 698 $r['user-agent'] = $r['headers']['user-agent']; 699 unset($r['headers']['user-agent']); 653 700 } 654 701 … … 660 707 if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] ) 661 708 $url = str_replace($arrURL['scheme'], 'http', $url); 709 710 // Convert Header array to string. 711 $strHeaders = ''; 712 if ( is_array( $r['headers'] ) ) 713 foreach( $r['headers'] as $name => $value ) 714 $strHeaders .= "{$name}: $value\r\n"; 715 else if ( is_string( $r['headers'] ) ) 716 $strHeaders = $r['headers']; 662 717 663 718 $arrContext = array('http' => … … 667 722 'max_redirects' => $r['redirection'], 668 723 'protocol_version' => (float) $r['httpversion'], 669 'header' => $ headers,724 'header' => $strHeaders, 670 725 'timeout' => $r['timeout'] 671 726 ) 672 727 ); 673 728 674 if ( ! is_null($ body) )675 $arrContext['http']['content'] = $ body;729 if ( ! is_null($r['body']) && ! empty($r['body'] ) ) 730 $arrContext['http']['content'] = $r['body']; 676 731 677 732 $context = stream_context_create($arrContext); … … 696 751 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']); 697 752 753 if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 754 $theBody = WP_Http::chunkTransferDecode($strResponse); 755 698 756 fclose($handle); 699 757 … … 744 802 * @param string $url 745 803 * @param str|array $args Optional. Override the defaults. 746 * @param array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.747 * @param string $body Optional. The body that should be sent. Expected to be already processed.748 804 * @return array 'headers', 'body', and 'response' keys. 749 805 */ 750 function request($url, $args = array(), $headers = null, $body = null) { 751 global $wp_version; 752 806 function request($url, $args = array()) { 753 807 $defaults = array( 754 808 'method' => 'GET', 'timeout' => 3, 755 809 'redirection' => 5, 'httpversion' => '1.0', 756 'blocking' => true 810 'blocking' => true, 811 'headers' => array(), 'body' => null 757 812 ); 758 813 759 814 $r = wp_parse_args( $args, $defaults ); 760 815 761 if ( isset($headers['User-Agent']) ) { 762 $r['user-agent'] = $headers['User-Agent']; 763 unset($headers['User-Agent']); 764 } else if( isset($headers['user-agent']) ) { 765 $r['user-agent'] = $headers['user-agent']; 766 unset($headers['user-agent']); 767 } else { 768 $r['user-agent'] = apply_filters('http_headers_useragent', 'WordPress/' . $wp_version ); 816 if ( isset($r['headers']['User-Agent']) ) { 817 $r['user-agent'] = $r['headers']['User-Agent']; 818 unset($r['headers']['User-Agent']); 819 } else if( isset($r['headers']['user-agent']) ) { 820 $r['user-agent'] = $r['headers']['user-agent']; 821 unset($r['headers']['user-agent']); 769 822 } 770 823 … … 793 846 'redirect' => $r['redirection'], 794 847 'useragent' => $r['user-agent'], 795 'headers' => $ headers,848 'headers' => $r['headers'], 796 849 ); 797 850 798 $strResponse = http_request($r['method'], $url, $ body, $options, $info);851 $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); 799 852 800 853 if ( false === $strResponse ) … … 851 904 * @param string $url 852 905 * @param str|array $args Optional. Override the defaults. 853 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.854 * @param string $body Optional. The body that should be sent. Expected to be already processed.855 906 * @return array 'headers', 'body', and 'response' keys. 856 907 */ 857 function request($url, $args = array(), $headers = null, $body = null) { 858 global $wp_version; 859 908 function request($url, $args = array()) { 860 909 $defaults = array( 861 910 'method' => 'GET', 'timeout' => 3, 862 911 'redirection' => 5, 'httpversion' => '1.0', 863 'blocking' => true 912 'blocking' => true, 913 'headers' => array(), 'body' => null 864 914 ); 865 915 866 916 $r = wp_parse_args( $args, $defaults ); 867 917 868 if ( isset($headers['User-Agent']) ) { 869 $r['user-agent'] = $headers['User-Agent']; 870 unset($headers['User-Agent']); 871 } else if( isset($headers['user-agent']) ) { 872 $r['user-agent'] = $headers['user-agent']; 873 unset($headers['user-agent']); 874 } else { 875 $r['user-agent'] = apply_filters('http_headers_useragent', 'WordPress/' . $wp_version ); 918 if ( isset($r['headers']['User-Agent']) ) { 919 $r['user-agent'] = $r['headers']['User-Agent']; 920 unset($r['headers']['User-Agent']); 921 } else if( isset($r['headers']['user-agent']) ) { 922 $r['user-agent'] = $r['headers']['user-agent']; 923 unset($r['headers']['user-agent']); 876 924 } 877 925 … … 897 945 curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true ); 898 946 899 if( ! is_null($ headers) )900 curl_setopt( $handle, CURLOPT_HTTPHEADER, $ headers);947 if( ! is_null($r['headers']) ) 948 curl_setopt( $handle, CURLOPT_HTTPHEADER, $r['headers'] ); 901 949 902 950 if ( $r['httpversion'] == '1.0' ) … … 915 963 list($theHeaders, $theBody) = explode("\r\n\r\n", $theResponse, 2); 916 964 $theHeaders = WP_Http::processHeaders($theHeaders); 965 966 if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) 967 $theBody = WP_Http::chunkTransferDecode($theBody); 917 968 918 969 $response = array(); … … 987 1038 * @param string $url Site URL to retrieve. 988 1039 * @param array $args Optional. Override the defaults. 989 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.990 * @param string $body Optional. The body that should be sent. Expected to be already processed.991 1040 * @return string The body of the response 992 1041 */ 993 function wp_remote_request($url, $args = array() , $headers = null, $body = null) {1042 function wp_remote_request($url, $args = array()) { 994 1043 $objFetchSite = _wp_http_get_object(); 995 996 return $objFetchSite->request($url, $args, $headers, $body); 1044 return $objFetchSite->request($url, $args); 997 1045 } 998 1046 … … 1006 1054 * @param string $url Site URL to retrieve. 1007 1055 * @param array $args Optional. Override the defaults. 1008 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.1009 * @param string $body Optional. The body that should be sent. Expected to be already processed.1010 1056 * @return string The body of the response 1011 1057 */ 1012 function wp_remote_get($url, $args = array() , $headers = null, $body = null) {1058 function wp_remote_get($url, $args = array()) { 1013 1059 $objFetchSite = _wp_http_get_object(); 1014 1060 1015 return $objFetchSite->get($url, $args , $headers, $body);1061 return $objFetchSite->get($url, $args); 1016 1062 } 1017 1063 … … 1025 1071 * @param string $url Site URL to retrieve. 1026 1072 * @param array $args Optional. Override the defaults. 1027 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.1028 * @param string $body Optional. The body that should be sent. Expected to be already processed.1029 1073 * @return string The body of the response 1030 1074 */ 1031 function wp_remote_post($url, $args = array() , $headers = null, $body = null) {1075 function wp_remote_post($url, $args = array()) { 1032 1076 $objFetchSite = _wp_http_get_object(); 1033 1034 return $objFetchSite->post($url, $args, $headers, $body); 1077 return $objFetchSite->post($url, $args); 1035 1078 } 1036 1079 … … 1044 1087 * @param string $url Site URL to retrieve. 1045 1088 * @param array $args Optional. Override the defaults. 1046 * @param string|array $headers Optional. Either the header string or array of Header name and value pairs.1047 * @param string $body Optional. The body that should be sent. Expected to be already processed.1048 1089 * @return string The body of the response 1049 1090 */ 1050 function wp_remote_head($url, $args = array() , $headers = null, $body = null) {1091 function wp_remote_head($url, $args = array()) { 1051 1092 $objFetchSite = _wp_http_get_object(); 1052 1053 return $objFetchSite->head($url, $args, $headers, $body); 1093 return $objFetchSite->head($url, $args); 1054 1094 } 1055 1095 -
trunk/wp-includes/update.php
r8595 r8630 1 1 <?php 2 2 /** 3 * A simple set of functions to check our version 1.0 update service 3 * A simple set of functions to check our version 1.0 update service. 4 4 * 5 5 * @package WordPress … … 8 8 9 9 /** 10 * Check WordPress version against the newest version. * 10 * Check WordPress version against the newest version. 11 * 11 12 * The WordPress version, PHP version, and Locale is sent. Checks against the 12 13 * WordPress server at api.wordpress.org server. Will only check if WordPress 13 14 * isn't installing. 14 15 15 * 16 16 * @package WordPress … … 42 42 43 43 $url = "http://api.wordpress.org/core/version-check/1.2/?version=$wp_version&php=$php_version&locale=$locale"; 44 44 45 $options = array('timeout' => 3); 45 46 $headers = array( 46 $options['headers'] = array( 47 47 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 48 48 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url') 49 49 ); 50 50 51 $response = wp_remote_request($url, $options, $headers); 51 $response = wp_remote_request($url, $options); 52 53 if ( is_wp_error( $response ) ) 54 return false; 52 55 53 56 if ( 200 != $response['response']['code'] ) 54 57 return false; 55 58 56 $body = $response['body']; 57 $body = trim( $body ); 59 $body = trim( $response['body'] ); 58 60 $body = str_replace(array("\r\n", "\r"), "\n", $body); 59 61 $returns = explode("\n", $body); … … 74 76 75 77 /** 76 * wp_update_plugins() -Check plugin versions against the latest versions hosted on WordPress.org.78 * Check plugin versions against the latest versions hosted on WordPress.org. 77 79 * 78 * The WordPress version, PHP version, and Locale is sent along with a list of all plugins installed. 79 * Checks against the WordPress server at api.wordpress.org. 80 * Will only check if PHP has fsockopen enabled and WordPress isn't installing. 80 * The WordPress version, PHP version, and Locale is sent along with a list of 81 * all plugins installed. Checks against the WordPress server at 82 * api.wordpress.org. Will only check if PHP has fsockopen enabled and WordPress 83 * isn't installing. 81 84 * 82 85 * @package WordPress … … 89 92 global $wp_version; 90 93 91 if ( !function_exists('fsockopen') ||defined('WP_INSTALLING') )94 if ( defined('WP_INSTALLING') ) 92 95 return false; 93 96 … … 117 120 } 118 121 119 foreach ( (array) $current->response as $plugin_file => $update_details ) { 120 if ( ! isset($plugins[ $plugin_file ]) ) { 121 $plugin_changed = true; 122 if ( isset ( $current->response ) && is_array( $current->response ) ) { 123 foreach ( $current->response as $plugin_file => $update_details ) { 124 if ( ! isset($plugins[ $plugin_file ]) ) { 125 $plugin_changed = true; 126 } 122 127 } 123 128 } … … 130 135 $to_send->active = $active; 131 136 $send = serialize( $to_send ); 137 $body = 'plugins=' . urlencode( $send ); 132 138 133 $request = 'plugins=' . urlencode( $send ); 134 $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n"; 135 $http_request .= "Host: api.wordpress.org\r\n"; 136 $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n"; 137 $http_request .= "Content-Length: " . strlen($request) . "\r\n"; 138 $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n"; 139 $http_request .= "\r\n"; 140 $http_request .= $request; 139 $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body); 140 $options['headers'] = array( 141 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 142 'Content-Length' => strlen($body), 143 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url') 144 ); 141 145 142 $response = ''; 143 if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) { 144 fwrite($fs, $http_request); 146 $raw_response = wp_remote_request('http://api.wordpress.org/plugins/update-check/1.0/', $options); 145 147 146 while ( !feof($fs) ) 147 $response .= fgets($fs, 1160); // One TCP-IP packet 148 fclose($fs); 149 $response = explode("\r\n\r\n", $response, 2); 148 if( 200 != $raw_response['response']['code'] ) { 149 return false; 150 150 } 151 151 152 $response = unserialize( $r esponse[1] );152 $response = unserialize( $raw_response['body'] ); 153 153 154 154 if ( $response )
Note: See TracChangeset
for help on using the changeset viewer.