/** * @see DOIExportPlugin::registerDoi() */ function registerDoi(&$request, &$journal, &$object, $filename) { $shoulder = $this->getSetting($journal->getId(), 'shoulder'); // Transmit CrossRef XML metadata. assert(is_readable($filename)); $payload = file_get_contents($filename); assert($payload !== false && !empty($payload)); // we only consider articles and issues here $result = true; if (is_a($object, 'PublishedArticle') || is_a($object, 'Issue')) { $input = "_profile: crossref" . PHP_EOL; $input .= "crossref: " . $this->_doiMetadataEscape($payload) . PHP_EOL; // TODO: SHOW BOTH DATACITE METADATA AS WELL //5 required datacite fields: $input .= "datacite.creator: "; if (is_a($object, 'PublishedArticle')) { foreach ($object->getAuthors() as $author) { $input .= $author->getLastName() . ", " . $author->getFirstName() . " " . $author->getMiddleName() . "; "; } } $input .= PHP_EOL; $input .= "datacite.title: " . $object->getLocalizedTitle() . PHP_EOL; $input .= "datacite.publisher: " . $journal->getSetting('publisherInstitution') . PHP_EOL; $input .= "datacite.publicationyear: " . date('Y', strtotime($object->getDatePublished())) . PHP_EOL; $input .= "datacite.resourcetype: " . $object->getLocalizedData('type') . PHP_EOL; if ($object->getData('ezid::registeredDoi')) { $webServiceRequest = new WebServiceRequest(EZID_API_CRUD_URL . $object->getData('ezid::registeredDoi'), $input, 'POST'); $expectedResponse = EZID_API_RESPONSE_OK; } else { $webServiceRequest = new WebServiceRequest(EZID_API_MINT_URL . $shoulder, $input, 'POST'); $expectedResponse = EZID_API_RESPONSE_CREATED; } $webServiceRequest->setHeader('Content-Type', 'text/plain; charset=UTF-8'); $webServiceRequest->setHeader('Content-Length', strlen($input)); $webService = new WebService(); $username = $this->getSetting($journal->getId(), 'username'); $password = $this->getSetting($journal->getId(), 'password'); $webService->setAuthUsername($username); $webService->setAuthPassword($password); $response =& $webService->call($webServiceRequest); if ($response === false) { $result = array(array('plugins.importexport.common.register.error.mdsError', __('plugins.importexport.ezid.error.webserviceNoResponse'))); } else { if ($response === NULL) { $result = array(array('plugins.importexport.ezid.error.webserviceInvalidRequest')); } else { $status = $webService->getLastResponseStatus(); if ($status != $expectedResponse) { $result = array(array('plugins.importexport.common.register.error.mdsError', "{$status} - " . htmlentities($response))); } } } } else { return false; } if ($result === true) { # trim off "success: doi:" $trimmed_body = preg_replace('/(success: doi:)/', '', $response); if (strstr($trimmed_body, ' | ark:') !== FALSE) { list($doi, $ark) = explode(' | ark:', $trimmed_body, 2); $ark = 'ark:' . $ark; } else { $doi = $trimmed_body; $ark = ''; } if (is_a($object, 'Issue')) { $dao =& DAORegistry::getDAO('IssueDAO'); $dao->changePubId($object->getId(), 'doi', $doi); $object->setStoredPubId('doi', $doi); } elseif (is_a($object, 'Article')) { $dao =& DAORegistry::getDAO('ArticleDAO'); $dao->changePubId($object->getId(), 'doi', $doi); $object->setStoredPubId('doi', $doi); } // Mark the object as registered. $this->markRegistered($request, $object, $shoulder); } return $result; }