]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-IXR.php
Wizard 2.8.2-scripts
[autoinstalls/wordpress.git] / wp-includes / class-IXR.php
index f27be3f9cf26f0dea5e1da88983e89718edcb907..a4bcfbd572a0904c942fd6de2ac860eef56e62af 100644 (file)
@@ -22,6 +22,7 @@
 class IXR_Value {
     var $data;
     var $type;
+
     function IXR_Value ($data, $type = false) {
         $this->data = $data;
         if (!$type) {
@@ -40,6 +41,7 @@ class IXR_Value {
             }
         }
     }
+
     function calculateType() {
         if ($this->data === true || $this->data === false) {
             return 'boolean';
@@ -73,6 +75,7 @@ class IXR_Value {
             return 'array';
         }
     }
+
     function getXml() {
         /* Return XML for this value */
         switch ($this->type) {
@@ -113,6 +116,7 @@ class IXR_Value {
         }
         return false;
     }
+
     function isStruct($array) {
         /* Nasty function to check if an array is a struct or not */
         $expected = 0;
@@ -154,7 +158,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);
         if (trim($this->message) == '') {
             return false;
         }
@@ -180,7 +184,7 @@ class IXR_Message {
         return true;
     }
     function tag_open($parser, $tag, $attr) {
-               $this->_currentTagContents = '';
+        $this->_currentTagContents = '';
         $this->currentTag = $tag;
         switch($tag) {
             case 'methodCall':
@@ -270,7 +274,7 @@ class IXR_Message {
                 $this->params[] = $value;
             }
         }
-               $this->_currentTagContents = '';
+        $this->_currentTagContents = '';
     }
 }
 
@@ -297,6 +301,7 @@ class IXR_Server {
         if (!$data) {
             global $HTTP_RAW_POST_DATA;
             if (!$HTTP_RAW_POST_DATA) {
+               header( 'Content-Type: text/plain' );
                die('XML-RPC server accepts POST requests only.');
             }
             $data = $HTTP_RAW_POST_DATA;
@@ -334,7 +339,8 @@ EOD;
     }
     function call($methodname, $args) {
         if (!$this->hasMethod($methodname)) {
-            return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
+            return new IXR_Error(-32601, 'server error. requested method '.
+                $methodname.' does not exist.');
         }
         $method = $this->callbacks[$methodname];
         // Perform the callback and send the response
@@ -347,18 +353,21 @@ EOD;
             // 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.');
+                return new IXR_Error(-32601, 'server error. requested class method "'.
+                    $method.'" does not exist.');
             }
             // Call the method
             $result = $this->$method($args);
         } else {
             // It's a function - does it exist?
             if (is_array($method)) {
-               if (!method_exists($method[0], $method[1])) {
-                return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
-               }
+                if (!method_exists($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.');
+                return new IXR_Error(-32601, 'server error. requested function "'.
+                    $method.'" does not exist.');
             }
             // Call the function
             $result = call_user_func($method, $args);
@@ -487,10 +496,11 @@ class IXR_Client {
     var $port;
     var $path;
     var $useragent;
+       var $headers;
     var $response;
     var $message = false;
     var $debug = false;
-       var $timeout;
+    var $timeout;
     // Storage place for an error message
     var $error = false;
     function IXR_Client($server, $path = false, $port = 80, $timeout = false) {
@@ -509,8 +519,8 @@ class IXR_Client {
             $this->path = $path;
             $this->port = $port;
         }
-        $this->useragent = 'Incutio XML-RPC';
-               $this->timeout = $timeout;
+        $this->useragent = 'The Incutio XML-RPC PHP Library';
+        $this->timeout = $timeout;
     }
     function query() {
         $args = func_get_args();
@@ -520,14 +530,21 @@ class IXR_Client {
         $xml = $request->getXml();
         $r = "\r\n";
         $request  = "POST {$this->path} HTTP/1.0$r";
-        $request .= "Host: {$this->server}$r";
-        $request .= "Content-Type: text/xml$r";
-        $request .= "User-Agent: {$this->useragent}$r";
-        $request .= "Content-length: {$length}$r$r";
+
+               $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;
+
         $request .= $xml;
         // Now send the request
         if ($this->debug) {
-            echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n";
+            echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
         }
         if ($this->timeout) {
             $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
@@ -540,6 +557,7 @@ class IXR_Client {
         }
         fputs($fp, $request);
         $contents = '';
+        $debug_contents = '';
         $gotFirstLine = false;
         $gettingHeaders = true;
         while (!feof($fp)) {
@@ -547,7 +565,7 @@ class IXR_Client {
             if (!$gotFirstLine) {
                 // Check line for '200'
                 if (strstr($line, '200') === false) {
-                    $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
+                    $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200');
                     return false;
                 }
                 $gotFirstLine = true;
@@ -556,11 +574,14 @@ class IXR_Client {
                 $gettingHeaders = false;
             }
             if (!$gettingHeaders) {
-                $contents .= trim($line)."\n";
+                $contents .= trim($line);
+            }
+            if ($this->debug) {
+                $debug_contents .= $line;
             }
         }
         if ($this->debug) {
-            echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";
+            echo '<pre class="ixr_response">'.htmlspecialchars($debug_contents)."\n</pre>\n\n";
         }
         // Now parse what we've got back
         $this->message = new IXR_Message($contents);
@@ -603,6 +624,7 @@ class IXR_Error {
     var $message;
     function IXR_Error($code, $message) {
         $this->code = $code;
+        // WP adds htmlspecialchars(). See #5666
         $this->message = htmlspecialchars($message);
     }
     function getXml() {
@@ -642,6 +664,7 @@ class IXR_Date {
     var $hour;
     var $minute;
     var $second;
+    var $timezone;
     function IXR_Date($time) {
         // $time can be a PHP timestamp or an ISO one
         if (is_numeric($time)) {
@@ -657,6 +680,8 @@ class IXR_Date {
         $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) {
         $this->year = substr($iso, 0, 4);
@@ -665,9 +690,11 @@ class IXR_Date {
         $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
         return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
     }
     function getXml() {