/** * Call MetaLib X-Server * * @param string $operation X-Server operation * @param array $params URL Parameters * * @return mixed simpleXMLElement | PEAR_Error * @access protected */ protected function callXServer($operation, $params) { $request = new Proxy_Request($this->config['General']['url'], array('method' => 'POST')); // Declare UTF-8 encoding so that SimpleXML won't encode characters. $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><x_server_request/>'); $op = $xml->addChild($operation); $this->paramsToXml($op, $params); $request->addPostdata('xml', $xml->asXML()); if ($this->debug) { echo "<!-- {$operation}\n"; if ($operation != 'login_request') { echo $xml->asXML(); } echo "-->\n"; } $result = $request->sendRequest(); if (PEAR::isError($result)) { return $result; } if ($this->debug) { echo "<!-- \n"; echo $request->getResponseBody(); echo "-->\n\n\n"; } if ($request->getResponseCode() >= 400) { return new PEAR_Error("HTTP Request failed: " . $request->getResponseCode()); } $xml = simplexml_load_string($request->getResponseBody()); $errors = $xml->xpath('//local_error | //global_error'); if (!empty($errors)) { if ($errors[0]->error_code == 6026) { return new PEAR_Error('Search timed out'); } return new PEAR_Error($errors[0]->asXML()); } return $xml; }