16 import(
'plugins.importexport.medra.filter.O4DOIXmlFilter');
26 parent::__construct($filterGroup);
40 return 'ONIXDOISerialArticleWorkRegistrationMessage';
50 return 'plugins.importexport.medra.filter.ArticleMedraXmlFilter';
63 $doc =
new DOMDocument(
'1.0',
'utf-8');
64 $doc->preserveWhiteSpace =
false;
65 $doc->formatOutput =
true;
67 $context = $deployment->getContext();
71 $doc->appendChild($rootNode);
78 foreach($pubObjects as $pubObject) {
92 $context = $deployment->getContext();
93 $cache = $deployment->getCache();
94 $plugin = $deployment->getPlugin();
96 $router = $request->getRouter();
98 assert ((is_a($pubObject,
'Submission') && $this->
isWork($context, $plugin)) ||
99 (is_a($pubObject,
'ArticleGalley') && !$this->
isWork($context, $plugin)));
101 if (is_a($pubObject,
'Submission')) {
103 $article = $pubObject;
104 if (!$cache->isCached(
'articles', $article->getId())) {
105 $cache->add($article,
null);
107 $articleNodeName =
'DOISerialArticleWork';
108 $workOrProduct =
'Work';
109 $epubFormat = O4DOI_EPUB_FORMAT_HTML;
111 $galley = $pubObject;
112 $publication =
Services::get(
'publication')->get($galley->getData(
'publicationId'));
113 if ($cache->isCached(
'articles', $publication->getData(
'submissionId'))) {
114 $article = $cache->get(
'articles', $publication->getData(
'submissionId'));
116 $article =
Services::get(
'submission')->get($publication->getData(
'submissionId'));
117 if ($article && $article->getData(
'status') === STATUS_PUBLISHED) $cache->add($article,
null);
119 $articleNodeName =
'DOISerialArticleVersion';
120 $workOrProduct =
'Product';
122 if ($galley->isPdfGalley()) {
123 $epubFormat = O4DOI_EPUB_FORMAT_PDF;
124 }
else if ($galley->getRemoteURL() || $galley->getFileType() ==
'text/html') {
125 $epubFormat = O4DOI_EPUB_FORMAT_HTML;
129 $articleNode = $doc->createElementNS($deployment->getNamespace(), $articleNodeName);
131 $doi = $pubObject->getStoredPubId(
'doi');
132 $registeredDoi = $pubObject->getData(
'medra::registeredDoi');
133 assert(empty($registeredDoi) || $registeredDoi == $doi);
134 $notificationType = (empty($registeredDoi) ? O4DOI_NOTIFICATION_TYPE_NEW : O4DOI_NOTIFICATION_TYPE_UPDATE);
135 $articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'NotificationType', $notificationType));
137 $articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'DOI', htmlspecialchars($doi, ENT_COMPAT,
'UTF-8')));
139 $urlPath = $article->getBestId();
140 if ($galley) $urlPath = array($article->getBestId(), $galley->getBestGalleyId());
141 $url = $router->url($request, $context->getPath(),
'article',
'view', $urlPath,
null,
null,
true);
142 if ($plugin->isTestMode($context)) {
146 $articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'DOIWebsiteLink', $url));
148 $articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'DOIStructuralType', $this->getDOIStructuralType()));
150 $articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'RegistrantName', htmlspecialchars($plugin->getSetting($context->getId(),
'registrantName'), ENT_COMPAT,
'UTF-8')));
152 $articleNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'RegistrationAuthority',
'mEDRA'));
154 $pubObjectProprietaryId = $context->getId() .
'-' . $article->getCurrentPublication()->getData(
'issueId') .
'-' . $article->getId();
155 if ($galley) $pubObjectProprietaryId .=
'-g' . $galley->getId();
156 $articleNode->appendChild($this->
createIdentifierNode($doc, $workOrProduct, O4DOI_ID_TYPE_PROPRIETARY, $pubObjectProprietaryId));
162 $issueId = $article->getCurrentPublication()->getData(
'issueId');
163 if ($cache->isCached(
'issues', $issueId)) {
164 $issue = $cache->get(
'issues', $issueId);
167 $issue = $issueDao->getById($issueId, $context->getId());
168 if ($issue) $cache->add($issue,
null);
175 $articleNode->appendChild($this->
createContentItemNode($doc, $issue, $article, $galley, $objectLocalePrecedence));
190 $context = $deployment->getContext();
191 $plugin = $deployment->getPlugin();
192 $contentItemNode = $doc->createElementNS($deployment->getNamespace(),
'ContentItem');
194 $seq = $article->getCurrentPublication()->getData(
'seq');
196 $contentItemNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'SequenceNumber', $seq));
199 $pages = $article->getCurrentPublication()->getPageArray();
201 $textItemNode = $doc->createElementNS($deployment->getNamespace(),
'TextItem');
202 foreach ($pages as $range) {
203 $pageRunNode = $doc->createElementNS($deployment->getNamespace(),
'PageRun');
204 $node = $doc->createElementNS($deployment->getNamespace(),
'FirstPageNumber', htmlspecialchars($range[0]));
205 $pageRunNode->appendChild($node);
206 if (isset($range[1])) {
207 $node = $doc->createElementNS($deployment->getNamespace(),
'LastPageNumber', htmlspecialchars($range[1]));
208 $pageRunNode->appendChild($node);
210 $textItemNode->appendChild($pageRunNode);
212 $contentItemNode->appendChild($textItemNode);
215 if ($galley && !$galley->getRemoteURL()) {
216 $galleyFile = $galley->getFile();
217 if ($galleyFile) $contentItemNode->appendChild($this->
createExtentNode($doc, $galleyFile));
221 assert(!empty($titles));
222 foreach ($titles as $locale => $title) {
223 $contentItemNode->appendChild($this->
createTitleNode($doc, $locale, $title, O4DOI_TITLE_TYPE_FULL));
226 $authors = $article->getCurrentPublication()->getData(
'authors');
227 assert(!empty($authors));
228 foreach ($authors as $author) {
233 assert(!empty($languageCode));
234 $languageNode = $doc->createElementNS($deployment->getNamespace(),
'Language');
235 $languageNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'LanguageRole', O4DOI_LANGUAGE_ROLE_LANGUAGE_OF_TEXT));
236 $languageNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'LanguageCode', $languageCode));
237 $contentItemNode->appendChild($languageNode);
241 $allKeywords = $submissionKeywordDao->getKeywords($article->getCurrentPublication()->getId(), $context->getSupportedSubmissionLocales());
243 if (!empty($keywords)) {
244 $keywordsString = implode(
';', $keywords);
245 $contentItemNode->appendChild($this->
createSubjectNode($doc, O4DOI_SUBJECT_SCHEME_PUBLISHER, $keywordsString));
248 $descriptions = $this->
getTranslationsByPrecedence($article->getCurrentPublication()->getData(
'abstract'), $objectLocalePrecedence);
249 foreach ($descriptions as $locale => $description) {
253 $datePublished = $article->getCurrentPublication()->getData(
'datePublished');
254 if (!empty($datePublished)) {
255 $contentItemNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'PublicationDate', date(
'Ymd', strtotime($datePublished))));
260 if ($plugin->getSetting($context->getId(),
'exportIssuesAs') == O4DOI_ISSUE_AS_WORK) {
263 $issueWorkOrProduct =
'Work';
267 $issueWorkOrProduct =
'Product';
269 $issueProprietaryId = $context->getId() .
'-' . $issue->getId();
270 $relatedIssueIds = array(O4DOI_ID_TYPE_PROPRIETARY => $issueProprietaryId);
271 $issueDoi = $issue->getStoredPubId(
'doi');
272 if (!empty($issueDoi)) $relatedIssueIds[O4DOI_ID_TYPE_DOI] = $issueDoi;
273 $relatedIssueNode = $this->
createRelatedNode($doc, $issueWorkOrProduct, O4DOI_RELATION_IS_PART_OF, $relatedIssueIds);
275 $galleysByArticle = $article->getCurrentPublication()->getData(
'galleys');
277 $contentItemNode->appendChild($relatedIssueNode);
280 foreach($galleysByArticle as $relatedGalley) {
281 $galleyProprietaryId = $context->getId() .
'-' . $issue->getId() .
'-' . $article->getId() .
'-g' . $relatedGalley->getId();
282 $relatedGalleyIds = array(O4DOI_ID_TYPE_PROPRIETARY => $galleyProprietaryId);
283 $galleyDoi = $relatedGalley->getStoredPubId(
'doi');
284 if (!empty($galleyDoi)) $relatedGalleyIds[O4DOI_ID_TYPE_DOI] = $galleyDoi;
285 $contentItemNode->appendChild($this->
createRelatedNode($doc,
'Product', O4DOI_RELATION_IS_MANIFESTED_IN, $relatedGalleyIds));
286 unset($relatedGalley, $relatedGalleyIds, $galleyProprietaryId, $galleyDoi);
290 if ($issueWorkOrProduct ==
'Work') $contentItemNode->appendChild($relatedIssueNode);
294 $articleProprietaryId = $context->getId() .
'-' . $article->getCurrentPublication()->getData(
'issueId') .
'-' . $article->getId();
295 $relatedArticleIds = array(O4DOI_ID_TYPE_PROPRIETARY => $articleProprietaryId);
296 $doi = $article->getCurrentPublication()->getStoredPubId(
'doi');
297 if (!empty($doi)) $relatedArticleIds[O4DOI_ID_TYPE_DOI] = $doi;
298 $contentItemNode->appendChild($this->
createRelatedNode($doc,
'Work', O4DOI_RELATION_IS_A_MANIFESTATION_OF, $relatedArticleIds));
299 unset($relatedArticleIds);
302 if ($issueWorkOrProduct ==
'Product')$contentItemNode->appendChild($relatedIssueNode);
305 foreach($galleysByArticle as $relatedGalley) {
306 $galleyProprietaryId = $context->getId() .
'-' . $issue->getId() .
'-' . $article->getId() .
'-g' . $relatedGalley->getId();
307 $relatedGalleyIds = array(O4DOI_ID_TYPE_PROPRIETARY => $galleyProprietaryId);
308 $galleyDoi = $relatedGalley->getStoredPubId(
'doi');
309 if (!empty($galleyDoi)) $relatedGalleyIds[O4DOI_ID_TYPE_DOI] = $galleyDoi;
313 if ($galley->getLocale() == $relatedGalley->getLocale() &&
314 $galley->getLabel() != $relatedGalley->getLabel()) {
316 $contentItemNode->appendChild($this->
createRelatedNode($doc,
'Product', O4DOI_RELATION_IS_A_DIFFERENT_FORM_OF, $relatedGalleyIds));
321 if ($galley->getLabel() == $relatedGalley->getLabel() &&
322 $galley->getLocale() != $relatedGalley->getLocale()) {
324 $contentItemNode->appendChild($this->
createRelatedNode($doc,
'Product', O4DOI_RELATION_IS_A_LANGUAGE_VERSION_OF, $relatedGalleyIds));
326 unset($relatedGalley, $relatedGalleyIds, $galleyProprietaryId, $galleyDoi);
330 return $contentItemNode;
342 $contributorNode = $doc->createElementNS($deployment->getNamespace(),
'Contributor');
344 $seq = $author->getSequence() ?? 0;
346 $contributorNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'SequenceNumber', $seq));
348 $contributorNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'ContributorRole', O4DOI_CONTRIBUTOR_ROLE_ACTUAL_AUTHOR));
350 $personName = $author->getFullName(
false);
351 assert(!empty($personName));
352 $contributorNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'PersonName', htmlspecialchars($personName, ENT_COMPAT,
'UTF-8')));
354 $invertedPersonName = $author->getFullName(
false,
true);
355 assert(!empty($invertedPersonName));
356 $contributorNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'PersonNameInverted', htmlspecialchars($invertedPersonName, ENT_COMPAT,
'UTF-8')));
359 if (!empty($affiliation)) {
360 $affiliationNode = $doc->createElementNS($deployment->getNamespace(),
'ProfessionalAffiliation');
361 $affiliationNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'Affiliation', htmlspecialchars($affiliation, ENT_COMPAT,
'UTF-8')));
362 $contributorNode->appendChild($affiliationNode);
366 if (!empty($bioNote)) {
367 $contributorNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'BiographicalNote', htmlspecialchars(
PKPString::html2text($bioNote), ENT_COMPAT,
'UTF-8')));
369 return $contributorNode;
380 function createSubjectNode($doc, $subjectSchemeId, $subjectHeadingOrCode, $subjectSchemeName =
null) {
382 $subjectNode = $doc->createElementNS($deployment->getNamespace(),
'Subject');
384 $subjectNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'SubjectSchemeIdentifier', $subjectSchemeId));
385 if (is_null($subjectSchemeName)) {
387 $subjectNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'SubjectHeadingText', htmlspecialchars($subjectHeadingOrCode, ENT_COMPAT,
'UTF-8')));
390 $subjectNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'SubjectSchemeName', htmlspecialchars($subjectSchemeName, ENT_COMPAT,
'UTF-8')));
392 $subjectNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(),
'SubjectCode', htmlspecialchars($subjectHeadingOrCode, ENT_COMPAT,
'UTF-8')));