Edit File by line
/home/barbar84/www/wp-inclu.../IXR
File: class-IXR-client.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* IXR_Client
[3] Fix | Delete
*
[4] Fix | Delete
* @package IXR
[5] Fix | Delete
* @since 1.5.0
[6] Fix | Delete
*
[7] Fix | Delete
*/
[8] Fix | Delete
class IXR_Client
[9] Fix | Delete
{
[10] Fix | Delete
var $server;
[11] Fix | Delete
var $port;
[12] Fix | Delete
var $path;
[13] Fix | Delete
var $useragent;
[14] Fix | Delete
var $response;
[15] Fix | Delete
var $message = false;
[16] Fix | Delete
var $debug = false;
[17] Fix | Delete
var $timeout;
[18] Fix | Delete
var $headers = array();
[19] Fix | Delete
[20] Fix | Delete
// Storage place for an error message
[21] Fix | Delete
var $error = false;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* PHP5 constructor.
[25] Fix | Delete
*/
[26] Fix | Delete
function __construct( $server, $path = false, $port = 80, $timeout = 15 )
[27] Fix | Delete
{
[28] Fix | Delete
if (!$path) {
[29] Fix | Delete
// Assume we have been given a URL instead
[30] Fix | Delete
$bits = parse_url($server);
[31] Fix | Delete
$this->server = $bits['host'];
[32] Fix | Delete
$this->port = isset($bits['port']) ? $bits['port'] : 80;
[33] Fix | Delete
$this->path = isset($bits['path']) ? $bits['path'] : '/';
[34] Fix | Delete
[35] Fix | Delete
// Make absolutely sure we have a path
[36] Fix | Delete
if (!$this->path) {
[37] Fix | Delete
$this->path = '/';
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
if ( ! empty( $bits['query'] ) ) {
[41] Fix | Delete
$this->path .= '?' . $bits['query'];
[42] Fix | Delete
}
[43] Fix | Delete
} else {
[44] Fix | Delete
$this->server = $server;
[45] Fix | Delete
$this->path = $path;
[46] Fix | Delete
$this->port = $port;
[47] Fix | Delete
}
[48] Fix | Delete
$this->useragent = 'The Incutio XML-RPC PHP Library';
[49] Fix | Delete
$this->timeout = $timeout;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* PHP4 constructor.
[54] Fix | Delete
*/
[55] Fix | Delete
public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
[56] Fix | Delete
self::__construct( $server, $path, $port, $timeout );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* @since 1.5.0
[61] Fix | Delete
* @since 5.5.0 Formalized the existing `...$args` parameter by adding it
[62] Fix | Delete
* to the function signature.
[63] Fix | Delete
*
[64] Fix | Delete
* @return bool
[65] Fix | Delete
*/
[66] Fix | Delete
function query( ...$args )
[67] Fix | Delete
{
[68] Fix | Delete
$method = array_shift($args);
[69] Fix | Delete
$request = new IXR_Request($method, $args);
[70] Fix | Delete
$length = $request->getLength();
[71] Fix | Delete
$xml = $request->getXml();
[72] Fix | Delete
$r = "\r\n";
[73] Fix | Delete
$request = "POST {$this->path} HTTP/1.0$r";
[74] Fix | Delete
[75] Fix | Delete
// Merged from WP #8145 - allow custom headers
[76] Fix | Delete
$this->headers['Host'] = $this->server;
[77] Fix | Delete
$this->headers['Content-Type'] = 'text/xml';
[78] Fix | Delete
$this->headers['User-Agent'] = $this->useragent;
[79] Fix | Delete
$this->headers['Content-Length']= $length;
[80] Fix | Delete
[81] Fix | Delete
foreach( $this->headers as $header => $value ) {
[82] Fix | Delete
$request .= "{$header}: {$value}{$r}";
[83] Fix | Delete
}
[84] Fix | Delete
$request .= $r;
[85] Fix | Delete
[86] Fix | Delete
$request .= $xml;
[87] Fix | Delete
[88] Fix | Delete
// Now send the request
[89] Fix | Delete
if ($this->debug) {
[90] Fix | Delete
echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
if ($this->timeout) {
[94] Fix | Delete
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
[95] Fix | Delete
} else {
[96] Fix | Delete
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
[97] Fix | Delete
}
[98] Fix | Delete
if (!$fp) {
[99] Fix | Delete
$this->error = new IXR_Error(-32300, 'transport error - could not open socket');
[100] Fix | Delete
return false;
[101] Fix | Delete
}
[102] Fix | Delete
fputs($fp, $request);
[103] Fix | Delete
$contents = '';
[104] Fix | Delete
$debugContents = '';
[105] Fix | Delete
$gotFirstLine = false;
[106] Fix | Delete
$gettingHeaders = true;
[107] Fix | Delete
while (!feof($fp)) {
[108] Fix | Delete
$line = fgets($fp, 4096);
[109] Fix | Delete
if (!$gotFirstLine) {
[110] Fix | Delete
// Check line for '200'
[111] Fix | Delete
if (strstr($line, '200') === false) {
[112] Fix | Delete
$this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
[113] Fix | Delete
return false;
[114] Fix | Delete
}
[115] Fix | Delete
$gotFirstLine = true;
[116] Fix | Delete
}
[117] Fix | Delete
if (trim($line) == '') {
[118] Fix | Delete
$gettingHeaders = false;
[119] Fix | Delete
}
[120] Fix | Delete
if (!$gettingHeaders) {
[121] Fix | Delete
// merged from WP #12559 - remove trim
[122] Fix | Delete
$contents .= $line;
[123] Fix | Delete
}
[124] Fix | Delete
if ($this->debug) {
[125] Fix | Delete
$debugContents .= $line;
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
if ($this->debug) {
[129] Fix | Delete
echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
// Now parse what we've got back
[133] Fix | Delete
$this->message = new IXR_Message($contents);
[134] Fix | Delete
if (!$this->message->parse()) {
[135] Fix | Delete
// XML error
[136] Fix | Delete
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
[137] Fix | Delete
return false;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
// Is the message a fault?
[141] Fix | Delete
if ($this->message->messageType == 'fault') {
[142] Fix | Delete
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
[143] Fix | Delete
return false;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
// Message must be OK
[147] Fix | Delete
return true;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
function getResponse()
[151] Fix | Delete
{
[152] Fix | Delete
// methodResponses can only have one param - return that
[153] Fix | Delete
return $this->message->params[0];
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
function isError()
[157] Fix | Delete
{
[158] Fix | Delete
return (is_object($this->error));
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
function getErrorCode()
[162] Fix | Delete
{
[163] Fix | Delete
return $this->error->code;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
function getErrorMessage()
[167] Fix | Delete
{
[168] Fix | Delete
return $this->error->message;
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function