[ Index ]

PHP Cross Reference of bbPress

title

Body

[close]

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


Generated: Fri May 24 03:58:41 2013 Hosted by follow the white rabbit.