[ Index ]

PHP Cross Reference of BackPress

title

Body

[close]

/includes/ -> class.wp-http-ixr-client.php (source)

   1  <?php
   2  /**
   3   * WP_HTTP_IXR_Client
   4   *
   5   * @package WordPress
   6   * @since 3.1.0
   7   *
   8   */
   9  class WP_HTTP_IXR_Client extends IXR_Client
  10  {
  11      function __construct($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'] : '/';
  20  
  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      }
  34  
  35      function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15)
  36      {
  37          self::__construct($server, $path, $port, $timeout);
  38      }
  39  
  40      function query()
  41      {
  42          $args = func_get_args();
  43          $method = array_shift($args);
  44          $request = new IXR_Request($method, $args);
  45          $xml = $request->getXml();
  46  
  47          $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path;
  48          $args = array(
  49              'headers'    => array('Content-Type' => 'text/xml'),
  50              'user-agent' => $this->useragent,
  51              'body'       => $xml,
  52          );
  53          
  54          // Merge Custom headers ala #8145
  55          foreach ( $this->headers as $header => $value )
  56              $args['headers'][$header] = $value;
  57          
  58          if ( $this->timeout !== false )
  59              $args['timeout'] = $this->timeout;
  60              
  61          // Now send the request
  62          if ($this->debug) {
  63              echo '<pre class="ixr_request">'.htmlspecialchars($xml)."\n</pre>\n\n";
  64          }
  65  
  66          $response = wp_remote_post($url, $args); 
  67  
  68          if ( is_wp_error($response) ) { 
  69              $errno    = $response->get_error_code(); 
  70              $errorstr = $response->get_error_message(); 
  71              $this->error = new IXR_Error(-32300, "transport error: $errno $errstr"); 
  72              return false;
  73          }
  74       
  75          $code = $response['response']['code']; 
  76          if ( $code != 200 ) { 
  77              $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ($code)");             return false;
  78          }
  79  
  80          if ($this->debug) {
  81              echo '<pre class="ixr_response">'.htmlspecialchars($response['body'])."\n</pre>\n\n";
  82          }
  83  
  84          // Now parse what we've got back
  85          $this->message = new IXR_Message( $response['body'] );
  86          if (!$this->message->parse()) {
  87              // XML error
  88              $this->error = new IXR_Error(-32700, 'parse error. not well formed');
  89              return false;
  90          }
  91  
  92          // Is the message a fault?
  93          if ($this->message->messageType == 'fault') {
  94              $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
  95              return false;
  96          }
  97  
  98          // Message must be OK
  99          return true;
 100      }
 101  }
 102  ?>


Generated: Wed Dec 19 01:01:51 2018 Cross-referenced by PHPXref 0.7.1