WP_HTTP_IXR_Client

WP_HTTP_IXR_Client.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-includes/backpress/class.wp-http-ixr-client.php  
  1. class WP_HTTP_IXR_Client extends IXR_Client 
  2. function __construct($server, $path = false, $port = 80, $timeout = 15) 
  3. if (!$path) { 
  4. // Assume we have been given a URL instead 
  5. $bits = parse_url($server); 
  6. $this->scheme = $bits['scheme']; 
  7. $this->server = $bits['host']; 
  8. $this->port = isset($bits['port']) ? $bits['port'] : 80; 
  9. $this->path = isset($bits['path']) ? $bits['path'] : '/'; 
  10.  
  11. // Make absolutely sure we have a path 
  12. if (!$this->path) { 
  13. $this->path = '/'; 
  14. } else { 
  15. $this->scheme = 'http';  
  16. $this->server = $server; 
  17. $this->path = $path; 
  18. $this->port = $port; 
  19. $this->useragent = 'The Incutio XML-RPC PHP Library'; 
  20. $this->timeout = $timeout; 
  21.  
  22. function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15) 
  23. $this->__construct($server, $path, $port, $timeout); 
  24.  
  25. function query() 
  26. $args = func_get_args(); 
  27. $method = array_shift($args); 
  28. $request = new IXR_Request($method, $args); 
  29. $xml = $request->getXml(); 
  30.  
  31. $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path; 
  32. $args = array( 
  33. 'headers' => array('Content-Type' => 'text/xml'),  
  34. 'user-agent' => $this->useragent,  
  35. 'body' => $xml,  
  36. ); 
  37.  
  38. // Merge Custom headers ala #8145 
  39. foreach ( $this->headers as $header => $value ) 
  40. $args['headers'][$header] = $value; 
  41.  
  42. if ( $this->timeout !== false ) 
  43. $args['timeout'] = $this->timeout; 
  44.  
  45. // Now send the request 
  46. if ($this->debug) { 
  47. echo '<pre class="ixr_request">'.htmlspecialchars($xml)."\n</pre>\n\n"; 
  48.  
  49. $response = wp_remote_post($url, $args);  
  50.  
  51. if ( is_wp_error($response) ) {  
  52. $errno = $response->get_error_code();  
  53. $errorstr = $response->get_error_message();  
  54. $this->error = new IXR_Error(-32300, "transport error: $errno $errstr");  
  55. return false; 
  56.  
  57. $code = $response['response']['code'];  
  58. if ( $code != 200 ) {  
  59. $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ($code)"); return false; 
  60.  
  61. if ($this->debug) { 
  62. echo '<pre class="ixr_response">'.htmlspecialchars($response['body'])."\n</pre>\n\n"; 
  63.  
  64. // Now parse what we've got back 
  65. $this->message = new IXR_Message( $response['body'] ); 
  66. if (!$this->message->parse()) { 
  67. // XML error 
  68. $this->error = new IXR_Error(-32700, 'parse error. not well formed'); 
  69. return false; 
  70.  
  71. // Is the message a fault? 
  72. if ($this->message->messageType == 'fault') { 
  73. $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); 
  74. return false; 
  75.  
  76. // Message must be OK 
  77. return true;