IXR_Client

IXR_Client.

Defined (1)

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

/bp-forums/bbpress/bb-includes/backpress/class.ixr.php  
  1. class IXR_Client 
  2. var $server; 
  3. var $port; 
  4. var $path; 
  5. var $useragent; 
  6. var $response; 
  7. var $message = false; 
  8. var $debug = false; 
  9. var $timeout; 
  10. var $headers = array(); 
  11.  
  12. // Storage place for an error message 
  13. var $error = false; 
  14.  
  15. function __construct($server, $path = false, $port = 80, $timeout = 15) 
  16. if (!$path) { 
  17. // Assume we have been given a URL instead 
  18. $bits = parse_url($server); 
  19. $this->server = $bits['host']; 
  20. $this->port = isset($bits['port']) ? $bits['port'] : 80; 
  21. $this->path = isset($bits['path']) ? $bits['path'] : '/'; 
  22.  
  23. // Make absolutely sure we have a path 
  24. if (!$this->path) { 
  25. $this->path = '/'; 
  26. } else { 
  27. $this->server = $server; 
  28. $this->path = $path; 
  29. $this->port = $port; 
  30. $this->useragent = 'The Incutio XML-RPC PHP Library'; 
  31. $this->timeout = $timeout; 
  32.  
  33. function IXR_Client($server, $path = false, $port = 80, $timeout = 15) 
  34. $this->__construct($server, $path, $port, $timeout); 
  35.  
  36. function query() 
  37. $args = func_get_args(); 
  38. $method = array_shift($args); 
  39. $request = new IXR_Request($method, $args); 
  40. $length = $request->getLength(); 
  41. $xml = $request->getXml(); 
  42. $r = "\r\n"; 
  43. $request = "POST {$this->path} HTTP/1.0$r"; 
  44.  
  45. // Merged from WP #8145 - allow custom headers 
  46. $this->headers['Host'] = $this->server; 
  47. $this->headers['Content-Type'] = 'text/xml'; 
  48. $this->headers['User-Agent'] = $this->useragent; 
  49. $this->headers['Content-Length']= $length; 
  50.  
  51. foreach( $this->headers as $header => $value ) { 
  52. $request .= "{$header}: {$value}{$r}"; 
  53. $request .= $r; 
  54.  
  55. $request .= $xml; 
  56.  
  57. // Now send the request 
  58. if ($this->debug) { 
  59. echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; 
  60.  
  61. if ($this->timeout) { 
  62. $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); 
  63. } else { 
  64. $fp = @fsockopen($this->server, $this->port, $errno, $errstr); 
  65. if (!$fp) { 
  66. $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); 
  67. return false; 
  68. fputs($fp, $request); 
  69. $contents = ''; 
  70. $debugContents = ''; 
  71. $gotFirstLine = false; 
  72. $gettingHeaders = true; 
  73. while (!feof($fp)) { 
  74. $line = fgets($fp, 4096); 
  75. if (!$gotFirstLine) { 
  76. // Check line for '200' 
  77. if (strstr($line, '200') === false) { 
  78. $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); 
  79. return false; 
  80. $gotFirstLine = true; 
  81. if (trim($line) == '') { 
  82. $gettingHeaders = false; 
  83. if (!$gettingHeaders) { 
  84. // merged from WP #12559 - remove trim 
  85. $contents .= $line; 
  86. if ($this->debug) { 
  87. $debugContents .= $line; 
  88. if ($this->debug) { 
  89. echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; 
  90.  
  91. // Now parse what we've got back 
  92. $this->message = new IXR_Message($contents); 
  93. if (!$this->message->parse()) { 
  94. // XML error 
  95. $this->error = new IXR_Error(-32700, 'parse error. not well formed'); 
  96. return false; 
  97.  
  98. // Is the message a fault? 
  99. if ($this->message->messageType == 'fault') { 
  100. $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); 
  101. return false; 
  102.  
  103. // Message must be OK 
  104. return true; 
  105.  
  106. function getResponse() 
  107. // methodResponses can only have one param - return that 
  108. return $this->message->params[0]; 
  109.  
  110. function isError() 
  111. return (is_object($this->error)); 
  112.  
  113. function getErrorCode() 
  114. return $this->error->code; 
  115.  
  116. function getErrorMessage() 
  117. return $this->error->message;