diff --git a/OAIMetadataFormat_OpenAIRE.php b/OAIMetadataFormat_OpenAIRE.php index 328603f..8060bce 100644 --- a/OAIMetadataFormat_OpenAIRE.php +++ b/OAIMetadataFormat_OpenAIRE.php @@ -22,40 +22,46 @@ use APP\core\Application; use PKP\core\PKPString; +use PKP\db\DAORegistry; use PKP\oai\OAIMetadataFormat; -use PKP\plugins\PluginRegistry; use PKP\plugins\Hook; -use PKP\db\DAORegistry; -use PKP\submission\GenreDAO; +use PKP\plugins\PluginRegistry; -class OAIMetadataFormat_OpenAIRE extends OAIMetadataFormat { +class OAIMetadataFormat_OpenAIRE extends OAIMetadataFormat +{ - /** - * @see OAIMetadataFormat#toXml - */ - function toXml($record, $format = null) { - $request = Application::get()->getRequest(); - $article = $record->getData('article'); - $journal = $record->getData('journal'); - $section = $record->getData('section'); - $issue = $record->getData('issue'); - $galleys = $record->getData('galleys'); - $articleId = $article->getId(); - $publication = $article->getCurrentPublication(); - $abbreviation = $journal->getLocalizedSetting('abbreviation'); - $printIssn = $journal->getSetting('printIssn'); - $onlineIssn = $journal->getSetting('onlineIssn'); - $articleLocale = $article->getLocale(); - $publisherInstitution = $journal->getSetting('publisherInstitution'); - $datePublished = $article->getDatePublished(); - $articleDoi = $article->getStoredPubId('doi'); - $accessRights = $this->_getAccessRights($journal, $issue, $article); - $resourceType = ($section->getData('resourceType') ? $section->getData('resourceType') : 'http://purl.org/coar/resource_type/c_6501'); # COAR resource type URI, defaults to "journal article" - if (!$datePublished) $datePublished = $issue->getDatePublished(); - if ($datePublished) $datePublished = strtotime($datePublished); - $parentPlugin = PluginRegistry::getPlugin('generic', 'openaireplugin'); + /** + * @see OAIMetadataFormat#toXml + * @throws \Exception + */ + function toXml($record, $format = null) + { + $request = Application::get()->getRequest(); + $article = $record->getData('article'); + $journal = $record->getData('journal'); + $section = $record->getData('section'); + $issue = $record->getData('issue'); + $galleys = $record->getData('galleys'); + $articleId = $article->getId(); + // Be defensive: some records may not have a current publication (eg, legacy data) + $publication = $article->getCurrentPublication(); + if (!$publication && method_exists($article, 'getLatestPublication')) { + $publication = $article->getLatestPublication(); + } + $abbreviation = $journal->getLocalizedSetting('abbreviation'); + $printIssn = $journal->getSetting('printIssn'); + $onlineIssn = $journal->getSetting('onlineIssn'); + $articleLocale = $article->getData('locale'); + $publisherInstitution = $journal->getSetting('publisherInstitution'); + $datePublished = $article->getData('datePublished'); + $articleDoi = $article->getStoredPubId('doi'); + $accessRights = $this->_getAccessRights($journal, $issue, $article); + $resourceType = ($section->getData('resourceType') ? $section->getData('resourceType') : 'http://purl.org/coar/resource_type/c_6501'); # COAR resource type URI, defaults to "journal article" + if (!$datePublished) $datePublished = $issue->getData('datePublished'); + if ($datePublished) $datePublished = strtotime($datePublished); + $parentPlugin = PluginRegistry::getPlugin('generic', 'openaireplugin'); - $response = " + $response = "
" . htmlspecialchars($journal->getPath()) . " getPrimaryLocale(), 0, 2) . "\">" . htmlspecialchars($journal->getName($journal->getPrimaryLocale())) . "\n"; - // Translated journal titles - foreach ($journal->getName(null) as $locale => $title) { - if ($locale == $journal->getPrimaryLocale()) continue; - $response .= "\t\t\t" . htmlspecialchars($title) . "\n"; - } - $response .= ($journal->getAcronym($journal->getPrimaryLocale())?"\t\t\tgetPrimaryLocale(), 0, 2) . "\">" . htmlspecialchars($journal->getAcronym($journal->getPrimaryLocale())) . "":''); - $response .= "\n\t\t\t\n"; + // Translated journal titles + $journalNames = $journal->getName(null); + if (is_array($journalNames)) foreach ($journalNames as $locale => $title) { + if ($locale == $journal->getPrimaryLocale()) continue; + $response .= "\t\t\t" . htmlspecialchars($title) . "\n"; + } + $response .= ($journal->getAcronym($journal->getPrimaryLocale()) ? "\t\t\tgetPrimaryLocale(), 0, 2) . "\">" . htmlspecialchars($journal->getAcronym($journal->getPrimaryLocale())) . "" : ''); + $response .= "\n\t\t\t\n"; + + $response .= + (!empty($onlineIssn) ? "\t\t\t" . htmlspecialchars($onlineIssn) . "\n" : '') . + (!empty($printIssn) ? "\t\t\t" . htmlspecialchars($printIssn) . "\n" : '') . + ($publisherInstitution != '' ? "\t\t\t" . htmlspecialchars($publisherInstitution) . "\n" : '') . + "\t\t\n" . + "\t\t\n" . + "\t\t\t" . $article->getId() . "\n" . + (!empty($articleDoi) ? "\t\t\t" . htmlspecialchars($articleDoi) . "\n" : '') . + "\t\t\tgetPrimaryLocale() . "\" subj-group-type=\"heading\">" . htmlspecialchars($section->getLocalizedTitle()) . "\n" . + "\t\t\t\n" . + "\t\t\t\t" . htmlspecialchars(strip_tags((string)$article->getData('title', $articleLocale))) . "\n"; + if (!empty($subtitle = $article->getData('subtitle', $articleLocale))) $response .= "\t\t\t\t" . htmlspecialchars($subtitle) . "\n"; + + // Translated article titles + $allTitles = $article->getData('title'); + if (is_array($allTitles)) foreach ($allTitles as $locale => $title) { + if ($locale == $articleLocale) continue; + if ($title) { + $response .= "\t\t\t\t\n"; + $response .= "\t\t\t\t\t" . htmlspecialchars(strip_tags((string)$title)) . "\n"; + if (!empty($subtitle = $article->getData('subtitle', $locale))) $response .= "\t\t\t\t\t" . htmlspecialchars($subtitle) . "\n"; + $response .= "\t\t\t\t\t\n"; + } + } + $response .= + "\t\t\t\n" . + "\t\t\t\n"; - $response .= - (!empty($onlineIssn)?"\t\t\t" . htmlspecialchars($onlineIssn) . "\n":'') . - (!empty($printIssn)?"\t\t\t" . htmlspecialchars($printIssn) . "\n":'') . - ($publisherInstitution != ''?"\t\t\t" . htmlspecialchars($publisherInstitution) . "\n":'') . - "\t\t\n" . - "\t\t\n" . - "\t\t\t" . $article->getId() . "\n" . - (!empty($articleDoi)?"\t\t\t" . htmlspecialchars($articleDoi) . "\n":'') . - "\t\t\tgetPrimaryLocale() . "\" subj-group-type=\"heading\">" . htmlspecialchars($section->getLocalizedTitle()) . "\n" . - "\t\t\t\n" . - "\t\t\t\t" . htmlspecialchars(strip_tags($article->getTitle($articleLocale))) . "\n"; - if (!empty($subtitle = $article->getSubtitle($articleLocale))) $response .= "\t\t\t\t" . htmlspecialchars($subtitle) . "\n"; + // Authors + $affiliations = array(); + $authors = $publication ? $publication->getData('authors') : (method_exists($article, 'getAuthors') ? $article->getAuthors() : []); + if (is_array($authors)) foreach ($authors as $author) { + $affiliation = method_exists($author, 'getLocalizedAffiliation') ? $author->getLocalizedAffiliation() : $author->getData('affiliation'); + $affiliationToken = array_search($affiliation, $affiliations); + if ($affiliation && !$affiliationToken) { + $affiliationToken = 'aff-' . (count($affiliations) + 1); + $affiliations[$affiliationToken] = $affiliation; + } + $response .= + "\t\t\t\tgetPrimaryContact() ? 'corresp="yes" ' : '') . ">\n" . + "\t\t\t\t\t\n" . + "\t\t\t\t\t\t" . htmlspecialchars(method_exists($author, 'getLastName') ? $author->getLastName() : $author->getLocalizedFamilyName()) . "\n" . + "\t\t\t\t\t\t" . htmlspecialchars(method_exists($author, 'getFirstName') ? $author->getFirstName() : $author->getLocalizedGivenName()) . (((method_exists($author, 'getMiddleName') && ($s = $author->getMiddleName())) != '') ? " $s" : '') . "\n" . + "\t\t\t\t\t\n" . + ($affiliationToken ? "\t\t\t\t\t\n" : '') . + ($author->getOrcid() ? "\t\t\t\t\t" . htmlspecialchars($author->getOrcid()) . "\n" : '') . + "\t\t\t\t\n"; + } + $response .= "\t\t\t\n"; + foreach ($affiliations as $affiliationToken => $affiliation) { + $response .= "\t\t\t" . htmlspecialchars($affiliation) . "\n"; + } - // Translated article titles - foreach ($article->getTitle(null) as $locale => $title) { - if ($locale == $articleLocale) continue; - if ($title){ - $response .= "\t\t\t\t\n"; - $response .= "\t\t\t\t\t" . htmlspecialchars(strip_tags($title)) . "\n"; - if (!empty($subtitle = $article->getSubtitle($locale))) $response .= "\t\t\t\t\t" . htmlspecialchars($subtitle) . "\n"; - $response .= "\t\t\t\t\t\n"; - } - } - $response .= - "\t\t\t\n" . - "\t\t\t\n"; + // Publication date + if ($datePublished) { + $response .= + "\t\t\t\n" . + "\t\t\t\t" . date('d', $datePublished) . "\n" . + "\t\t\t\t" . date('m', $datePublished) . "\n" . + "\t\t\t\t" . date('Y', $datePublished) . "\n" . + "\t\t\t\n"; + } - // Authors - $affiliations = array(); - foreach ($article->getCurrentPublication()->getData('authors') as $author) { - $affiliation = $author->getLocalizedAffiliation(); - $affiliationToken = array_search($affiliation, $affiliations); - if ($affiliation && !$affiliationToken) { - $affiliationToken = 'aff-' . (count($affiliations)+1); - $affiliations[$affiliationToken] = $affiliation; - } - $response .= - "\t\t\t\tgetPrimaryContact()?'corresp="yes" ':'') . ">\n" . - "\t\t\t\t\t\n" . - "\t\t\t\t\t\t" . htmlspecialchars(method_exists($author, 'getLastName')?$author->getLastName():$author->getLocalizedFamilyName()) . "\n" . - "\t\t\t\t\t\t" . htmlspecialchars(method_exists($author, 'getFirstName')?$author->getFirstName():$author->getLocalizedGivenName()) . (((method_exists($author, 'getMiddleName') && $s = $author->getMiddleName()) != '')?" $s":'') . "\n" . - "\t\t\t\t\t\n" . - ($affiliationToken?"\t\t\t\t\t\n":'') . - ($author->getOrcid()?"\t\t\t\t\t" . htmlspecialchars($author->getOrcid()) . "\n":'') . - "\t\t\t\t\n"; - } - $response .= "\t\t\t\n"; - foreach ($affiliations as $affiliationToken => $affiliation) { - $response .= "\t\t\t" . htmlspecialchars($affiliation) . "\n"; - } + // Issue details + if ($issue->getVolume() && $issue->getShowVolume()) + $response .= "\t\t\t" . htmlspecialchars($issue->getVolume()) . "\n"; + if ($issue->getNumber() && $issue->getShowNumber()) + $response .= "\t\t\t" . htmlspecialchars($issue->getNumber()) . "\n"; - // Publication date - if ($datePublished) $response .= - "\t\t\t\n" . - "\t\t\t\t" . strftime('%d', $datePublished) . "\n" . - "\t\t\t\t" . strftime('%m', $datePublished) . "\n" . - "\t\t\t\t" . strftime('%Y', $datePublished) . "\n" . - "\t\t\t\n"; + // Page info, if available and parseable. + $pageInfo = $this->_getPageInfo($article); + if ($pageInfo) { + $response .= + "\t\t\t\t" . $pageInfo['fpage'] . "\n" . + "\t\t\t\t" . $pageInfo['lpage'] . "\n"; + } - // Issue details - if ($issue->getVolume() && $issue->getShowVolume()) - $response .= "\t\t\t" . htmlspecialchars($issue->getVolume()) . "\n"; - if ($issue->getNumber() && $issue->getShowNumber()) - $response .= "\t\t\t" . htmlspecialchars($issue->getNumber()) . "\n"; + // Fetch funding data from other plugins if available + $fundingReferences = null; + Hook::call('OAIMetadataFormat_OpenAIRE::findFunders', [&$articleId, &$fundingReferences]); + if ($fundingReferences) { + $response .= $fundingReferences; + } - // Page info, if available and parseable. - $pageInfo = $this->_getPageInfo($article); - if ($pageInfo){ - $response .= - "\t\t\t\t" . $pageInfo['fpage'] . "\n" . - "\t\t\t\t" . $pageInfo['lpage'] . "\n"; - } + // Copyright, license and other permissions + $copyrightYear = $article->getData('copyrightYear'); + $copyrightHolder = $article->getData('copyrightHolder'); + $licenseUrl = $article->getData('licenseUrl'); + $ccBadge = Application::get()->getCCLicenseBadge($licenseUrl); + $openAccessDate = null; + if ($accessRights == 'embargoedAccess') { + $openAccessDate = date('Y-m-d', strtotime($issue->getOpenAccessDate())); + } + if ($copyrightYear || $copyrightHolder || $licenseUrl || $ccBadge || $openAccessDate || $accessRights == "openAccess") $response .= + "\t\t\t\n" . + (($copyrightYear || $copyrightHolder) ? "\t\t\t\t" . htmlspecialchars(__('submission.copyrightStatement', array('copyrightYear' => $copyrightYear, 'copyrightHolder' => $copyrightHolder))) . "\n" : '') . + ($copyrightYear ? "\t\t\t\t" . htmlspecialchars($copyrightYear) . "\n" : '') . + ($copyrightHolder ? "\t\t\t\t" . htmlspecialchars($copyrightHolder) . "\n" : '') . + ($licenseUrl ? "\t\t\t\t\n" . + ($ccBadge ? "\t\t\t\t\t" . strip_tags($ccBadge) . "\n" : '') . + "\t\t\t\t\n" : '') . + ($openAccessDate ? "\t\t\t\t\n" : '') . + ($accessRights == "openAccess" ? "\t\t\t\t\n" : '') . + "\t\t\t\n"; - // Fetch funding data from other plugins if available - $fundingReferences = null; - Hook::call('OAIMetadataFormat_OpenAIRE::findFunders', [&$articleId, &$fundingReferences]); - if ($fundingReferences){ - $response .= $fundingReferences; - } + // landing page link + $response .= "\t\t\turl($journal->getPath(), 'article', 'view', [$article->getBestId()])) . "\" />\n"; - // Copyright, license and other permissions - $copyrightYear = $article->getCopyrightYear(); - $copyrightHolder = $article->getLocalizedCopyrightHolder(); - $licenseUrl = $article->getLicenseURL(); - $ccBadge = Application::get()->getCCLicenseBadge($licenseUrl); - $openAccessDate = null; - if ($accessRights == 'embargoedAccess') { - $openAccessDate = date('Y-m-d', strtotime($issue->getOpenAccessDate())); - } - if ($copyrightYear || $copyrightHolder || $licenseUrl || $ccBadge || $openAccessDate || $accessRights == "openAccess" ) $response .= - "\t\t\t\n" . - (($copyrightYear||$copyrightHolder)?"\t\t\t\t" . htmlspecialchars(__('submission.copyrightStatement', array('copyrightYear' => $copyrightYear, 'copyrightHolder' => $copyrightHolder))) . "\n":'') . - ($copyrightYear?"\t\t\t\t" . htmlspecialchars($copyrightYear) . "\n":'') . - ($copyrightHolder?"\t\t\t\t" . htmlspecialchars($copyrightHolder) . "\n":'') . - ($licenseUrl?"\t\t\t\t\n" . - ($ccBadge?"\t\t\t\t\t" . strip_tags($ccBadge) . "\n":'') . - "\t\t\t\t\n":'') . - ($openAccessDate?"\t\t\t\t\n":'') . - ($accessRights == "openAccess"?"\t\t\t\t\n":'') . - "\t\t\t\n"; + // full text links + $galleys = $article->getGalleys(); + $primaryGalleys = array(); + if ($galleys) { + $genreDao = DAORegistry::getDAO('GenreDAO'); + $primaryGenres = $genreDao->getPrimaryByContextId($journal->getId())->toArray(); + $primaryGenreIds = array_map(function ($genre) { + return $genre->getId(); + }, $primaryGenres); + foreach ($galleys as $galley) { + // Fix typo and read remote URL correctly + $remoteUrl = $galley->getData('remoteUrl'); + $file = $galley->getFile(); + if (!$remoteUrl && !$file) { + continue; + } + if ($remoteUrl || in_array($file->getGenreId(), $primaryGenreIds)) { + $response .= "\t\t\tgetFileType() . "\" xlink:href=\"" . htmlspecialchars($request->url($journal->getPath(), 'article', 'download', array($article->getBestId(), $galley->getBestGalleyId()), null, null, true)) . "\" />\n"; + } + } + } - // landing page link - $response .= "\t\t\turl($journal->getPath(), 'article', 'view', $article->getBestArticleId())) . "\" />\n"; + // Keywords + $subjects = array(); + if (is_array($article->getData('subject'))) foreach ($article->getData('subject') as $locale => $subject) { + $s = array_map('trim', explode(';', $subject)); + if (!empty($s)) $subjects[$locale] = $s; + } + if (!empty($subjects)) foreach ($subjects as $locale => $s) { + $response .= "\t\t\t\n"; + foreach ($s as $subject) $response .= "\t\t\t\t" . htmlspecialchars($subject) . "\n"; + $response .= "\t\t\t\n"; + } - // full text links - $galleys = $article->getGalleys(); - $primaryGalleys = array(); - if ($galleys) { - $genreDao = DAORegistry::getDAO('GenreDAO'); - $primaryGenres = $genreDao->getPrimaryByContextId($journal->getId())->toArray(); - $primaryGenreIds = array_map(function($genre) { - return $genre->getId(); - }, $primaryGenres); - foreach ($galleys as $galley) { - $remoteUrl = $galley->getRemoteURL(); - $file = $galley->getFile(); - if (!$remoteUrl && !$file) { - continue; - } - if ($remoteUrl || in_array($file->getGenreId(), $primaryGenreIds)) { - $response .= "\t\t\tgetFileType() . "\" xlink:href=\"" . htmlspecialchars($request->url($journal->getPath(), 'article', 'download', array($article->getBestArticleId(), $galley->getBestGalleyId()), null, null, true)) . "\" />\n"; - } - } - } + // Publication keywords (guard against missing publication and DAO differences across OJS versions) + if ($publication) { + $pubKeywords = $publication->getData('keywords'); // expected: [locale => [kw1, kw2, ...]] + if (is_array($pubKeywords)) { + foreach ($pubKeywords as $locale => $keywords) { + if (empty($keywords) || !is_array($keywords)) continue; + $response .= "\t\t\t\n"; + foreach ($keywords as $keyword) { + $response .= "\t\t\t\t" . htmlspecialchars($keyword) . "\n"; + } + $response .= "\t\t\t\n"; + } + } + } - // Keywords - $subjects = array(); - if (is_array($article->getSubject(null))) foreach ($article->getSubject(null) as $locale => $subject) { - $s = array_map('trim', explode(';', $subject)); - if (!empty($s)) $subjects[$locale] = $s; - } - if (!empty($subjects)) foreach ($subjects as $locale => $s) { - $response .= "\t\t\t\n"; - foreach ($s as $subject) $response .= "\t\t\t\t" . htmlspecialchars($subject) . "\n"; - $response .= "\t\t\t\n"; - } + // abstract + if ($article->getData('abstract', $articleLocale)) { + $abstract = PKPString::html2text($article->getData('abstract', $articleLocale)); + $response .= "\t\t\t

" . htmlspecialchars($abstract) . "

\n"; + } + // Include translated abstracts + $abstracts = $article->getData('abstract'); + if (is_array($abstracts)) foreach ($abstracts as $locale => $abstract) { + if ($locale == $articleLocale) continue; + if ($abstract) { + $abstract = PKPString::html2text($abstract); + $response .= "\t\t\t

" . htmlspecialchars($abstract) . "

\n"; + } + } - $submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); - foreach ($submissionKeywordDao->getKeywords($publication->getId(), $journal->getSupportedLocales()) as $locale => $keywords) { - if (empty($keywords)) continue; - // Load the article.subject locale key in possible other languages - $response .= "\t\t\t\n"; - foreach ($keywords as $keyword) $response .= "\t\t\t\t" . htmlspecialchars($keyword) . "\n"; - $response .= "\t\t\t\n"; - } + // Page count + $response .= + ($pageInfo ? "\t\t\t\n" : ''); - // abstract - if ($article->getAbstract($articleLocale)) { - $abstract = PKPString::html2text($article->getAbstract($articleLocale)); - $response .= "\t\t\t

" . htmlspecialchars($abstract) . "

\n"; - } - // Include translated abstracts - foreach ($article->getAbstract(null) as $locale => $abstract) { - if ($locale == $articleLocale) continue; - if ($abstract){ - $abstract = PKPString::html2text($abstract); - $response .= "\t\t\t

" . htmlspecialchars($abstract) . "

\n"; - } - } + // OpenAIRE COAR Access Rights and OpenAIRE COAR Resource Type + $coarAccessRights = $this->_getCoarAccessRights(); + $coarResourceLabel = $parentPlugin && method_exists($parentPlugin, '_getCoarResourceType') ? $parentPlugin->_getCoarResourceType($resourceType) : null; - // Page count - $response .= - ($pageInfo?"\t\t\t\n":''); + if ($accessRights || $coarResourceLabel) { + $response .= "\t\t\t\n"; + if ($accessRights) $response .= + "\t\t\t\t\n" . + "\t\t\t\t\t" . $coarAccessRights[$accessRights]['label'] . "\n" . + "\t\t\t\t\t" . $coarAccessRights[$accessRights]['url'] . "\n" . + "\t\t\t\t\n"; + if ($coarResourceLabel) $response .= + "\t\t\t\t\n" . + "\t\t\t\t\t" . $coarResourceLabel . "\n" . + "\t\t\t\t\t" . $resourceType . "\n" . + "\t\t\t\t\n"; + $response .= "\t\t\t\n"; + } - // OpenAIRE COAR Access Rights and OpenAIRE COAR Resource Type - $coarAccessRights = $this->_getCoarAccessRights(); - $coarResourceLabel = $parentPlugin->_getCoarResourceType($resourceType); + $response .= + "\t\t
\n" . + "\t\n" . + "
"; - if ($accessRights || $coarResourceLabel){ - $response .= "\t\t\t\n"; - if ($accessRights) $response .= - "\t\t\t\t\n" . - "\t\t\t\t\t" . $coarAccessRights[$accessRights]['label'] . "\n" . - "\t\t\t\t\t" . $coarAccessRights[$accessRights]['url'] . "\n" . - "\t\t\t\t\n"; - if ($coarResourceLabel) $response .= - "\t\t\t\t\n" . - "\t\t\t\t\t" . $coarResourceLabel . "\n" . - "\t\t\t\t\t" . $resourceType . "\n" . - "\t\t\t\t\n"; - $response .= "\t\t\t\n"; - } + return $response; + } - $response .= - "\t\t\n" . - "\t\n" . - ""; + /** + * Get an associative array containing COAR Access Rights. + * @return array + */ + function _getCoarAccessRights() + { + static $coarAccessRights = array( + 'openAccess' => array('label' => 'open access', 'url' => 'http://purl.org/coar/access_right/c_abf2'), + 'embargoedAccess' => array('label' => 'embargoed access', 'url' => 'http://purl.org/coar/access_right/c_abf2'), + 'restrictedAccess' => array('label' => 'restricted access', 'url' => 'http://purl.org/coar/access_right/c_abf2'), + 'metadataOnlyAccess' => array('label' => 'metadata only access', 'url' => 'http://purl.org/coar/access_right/c_abf2') + ); + return $coarAccessRights; + } - return $response; - } + /** + * Get a JATS article-type string based on COAR Resource Type URI. + * https://jats.nlm.nih.gov/archiving/tag-library/1.1/attribute/article-type.html + * @param $uri string + * @return string + */ + function _mapCoarResourceTypeToJatsArticleType($uri) + { + $resourceTypes = array( + 'http://purl.org/coar/resource_type/c_6501' => 'research-article', + 'http://purl.org/coar/resource_type/c_2df8fbb1' => 'research-article', + 'http://purl.org/coar/resource_type/c_dcae04bc' => 'review-article', + 'http://purl.org/coar/resource_type/c_beb9' => 'research-article', + 'http://purl.org/coar/resource_type/c_7bab' => 'research-article', + 'http://purl.org/coar/resource_type/c_b239' => 'editorial', + 'http://purl.org/coar/resource_type/c_545b' => 'letter', + 'http://purl.org/coar/resource_type/c_93fc' => 'case-report', + 'http://purl.org/coar/resource_type/c_efa0' => 'product-review', + 'http://purl.org/coar/resource_type/c_ba08' => 'book-review', + 'http://purl.org/coar/resource_type/c_5794' => 'meeting-report', + 'http://purl.org/coar/resource_type/c_46ec' => 'dissertation', + 'http://purl.org/coar/resource_type/c_8042' => 'research-article', + 'http://purl.org/coar/resource_type/c_816b' => 'research-article' + ); + return $resourceTypes[$uri] ?? 'research-article'; + } - /** - * Get an associative array containing COAR Access Rights. - * @return array - */ - function _getCoarAccessRights() { - static $coarAccessRights = array( - 'openAccess' => array('label' => 'open access', 'url' => 'http://purl.org/coar/access_right/c_abf2'), - 'embargoedAccess' => array('label' => 'embargoed access', 'url' => 'http://purl.org/coar/access_right/c_abf2'), - 'restrictedAccess' => array('label' => 'restricted access', 'url' => 'http://purl.org/coar/access_right/c_abf2'), - 'metadataOnlyAccess' => array('label' => 'metadata only access', 'url' => 'http://purl.org/coar/access_right/c_abf2') - ); - return $coarAccessRights; - } + /** + * Get an associative array containing page info + * @return array + */ + function _getPageInfo($article) + { + $matches = $pageCount = null; + $pages = (string)$article->getData('pages'); + if (preg_match('/^(\d+)$/', $pages, $matches)) { + $matchedPage = htmlspecialchars($matches[1]); + return array('fpage' => $matchedPage, 'lpage' => $matchedPage, 'pagecount' => '1'); + } elseif (preg_match('/^[Pp][Pp]?[.]?[ ]?(\d+)$/', $pages, $matches)) { + $matchedPage = htmlspecialchars($matches[1]); + return array('fpage' => $matchedPage, 'lpage' => $matchedPage, 'pagecount' => '1'); + } elseif (preg_match('/^[Pp][Pp]?[.]?[ ]?(\d+)[ ]?-[ ]?([Pp][Pp]?[.]?[ ]?)?(\d+)$/', $pages, $matches)) { + $matchedPageFrom = htmlspecialchars($matches[1]); + $matchedPageTo = htmlspecialchars($matches[3]); + $pageCount = $matchedPageTo - $matchedPageFrom + 1; + return array('fpage' => $matchedPageFrom, 'lpage' => $matchedPageTo, 'pagecount' => $pageCount); + } elseif (preg_match('/^(\d+)[ ]?-[ ]?(\d+)$/', $pages, $matches)) { + $matchedPageFrom = htmlspecialchars($matches[1]); + $matchedPageTo = htmlspecialchars($matches[2]); + $pageCount = $matchedPageTo - $matchedPageFrom + 1; + return array('fpage' => $matchedPageFrom, 'lpage' => $matchedPageTo, 'pagecount' => $pageCount); + } else { + return null; + } + } - /** - * Get a JATS article-type string based on COAR Resource Type URI. - * https://jats.nlm.nih.gov/archiving/tag-library/1.1/attribute/article-type.html - * @param $uri string - * @return string - */ - function _mapCoarResourceTypeToJatsArticleType($uri) { - $resourceTypes = array( - 'http://purl.org/coar/resource_type/c_6501' => 'research-article', - 'http://purl.org/coar/resource_type/c_2df8fbb1' => 'research-article', - 'http://purl.org/coar/resource_type/c_dcae04bc' => 'review-article', - 'http://purl.org/coar/resource_type/c_beb9' => 'research-article', - 'http://purl.org/coar/resource_type/c_7bab' => 'research-article', - 'http://purl.org/coar/resource_type/c_b239' => 'editorial', - 'http://purl.org/coar/resource_type/c_545b' => 'letter', - 'http://purl.org/coar/resource_type/c_93fc' => 'case-report', - 'http://purl.org/coar/resource_type/c_efa0' => 'product-review', - 'http://purl.org/coar/resource_type/c_ba08' => 'book-review', - 'http://purl.org/coar/resource_type/c_5794' => 'meeting-report', - 'http://purl.org/coar/resource_type/c_46ec' => 'dissertation', - 'http://purl.org/coar/resource_type/c_8042' => 'research-article', - 'http://purl.org/coar/resource_type/c_816b' => 'research-article' - ); - return $resourceTypes[$uri]; - } + /** + * Get article access rights + * @param $journal + * @param $issue + * @param $article + * @return string + */ + function _getAccessRights($journal, $issue, $article) + { + $accessRights = null; + $publishingMode = $journal ? $journal->getData('publishingMode') : null; + // Use namespaced constants available in current OJS/OMP + $PUBLISHING_MODE_OPEN = \APP\journal\Journal::PUBLISHING_MODE_OPEN; + $PUBLISHING_MODE_SUBSCRIPTION = \APP\journal\Journal::PUBLISHING_MODE_SUBSCRIPTION; + $ISSUE_ACCESS_OPEN = \APP\issue\Issue::ISSUE_ACCESS_OPEN; + $ISSUE_ACCESS_SUBSCRIPTION = \APP\issue\Issue::ISSUE_ACCESS_SUBSCRIPTION; + $ARTICLE_ACCESS_OPEN = \APP\submission\Submission::ARTICLE_ACCESS_OPEN; - /** - * Get an associative array containing page info - * @return array - */ - function _getPageInfo($article) { - $matches = $pageCount = null; - if (PKPString::regexp_match_get('/^(\d+)$/', $article->getPages(), $matches)) { - $matchedPage = htmlspecialchars($matches[1]); - return array('fpage' => $matchedPage, 'lpage' => $matchedPage, 'pagecount' => '1'); - } elseif (PKPString::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)$/', $article->getPages(), $matches)) { - $matchedPage = htmlspecialchars($matches[1]); - return array('fpage' => $matchedPage, 'lpage' => $matchedPage, 'pagecount' => '1'); - } elseif (PKPString::regexp_match_get('/^[Pp][Pp]?[.]?[ ]?(\d+)[ ]?-[ ]?([Pp][Pp]?[.]?[ ]?)?(\d+)$/', $article->getPages(), $matches)) { - $matchedPageFrom = htmlspecialchars($matches[1]); - $matchedPageTo = htmlspecialchars($matches[3]); - $pageCount = $matchedPageTo - $matchedPageFrom + 1; - return array('fpage' => $matchedPageFrom, 'lpage' => $matchedPageTo, 'pagecount' => $pageCount); - } elseif (PKPString::regexp_match_get('/^(\d+)[ ]?-[ ]?(\d+)$/', $article->getPages(), $matches)) { - $matchedPageFrom = htmlspecialchars($matches[1]); - $matchedPageTo = htmlspecialchars($matches[2]); - $pageCount = $matchedPageTo - $matchedPageFrom + 1; - return array('fpage' => $matchedPageFrom, 'lpage' => $matchedPageTo, 'pagecount' => $pageCount); - } else { - return null; - } - } - - /** - * Get article access rights - * @param $journal - * @param $issue - * @param $article - * @return string - */ - function _getAccessRights($journal, $issue, $article) { - $accessRights = null; - if ($journal->getData('publishingMode') == PUBLISHING_MODE_OPEN) { - $accessRights = 'openAccess'; - } else if ($journal->getData('publishingMode') == PUBLISHING_MODE_SUBSCRIPTION) { - if ($issue->getAccessStatus() == 0 || $issue->getAccessStatus() == ISSUE_ACCESS_OPEN) { - $accessRights = 'openAccess'; - } else if ($issue->getAccessStatus() == ISSUE_ACCESS_SUBSCRIPTION) { - if (is_a($article, 'PublishedArticle') && $article->getAccessStatus() == ARTICLE_ACCESS_OPEN) { - $accessRights = 'openAccess'; - } else if ($issue->getAccessStatus() == ISSUE_ACCESS_SUBSCRIPTION && $issue->getOpenAccessDate() != NULL) { - $accessRights = 'embargoedAccess'; - } else if ($issue->getAccessStatus() == ISSUE_ACCESS_SUBSCRIPTION && $issue->getOpenAccessDate() == NULL) { - $accessRights = 'metadataOnlyAccess'; - } - } - } - if ($journal->getData('restrictSiteAccess') == 1 || $journal->getData('restrictArticleAccess') == 1) { - $accessRights = 'restrictedAccess'; - } - return $accessRights; - } + if ($publishingMode === $PUBLISHING_MODE_OPEN) { + $accessRights = 'openAccess'; + } else if ($publishingMode === $PUBLISHING_MODE_SUBSCRIPTION) { + if ($issue && ($issue->getAccessStatus() == 0 || $issue->getAccessStatus() === $ISSUE_ACCESS_OPEN)) { + $accessRights = 'openAccess'; + } else if ($issue && $issue->getAccessStatus() === $ISSUE_ACCESS_SUBSCRIPTION) { + // In newer OJS versions, article access is on the Publication + $pub = method_exists($article, 'getCurrentPublication') ? $article->getCurrentPublication() : null; + $articleAccess = $pub ? $pub->getData('accessStatus') : (method_exists($article, 'getAccessStatus') ? $article->getAccessStatus() : null); + if ($articleAccess === $ARTICLE_ACCESS_OPEN) { + $accessRights = 'openAccess'; + } else if ($issue->getOpenAccessDate() !== null) { + $accessRights = 'embargoedAccess'; + } else { + $accessRights = 'metadataOnlyAccess'; + } + } + } + if ($journal && ($journal->getData('restrictSiteAccess') == 1 || $journal->getData('restrictArticleAccess') == 1)) { + $accessRights = 'restrictedAccess'; + } + return $accessRights; + } }