]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-http-ixr-client.php
WordPress 4.1.4-scripts
[autoinstalls/wordpress.git] / wp-includes / class-wp-http-ixr-client.php
index 4c36334eeef5d4117afbb3ab2e55119065316267..0605955d4991f6fa2321c036f50be81c2cf04790 100644 (file)
@@ -7,18 +7,35 @@
  *
  */
 class WP_HTTP_IXR_Client extends IXR_Client {
-       function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15) {
+       public $scheme;
+       /**
+        * @var IXR_Error
+        */
+       public $error;
+
+       /**
+        * @param string $server
+        * @param string|bool $path
+        * @param int|bool $port
+        * @param int $timeout
+        */
+       public function __construct($server, $path = false, $port = false, $timeout = 15) {
                if ( ! $path ) {
                        // Assume we have been given a URL instead
                        $bits = parse_url($server);
                        $this->scheme = $bits['scheme'];
                        $this->server = $bits['host'];
-                       $this->port = isset($bits['port']) ? $bits['port'] : 80;
+                       $this->port = isset($bits['port']) ? $bits['port'] : $port;
                        $this->path = !empty($bits['path']) ? $bits['path'] : '/';
 
                        // Make absolutely sure we have a path
-                       if ( ! $this->path )
+                       if ( ! $this->path ) {
                                $this->path = '/';
+                       }
+
+                       if ( ! empty( $bits['query'] ) ) {
+                               $this->path .= '?' . $bits['query'];
+                       }
                } else {
                        $this->scheme = 'http';
                        $this->server = $server;
@@ -29,13 +46,14 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                $this->timeout = $timeout;
        }
 
-       function query() {
+       public function query() {
                $args = func_get_args();
                $method = array_shift($args);
                $request = new IXR_Request($method, $args);
                $xml = $request->getXml();
 
-               $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path;
+               $port = $this->port ? ":$this->port" : '';
+               $url = $this->scheme . '://' . $this->server . $port . $this->path;
                $args = array(
                        'headers'    => array('Content-Type' => 'text/xml'),
                        'user-agent' => $this->useragent,
@@ -62,16 +80,16 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                        return false;
                }
 
-               if ( $response['response']['code'] != 200 ) {
-                       $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})");
+               if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
+                       $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')');
                        return false;
                }
 
                if ( $this->debug )
-                       echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
+                       echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
 
                // Now parse what we've got back
-               $this->message = new IXR_Message( $response['body'] );
+               $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
                if ( ! $this->message->parse() ) {
                        // XML error
                        $this->error = new IXR_Error(-32700, 'parse error. not well formed');
@@ -88,4 +106,3 @@ class WP_HTTP_IXR_Client extends IXR_Client {
                return true;
        }
 }
-?>
\ No newline at end of file