From 59bc3b48fdffb76ee65a4b630be3ffa1f6c20c80 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 29 Sep 2014 21:45:27 +0200 Subject: more scrutinizer issue improvements --- inc/IXR_Library.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 979dc4d16..2becf4a54 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -15,6 +15,7 @@ class IXR_Value { + /** @var IXR_Value[]|IXR_Date|IXR_Base64|int|bool|double|string */ var $data; var $type; function IXR_Value ($data, $type = false) { @@ -177,7 +178,7 @@ class IXR_Message { return true; } function tag_open($parser, $tag, $attr) { - $this->currentTag = $tag; + $this->_currentTag = $tag; $this->_currentTagContents = ''; switch($tag) { case 'methodCall': -- cgit v1.2.3 From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- inc/IXR_Library.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 2becf4a54..6ec397894 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -140,6 +140,10 @@ class IXR_Message { var $_lastseen; // The XML parser var $_parser; + + /** + * @param string $message + */ function IXR_Message ($message) { $this->message = $message; } @@ -684,6 +688,13 @@ class IXR_IntrospectionServer extends IXR_Server { 'Returns a documentation string for the specified method' ); } + + /** + * @param string $method + * @param string $callback + * @param string[] $args + * @param string $help + */ function addCallback($method, $callback, $args, $help) { $this->callbacks[$method] = $callback; $this->signatures[$method] = $args; -- cgit v1.2.3 From 67b5a1455c2585e08f87cc622641b843ad4f2171 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 2 Oct 2014 14:55:56 +0200 Subject: PHPDocs --- inc/IXR_Library.php | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 230 insertions(+), 9 deletions(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 6ec397894..c11c959b6 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -13,11 +13,20 @@ * @author Andreas Gohr */ - +/** + * Class IXR_Value + */ class IXR_Value { + /** @var IXR_Value[]|IXR_Date|IXR_Base64|int|bool|double|string */ var $data; + /** @var string */ var $type; + + /** + * @param mixed $data + * @param bool $type + */ function IXR_Value ($data, $type = false) { $this->data = $data; if (!$type) { @@ -36,6 +45,10 @@ class IXR_Value { } } } + + /** + * @return string + */ function calculateType() { if ($this->data === true || $this->data === false) { return 'boolean'; @@ -69,6 +82,10 @@ class IXR_Value { return 'array'; } } + + /** + * @return bool|string + */ function getXml() { /* Return XML for this value */ switch ($this->type) { @@ -108,6 +125,11 @@ class IXR_Value { } return false; } + + /** + * @param array $array + * @return bool + */ function isStruct($array) { /* Nasty function to check if an array is a struct or not */ $expected = 0; @@ -121,7 +143,9 @@ class IXR_Value { } } - +/** + * Class IXR_Message + */ class IXR_Message { var $message; var $messageType; // methodCall / methodResponse / fault @@ -147,6 +171,10 @@ class IXR_Message { function IXR_Message ($message) { $this->message = $message; } + + /** + * @return bool + */ function parse() { // first remove the XML declaration $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); @@ -181,6 +209,12 @@ class IXR_Message { } return true; } + + /** + * @param $parser + * @param string $tag + * @param $attr + */ function tag_open($parser, $tag, $attr) { $this->_currentTag = $tag; $this->_currentTagContents = ''; @@ -202,9 +236,19 @@ class IXR_Message { } $this->_lastseen = $tag; } + + /** + * @param $parser + * @param string $cdata + */ function cdata($parser, $cdata) { $this->_currentTagContents .= $cdata; } + + /** + * @param $parser + * @param $tag + */ function tag_close($parser, $tag) { $valueFlag = false; switch($tag) { @@ -291,12 +335,21 @@ class IXR_Message { } } - +/** + * Class IXR_Server + */ class IXR_Server { var $data; + /** @var array */ var $callbacks = array(); var $message; + /** @var array */ var $capabilities; + + /** + * @param array|bool $callbacks + * @param bool $data + */ function IXR_Server($callbacks = false, $data = false) { $this->setCapabilities(); if ($callbacks) { @@ -305,6 +358,10 @@ class IXR_Server { $this->setCallbacks(); $this->serve($data); } + + /** + * @param bool|string $data + */ function serve($data = false) { if (!$data) { @@ -345,6 +402,12 @@ EOD; // Send it $this->output($xml); } + + /** + * @param string $methodname + * @param array $args + * @return IXR_Error|mixed + */ function call($methodname, $args) { if (!$this->hasMethod($methodname)) { return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); @@ -393,6 +456,10 @@ EOD; return $result; } + /** + * @param int $error + * @param string|bool $message + */ function error($error, $message = false) { // Accepts either an error object or an error code and message if ($message && !is_object($error)) { @@ -400,11 +467,20 @@ EOD; } $this->output($error->getXml()); } + + /** + * @param $xml + */ function output($xml) { header('Content-Type: text/xml; charset=utf-8'); echo '', "\n", $xml; exit; } + + /** + * @param string $method + * @return bool + */ function hasMethod($method) { return in_array($method, array_keys($this->callbacks)); } @@ -425,6 +501,10 @@ EOD; ), ); } + + /** + * @return mixed + */ function getCapabilities() { return $this->capabilities; } @@ -433,11 +513,20 @@ EOD; $this->callbacks['system.listMethods'] = 'this:listMethods'; $this->callbacks['system.multicall'] = 'this:multiCall'; } + + /** + * @return array + */ function listMethods() { // Returns a list of methods - uses array_reverse to ensure user defined // methods are listed before server defined methods return array_reverse(array_keys($this->callbacks)); } + + /** + * @param array $methodcalls + * @return array + */ function multiCall($methodcalls) { // See http://www.xmlrpc.com/discuss/msgReader$1208 $return = array(); @@ -462,10 +551,21 @@ EOD; } } +/** + * Class IXR_Request + */ class IXR_Request { + /** @var string */ var $method; + /** @var array */ var $args; + /** @var string */ var $xml; + + /** + * @param string $method + * @param array $args + */ function IXR_Request($method, $args) { $this->method = $method; $this->args = $args; @@ -484,9 +584,17 @@ EOD; } $this->xml .= ''; } + + /** + * @return int + */ function getLength() { return strlen($this->xml); } + + /** + * @return string + */ function getXml() { return $this->xml; } @@ -503,9 +611,16 @@ EOD; */ class IXR_Client extends DokuHTTPClient { var $posturl = ''; + /** @var IXR_Message|bool */ var $message = false; + /** @var IXR_Error|bool */ var $xmlerror = false; + /** + * @param string $server + * @param string|bool $path + * @param int $port + */ function IXR_Client($server, $path = false, $port = 80) { parent::__construct(); if (!$path) { @@ -516,6 +631,10 @@ class IXR_Client extends DokuHTTPClient { } } + /** + * parameters: method and arguments + * @return bool success or error + */ function query() { $args = func_get_args(); $method = array_shift($args); @@ -549,29 +668,56 @@ class IXR_Client extends DokuHTTPClient { // Message must be OK return true; } + + /** + * @return mixed + */ function getResponse() { // methodResponses can only have one param - return that return $this->message->params[0]; } + + /** + * @return bool + */ function isError() { return (is_object($this->xmlerror)); } + + /** + * @return int + */ function getErrorCode() { return $this->xmlerror->code; } + + /** + * @return string + */ function getErrorMessage() { return $this->xmlerror->message; } } - +/** + * Class IXR_Error + */ class IXR_Error { var $code; var $message; + + /** + * @param int $code + * @param string $message + */ function IXR_Error($code, $message) { $this->code = $code; $this->message = $message; } + + /** + * @return string + */ function getXml() { $xml = << @@ -596,7 +742,9 @@ EOD; } } - +/** + * Class IXR_Date + */ class IXR_Date { var $year; var $month; @@ -604,6 +752,10 @@ class IXR_Date { var $hour; var $minute; var $second; + + /** + * @param int|string $time + */ function IXR_Date($time) { // $time can be a PHP timestamp or an ISO one if (is_numeric($time)) { @@ -612,6 +764,10 @@ class IXR_Date { $this->parseIso($time); } } + + /** + * @param int $timestamp + */ function parseTimestamp($timestamp) { $this->year = gmdate('Y', $timestamp); $this->month = gmdate('m', $timestamp); @@ -620,6 +776,10 @@ class IXR_Date { $this->minute = gmdate('i', $timestamp); $this->second = gmdate('s', $timestamp); } + + /** + * @param string $iso + */ function parseIso($iso) { if(preg_match('/^(\d\d\d\d)-?(\d\d)-?(\d\d)([T ](\d\d):(\d\d)(:(\d\d))?)?/',$iso,$match)){ $this->year = (int) $match[1]; @@ -630,32 +790,59 @@ class IXR_Date { $this->second = (int) $match[8]; } } + + /** + * @return string + */ function getIso() { return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; } + + /** + * @return string + */ function getXml() { return ''.$this->getIso().''; } + + /** + * @return int + */ function getTimestamp() { return gmmktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); } } - +/** + * Class IXR_Base64 + */ class IXR_Base64 { var $data; + + /** + * @param string $data + */ function IXR_Base64($data) { $this->data = $data; } + + /** + * @return string + */ function getXml() { return ''.base64_encode($this->data).''; } } - +/** + * Class IXR_IntrospectionServer + */ class IXR_IntrospectionServer extends IXR_Server { - var $signatures; + /** @var array[] */ + var $signatures + /** @var string[] */; var $help; + function IXR_IntrospectionServer() { $this->setCallbacks(); $this->setCapabilities(); @@ -700,6 +887,12 @@ class IXR_IntrospectionServer extends IXR_Server { $this->signatures[$method] = $args; $this->help[$method] = $help; } + + /** + * @param string $methodname + * @param array $args + * @return IXR_Error|mixed + */ function call($methodname, $args) { // Make sure it's in an array if ($args && !is_array($args)) { @@ -762,6 +955,11 @@ class IXR_IntrospectionServer extends IXR_Server { // It passed the test - run the "real" method call return parent::call($methodname, $argsbackup); } + + /** + * @param string $method + * @return array|IXR_Error + */ function methodSignature($method) { if (!$this->hasMethod($method)) { return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); @@ -800,18 +998,37 @@ class IXR_IntrospectionServer extends IXR_Server { } return $return; } + + /** + * @param string $method + * @return mixed + */ function methodHelp($method) { return $this->help[$method]; } } - +/** + * Class IXR_ClientMulticall + */ class IXR_ClientMulticall extends IXR_Client { + + /** @var array[] */ var $calls = array(); + + /** + * @param string $server + * @param string|bool $path + * @param int $port + */ function IXR_ClientMulticall($server, $path = false, $port = 80) { parent::IXR_Client($server, $path, $port); //$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; } + + /** + * Add a call + */ function addCall() { $args = func_get_args(); $methodName = array_shift($args); @@ -821,6 +1038,10 @@ class IXR_ClientMulticall extends IXR_Client { ); $this->calls[] = $struct; } + + /** + * @return bool + */ function query() { // Prepare multicall, then call the parent::query() method return parent::query('system.multicall', $this->calls); -- cgit v1.2.3 From a6eab1402c41508e5406f4b8e635d012fa684247 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 2 Oct 2014 15:06:45 +0200 Subject: Reformatting IXR library --- inc/IXR_Library.php | 236 ++++++++++++++++++++++++++-------------------------- 1 file changed, 119 insertions(+), 117 deletions(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index c11c959b6..699f8baa8 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -20,27 +20,27 @@ class IXR_Value { /** @var IXR_Value[]|IXR_Date|IXR_Base64|int|bool|double|string */ var $data; - /** @var string */ + /** @var string */ var $type; /** * @param mixed $data * @param bool $type */ - function IXR_Value ($data, $type = false) { + function IXR_Value($data, $type = false) { $this->data = $data; - if (!$type) { + if(!$type) { $type = $this->calculateType(); } $this->type = $type; - if ($type == 'struct') { + if($type == 'struct') { /* Turn all the values in the array in to new IXR_Value objects */ - foreach ($this->data as $key => $value) { + foreach($this->data as $key => $value) { $this->data[$key] = new IXR_Value($value); } } - if ($type == 'array') { - for ($i = 0, $j = count($this->data); $i < $j; $i++) { + if($type == 'array') { + for($i = 0, $j = count($this->data); $i < $j; $i++) { $this->data[$i] = new IXR_Value($this->data[$i]); } } @@ -50,33 +50,33 @@ class IXR_Value { * @return string */ function calculateType() { - if ($this->data === true || $this->data === false) { + if($this->data === true || $this->data === false) { return 'boolean'; } - if (is_integer($this->data)) { + if(is_integer($this->data)) { return 'int'; } - if (is_double($this->data)) { + if(is_double($this->data)) { return 'double'; } // Deal with IXR object types base64 and date - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { + if(is_object($this->data) && is_a($this->data, 'IXR_Date')) { return 'date'; } - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { + if(is_object($this->data) && is_a($this->data, 'IXR_Base64')) { return 'base64'; } // If it is a normal PHP object convert it in to a struct - if (is_object($this->data)) { + if(is_object($this->data)) { $this->data = get_object_vars($this->data); return 'struct'; } - if (!is_array($this->data)) { + if(!is_array($this->data)) { return 'string'; } /* We have an array - is it an array or a struct ? */ - if ($this->isStruct($this->data)) { + if($this->isStruct($this->data)) { return 'struct'; } else { return 'array'; @@ -88,32 +88,32 @@ class IXR_Value { */ function getXml() { /* Return XML for this value */ - switch ($this->type) { + switch($this->type) { case 'boolean': - return ''.(($this->data) ? '1' : '0').''; + return '' . (($this->data) ? '1' : '0') . ''; break; case 'int': - return ''.$this->data.''; + return '' . $this->data . ''; break; case 'double': - return ''.$this->data.''; + return '' . $this->data . ''; break; case 'string': - return ''.htmlspecialchars($this->data).''; + return '' . htmlspecialchars($this->data) . ''; break; case 'array': - $return = ''."\n"; - foreach ($this->data as $item) { - $return .= ' '.$item->getXml()."\n"; + $return = '' . "\n"; + foreach($this->data as $item) { + $return .= ' ' . $item->getXml() . "\n"; } $return .= ''; return $return; break; case 'struct': - $return = ''."\n"; - foreach ($this->data as $name => $value) { + $return = '' . "\n"; + foreach($this->data as $name => $value) { $return .= " $name"; - $return .= $value->getXml()."\n"; + $return .= $value->getXml() . "\n"; } $return .= ''; return $return; @@ -133,8 +133,8 @@ class IXR_Value { function isStruct($array) { /* Nasty function to check if an array is a struct or not */ $expected = 0; - foreach ($array as $key => $value) { - if ((string)$key != (string)$expected) { + foreach($array as $key => $value) { + if((string) $key != (string) $expected) { return true; } $expected++; @@ -148,15 +148,15 @@ class IXR_Value { */ class IXR_Message { var $message; - var $messageType; // methodCall / methodResponse / fault + var $messageType; // methodCall / methodResponse / fault var $faultCode; var $faultString; var $methodName; var $params; // Current variable stacks - var $_arraystructs = array(); // The stack used to keep track of the current array/struct + var $_arraystructs = array(); // The stack used to keep track of the current array/struct var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array - var $_currentStructName = array(); // A stack as well + var $_currentStructName = array(); // A stack as well var $_param; var $_value; var $_currentTag; @@ -168,7 +168,7 @@ class IXR_Message { /** * @param string $message */ - function IXR_Message ($message) { + function IXR_Message($message) { $this->message = $message; } @@ -177,7 +177,7 @@ class IXR_Message { */ function parse() { // first remove the XML declaration - $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); + $this->message = preg_replace('/<\?xml(.*)?\?' . '>/', '', $this->message); // workaround for a bug in PHP/libxml2, see http://bugs.php.net/bug.php?id=45996 $this->message = str_replace('<', '<', $this->message); $this->message = str_replace('>', '>', $this->message); @@ -185,7 +185,7 @@ class IXR_Message { $this->message = str_replace(''', ''', $this->message); $this->message = str_replace('"', '"', $this->message); $this->message = str_replace("\x0b", ' ', $this->message); //vertical tab - if (trim($this->message) == '') { + if(trim($this->message) == '') { return false; } $this->_parser = xml_parser_create(); @@ -195,7 +195,7 @@ class IXR_Message { xml_set_object($this->_parser, $this); xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); xml_set_character_data_handler($this->_parser, 'cdata'); - if (!xml_parse($this->_parser, $this->message)) { + if(!xml_parse($this->_parser, $this->message)) { /* die(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser))); */ @@ -203,7 +203,7 @@ class IXR_Message { } xml_parser_free($this->_parser); // Grab the error messages, if any - if ($this->messageType == 'fault') { + if($this->messageType == 'fault') { $this->faultCode = $this->params[0]['faultCode']; $this->faultString = $this->params[0]['faultString']; } @@ -225,7 +225,7 @@ class IXR_Message { $this->messageType = $tag; break; /* Deal with stacks of arrays and structs */ - case 'data': // data is to all intents and puposes more interesting than array + case 'data': // data is to all intents and puposes more interesting than array $this->_arraystructstypes[] = 'array'; $this->_arraystructs[] = array(); break; @@ -254,17 +254,17 @@ class IXR_Message { switch($tag) { case 'int': case 'i4': - $value = (int)trim($this->_currentTagContents); + $value = (int) trim($this->_currentTagContents); $this->_currentTagContents = ''; $valueFlag = true; break; case 'double': - $value = (double)trim($this->_currentTagContents); + $value = (double) trim($this->_currentTagContents); $this->_currentTagContents = ''; $valueFlag = true; break; case 'string': - $value = (string)$this->_currentTagContents; + $value = (string) $this->_currentTagContents; $this->_currentTagContents = ''; $valueFlag = true; break; @@ -276,14 +276,14 @@ class IXR_Message { break; case 'value': // "If no type is indicated, the type is string." - if($this->_lastseen == 'value'){ - $value = (string)$this->_currentTagContents; + if($this->_lastseen == 'value') { + $value = (string) $this->_currentTagContents; $this->_currentTagContents = ''; $valueFlag = true; } break; case 'boolean': - $value = (boolean)trim($this->_currentTagContents); + $value = (boolean) trim($this->_currentTagContents); $this->_currentTagContents = ''; $valueFlag = true; break; @@ -311,20 +311,20 @@ class IXR_Message { $this->_currentTagContents = ''; break; } - if ($valueFlag) { + if($valueFlag) { /* if (!is_array($value) && !is_object($value)) { $value = trim($value); } */ - if (count($this->_arraystructs) > 0) { + if(count($this->_arraystructs) > 0) { // Add value to struct or array - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { + if($this->_arraystructstypes[count($this->_arraystructstypes) - 1] == 'struct') { // Add to struct - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; + $this->_arraystructs[count($this->_arraystructs) - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; } else { // Add to array - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; + $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; } } else { // Just add as a paramater @@ -340,10 +340,10 @@ class IXR_Message { */ class IXR_Server { var $data; - /** @var array */ + /** @var array */ var $callbacks = array(); var $message; - /** @var array */ + /** @var array */ var $capabilities; /** @@ -352,7 +352,7 @@ class IXR_Server { */ function IXR_Server($callbacks = false, $data = false) { $this->setCapabilities(); - if ($callbacks) { + if($callbacks) { $this->callbacks = $callbacks; } $this->setCallbacks(); @@ -363,24 +363,24 @@ class IXR_Server { * @param bool|string $data */ function serve($data = false) { - if (!$data) { + if(!$data) { $postData = trim(http_get_raw_post_data()); - if (!$postData) { + if(!$postData) { die('XML-RPC server accepts POST requests only.'); } $data = $postData; } $this->message = new IXR_Message($data); - if (!$this->message->parse()) { + if(!$this->message->parse()) { $this->error(-32700, 'parse error. not well formed'); } - if ($this->message->messageType != 'methodCall') { + if($this->message->messageType != 'methodCall') { $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); } $result = $this->call($this->message->methodName, $this->message->params); // Is the result an error? - if (is_a($result, 'IXR_Error')) { + if(is_a($result, 'IXR_Error')) { $this->error($result); } // Encode the result @@ -405,12 +405,12 @@ EOD; /** * @param string $methodname - * @param array $args + * @param array $args * @return IXR_Error|mixed */ function call($methodname, $args) { - if (!$this->hasMethod($methodname)) { - return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); + if(!$this->hasMethod($methodname)) { + return new IXR_Error(-32601, 'server error. requested method ' . $methodname . ' does not exist.'); } $method = $this->callbacks[$methodname]; // Perform the callback and send the response @@ -427,16 +427,16 @@ EOD; $args = (array) $args; // Are we dealing with a function or a method? - if (substr($method, 0, 5) == 'this:') { + if(substr($method, 0, 5) == 'this:') { // It's a class method - check it exists $method = substr($method, 5); - if (!method_exists($this, $method)) { - return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); + if(!method_exists($this, $method)) { + return new IXR_Error(-32601, 'server error. requested class method "' . $method . '" does not exist.'); } // Call the method #$result = $this->$method($args); - $result = call_user_func_array(array(&$this,$method),$args); - } elseif (substr($method, 0, 7) == 'plugin:') { + $result = call_user_func_array(array(&$this, $method), $args); + } elseif(substr($method, 0, 7) == 'plugin:') { list($pluginname, $callback) = explode(':', substr($method, 7), 2); if(!plugin_isdisabled($pluginname)) { $plugin = plugin_load('action', $pluginname); @@ -446,12 +446,12 @@ EOD; } } else { // It's a function - does it exist? - if (!function_exists($method)) { - return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); + if(!function_exists($method)) { + return new IXR_Error(-32601, 'server error. requested function "' . $method . '" does not exist.'); } // Call the function #$result = $method($args); - $result = call_user_func_array($method,$args); + $result = call_user_func_array($method, $args); } return $result; } @@ -462,7 +462,7 @@ EOD; */ function error($error, $message = false) { // Accepts either an error object or an error code and message - if ($message && !is_object($error)) { + if($message && !is_object($error)) { $error = new IXR_Error($error, $message); } $this->output($error->getXml()); @@ -484,6 +484,7 @@ EOD; function hasMethod($method) { return in_array($method, array_keys($this->callbacks)); } + function setCapabilities() { // Initialises capabilities array $this->capabilities = array( @@ -508,6 +509,7 @@ EOD; function getCapabilities() { return $this->capabilities; } + function setCallbacks() { $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; $this->callbacks['system.listMethods'] = 'this:listMethods'; @@ -530,15 +532,15 @@ EOD; function multiCall($methodcalls) { // See http://www.xmlrpc.com/discuss/msgReader$1208 $return = array(); - foreach ($methodcalls as $call) { + foreach($methodcalls as $call) { $method = $call['methodName']; $params = $call['params']; - if ($method == 'system.multicall') { + if($method == 'system.multicall') { $result = new IXR_Error(-32800, 'Recursive calls to system.multicall are forbidden'); } else { $result = $this->call($method, $params); } - if (is_a($result, 'IXR_Error')) { + if(is_a($result, 'IXR_Error')) { $return[] = array( 'faultCode' => $result->code, 'faultString' => $result->message @@ -555,16 +557,16 @@ EOD; * Class IXR_Request */ class IXR_Request { - /** @var string */ + /** @var string */ var $method; - /** @var array */ + /** @var array */ var $args; - /** @var string */ + /** @var string */ var $xml; /** * @param string $method - * @param array $args + * @param array $args */ function IXR_Request($method, $args) { $this->method = $method; @@ -576,7 +578,7 @@ class IXR_Request { EOD; - foreach ($this->args as $arg) { + foreach($this->args as $arg) { $this->xml .= ''; $v = new IXR_Value($arg); $this->xml .= $v->getXml(); @@ -611,7 +613,7 @@ EOD; */ class IXR_Client extends DokuHTTPClient { var $posturl = ''; - /** @var IXR_Message|bool */ + /** @var IXR_Message|bool */ var $message = false; /** @var IXR_Error|bool */ var $xmlerror = false; @@ -623,11 +625,11 @@ class IXR_Client extends DokuHTTPClient { */ function IXR_Client($server, $path = false, $port = 80) { parent::__construct(); - if (!$path) { + if(!$path) { // Assume we have been given a URL instead $this->posturl = $server; - }else{ - $this->posturl = 'http://'.$server.':'.$port.$path; + } else { + $this->posturl = 'http://' . $server . ':' . $port . $path; } } @@ -642,26 +644,26 @@ class IXR_Client extends DokuHTTPClient { $xml = $request->getXml(); $this->headers['Content-Type'] = 'text/xml'; - if(!$this->sendRequest($this->posturl,$xml,'POST')){ - $this->xmlerror = new IXR_Error(-32300, 'transport error - '.$this->error); + if(!$this->sendRequest($this->posturl, $xml, 'POST')) { + $this->xmlerror = new IXR_Error(-32300, 'transport error - ' . $this->error); return false; } // Check HTTP Response code - if($this->status < 200 || $this->status > 206){ - $this->xmlerror = new IXR_Error(-32300, 'transport error - HTTP status '.$this->status); + if($this->status < 200 || $this->status > 206) { + $this->xmlerror = new IXR_Error(-32300, 'transport error - HTTP status ' . $this->status); return false; } // Now parse what we've got back $this->message = new IXR_Message($this->resp_body); - if (!$this->message->parse()) { + if(!$this->message->parse()) { // XML error $this->xmlerror = new IXR_Error(-32700, 'parse error. not well formed'); return false; } // Is the message a fault? - if ($this->message->messageType == 'fault') { + if($this->message->messageType == 'fault') { $this->xmlerror = new IXR_Error($this->message->faultCode, $this->message->faultString); return false; } @@ -758,7 +760,7 @@ class IXR_Date { */ function IXR_Date($time) { // $time can be a PHP timestamp or an ISO one - if (is_numeric($time)) { + if(is_numeric($time)) { $this->parseTimestamp($time); } else { $this->parseIso($time); @@ -781,11 +783,11 @@ class IXR_Date { * @param string $iso */ function parseIso($iso) { - if(preg_match('/^(\d\d\d\d)-?(\d\d)-?(\d\d)([T ](\d\d):(\d\d)(:(\d\d))?)?/',$iso,$match)){ - $this->year = (int) $match[1]; - $this->month = (int) $match[2]; - $this->day = (int) $match[3]; - $this->hour = (int) $match[5]; + if(preg_match('/^(\d\d\d\d)-?(\d\d)-?(\d\d)([T ](\d\d):(\d\d)(:(\d\d))?)?/', $iso, $match)) { + $this->year = (int) $match[1]; + $this->month = (int) $match[2]; + $this->day = (int) $match[3]; + $this->hour = (int) $match[5]; $this->minute = (int) $match[6]; $this->second = (int) $match[8]; } @@ -795,14 +797,14 @@ class IXR_Date { * @return string */ function getIso() { - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; + return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second; } /** * @return string */ function getXml() { - return ''.$this->getIso().''; + return '' . $this->getIso() . ''; } /** @@ -830,7 +832,7 @@ class IXR_Base64 { * @return string */ function getXml() { - return ''.base64_encode($this->data).''; + return '' . base64_encode($this->data) . ''; } } @@ -838,9 +840,9 @@ class IXR_Base64 { * Class IXR_IntrospectionServer */ class IXR_IntrospectionServer extends IXR_Server { - /** @var array[] */ - var $signatures - /** @var string[] */; + /** @var array[] */ + var $signatures/** @var string[] */ + ; var $help; function IXR_IntrospectionServer() { @@ -877,10 +879,10 @@ class IXR_IntrospectionServer extends IXR_Server { } /** - * @param string $method - * @param string $callback + * @param string $method + * @param string $callback * @param string[] $args - * @param string $help + * @param string $help */ function addCallback($method, $callback, $args, $help) { $this->callbacks[$method] = $callback; @@ -895,60 +897,60 @@ class IXR_IntrospectionServer extends IXR_Server { */ function call($methodname, $args) { // Make sure it's in an array - if ($args && !is_array($args)) { + 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.'); + if(!$this->hasMethod($methodname)) { + return new IXR_Error(-32601, 'server error. requested method "' . $this->message->methodName . '" not specified.'); } $method = $this->callbacks[$methodname]; $signature = $this->signatures[$methodname]; $returnType = array_shift($signature); // Check the number of arguments. Check only, if the minimum count of parameters is specified. More parameters are possible. // This is a hack to allow optional parameters... - if (count($args) < count($signature)) { + if(count($args) < count($signature)) { // print 'Num of args: '.count($args).' Num in signature: '.count($signature); return new IXR_Error(-32602, 'server error. wrong number of method parameters'); } // Check the argument types $ok = true; $argsbackup = $args; - for ($i = 0, $j = count($args); $i < $j; $i++) { + for($i = 0, $j = count($args); $i < $j; $i++) { $arg = array_shift($args); $type = array_shift($signature); - switch ($type) { + switch($type) { case 'int': case 'i4': - if (is_array($arg) || !is_int($arg)) { + if(is_array($arg) || !is_int($arg)) { $ok = false; } break; case 'base64': case 'string': - if (!is_string($arg)) { + if(!is_string($arg)) { $ok = false; } break; case 'boolean': - if ($arg !== false && $arg !== true) { + if($arg !== false && $arg !== true) { $ok = false; } break; case 'float': case 'double': - if (!is_float($arg)) { + if(!is_float($arg)) { $ok = false; } break; case 'date': case 'dateTime.iso8601': - if (!is_a($arg, 'IXR_Date')) { + if(!is_a($arg, 'IXR_Date')) { $ok = false; } break; } - if (!$ok) { + if(!$ok) { return new IXR_Error(-32602, 'server error. invalid method parameters'); } } @@ -961,14 +963,14 @@ class IXR_IntrospectionServer extends IXR_Server { * @return array|IXR_Error */ function methodSignature($method) { - if (!$this->hasMethod($method)) { - return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); + if(!$this->hasMethod($method)) { + return new IXR_Error(-32601, 'server error. requested method "' . $method . '" not specified.'); } // We should be returning an array of types $types = $this->signatures[$method]; $return = array(); - foreach ($types as $type) { - switch ($type) { + foreach($types as $type) { + switch($type) { case 'string': $return[] = 'string'; break; -- cgit v1.2.3 From 0a8880f674dca9ad836481eb6d5403510bf886f5 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Fri, 3 Oct 2014 00:46:37 +0200 Subject: Update IXR lib from 1.61 to 1.7.4 + WP improvements Update to latest Incutio XML-RPC Library include also some Wordpress improvements (see for more details the log of the lib as included in WP: https://core.trac.wordpress.org/log/trunk/src/wp-includes/class-IXR.php ) --- inc/IXR_Library.php | 211 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 147 insertions(+), 64 deletions(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 699f8baa8..839298680 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -1,21 +1,46 @@ */ - -/** - * Class IXR_Value - */ class IXR_Value { /** @var IXR_Value[]|IXR_Date|IXR_Base64|int|bool|double|string */ @@ -34,7 +59,7 @@ class IXR_Value { } $this->type = $type; if($type == 'struct') { - /* Turn all the values in the array in to new IXR_Value objects */ + // Turn all the values in the array in to new IXR_Value objects foreach($this->data as $key => $value) { $this->data[$key] = new IXR_Value($value); } @@ -59,6 +84,7 @@ class IXR_Value { if(is_double($this->data)) { return 'double'; } + // Deal with IXR object types base64 and date if(is_object($this->data) && is_a($this->data, 'IXR_Date')) { return 'date'; @@ -66,16 +92,17 @@ class IXR_Value { if(is_object($this->data) && is_a($this->data, 'IXR_Base64')) { return 'base64'; } + // If it is a normal PHP object convert it in to a struct if(is_object($this->data)) { - $this->data = get_object_vars($this->data); return 'struct'; } if(!is_array($this->data)) { return 'string'; } - /* We have an array - is it an array or a struct ? */ + + // We have an array - is it an array or a struct? if($this->isStruct($this->data)) { return 'struct'; } else { @@ -87,7 +114,7 @@ class IXR_Value { * @return bool|string */ function getXml() { - /* Return XML for this value */ + // Return XML for this value switch($this->type) { case 'boolean': return '' . (($this->data) ? '1' : '0') . ''; @@ -127,11 +154,12 @@ class IXR_Value { } /** + * Checks whether or not the supplied array is a struct or not + * * @param array $array - * @return bool + * @return boolean */ function isStruct($array) { - /* Nasty function to check if an array is a struct or not */ $expected = 0; foreach($array as $key => $value) { if((string) $key != (string) $expected) { @@ -144,7 +172,11 @@ class IXR_Value { } /** - * Class IXR_Message + * IXR_MESSAGE + * + * @package IXR + * @since 1.5 + * */ class IXR_Message { var $message; @@ -153,6 +185,7 @@ class IXR_Message { var $faultString; var $methodName; var $params; + // Current variable stacks var $_arraystructs = array(); // The stack used to keep track of the current array/struct var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array @@ -169,7 +202,7 @@ class IXR_Message { * @param string $message */ function IXR_Message($message) { - $this->message = $message; + $this->message =& $message; } /** @@ -177,7 +210,10 @@ class IXR_Message { */ function parse() { // first remove the XML declaration - $this->message = preg_replace('/<\?xml(.*)?\?' . '>/', '', $this->message); + // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages + $header = preg_replace('/<\?xml.*?\?' . '>/', '', substr($this->message, 0, 100), 1); + $this->message = substr_replace($this->message, $header, 0, 100); + // workaround for a bug in PHP/libxml2, see http://bugs.php.net/bug.php?id=45996 $this->message = str_replace('<', '<', $this->message); $this->message = str_replace('>', '>', $this->message); @@ -195,13 +231,23 @@ class IXR_Message { xml_set_object($this->_parser, $this); xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); xml_set_character_data_handler($this->_parser, 'cdata'); - if(!xml_parse($this->_parser, $this->message)) { - /* die(sprintf('XML error: %s at line %d', - xml_error_string(xml_get_error_code($this->_parser)), - xml_get_current_line_number($this->_parser))); */ - return false; - } + $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages + $final = false; + do { + if(strlen($this->message) <= $chunk_size) { + $final = true; + } + $part = substr($this->message, 0, $chunk_size); + $this->message = substr($this->message, $chunk_size); + if(!xml_parse($this->_parser, $part, $final)) { + return false; + } + if($final) { + break; + } + } while(true); xml_parser_free($this->_parser); + // Grab the error messages, if any if($this->messageType == 'fault') { $this->faultCode = $this->params[0]['faultCode']; @@ -216,8 +262,9 @@ class IXR_Message { * @param $attr */ function tag_open($parser, $tag, $attr) { - $this->_currentTag = $tag; $this->_currentTagContents = ''; + $this->_currentTag = $tag; + switch($tag) { case 'methodCall': case 'methodResponse': @@ -225,7 +272,7 @@ class IXR_Message { $this->messageType = $tag; break; /* Deal with stacks of arrays and structs */ - case 'data': // data is to all intents and puposes more interesting than array + case 'data': // data is to all intents and purposes more interesting than array $this->_arraystructstypes[] = 'array'; $this->_arraystructs[] = array(); break; @@ -255,41 +302,33 @@ class IXR_Message { case 'int': case 'i4': $value = (int) trim($this->_currentTagContents); - $this->_currentTagContents = ''; $valueFlag = true; break; case 'double': $value = (double) trim($this->_currentTagContents); - $this->_currentTagContents = ''; $valueFlag = true; break; case 'string': $value = (string) $this->_currentTagContents; - $this->_currentTagContents = ''; $valueFlag = true; break; case 'dateTime.iso8601': $value = new IXR_Date(trim($this->_currentTagContents)); - // $value = $iso->getTimestamp(); - $this->_currentTagContents = ''; $valueFlag = true; break; case 'value': // "If no type is indicated, the type is string." if($this->_lastseen == 'value') { $value = (string) $this->_currentTagContents; - $this->_currentTagContents = ''; $valueFlag = true; } break; case 'boolean': $value = (boolean) trim($this->_currentTagContents); - $this->_currentTagContents = ''; $valueFlag = true; break; case 'base64': $value = base64_decode($this->_currentTagContents); - $this->_currentTagContents = ''; $valueFlag = true; break; /* Deal with stacks of arrays and structs */ @@ -304,19 +343,13 @@ class IXR_Message { break; case 'name': $this->_currentStructName[] = trim($this->_currentTagContents); - $this->_currentTagContents = ''; break; case 'methodName': $this->methodName = trim($this->_currentTagContents); - $this->_currentTagContents = ''; break; } + if($valueFlag) { - /* - if (!is_array($value) && !is_object($value)) { - $value = trim($value); - } - */ if(count($this->_arraystructs) > 0) { // Add value to struct or array if($this->_arraystructstypes[count($this->_arraystructstypes) - 1] == 'struct') { @@ -327,16 +360,20 @@ class IXR_Message { $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; } } else { - // Just add as a paramater + // Just add as a parameter $this->params[] = $value; } } + $this->_currentTagContents = ''; $this->_lastseen = $tag; } } /** - * Class IXR_Server + * IXR_Server + * + * @package IXR + * @since 1.5 */ class IXR_Server { var $data; @@ -349,14 +386,18 @@ class IXR_Server { /** * @param array|bool $callbacks * @param bool $data + * @param bool $wait */ - function IXR_Server($callbacks = false, $data = false) { + function IXR_Server($callbacks = false, $data = false, $wait = false) { $this->setCapabilities(); if($callbacks) { $this->callbacks = $callbacks; } $this->setCallbacks(); - $this->serve($data); + + if(!$wait) { + $this->serve($data); + } } /** @@ -367,6 +408,7 @@ class IXR_Server { $postData = trim(http_get_raw_post_data()); if(!$postData) { + header('Content-Type: text/plain'); // merged from WP #9093 die('XML-RPC server accepts POST requests only.'); } $data = $postData; @@ -379,13 +421,16 @@ class IXR_Server { $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); } $result = $this->call($this->message->methodName, $this->message->params); + // Is the result an error? if(is_a($result, 'IXR_Error')) { $this->error($result); } + // Encode the result $r = new IXR_Value($result); $resultxml = $r->getXml(); + // Create the XML $xml = << @@ -413,11 +458,12 @@ EOD; return new IXR_Error(-32601, 'server error. requested method ' . $methodname . ' does not exist.'); } $method = $this->callbacks[$methodname]; + // Perform the callback and send the response # Removed for DokuWiki to have a more consistent interface # if (count($args) == 1) { - # // If only one paramater just send that instead of the whole array + # // If only one parameter just send that instead of the whole array # $args = $args[0]; # } @@ -427,7 +473,7 @@ EOD; $args = (array) $args; // Are we dealing with a function or a method? - if(substr($method, 0, 5) == 'this:') { + if(is_string($method) && substr($method, 0, 5) == 'this:') { // It's a class method - check it exists $method = substr($method, 5); if(!method_exists($this, $method)) { @@ -446,12 +492,16 @@ EOD; } } else { // It's a function - does it exist? - if(!function_exists($method)) { + if(is_array($method)) { + if(!is_callable(array($method[0], $method[1]))) { + return new IXR_Error(-32601, 'server error. requested object method "' . $method[1] . '" does not exist.'); + } + } else if(!function_exists($method)) { return new IXR_Error(-32601, 'server error. requested function "' . $method . '" does not exist.'); } + // Call the function - #$result = $method($args); - $result = call_user_func_array($method, $args); + $result = call_user_func($method, $args); } return $result; } @@ -469,7 +519,7 @@ EOD; } /** - * @param $xml + * @param string $xml */ function output($xml) { header('Content-Type: text/xml; charset=utf-8'); @@ -554,7 +604,10 @@ EOD; } /** - * Class IXR_Request + * IXR_Request + * + * @package IXR + * @since 1.5 */ class IXR_Request { /** @var string */ @@ -603,6 +656,11 @@ EOD; } /** + * IXR_Client + * + * @package IXR + * @since 1.5 + * * Changed for DokuWiki to use DokuHTTPClient * * This should be compatible to the original class, but uses DokuWiki's @@ -615,6 +673,8 @@ class IXR_Client extends DokuHTTPClient { var $posturl = ''; /** @var IXR_Message|bool */ var $message = false; + + // Storage place for an error message /** @var IXR_Error|bool */ var $xmlerror = false; @@ -622,8 +682,9 @@ class IXR_Client extends DokuHTTPClient { * @param string $server * @param string|bool $path * @param int $port + * @param int $timeout */ - function IXR_Client($server, $path = false, $port = 80) { + function IXR_Client($server, $path = false, $port = 80, $timeout = 15) { parent::__construct(); if(!$path) { // Assume we have been given a URL instead @@ -631,6 +692,7 @@ class IXR_Client extends DokuHTTPClient { } else { $this->posturl = 'http://' . $server . ':' . $port . $path; } + $this->timeout = $timeout; } /** @@ -662,11 +724,13 @@ class IXR_Client extends DokuHTTPClient { $this->xmlerror = new IXR_Error(-32700, 'parse error. not well formed'); return false; } + // Is the message a fault? if($this->message->messageType == 'fault') { $this->xmlerror = new IXR_Error($this->message->faultCode, $this->message->faultString); return false; } + // Message must be OK return true; } @@ -702,7 +766,10 @@ class IXR_Client extends DokuHTTPClient { } /** - * Class IXR_Error + * IXR_Error + * + * @package IXR + * @since 1.5 */ class IXR_Error { var $code; @@ -714,7 +781,7 @@ class IXR_Error { */ function IXR_Error($code, $message) { $this->code = $code; - $this->message = $message; + $this->message = htmlspecialchars($message); } /** @@ -745,7 +812,10 @@ EOD; } /** - * Class IXR_Date + * IXR_Date + * + * @package IXR + * @since 1.5 */ class IXR_Date { var $year; @@ -754,6 +824,7 @@ class IXR_Date { var $hour; var $minute; var $second; + var $timezone; /** * @param int|string $time @@ -777,6 +848,7 @@ class IXR_Date { $this->hour = gmdate('H', $timestamp); $this->minute = gmdate('i', $timestamp); $this->second = gmdate('s', $timestamp); + $this->timezone = ''; } /** @@ -797,7 +869,7 @@ class IXR_Date { * @return string */ function getIso() { - return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second; + return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second . $this->timezone; } /** @@ -816,7 +888,10 @@ class IXR_Date { } /** - * Class IXR_Base64 + * IXR_Base64 + * + * @package IXR + * @since 1.5 */ class IXR_Base64 { var $data; @@ -837,12 +912,15 @@ class IXR_Base64 { } /** - * Class IXR_IntrospectionServer + * IXR_IntrospectionServer + * + * @package IXR + * @since 1.5 */ class IXR_IntrospectionServer extends IXR_Server { /** @var array[] */ - var $signatures/** @var string[] */ - ; + var $signatures; + /** @var string[] */ var $help; function IXR_IntrospectionServer() { @@ -900,6 +978,7 @@ class IXR_IntrospectionServer extends IXR_Server { 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.'); @@ -913,6 +992,7 @@ class IXR_IntrospectionServer extends IXR_Server { // print 'Num of args: '.count($args).' Num in signature: '.count($signature); return new IXR_Error(-32602, 'server error. wrong number of method parameters'); } + // Check the argument types $ok = true; $argsbackup = $args; @@ -1011,7 +1091,10 @@ class IXR_IntrospectionServer extends IXR_Server { } /** - * Class IXR_ClientMulticall + * IXR_ClientMulticall + * + * @package IXR + * @since 1.5 */ class IXR_ClientMulticall extends IXR_Client { -- cgit v1.2.3 From 26e22ab837dcabe137a0912fcd2f96d0c35f48c8 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Fri, 15 May 2015 19:03:34 +0200 Subject: Changes for PHP 7 Compatibility - replace PHP4 style class constructor function names (based on class name) with php 5 __construct() Also remove some '&' reference operators used with objects And add some object type hints --- inc/IXR_Library.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 839298680..301a8d9e1 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -52,7 +52,7 @@ class IXR_Value { * @param mixed $data * @param bool $type */ - function IXR_Value($data, $type = false) { + function __construct($data, $type = false) { $this->data = $data; if(!$type) { $type = $this->calculateType(); @@ -201,7 +201,7 @@ class IXR_Message { /** * @param string $message */ - function IXR_Message($message) { + function __construct($message) { $this->message =& $message; } @@ -388,7 +388,7 @@ class IXR_Server { * @param bool $data * @param bool $wait */ - function IXR_Server($callbacks = false, $data = false, $wait = false) { + function __construct($callbacks = false, $data = false, $wait = false) { $this->setCapabilities(); if($callbacks) { $this->callbacks = $callbacks; @@ -621,7 +621,7 @@ class IXR_Request { * @param string $method * @param array $args */ - function IXR_Request($method, $args) { + function __construct($method, $args) { $this->method = $method; $this->args = $args; $this->xml = <<code = $code; $this->message = htmlspecialchars($message); } @@ -829,7 +829,7 @@ class IXR_Date { /** * @param int|string $time */ - function IXR_Date($time) { + function __construct($time) { // $time can be a PHP timestamp or an ISO one if(is_numeric($time)) { $this->parseTimestamp($time); @@ -899,7 +899,7 @@ class IXR_Base64 { /** * @param string $data */ - function IXR_Base64($data) { + function __construct($data) { $this->data = $data; } @@ -923,7 +923,7 @@ class IXR_IntrospectionServer extends IXR_Server { /** @var string[] */ var $help; - function IXR_IntrospectionServer() { + function __construct() { $this->setCallbacks(); $this->setCapabilities(); $this->capabilities['introspection'] = array( @@ -1106,7 +1106,7 @@ class IXR_ClientMulticall extends IXR_Client { * @param string|bool $path * @param int $port */ - function IXR_ClientMulticall($server, $path = false, $port = 80) { + function __construct($server, $path = false, $port = 80) { parent::IXR_Client($server, $path, $port); //$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; } -- cgit v1.2.3 From 4d1366e45cecd27c337b0a8d606cfcde58f9ac8c Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 30 Jun 2015 23:55:08 +0200 Subject: Use a DateTime object in the IXR_Date --- inc/IXR_Library.php | 56 +++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 301a8d9e1..4bd57aa26 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -818,18 +818,14 @@ EOD; * @since 1.5 */ class IXR_Date { - var $year; - var $month; - var $day; - var $hour; - var $minute; - var $second; - var $timezone; + + /** @var DateTime */ + protected $date; /** * @param int|string $time */ - function __construct($time) { + public function __construct($time) { // $time can be a PHP timestamp or an ISO one if(is_numeric($time)) { $this->parseTimestamp($time); @@ -839,51 +835,48 @@ class IXR_Date { } /** + * Parse unix timestamp + * * @param int $timestamp */ - function parseTimestamp($timestamp) { - $this->year = gmdate('Y', $timestamp); - $this->month = gmdate('m', $timestamp); - $this->day = gmdate('d', $timestamp); - $this->hour = gmdate('H', $timestamp); - $this->minute = gmdate('i', $timestamp); - $this->second = gmdate('s', $timestamp); - $this->timezone = ''; + protected function parseTimestamp($timestamp) { + $this->date = new DateTime('@' . $timestamp); } /** + * Parses less or more complete iso dates and much more, if no timezone given assumes UTC + * * @param string $iso */ - function parseIso($iso) { - if(preg_match('/^(\d\d\d\d)-?(\d\d)-?(\d\d)([T ](\d\d):(\d\d)(:(\d\d))?)?/', $iso, $match)) { - $this->year = (int) $match[1]; - $this->month = (int) $match[2]; - $this->day = (int) $match[3]; - $this->hour = (int) $match[5]; - $this->minute = (int) $match[6]; - $this->second = (int) $match[8]; - } + protected function parseIso($iso) { + $this->date = new DateTime($iso, new DateTimeZone("UTC")); } /** + * Returns date in ISO 8601 format + * * @return string */ - function getIso() { - return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second . $this->timezone; + public function getIso() { + return $this->date->format(DateTime::ISO8601); } /** + * Returns date in valid xml + * * @return string */ - function getXml() { + public function getXml() { return '' . $this->getIso() . ''; } /** + * Returns Unix timestamp + * * @return int */ function getTimestamp() { - return gmmktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); + return $this->date->getTimestamp(); } } @@ -923,6 +916,9 @@ class IXR_IntrospectionServer extends IXR_Server { /** @var string[] */ var $help; + /** + * Constructor + */ function __construct() { $this->setCallbacks(); $this->setCapabilities(); @@ -1107,7 +1103,7 @@ class IXR_ClientMulticall extends IXR_Client { * @param int $port */ function __construct($server, $path = false, $port = 80) { - parent::IXR_Client($server, $path, $port); + parent::__construct($server, $path, $port); //$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; } -- cgit v1.2.3 From 47ab76cc8e7efb398f80a778639267a3e33c3f7d Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 30 Jun 2015 23:55:22 +0200 Subject: undefined var --- inc/IXR_Library.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/IXR_Library.php') diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 4bd57aa26..5ae1402b9 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -297,6 +297,7 @@ class IXR_Message { * @param $tag */ function tag_close($parser, $tag) { + $value = null; $valueFlag = false; switch($tag) { case 'int': -- cgit v1.2.3