20 import(
'lib.pkp.classes.xml.XMLNode');
22 define(
'MEDRA_WS_ENDPOINT_DEV',
'https://www-medra-dev.medra.org/servlet/ws/medraWS');
23 define(
'MEDRA_WS_ENDPOINT',
'https://www.medra.org/servlet/ws/medraWS');
24 define(
'MEDRA_WS_RESPONSE_OK', 200);
41 function __construct($endpoint, $login, $password) {
42 $this->_endpoint = $endpoint;
43 $this->_auth =
"$login:$password";
56 $attachment = array($attachmentId => $xml);
57 $arg =
"<med:contentID href=\"$attachmentId\" />";
58 return $this->
_doRequest(
'upload', $arg, $attachment);
66 $arg =
"<med:doi>$doi</med:doi>";
67 return $this->
_doRequest(
'viewMetadata', $arg);
81 function _doRequest($action, $arg, $attachment =
null) {
84 '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ' .
85 'xmlns:med="http://www.medra.org">' .
86 '<SOAP-ENV:Header/>' .
88 "<med:$action>$arg</med:$action>" .
90 '</SOAP-ENV:Envelope>';
94 assert(count($attachment) == 1);
96 "--MIME_boundary\r\n" .
98 "--MIME_boundary\r\n" .
99 $this->
_getMimePart(key($attachment), current($attachment)) .
100 "--MIME_boundary--\r\n";
101 $contentType =
'multipart/related; type="text/xml"; boundary="MIME_boundary"';
103 $request = $soapMessage;
104 $contentType =
'text/xml';
108 import(
'lib.pkp.classes.helpers.PKPCurlHelper');
111 curl_setopt($curlCh, CURLOPT_RETURNTRANSFER,
true);
112 curl_setopt($curlCh, CURLOPT_POST,
true);
115 curl_setopt($curlCh, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
116 curl_setopt($curlCh, CURLOPT_USERPWD, $this->_auth);
119 curl_setopt($curlCh, CURLOPT_URL, $this->_endpoint);
120 $extraHeaders = array(
121 'SOAPAction: "' . $action .
'"',
122 'Content-Type: ' . $contentType,
123 'UserAgent: OJS-mEDRA'
125 curl_setopt($curlCh, CURLOPT_HTTPHEADER, $extraHeaders);
126 curl_setopt($curlCh, CURLOPT_POSTFIELDS, $request);
129 $response = curl_exec($curlCh);
133 if ($response ===
false) {
134 $result =
'OJS-mEDRA: Expected string response.';
137 if ($result ===
true && ($status = curl_getinfo($curlCh, CURLINFO_HTTP_CODE)) != MEDRA_WS_RESPONSE_OK) {
138 $result =
'OJS-mEDRA: Expected ' . MEDRA_WS_RESPONSE_OK .
' response code, got ' . $status .
' instead.';
145 if (is_string($response)) {
148 if (empty($matches)) {
152 $parts = explode(
"\r\n\r\n", $response);
153 $result = array_pop($parts);
157 $result =
'mEDRA: ' . $status .
' - ' . $matches[1];
160 $result =
'OJS-mEDRA: Expected string response.';
174 "Content-Type: text/xml; charset=utf-8\r\n" .
175 "Content-ID: <${contentId}>\r\n" .
186 return $prefix . md5(uniqid()) .
'@medra.org';