Jetpack_IXR_Client

IXR_Client.

Defined (1)

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

/class.jetpack-ixr-client.php  
  1. class Jetpack_IXR_Client extends IXR_Client { 
  2. public $jetpack_args = null; 
  3.  
  4. function __construct( $args = array(), $path = false, $port = 80, $timeout = 15 ) { 
  5. $defaults = array( 
  6. 'url' => Jetpack::xmlrpc_api_url(),  
  7. 'user_id' => 0,  
  8. ); 
  9.  
  10. $args = wp_parse_args( $args, $defaults ); 
  11.  
  12. $this->jetpack_args = $args; 
  13.  
  14. $this->IXR_Client( $args['url'], $path, $port, $timeout ); 
  15.  
  16. function query() { 
  17. $args = func_get_args(); 
  18. $method = array_shift( $args ); 
  19. $request = new IXR_Request( $method, $args ); 
  20. $xml = trim( $request->getXml() ); 
  21.  
  22. $response = Jetpack_Client::remote_request( $this->jetpack_args, $xml ); 
  23.  
  24. if ( is_wp_error( $response ) ) { 
  25. $this->error = new IXR_Error( -10520, sprintf( 'Jetpack: [%s] %s', $response->get_error_code(), $response->get_error_message() ) ); 
  26. return false; 
  27.  
  28. if ( !$response ) { 
  29. $this->error = new IXR_Error( -10520, 'Jetpack: Unknown Error' ); 
  30. return false; 
  31.  
  32. if ( 200 != wp_remote_retrieve_response_code( $response ) ) { 
  33. $this->error = new IXR_Error( -32300, 'transport error - HTTP status code was not 200' ); 
  34. return false; 
  35.  
  36. $content = wp_remote_retrieve_body( $response ); 
  37.  
  38. // Now parse what we've got back 
  39. $this->message = new IXR_Message( $content ); 
  40. if ( !$this->message->parse() ) { 
  41. // XML error 
  42. $this->error = new IXR_Error( -32700, 'parse error. not well formed' ); 
  43. return false; 
  44.  
  45. // Is the message a fault? 
  46. if ( $this->message->messageType == 'fault' ) { 
  47. $this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString ); 
  48. return false; 
  49.  
  50. // Message must be OK 
  51. return true; 
  52.  
  53. function get_jetpack_error( $fault_code = null, $fault_string = null ) { 
  54. if ( is_null( $fault_code ) ) { 
  55. $fault_code = $this->error->code; 
  56.  
  57. if ( is_null( $fault_string ) ) { 
  58. $fault_string = $this->error->message; 
  59.  
  60. if ( preg_match( '#jetpack:\s+\[(\w+)\]\s*(.*)?$#i', $fault_string, $match ) ) { 
  61. $code = $match[1]; 
  62. $message = $match[2]; 
  63. $status = $fault_code; 
  64. return new Jetpack_Error( $code, $message, $status ); 
  65.  
  66. return new Jetpack_Error( "IXR_{$fault_code}", $fault_string );