WordPress.org

Make WordPress Core

Ticket #1400: class-IXR.php.diff

File class-IXR.php.diff, 10.4 KB (added by ringmaster, 13 years ago)

Diff of 1.7 against current SVN revision

  • class-IXR.php

     
    11<?php
    22
    33/*
    4    IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002
    5    Version 1.62WP - Simon Willison, 11th July 2003 (htmlentities -> htmlspecialchars)
    6            ^^^^^^ (We've made some changes)
     4   IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002-2005
     5   Version 1.7 (beta) - Simon Willison, 23rd May 2005
    76   Site:   http://scripts.incutio.com/xmlrpc/
    87   Manual: http://scripts.incutio.com/xmlrpc/manual.php
    9    Made available under the BSD License: http://www.opensource.org/licenses/bsd-license.php
     8   Made available under the Artistic License: http://www.opensource.org/licenses/artistic-license.php
     9   
     10   Changed in 1.7:
     11   * Fixed bug where whitespace between elements accumulated in _currentTagContents
     12   * Fixed bug in IXR_Date where Unix timestamps were parsed incorrectly
     13   * Fixed bug with request longer than 4096 bytes (thanks Ryuji Tamagawa)
     14   * Struct keys now have XML entities escaped (thanks Andrew Collington)
     15   Merged changes from WordPress (thanks, guys):
     16   * Trim before base64_decode: http://trac.wordpress.org/ticket/654
     17   * Added optional timeout parameter to IXR_Client: http://trac.wordpress.org/changeset/1673
     18   * Added support for class object callbacks: http://trac.wordpress.org/ticket/708
     19     (thanks Owen Winkler)
     20   
     21   Previous version was 1.61, released 11th July 2003
     22
    1023*/
    1124
    1225
     
    90103            case 'struct':
    91104                $return = '<struct>'."\n";
    92105                foreach ($this->data as $name => $value) {
     106                    $name = htmlspecialchars($name);
    93107                    $return .= "  <member><name>$name</name><value>";
    94108                    $return .= $value->getXml()."</value></member>\n";
    95109                }
     
    165179        return true;
    166180    }
    167181    function tag_open($parser, $tag, $attr) {
     182        $this->_currentTagContents = '';
    168183        $this->currentTag = $tag;
    169184        switch($tag) {
    170185            case 'methodCall':
     
    192207            case 'int':
    193208            case 'i4':
    194209                $value = (int)trim($this->_currentTagContents);
    195                 $this->_currentTagContents = '';
    196210                $valueFlag = true;
    197211                break;
    198212            case 'double':
    199213                $value = (double)trim($this->_currentTagContents);
    200                 $this->_currentTagContents = '';
    201214                $valueFlag = true;
    202215                break;
    203216            case 'string':
    204                 $value = (string)trim($this->_currentTagContents);
    205                 $this->_currentTagContents = '';
     217                $value = $this->_currentTagContents;
    206218                $valueFlag = true;
    207219                break;
    208220            case 'dateTime.iso8601':
    209221                $value = new IXR_Date(trim($this->_currentTagContents));
    210222                // $value = $iso->getTimestamp();
    211                 $this->_currentTagContents = '';
    212223                $valueFlag = true;
    213224                break;
    214225            case 'value':
    215226                // "If no type is indicated, the type is string."
    216227                if (trim($this->_currentTagContents) != '') {
    217228                    $value = (string)$this->_currentTagContents;
    218                     $this->_currentTagContents = '';
    219229                    $valueFlag = true;
    220230                }
    221231                break;
    222232            case 'boolean':
    223233                $value = (boolean)trim($this->_currentTagContents);
    224                 $this->_currentTagContents = '';
    225234                $valueFlag = true;
    226235                break;
    227236            case 'base64':
    228                 $value = base64_decode( trim($this->_currentTagContents) );
    229                 $this->_currentTagContents = '';
     237                $value = base64_decode(trim($this->_currentTagContents));
    230238                $valueFlag = true;
    231239                break;
    232240            /* Deal with stacks of arrays and structs */
     
    241249                break;
    242250            case 'name':
    243251                $this->_currentStructName[] = trim($this->_currentTagContents);
    244                 $this->_currentTagContents = '';
    245252                break;
    246253            case 'methodName':
    247254                $this->methodName = trim($this->_currentTagContents);
    248                 $this->_currentTagContents = '';
    249255                break;
    250256        }
    251257        if ($valueFlag) {
    252             /*
    253             if (!is_array($value) && !is_object($value)) {
    254                 $value = trim($value);
    255             }
    256             */
    257258            if (count($this->_arraystructs) > 0) {
    258259                // Add value to struct or array
    259260                if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
     
    268269                $this->params[] = $value;
    269270            }
    270271        }
     272        $this->_currentTagContents = '';
    271273    }       
    272274}
    273275
     
    326328    }
    327329    function call($methodname, $args) {
    328330        if (!$this->hasMethod($methodname)) {
    329             return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
     331            return new IXR_Error(-32601, 'server error. requested method '.
     332                $methodname.' does not exist.');
    330333        }
    331334        $method = $this->callbacks[$methodname];
    332335        // Perform the callback and send the response
     
    339342            // It's a class method - check it exists
    340343            $method = substr($method, 5);
    341344            if (!method_exists($this, $method)) {
    342                 return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
     345                return new IXR_Error(-32601, 'server error. requested class method "'.
     346                    $method.'" does not exist.');
    343347            }
    344348            // Call the method
    345349            $result = $this->$method($args);
    346350        } else {
    347351            // It's a function - does it exist?
    348352            if (is_array($method)) {
    349                 if (!method_exists($method[0], $method[1])) {
    350                 return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
    351                 }
     353                if (!method_exists($method[0], $method[1])) {
     354                    return new IXR_Error(-32601, 'server error. requested object method "'.
     355                        $method[1].'" does not exist.');
     356                }
    352357            } else if (!function_exists($method)) {
    353                 return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
     358                return new IXR_Error(-32601, 'server error. requested function "'.
     359                    $method.'" does not exist.');
    354360            }
    355361            // Call the function
    356362            $result = call_user_func($method, $args);
     
    469475    var $path;
    470476    var $useragent;
    471477    var $response;
    472     var $timeout;
    473     var $vendor = '';
    474478    var $message = false;
    475479    var $debug = false;
     480    var $timeout;
    476481    // Storage place for an error message
    477482    var $error = false;
    478     function IXR_Client($server, $path = false, $port = 80, $timeout = 30, $vendor = '') {
     483    function IXR_Client($server, $path = false, $port = 80, $timeout = false) {
    479484        if (!$path) {
    480485            // Assume we have been given a URL instead
    481486            $bits = parse_url($server);
     
    490495            $this->server = $server;
    491496            $this->path = $path;
    492497            $this->port = $port;
    493             $this->timeout = $timeout;
    494498        }
    495499        $this->useragent = 'The Incutio XML-RPC PHP Library';
     500        $this->timeout = $timeout;
    496501    }
    497502    function query() {
    498503        $args = func_get_args();
     
    511516        if ($this->debug) {
    512517            echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n";
    513518        }
    514         $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
     519        if ($this->timeout) {
     520            $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
     521        } else {
     522            $fp = @fsockopen($this->server, $this->port, $errno, $errstr);
     523        }
    515524        if (!$fp) {
    516             $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
     525            $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr");
    517526            return false;
    518527        }
    519528        fputs($fp, $request);
     
    534543                $gettingHeaders = false;
    535544            }
    536545            if (!$gettingHeaders) {
    537                 $contents .= trim($line)."\n";
     546                $contents .= trim($line);
    538547            }
    539548        }
    540549        if ($this->debug) {
     
    610619    var $hour;
    611620    var $minute;
    612621    var $second;
    613     var $timezone;
    614622    function IXR_Date($time) {
    615623        // $time can be a PHP timestamp or an ISO one
    616624        if (is_numeric($time)) {
     
    621629    }
    622630    function parseTimestamp($timestamp) {
    623631        $this->year = date('Y', $timestamp);
    624         $this->month = date('Y', $timestamp);
    625         $this->day = date('Y', $timestamp);
     632        $this->month = date('m', $timestamp);
     633        $this->day = date('d', $timestamp);
    626634        $this->hour = date('H', $timestamp);
    627635        $this->minute = date('i', $timestamp);
    628636        $this->second = date('s', $timestamp);
    629637    }
    630638    function parseIso($iso) {
    631639        $this->year = substr($iso, 0, 4);
    632         $this->month = substr($iso, 4, 2);
     640        $this->month = substr($iso, 4, 2); 
    633641        $this->day = substr($iso, 6, 2);
    634642        $this->hour = substr($iso, 9, 2);
    635643        $this->minute = substr($iso, 12, 2);
    636644        $this->second = substr($iso, 15, 2);
    637         $this->timezone = substr($iso, 17);
    638645    }
    639646    function getIso() {
    640         return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
     647        return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second;
    641648    }
    642649    function getXml() {
    643650        return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
     
    713720        $returnType = array_shift($signature);
    714721        // Check the number of arguments
    715722        if (count($args) != count($signature)) {
    716             // print 'Num of args: '.count($args).' Num in signature: '.count($signature);
    717723            return new IXR_Error(-32602, 'server error. wrong number of method parameters');
    718724        }
    719725        // Check the argument types
     
    825831    }
    826832}
    827833
    828 ?>
    829  No newline at end of file
     834?><?php
     835
     836?>