123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955 |
- <?php
- defined('GNUsocial') || die();
- define('MOLLOMPLUGIN_VERSION', '0.1');
- define('MOLLOM_API_VERSION', '1.0');
- define('MOLLOM_ANALYSIS_UNKNOWN', 0);
- define('MOLLOM_ANALYSIS_HAM', 1);
- define('MOLLOM_ANALYSIS_SPAM', 2);
- define('MOLLOM_ANALYSIS_UNSURE', 3);
- define('MOLLOM_MODE_DISABLED', 0);
- define('MOLLOM_MODE_CAPTCHA', 1);
- define('MOLLOM_MODE_ANALYSIS', 2);
- define('MOLLOM_FALLBACK_BLOCK', 0);
- define('MOLLOM_FALLBACK_ACCEPT', 1);
- define('MOLLOM_ERROR', 1000);
- define('MOLLOM_REFRESH', 1100);
- define('MOLLOM_REDIRECT', 1200);
- class MollomPlugin extends Plugin
- {
- public $public_key;
- public $private_key;
- public $servers = null;
- public function onStartNoticeSave($notice)
- {
- if ($this->public_key) {
-
- $data = [
- 'post_body' => $notice->content,
- 'author_name' => $profile->nickname,
- 'author_url' => $profile->homepage,
- 'author_id' => $profile->id,
- 'author_ip' => $this->getClientIp(),
- ];
- $response = $this->mollom('mollom.checkContent', $data);
- switch ($response['spam']) {
- case MOLLOM_ANALYSIS_SPAM:
-
- throw new ClientException(_m('Spam Detected.'), 400);
- case MOLLOM_ANALYSIS_UNSURE:
-
- break;
- case MOLLOM_ANALYSIS_HAM:
-
- break;
- }
- }
- return true;
- }
- public function getClientIP()
- {
- if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
-
- foreach (array('HTTP_X_FORWARDED_FOR', 'CLIENT-IP', 'REMOTE_ADDR') as $k) {
- if (isset($_SERVER[$k])) {
- return $_SERVER[$k];
- }
- }
- }
- return '127.0.0.1';
- }
-
- public function mollom($method, $data = [])
- {
- if (!extension_loaded('xmlrpc')) {
- if (!dl('xmlrpc.so')) {
- common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available.");
- }
- }
-
- $public_key = $this->public_key;
-
- $servers = $this->servers;
- if (is_null($servers)) {
-
- $servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
-
-
- }
- if (is_array($servers)) {
-
- foreach ($servers as $server) {
- $auth = $this->authentication();
- $data = array_merge($data, $auth);
- $result = $this->xmlrpc(
- $server . '/' . MOLLOM_API_VERSION,
- $method,
- $data
- );
-
- if (array_key_exists('session_id', $data)) {
- common_debug(
- "called {$method} at server {$server} with session ID "
- . "'{$data['session_id']}'"
- );
- } else {
- common_debug(
- "called {$method} at server {$server} with no session ID"
- );
- }
- if (!empty($errno = $this->xmlrpc_errno())) {
- common_log(LOG_ERR, sprintf(
- 'Error @errno: %s - %s - %s - <pre>%s</pre>',
- $this->xmlrpc_errno(),
- $server,
- $this->xmlrpc_error_msg(),
- $method,
- print_r($data, true)
- ));
- if ($errno === MOLLOM_REFRESH) {
-
- $servers = $this->xmlrpc(
- 'http://xmlrpc.mollom.com/' . MOLLOM_API_VERSION,
- 'mollom.getServerList',
- $this->authentication()
- );
-
-
- } elseif ($errno === MOLLOM_ERROR) {
- return $result;
- } elseif ($errno === MOLLOM_REDIRECT) {
-
- }
-
- $this->xmlrpc_error(0);
- } else {
- common_debug('Result = ' . print_r($result, true));
- return $result;
- }
- }
- }
-
- common_debug('none of the servers worked');
-
-
-
- }
-
- private function authentication()
- {
- $public_key = $this->public_key;
- $private_key = $this->private_key;
- $hash = hash_hmac('sha1', $private_key, $private_key, true);
-
-
- $data['public_key'] = $public_key;
- $data['time'] = $time;
- $data['hash'] = $hash;
- return $data;
- }
- public function xmlrpc($url)
- {
-
- $args = func_get_args();
- return call_user_func_array(['MollomPlugin', '_xmlrpc'], $args);
- }
-
- public function xmlrpc_value($data, $type = false)
- {
- $xmlrpc_value = new stdClass();
- $xmlrpc_value->data = $data;
- if (!$type) {
- $type = $this->xmlrpc_value_calculate_type($xmlrpc_value);
- }
- $xmlrpc_value->type = $type;
- if ($type === 'struct') {
-
- foreach ($xmlrpc_value->data as $key => $value) {
- $xmlrpc_value->data[$key] = $this->xmlrpc_value($value);
- }
- }
- if ($type === 'array') {
- for ($i = 0, $j = count($xmlrpc_value->data); $i < $j; ++$i) {
- $xmlrpc_value->data[$i] = $this->xmlrpc_value($xmlrpc_value->data[$i]);
- }
- }
- return $xmlrpc_value;
- }
-
- public function xmlrpc_value_calculate_type(&$xmlrpc_value)
- {
-
- if (is_bool($xmlrpc_value->data)) {
- return 'boolean';
- } elseif (is_double($xmlrpc_value->data)) {
- return 'double';
- } elseif (is_int($xmlrpc_value->data)) {
- return 'int';
- } elseif (is_array($xmlrpc_value->data)) {
-
- return empty($xmlrpc_value->data)
- || (range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct');
- }
- if (is_object($xmlrpc_value->data)) {
- if ($xmlrpc_value->data->is_date) {
- return 'date';
- } elseif ($xmlrpc_value->data->is_base64) {
- return 'base64';
- }
- $xmlrpc_value->data = get_object_vars($xmlrpc_value->data);
- return 'struct';
- }
-
- return 'string';
- }
-
- public function xmlrpc_value_get_xml($xmlrpc_value)
- {
- switch ($xmlrpc_value->type) {
- case 'boolean':
- return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
- break;
- case 'int':
- return '<int>'. $xmlrpc_value->data .'</int>';
- break;
- case 'double':
- return '<double>'. $xmlrpc_value->data .'</double>';
- break;
- case 'string':
-
-
- return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
- break;
- case 'array':
- $return = "<array><data>\n";
- foreach ($xmlrpc_value->data as $item) {
- $return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
- }
- $return .= '</data></array>';
- return $return;
- break;
- case 'struct':
- $return = "<struct>\n";
- foreach ($xmlrpc_value->data as $name => $value) {
- $return .= ' <member><name>' . htmlentities($name) . '</name><value>';
- $return .= $this->xmlrpc_value_get_xml($value) . "</value></member>\n";
- }
- $return .= '</struct>';
- return $return;
- break;
- case 'date':
- return $this->xmlrpc_date_get_xml($xmlrpc_value->data);
- break;
- case 'base64':
- return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
- break;
- }
- return false;
- }
-
- public function http_request(
- $url,
- $headers = [],
- $method = 'GET',
- $data = null,
- $retry = 3
- ) {
- global $db_prefix;
- $result = new stdClass();
-
- $uri = parse_url($url);
- if ($uri === false) {
- $result->error = 'unable to parse URL';
- return $result;
- }
- if (!array_key_exists('scheme', $uri)) {
- $result->error = 'missing schema';
- return $result;
- }
- switch ($uri['scheme']) {
- case 'http':
- $port = isset($uri['port']) ? $uri['port'] : 80;
- $host = $uri['host'] . ($port != 80 ? ':'. $port : '');
- $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
- break;
- case 'https':
-
- $port = isset($uri['port']) ? $uri['port'] : 443;
- $host = $uri['host'] . ($port != 443 ? ':'. $port : '');
- $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20);
- break;
- default:
- $result->error = 'invalid schema '. $uri['scheme'];
- return $result;
- }
-
- if ($fp === false) {
-
-
- $result->code = -$errno;
- $result->error = trim($errstr);
-
-
-
-
-
- return $result;
- }
-
- $path = $uri['path'] ?? '/';
- if (array_key_exists('query', $uri)) {
- $path .= '?' . $uri['query'];
- }
-
- $defaults = [
-
-
-
- 'Host' => "Host: {$host}",
- 'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
- 'Content-Length' => 'Content-Length: ' . strlen($data),
- ];
-
- if (array_key_exists('user', $uri)) {
- $defaults['Authorization'] = 'Authorization: Basic '
- . base64_encode($uri['user']
- . (!empty($uri['pass']) ? ':' . $uri['pass'] : ''));
- }
-
-
-
-
-
-
- if (
- is_string($db_prefix)
- && preg_match('/^simpletest\d+$/', $db_prefix, $matches)
- ) {
- $defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
- }
- foreach ($headers as $header => $value) {
- $defaults[$header] = $header . ': ' . $value;
- }
- $request = $method . ' ' . $path . " HTTP/1.0\r\n";
- $request .= implode("\r\n", $defaults);
- $request .= "\r\n\r\n";
- $request .= $data;
- $result->request = $request;
- fwrite($fp, $request);
-
- $response = '';
- while (!feof($fp) && ($chunk = fread($fp, 1024)) !== false) {
- $response .= $chunk;
- }
- fclose($fp);
-
- [$split, $result->data] = explode("\r\n\r\n", $response, 2);
- $split = preg_split("/\r\n|\n|\r/", $split);
- [$protocol, $code, $text] = explode(' ', trim(array_shift($split)), 3);
- $result->headers = [];
-
- while (($line = trim(array_shift($split))) !== '') {
- [$header, $value] = explode(':', $line, 2);
- if (
- array_key_exists($header, $result->headers)
- && $header === 'Set-Cookie'
- ) {
-
-
- $result->headers[$header] .= ',' . trim($value);
- } else {
- $result->headers[$header] = trim($value);
- }
- }
- $responses = [
- 100 => 'Continue', 101 => 'Switching Protocols',
- 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
- 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
- 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
- 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported',
- ];
-
-
- if (!array_key_exists($code, $responses)) {
- $code = floor($code / 100) * 100;
- }
- switch ($code) {
- case 200:
- case 304:
- break;
- case 301:
- case 302:
- case 307:
- $location = $result->headers['Location'];
- if ($retry) {
- $result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
- $result->redirect_code = $result->code;
- }
- $result->redirect_url = $location;
- break;
- default:
- $result->error = $text;
- }
- $result->code = $code;
- return $result;
- }
-
- public function xmlrpc_message($message)
- {
- $xmlrpc_message = new stdClass();
-
- $xmlrpc_message->array_structs = [];
-
- $xmlrpc_message->array_structs_types = [];
-
- $xmlrpc_message->current_struct_name = [];
- $xmlrpc_message->message = $message;
- return $xmlrpc_message;
- }
-
- public function xmlrpc_message_parse(&$xmlrpc_message)
- {
-
- $xmlrpc_message->message = preg_replace(
- '/<\?xml(.*)?\?'.'>/',
- '',
- $xmlrpc_message->message
- );
- if (trim($xmlrpc_message->message) === '') {
- return false;
- }
- $xmlrpc_message->_parser = xml_parser_create();
-
- xml_parser_set_option(
- $xmlrpc_message->_parser,
- XML_OPTION_CASE_FOLDING,
- false
- );
-
- xml_set_element_handler(
- $xmlrpc_message->_parser,
- ['MollomPlugin', 'xmlrpc_message_tag_open'],
- ['MollomPlugin', 'xmlrpc_message_tag_close']
- );
- xml_set_character_data_handler(
- $xmlrpc_message->_parser,
- ['MollomPlugin', 'xmlrpc_message_cdata']
- );
- $this->xmlrpc_message_set($xmlrpc_message);
- if (!xml_parse($xmlrpc_message->_parser, $xmlrpc_message->message)) {
- return false;
- }
- xml_parser_free($xmlrpc_message->_parser);
-
- $xmlrpc_message = $this->xmlrpc_message_get();
- if ($xmlrpc_message->messagetype === 'fault') {
- $xmlrpc_message->fault_code = $xmlrpc_message->params[0]['faultCode'];
- $xmlrpc_message->fault_string = $xmlrpc_message->params[0]['faultString'];
- }
- return true;
- }
-
- public function xmlrpc_message_set($value = null)
- {
- static $xmlrpc_message;
- if ($value) {
- $xmlrpc_message = $value;
- }
- return $xmlrpc_message;
- }
- public function xmlrpc_message_get()
- {
- return $this->xmlrpc_message_set();
- }
- public function xmlrpc_message_tag_open($parser, $tag, $attr)
- {
- $xmlrpc_message = $this->xmlrpc_message_get();
- $xmlrpc_message->current_tag_contents = '';
- $xmlrpc_message->last_open = $tag;
- switch ($tag) {
- case 'methodCall':
- case 'methodResponse':
- case 'fault':
- $xmlrpc_message->messagetype = $tag;
- break;
-
- case 'data':
- $xmlrpc_message->array_structs_types[] = 'array';
- $xmlrpc_message->array_structs[] = array();
- break;
- case 'struct':
- $xmlrpc_message->array_structs_types[] = 'struct';
- $xmlrpc_message->array_structs[] = array();
- break;
- }
- $this->xmlrpc_message_set($xmlrpc_message);
- }
- public function xmlrpc_message_cdata($parser, $cdata)
- {
- $xmlrpc_message = $this->xmlrpc_message_get();
- $xmlrpc_message->current_tag_contents .= $cdata;
- $this->xmlrpc_message_set($xmlrpc_message);
- }
- public function xmlrpc_message_tag_close($parser, $tag)
- {
- $xmlrpc_message = $this->xmlrpc_message_get();
- $value_flag = false;
- switch ($tag) {
- case 'int':
- case 'i4':
- $value = (int)trim($xmlrpc_message->current_tag_contents);
- $value_flag = true;
- break;
- case 'double':
- $value = (double)trim($xmlrpc_message->current_tag_contents);
- $value_flag = true;
- break;
- case 'string':
- $value = $xmlrpc_message->current_tag_contents;
- $value_flag = true;
- break;
- case 'dateTime.iso8601':
- $value = xmlrpc_date(trim($xmlrpc_message->current_tag_contents));
-
- $value_flag = true;
- break;
- case 'value':
-
-
- if (trim($xmlrpc_message->current_tag_contents) != '' || (isset($xmlrpc_message->last_open) && ($xmlrpc_message->last_open == 'value'))) {
- $value = (string)$xmlrpc_message->current_tag_contents;
- $value_flag = true;
- }
- unset($xmlrpc_message->last_open);
- break;
- case 'boolean':
- $value = (boolean)trim($xmlrpc_message->current_tag_contents);
- $value_flag = true;
- break;
- case 'base64':
- $value = base64_decode(trim($xmlrpc_message->current_tag_contents));
- $value_flag = true;
- break;
-
- case 'data':
- case 'struct':
- $value = array_pop($xmlrpc_message->array_structs);
- array_pop($xmlrpc_message->array_structs_types);
- $value_flag = true;
- break;
- case 'member':
- array_pop($xmlrpc_message->current_struct_name);
- break;
- case 'name':
- $xmlrpc_message->current_struct_name[] = trim($xmlrpc_message->current_tag_contents);
- break;
- case 'methodName':
- $xmlrpc_message->methodname = trim($xmlrpc_message->current_tag_contents);
- break;
- }
- if ($value_flag) {
- if (count($xmlrpc_message->array_structs) > 0) {
-
- if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types) - 1] === 'struct') {
-
- $xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name) - 1]] = $value;
- } else {
-
- $xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][] = $value;
- }
- } else {
-
- $xmlrpc_message->params[] = $value;
- }
- }
- if (!in_array($tag, ['data', 'struct', 'member'])) {
- $xmlrpc_message->current_tag_contents = '';
- }
- $this->xmlrpc_message_set($xmlrpc_message);
- }
-
- public function xmlrpc_request($method, $args)
- {
- $xmlrpc_request = new stdClass();
- $xmlrpc_request->method = $method;
- $xmlrpc_request->args = $args;
- $xmlrpc_request->xml = <<<EOD
- <?xml version="1.0"?>
- <methodCall>
- <methodName>{$xmlrpc_request->method}</methodName>
- <params>
- EOD;
- foreach ($xmlrpc_request->args as $arg) {
- $xmlrpc_request->xml .= '<param><value>';
- $v = $this->xmlrpc_value($arg);
- $xmlrpc_request->xml .= $this->xmlrpc_value_get_xml($v);
- $xmlrpc_request->xml .= "</value></param>\n";
- }
- $xmlrpc_request->xml .= '</params></methodCall>';
- return $xmlrpc_request;
- }
- public function xmlrpc_error($code = null, $message = null, $reset = false)
- {
- static $xmlrpc_error;
- if (!is_null($code)) {
- $xmlrpc_error = new stdClass();
- $xmlrpc_error->is_error = true;
- $xmlrpc_error->code = $code;
- $xmlrpc_error->message = $message;
- } elseif ($reset) {
- $xmlrpc_error = null;
- }
- return $xmlrpc_error;
- }
- public function xmlrpc_error_get_xml($xmlrpc_error)
- {
- return <<<EOD
- <methodResponse>
- <fault>
- <value>
- <struct>
- <member>
- <name>faultCode</name>
- <value><int>{$xmlrpc_error->code}</int></value>
- </member>
- <member>
- <name>faultString</name>
- <value><string>{$xmlrpc_error->message}</string></value>
- </member>
- </struct>
- </value>
- </fault>
- </methodResponse>
- EOD;
- }
- public function xmlrpc_date($time)
- {
- $xmlrpc_date = new stdClass();
- $xmlrpc_date->is_date = true;
-
- if (is_numeric($time)) {
- $xmlrpc_date->year = gmdate('Y', $time);
- $xmlrpc_date->month = gmdate('m', $time);
- $xmlrpc_date->day = gmdate('d', $time);
- $xmlrpc_date->hour = gmdate('H', $time);
- $xmlrpc_date->minute = gmdate('i', $time);
- $xmlrpc_date->second = gmdate('s', $time);
- $xmlrpc_date->iso8601 = gmdate('Ymd\TH:i:s', $time);
- } else {
- $xmlrpc_date->iso8601 = $time;
- $time = str_replace(array('-', ':'), '', $time);
- $xmlrpc_date->year = substr($time, 0, 4);
- $xmlrpc_date->month = substr($time, 4, 2);
- $xmlrpc_date->day = substr($time, 6, 2);
- $xmlrpc_date->hour = substr($time, 9, 2);
- $xmlrpc_date->minute = substr($time, 11, 2);
- $xmlrpc_date->second = substr($time, 13, 2);
- }
- return $xmlrpc_date;
- }
- public function xmlrpc_date_get_xml($xmlrpc_date)
- {
- return '<dateTime.iso8601>'
- . $xmlrpc_date->year
- . $xmlrpc_date->month
- . $xmlrpc_date->day
- . 'T' . $xmlrpc_date->hour
- . ':'. $xmlrpc_date->minute
- . ':'. $xmlrpc_date->second
- . '</dateTime.iso8601>';
- }
- public function xmlrpc_base64($data)
- {
- $xmlrpc_base64 = new stdClass();
- $xmlrpc_base64->is_base64 = true;
- $xmlrpc_base64->data = $data;
- return $xmlrpc_base64;
- }
- public function xmlrpc_base64_get_xml($xmlrpc_base64)
- {
- return '<base64>'. base64_encode($xmlrpc_base64->data) .'</base64>';
- }
-
- public function _xmlrpc()
- {
- $args = func_get_args();
- $url = array_shift($args);
- $this->xmlrpc_clear_error();
- if (is_array($args[0])) {
- $method = 'system.multicall';
- $multicall_args = [];
- foreach ($args[0] as $call) {
- $multicall_args[] = [
- 'methodName' => array_shift($call),
- 'params' => $call,
- ];
- }
- $args = [$multicall_args];
- } else {
- $method = array_shift($args);
- }
- $xmlrpc_request = $this->xmlrpc_request($method, $args);
- $result = $this->http_request($url, [
- 'Content-Type' => 'text/xml',
- ], 'POST', $xmlrpc_request->xml);
- if ($result->code !== 200) {
- $this->xmlrpc_error($result->code, $result->error);
- return false;
- }
- $message = $this->xmlrpc_message($result->data);
-
- if (!$this->xmlrpc_message_parse($message)) {
-
- $this->xmlrpc_error(-32700, t('Parse error. Not well formed'));
- return false;
- }
-
- if ($message->messagetype === 'fault') {
- $this->xmlrpc_error($message->fault_code, $message->fault_string);
- return false;
- }
-
- return $message->params[0];
- }
-
- public function xmlrpc_errno()
- {
- return $this->xmlrpc_error()->code ?? null;
- }
-
- public function xmlrpc_error_msg()
- {
- return xmlrpc_error()->message ?? null;
- }
-
- public function xmlrpc_clear_error()
- {
- $this->xmlrpc_error(null, null, true);
- }
- }
|