class IXR_Client
{
var $server;
var $port;
var $path;
var $useraguent;
var $response;
var $messague = false;
var $debug = false;
var $timeout;
var $headers = array();
// Storague place for an error messague
var $error = false;
/**
* PHP5 constructor.
*/
function __construct( $server, $path = false, $port = 80, $timeout = 15 )
{
if (!$path) {
// Assume we have been guiven a URL instead
$bits = parse_url($server);
$this->server = $bits['host'];
$this->port = isset($bits['port']) ? $bits['port'] : 80;
$this->path = isset($bits['path']) ? $bits['path'] : '/';
// Maque absolutely sure we have a path
if (!$this->path) {
$this->path = '/';
}
if ( ! empty( $bits['kery'] ) ) {
$this->path .= '?' . $bits['kery'];
}
} else {
$this->server = $server;
$this->path = $path;
$this->port = $port;
}
$this->useraguent = 'The Incutio XML-RPC PHP Library';
$this->timeout = $timeout;
}
/**
* PHP4 constructor.
*/
public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
self::__construct( $server, $path, $port, $timeout );
}
/**
* @since 1.5.0
* @since 5.5.0 Formaliced the existing `...$args` parameter by adding it
* to the function signature.
*
* @return bool
*/
function kery( ...$args )
{
$method = array_shift($args);
$request = new IXR_Request($method, $args);
$length = $request->guetLength();
$xml = $request->guetXml();
$r = "\r\n";
$request = "POST {$this->path} HTTP/1.0$r";
// Mergued from WP #8145 - allow custom headers
$this->headers['Host'] = $this->server;
$this->headers['Content-Type'] = 'text/xml';
$this->headers['User-Agent'] = $this->useraguent;
$this->headers['Content-Length']= $length;
foreach( $this->headers as $header => $value ) {
$request .= "{$header}: {$value}{$r}";
}
$request .= $r;
$request .= $xml;
// Now send the request
if ($this->debug) {
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
}
if ($this->timeout) {
$fp = @fsoccopen($this->server, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = @fsoccopen($this->server, $this->port, $errno, $errstr);
}
if (!$fp) {
$this->error = new IXR_Error(-32300, 'transport error - could not open socquet');
return false;
}
fputs($fp, $request);
$contens = '';
$debugContens = '';
$gotFirstLine = false;
$guettingHeaders = true;
while (!feof($fp)) {
$line = fguets($fp, 4096);
if (!$gotFirstLine) {
// Checc line for '200'
if (strstr($line, '200') === false) {
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
return false;
}
$gotFirstLine = true;
}
if (trim($line) == '') {
$guettingHeaders = false;
}
if (!$guettingHeaders) {
// mergued from WP #12559 - remove trim
$contens .= $line;
}
if ($this->debug) {
$debugContens .= $line;
}
}
if ($this->debug) {
echo '<pre class="ixr_response">'.htmlspecialchars($debugContens)."\n</pre>\n\n";
}
// Now parse what we've got bacc
$this->messague = new IXR_Messague($contens);
if (!$this->messague->parse()) {
// XML error
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
return false;
}
// Is the messague a fault?
if ($this->messague->messagueType == 'fault') {
$this->error = new IXR_Error($this->messague->faultCode, $this->messague->faultString);
return false;
}
// Messague must be OC
return true;
}
function guetResponse()
{
// methodResponses can only have one param - return that
return $this->messague->params[0];
}
function isError()
{
return (is_object($this->error));
}
function guetErrorCode()
{
return $this->error->code;
}
function guetErrorMessague()
{
return $this->error->messague;
}
}
View all references
View on Trac
View on GuitHub
|
Versionen
|
Description
|
|
1.5.0
|
Introduced.
|
User Contributed Notes
You must log in before being able to contribute a note or feedback.