xml .= '';
}
- function getLength() {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_Request( $method, $args ) {
+ self::__construct( $method, $args );
+ }
+
+ function getLength()
+ {
return strlen($this->xml);
}
- function getXml() {
+
+ function getXml()
+ {
return $this->xml;
}
}
@@ -496,31 +686,44 @@ EOD;
* IXR_Client
*
* @package IXR
- * @since 1.5
+ * @since 1.5.0
+ *
*/
-class IXR_Client {
+class IXR_Client
+{
var $server;
var $port;
var $path;
var $useragent;
- var $headers;
var $response;
var $message = false;
var $debug = false;
var $timeout;
+ var $headers = array();
+
// Storage place for an error message
var $error = false;
- function IXR_Client($server, $path = false, $port = 80, $timeout = false) {
+
+ /**
+ * PHP5 constructor.
+ */
+ function __construct( $server, $path = false, $port = 80, $timeout = 15 )
+ {
if (!$path) {
// Assume we have been given 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'] : '/';
+
// Make absolutely sure we have a path
if (!$this->path) {
$this->path = '/';
}
+
+ if ( ! empty( $bits['query'] ) ) {
+ $this->path .= '?' . $bits['query'];
+ }
} else {
$this->server = $server;
$this->path = $path;
@@ -529,7 +732,16 @@ class IXR_Client {
$this->useragent = 'The Incutio XML-RPC PHP Library';
$this->timeout = $timeout;
}
- function query() {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
+ self::__construct( $server, $path, $port, $timeout );
+ }
+
+ function query()
+ {
$args = func_get_args();
$method = array_shift($args);
$request = new IXR_Request($method, $args);
@@ -538,33 +750,36 @@ class IXR_Client {
$r = "\r\n";
$request = "POST {$this->path} HTTP/1.0$r";
- $this->headers['Host'] = $this->server;
- $this->headers['Content-Type'] = 'text/xml';
- $this->headers['User-Agent'] = $this->useragent;
- $this->headers['Content-Length']= $length;
+ // Merged from WP #8145 - allow custom headers
+ $this->headers['Host'] = $this->server;
+ $this->headers['Content-Type'] = 'text/xml';
+ $this->headers['User-Agent'] = $this->useragent;
+ $this->headers['Content-Length']= $length;
- foreach( $this->headers as $header => $value ) {
- $request .= "{$header}: {$value}{$r}";
- }
- $request .= $r;
+ foreach( $this->headers as $header => $value ) {
+ $request .= "{$header}: {$value}{$r}";
+ }
+ $request .= $r;
$request .= $xml;
+
// Now send the request
if ($this->debug) {
echo ''.htmlspecialchars($request)."\n
\n\n";
}
+
if ($this->timeout) {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
}
if (!$fp) {
- $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr");
+ $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
return false;
}
fputs($fp, $request);
$contents = '';
- $debug_contents = '';
+ $debugContents = '';
$gotFirstLine = false;
$gettingHeaders = true;
while (!feof($fp)) {
@@ -572,7 +787,7 @@ class IXR_Client {
if (!$gotFirstLine) {
// Check line for '200'
if (strstr($line, '200') === false) {
- $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200');
+ $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
return false;
}
$gotFirstLine = true;
@@ -581,15 +796,17 @@ class IXR_Client {
$gettingHeaders = false;
}
if (!$gettingHeaders) {
- $contents .= trim($line);
+ // merged from WP #12559 - remove trim
+ $contents .= $line;
}
if ($this->debug) {
- $debug_contents .= $line;
+ $debugContents .= $line;
}
}
if ($this->debug) {
- echo ''.htmlspecialchars($debug_contents)."\n
\n\n";
+ echo ''.htmlspecialchars($debugContents)."\n
\n\n";
}
+
// Now parse what we've got back
$this->message = new IXR_Message($contents);
if (!$this->message->parse()) {
@@ -597,44 +814,69 @@ class IXR_Client {
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
return false;
}
+
// Is the message a fault?
if ($this->message->messageType == 'fault') {
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
return false;
}
+
// Message must be OK
return true;
}
- function getResponse() {
+
+ function getResponse()
+ {
// methodResponses can only have one param - return that
return $this->message->params[0];
}
- function isError() {
+
+ function isError()
+ {
return (is_object($this->error));
}
- function getErrorCode() {
+
+ function getErrorCode()
+ {
return $this->error->code;
}
- function getErrorMessage() {
+
+ function getErrorMessage()
+ {
return $this->error->message;
}
}
+
/**
* IXR_Error
*
* @package IXR
- * @since 1.5
+ * @since 1.5.0
*/
-class IXR_Error {
+class IXR_Error
+{
var $code;
var $message;
- function IXR_Error($code, $message) {
+
+ /**
+ * PHP5 constructor.
+ */
+ function __construct( $code, $message )
+ {
$this->code = $code;
- // WP adds htmlspecialchars(). See #5666
$this->message = htmlspecialchars($message);
}
- function getXml() {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_Error( $code, $message ) {
+ self::__construct( $code, $message );
+ }
+
+ function getXml()
+ {
$xml = <<
@@ -662,7 +904,7 @@ EOD;
* IXR_Date
*
* @package IXR
- * @since 1.5
+ * @since 1.5.0
*/
class IXR_Date {
var $year;
@@ -672,7 +914,12 @@ class IXR_Date {
var $minute;
var $second;
var $timezone;
- function IXR_Date($time) {
+
+ /**
+ * PHP5 constructor.
+ */
+ function __construct( $time )
+ {
// $time can be a PHP timestamp or an ISO one
if (is_numeric($time)) {
$this->parseTimestamp($time);
@@ -680,34 +927,48 @@ class IXR_Date {
$this->parseIso($time);
}
}
- function parseTimestamp($timestamp) {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_Date( $time ) {
+ self::__construct( $time );
+ }
+
+ function parseTimestamp($timestamp)
+ {
$this->year = date('Y', $timestamp);
$this->month = date('m', $timestamp);
$this->day = date('d', $timestamp);
$this->hour = date('H', $timestamp);
$this->minute = date('i', $timestamp);
$this->second = date('s', $timestamp);
- // WP adds timezone. See #2036
$this->timezone = '';
}
- function parseIso($iso) {
+
+ function parseIso($iso)
+ {
$this->year = substr($iso, 0, 4);
$this->month = substr($iso, 4, 2);
$this->day = substr($iso, 6, 2);
$this->hour = substr($iso, 9, 2);
$this->minute = substr($iso, 12, 2);
$this->second = substr($iso, 15, 2);
- // WP adds timezone. See #2036
$this->timezone = substr($iso, 17);
}
- function getIso() {
- // WP adds timezone. See #2036
+
+ function getIso()
+ {
return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
}
- function getXml() {
+
+ function getXml()
+ {
return ''.$this->getIso().'';
}
- function getTimestamp() {
+
+ function getTimestamp()
+ {
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
}
}
@@ -716,14 +977,29 @@ class IXR_Date {
* IXR_Base64
*
* @package IXR
- * @since 1.5
+ * @since 1.5.0
*/
-class IXR_Base64 {
+class IXR_Base64
+{
var $data;
- function IXR_Base64($data) {
+
+ /**
+ * PHP5 constructor.
+ */
+ function __construct( $data )
+ {
$this->data = $data;
}
- function getXml() {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_Base64( $data ) {
+ self::__construct( $data );
+ }
+
+ function getXml()
+ {
return ''.base64_encode($this->data).'';
}
}
@@ -732,12 +1008,18 @@ class IXR_Base64 {
* IXR_IntrospectionServer
*
* @package IXR
- * @since 1.5
+ * @since 1.5.0
*/
-class IXR_IntrospectionServer extends IXR_Server {
+class IXR_IntrospectionServer extends IXR_Server
+{
var $signatures;
var $help;
- function IXR_IntrospectionServer() {
+
+ /**
+ * PHP5 constructor.
+ */
+ function __construct()
+ {
$this->setCallbacks();
$this->setCapabilities();
$this->capabilities['introspection'] = array(
@@ -769,16 +1051,28 @@ class IXR_IntrospectionServer extends IXR_Server {
'Returns a documentation string for the specified method'
);
}
- function addCallback($method, $callback, $args, $help) {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_IntrospectionServer() {
+ self::__construct();
+ }
+
+ function addCallback($method, $callback, $args, $help)
+ {
$this->callbacks[$method] = $callback;
$this->signatures[$method] = $args;
$this->help[$method] = $help;
}
- function call($methodname, $args) {
+
+ function call($methodname, $args)
+ {
// Make sure it's in an array
if ($args && !is_array($args)) {
$args = array($args);
}
+
// Over-rides default call method, adds signature check
if (!$this->hasMethod($methodname)) {
return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
@@ -786,10 +1080,12 @@ class IXR_IntrospectionServer extends IXR_Server {
$method = $this->callbacks[$methodname];
$signature = $this->signatures[$methodname];
$returnType = array_shift($signature);
+
// Check the number of arguments
if (count($args) != count($signature)) {
return new IXR_Error(-32602, 'server error. wrong number of method parameters');
}
+
// Check the argument types
$ok = true;
$argsbackup = $args;
@@ -834,7 +1130,9 @@ class IXR_IntrospectionServer extends IXR_Server {
// It passed the test - run the "real" method call
return parent::call($methodname, $argsbackup);
}
- function methodSignature($method) {
+
+ function methodSignature($method)
+ {
if (!$this->hasMethod($method)) {
return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
}
@@ -872,7 +1170,9 @@ class IXR_IntrospectionServer extends IXR_Server {
}
return $return;
}
- function methodHelp($method) {
+
+ function methodHelp($method)
+ {
return $this->help[$method];
}
}
@@ -881,15 +1181,30 @@ class IXR_IntrospectionServer extends IXR_Server {
* IXR_ClientMulticall
*
* @package IXR
- * @since 1.5
+ * @since 1.5.0
*/
-class IXR_ClientMulticall extends IXR_Client {
+class IXR_ClientMulticall extends IXR_Client
+{
var $calls = array();
- function IXR_ClientMulticall($server, $path = false, $port = 80) {
+
+ /**
+ * PHP5 constructor.
+ */
+ function __construct( $server, $path = false, $port = 80 )
+ {
parent::IXR_Client($server, $path, $port);
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
}
- function addCall() {
+
+ /**
+ * PHP4 constructor.
+ */
+ public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) {
+ self::__construct( $server, $path, $port );
+ }
+
+ function addCall()
+ {
$args = func_get_args();
$methodName = array_shift($args);
$struct = array(
@@ -898,10 +1213,10 @@ class IXR_ClientMulticall extends IXR_Client {
);
$this->calls[] = $struct;
}
- function query() {
+
+ function query()
+ {
// Prepare multicall, then call the parent::query() method
return parent::query('system.multicall', $this->calls);
}
}
-
-?>