Changeset 16871
- Timestamp:
- 12/11/2010 05:51:49 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-http-ixr-client.php
-
Property
svn:eol-style
set to
native
r16438 r16871 7 7 * 8 8 */ 9 class WP_HTTP_IXR_Client extends IXR_Client 10 { 11 function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15) 12 { 13 if (!$path) { 14 // Assume we have been given a URL instead 15 $bits = parse_url($server); 16 $this->scheme = $bits['scheme']; 17 $this->server = $bits['host']; 18 $this->port = isset($bits['port']) ? $bits['port'] : 80; 19 $this->path = isset($bits['path']) ? $bits['path'] : '/'; 9 class WP_HTTP_IXR_Client extends IXR_Client { 10 function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15) { 11 if ( ! $path ) { 12 // Assume we have been given a URL instead 13 $bits = parse_url($server); 14 $this->scheme = $bits['scheme']; 15 $this->server = $bits['host']; 16 $this->port = isset($bits['port']) ? $bits['port'] : 80; 17 $this->path = !empty($bits['path']) ? $bits['path'] : '/'; 20 18 21 // Make absolutely sure we have a path 22 if (!$this->path) { 23 $this->path = '/'; 24 } 25 } else { 26 $this->scheme = 'http'; 27 $this->server = $server; 28 $this->path = $path; 29 $this->port = $port; 30 } 31 $this->useragent = 'The Incutio XML-RPC PHP Library'; 32 $this->timeout = $timeout; 33 } 19 // Make absolutely sure we have a path 20 if ( ! $this->path ) 21 $this->path = '/'; 22 } else { 23 $this->scheme = 'http'; 24 $this->server = $server; 25 $this->path = $path; 26 $this->port = $port; 27 } 28 $this->useragent = 'The Incutio XML-RPC PHP Library'; 29 $this->timeout = $timeout; 30 } 34 31 35 function query() 36 { 37 $args = func_get_args(); 38 $method = array_shift($args); 39 $request = new IXR_Request($method, $args); 40 $xml = $request->getXml(); 32 function query() { 33 $args = func_get_args(); 34 $method = array_shift($args); 35 $request = new IXR_Request($method, $args); 36 $xml = $request->getXml(); 41 37 42 43 44 45 46 47 38 $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path; 39 $args = array( 40 'headers' => array('Content-Type' => 'text/xml'), 41 'user-agent' => $this->useragent, 42 'body' => $xml, 43 ); 48 44 49 45 // Merge Custom headers ala #8145 50 46 foreach ( $this->headers as $header => $value ) 51 47 $args['headers'][$header] = $value; … … 54 50 $args['timeout'] = $this->timeout; 55 51 56 // Now send the request 57 if ($this->debug) { 58 echo '<pre class="ixr_request">'.htmlspecialchars($xml)."\n</pre>\n\n"; 59 } 52 // Now send the request 53 if ( $this->debug ) 54 echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; 60 55 61 56 $response = wp_remote_post($url, $args); … … 64 59 $errno = $response->get_error_code(); 65 60 $errorstr = $response->get_error_message(); 66 $this->error = new IXR_Error(-32300, "transport error: $errno $err str");61 $this->error = new IXR_Error(-32300, "transport error: $errno $errorstr"); 67 62 return false; 68 63 } 69 64 70 $code = $response['response']['code'];71 if ( $code != 200 ) {72 $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ($code)");return false;73 65 if ( $response['response']['code'] != 200 ) { 66 $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})"); 67 return false; 68 } 74 69 75 if ($this->debug) { 76 echo '<pre class="ixr_response">'.htmlspecialchars($response['body'])."\n</pre>\n\n"; 77 } 70 if ( $this->debug ) 71 echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n"; 78 72 79 80 81 if (!$this->message->parse()) {82 83 84 85 73 // Now parse what we've got back 74 $this->message = new IXR_Message( $response['body'] ); 75 if ( ! $this->message->parse() ) { 76 // XML error 77 $this->error = new IXR_Error(-32700, 'parse error. not well formed'); 78 return false; 79 } 86 80 87 88 if ($this->message->messageType == 'fault') {89 90 91 81 // Is the message a fault? 82 if ( $this->message->messageType == 'fault' ) { 83 $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); 84 return false; 85 } 92 86 93 94 95 87 // Message must be OK 88 return true; 89 } 96 90 } 97 91 ?> -
Property
svn:eol-style
set to
Note: See TracChangeset
for help on using the changeset viewer.