1 | <?php |
||
12 | class Jetpack_IXR_Client extends IXR_Client { |
||
13 | public $jetpack_args = null; |
||
14 | |||
15 | function __construct( $args = array(), $path = false, $port = 80, $timeout = 15 ) { |
||
16 | $defaults = array( |
||
17 | 'url' => Jetpack::xmlrpc_api_url(), |
||
18 | 'user_id' => 0, |
||
19 | ); |
||
20 | |||
21 | $args = wp_parse_args( $args, $defaults ); |
||
22 | |||
23 | $this->jetpack_args = $args; |
||
24 | |||
25 | $this->IXR_Client( $args['url'], $path, $port, $timeout ); |
||
26 | } |
||
27 | |||
28 | function query() { |
||
29 | $args = func_get_args(); |
||
30 | $method = array_shift( $args ); |
||
31 | $request = new IXR_Request( $method, $args ); |
||
32 | $xml = trim( $request->getXml() ); |
||
33 | |||
34 | $response = Jetpack_Client::remote_request( $this->jetpack_args, $xml ); |
||
35 | |||
36 | if ( is_wp_error( $response ) ) { |
||
37 | $this->error = new IXR_Error( -10520, sprintf( 'Jetpack: [%s] %s', $response->get_error_code(), $response->get_error_message() ) ); |
||
38 | return false; |
||
39 | } |
||
40 | |||
41 | if ( !$response ) { |
||
42 | $this->error = new IXR_Error( -10520, 'Jetpack: Unknown Error' ); |
||
43 | return false; |
||
44 | } |
||
45 | |||
46 | if ( 200 != wp_remote_retrieve_response_code( $response ) ) { |
||
47 | $this->error = new IXR_Error( -32300, 'transport error - HTTP status code was not 200' ); |
||
48 | return false; |
||
49 | } |
||
50 | |||
51 | $content = wp_remote_retrieve_body( $response ); |
||
52 | |||
53 | // Now parse what we've got back |
||
54 | $this->message = new IXR_Message( $content ); |
||
55 | if ( !$this->message->parse() ) { |
||
56 | // XML error |
||
57 | $this->error = new IXR_Error( -32700, 'parse error. not well formed' ); |
||
58 | return false; |
||
59 | } |
||
60 | |||
61 | // Is the message a fault? |
||
62 | if ( $this->message->messageType == 'fault' ) { |
||
63 | $this->error = new IXR_Error( $this->message->faultCode, $this->message->faultString ); |
||
64 | return false; |
||
65 | } |
||
66 | |||
67 | // Message must be OK |
||
68 | return true; |
||
69 | } |
||
70 | |||
71 | function get_jetpack_error( $fault_code = null, $fault_string = null ) { |
||
89 | } |
||
90 | |||
91 | /** |
||
134 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.