Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#10046 fix onix export calls to get localized data #1701

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions classes/publication/Publication.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ public function getEditorString() {
return join(__('common.commaListSeparator') . ' ', $editorNames);
}

/**
* Get the URL to a cover image
*
* @param int $contextId
* @param string $preferredLocale Return the cover image in a specified locale.
* @return string
*/
public function getCoverImageUrl($contextId, $preferredLocale = null) {
$coverImage = $this->getData('coverImage', $preferredLocale);

if (!$coverImage) {
return Application::get()->getRequest()->getBaseUrl() . '/templates/images/book-default.png';
}

import('classes.file.PublicFileManager');
$publicFileManager = new PublicFileManager();

return join('/', [
Application::get()->getRequest()->getBaseUrl(),
$publicFileManager->getContextFilesPath($contextId),
$coverImage['uploadName'],
]);
}

/**
* Get the URL to a localized cover image
*
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
85 changes: 43 additions & 42 deletions plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @file plugins/importexport/onix30/filter/MonographONIX30XmlFilter.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Copyright (c) 2014-2024 Simon Fraser University
* Copyright (c) 2000-2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class MonographONIX30XmlFilter
Expand All @@ -29,7 +29,6 @@ function __construct($filterGroup) {
parent::__construct($filterGroup);
}


//
// Implement template methods from PersistableFilter
//
Expand Down Expand Up @@ -121,7 +120,7 @@ function createHeaderNode($doc) {
$senderNode->appendChild($senderIdentifierNode);

// Assemble SenderName element.
$senderNode->appendChild($this->_buildTextNode($doc, 'SenderName', $context->getLocalizedName()));
$senderNode->appendChild($this->_buildTextNode($doc, 'SenderName', $context->getName($context->getPrimaryLocale())));
$senderNode->appendChild($this->_buildTextNode($doc, 'ContactName', $context->getContactName()));
$senderNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $context->getContactEmail()));

Expand Down Expand Up @@ -248,13 +247,14 @@ function createProductNode($doc, $submission, $publicationFormat) {
/* --- License information --- */

$publication = $submission->getCurrentPublication();
$pubLocale = $publication->getData('locale');

if ($publication->isCCLicense()) {
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION); // For CC License Names
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, $pubLocale); // For CC License Names
$licenseOpts = Application::getCCLicenseOptions();
$licenseUrl = $publication->getData('licenseUrl');
if (array_key_exists($licenseUrl, $licenseOpts)) {
$licenseName = (__($licenseOpts[$licenseUrl], [], $publication->getData('locale')));
$licenseName = (__($licenseOpts[$licenseUrl], [], $pubLocale));
kaitlinnewson marked this conversation as resolved.
Show resolved Hide resolved

$epubLicenseNode = $doc->createElementNS($deployment->getNamespace(), 'EpubLicense');
$descDetailNode->appendChild($epubLicenseNode);
Expand Down Expand Up @@ -291,19 +291,25 @@ function createProductNode($doc, $submission, $publicationFormat) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'PartNumber', $submission->getCurrentPublication()->getData('seriesPosition')));
}

if ($series->getLocalizedPrefix() == '' || $series->getLocalizedTitle(false) == '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim(join(' ', array($series->getLocalizedPrefix(), $series->getLocalizedTitle(false))))));
$seriesLocale = $pubLocale;
// If the series title doesn't exist in the submission locale, use the press locale
if ($series->getTitle($seriesLocale, false) == '') {
$seriesLocale = $context->getPrimaryLocale();
}

if ($series->getPrefix($seriesLocale) == '' || $series->getTitle($seriesLocale, false) == '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim(join(' ', array($series->getPrefix($seriesLocale), $series->getTitle($seriesLocale, false))))));
} else {
if ($series->getLocalizedPrefix() != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getLocalizedPrefix()));
if ($series->getPrefix($seriesLocale) != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $series->getPrefix($seriesLocale)));
} else {
$titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix'));
}
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getLocalizedTitle(false)));
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $series->getTitle($seriesLocale, false)));
}

if ($series->getLocalizedSubtitle() != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getLocalizedSubtitle()));
if ($series->getSubtitle($seriesLocale) != '') {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $series->getSubtitle($seriesLocale)));
}
} else {
$seriesCollectionNode = $doc->createElementNS($deployment->getNamespace(), 'NoCollection');
Expand All @@ -322,20 +328,20 @@ function createProductNode($doc, $submission, $publicationFormat) {

$productTitleDetailNode->appendChild($titleElementNode);

if (!$publication->getLocalizedData('prefix') || !$publication->getLocalizedData('title')) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim($publication->getLocalizedData('prefix') ?? $publication->getLocalizedTitle())));
if (!$publication->getData('prefix', $pubLocale) || !$publication->getData('title', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleText', trim($publication->getData('prefix', $pubLocale) ?? $publication->getData('title', $pubLocale))));
} else {
if ($publication->getLocalizedData('prefix')) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $publication->getLocalizedData('prefix')));
if ($publication->getData('prefix', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitlePrefix', $publication->getData('prefix', $pubLocale)));
} else {
$titleElementNode->appendChild($doc->createElementNS($deployment->getNamespace(), 'NoPrefix'));
}

$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $publication->getLocalizedTitle()));
$titleElementNode->appendChild($this->_buildTextNode($doc, 'TitleWithoutPrefix', $publication->getData('title', $pubLocale)));
}

if ($publication->getData('subtitle', $publication->getData('locale'))) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $publication->getData('subtitle', $publication->getData('locale'))));
if ($publication->getData('subtitle', $pubLocale)) {
$titleElementNode->appendChild($this->_buildTextNode($doc, 'Subtitle', $publication->getData('subtitle', $pubLocale)));
}

/* --- Contributor information --- */
Expand All @@ -355,17 +361,17 @@ function createProductNode($doc, $submission, $publicationFormat) {
$role = array_key_exists($nameKey, $userGroupOnixMap) ? $userGroupOnixMap[$nameKey] : 'Z99'; // Z99 - unknown contributor type.

$contributorNode->appendChild($this->_buildTextNode($doc, 'ContributorRole', $role));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonName', $author->getFullName(false)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonNameInverted', $author->getFullName(false, true)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'NamesBeforeKey', $author->getLocalizedGivenName()));
if ($author->getLocalizedFamilyName() != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getLocalizedFamilyName()));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonName', $author->getFullName(false, false, null, $pubLocale)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'PersonNameInverted', $author->getFullName(false, true, null, $pubLocale)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'NamesBeforeKey', $author->getGivenName($pubLocale)));
if ($author->getFamilyName($pubLocale) != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFamilyName($pubLocale)));
} else {
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFullName(false)));
$contributorNode->appendChild($this->_buildTextNode($doc, 'KeyNames', $author->getFullName(false, false, null, $pubLocale)));
}

if ($author->getLocalizedBiography() != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'BiographicalNote', $author->getLocalizedBiography()));
if ($author->getBiography($pubLocale) != '') {
$contributorNode->appendChild($this->_buildTextNode($doc, 'BiographicalNote', $author->getBiography($pubLocale)));
}

if ($author->getCountry() != '') {
Expand Down Expand Up @@ -442,13 +448,13 @@ function createProductNode($doc, $submission, $publicationFormat) {
$subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '12')); // 12 is BIC subject category code list.
$subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeVersion', '2')); // Version 2 of ^^

$allSubjects = ($publication->getData('subjects')[$publication->getData('locale')]);
$allSubjects = ($publication->getData('subjects')[$pubLocale]);
$subjectNode->appendChild($this->_buildTextNode($doc, 'SubjectCode', trim(join(', ', $allSubjects))));
$descDetailNode->appendChild($subjectNode);
}

if ($publication->getData('keywords')) {
$allKeywords = ($publication->getData('keywords')[$publication->getData('locale')]);
$allKeywords = ($publication->getData('keywords')[$pubLocale]);
$keywordNode = $doc->createElementNS($deployment->getNamespace(), 'Subject');
$keywordNode->appendChild($this->_buildTextNode($doc, 'SubjectSchemeIdentifier', '20')); // Keywords
$keywordNode->appendChild($this->_buildTextNode($doc, 'SubjectHeadingText', trim(join(', ', $allKeywords))));
Expand Down Expand Up @@ -493,7 +499,7 @@ function createProductNode($doc, $submission, $publicationFormat) {
$collateralDetailNode = $doc->createElementNS($deployment->getNamespace(), 'CollateralDetail');
$productNode->appendChild($collateralDetailNode);

$abstract = strip_tags($publication->getLocalizedData('abstract'));
$abstract = strip_tags($publication->getData('abstract', $pubLocale));

$textContentNode = $doc->createElementNS($deployment->getNamespace(), 'TextContent');
$collateralDetailNode->appendChild($textContentNode);
Expand All @@ -517,7 +523,7 @@ function createProductNode($doc, $submission, $publicationFormat) {
$resourceVersionNode = $doc->createElementNS($deployment->getNamespace(), 'ResourceVersion');
$supportingResourceNode->appendChild($resourceVersionNode);
$resourceVersionNode->appendChild($this->_buildTextNode($doc, 'ResourceForm', '01')); // Linkable resource
$resourceVersionNode->appendChild($this->_buildTextNode($doc, 'ResourceLink', $publication->getLocalizedCoverImageUrl($context->getId(), $publication->getData('locale'))));
$resourceVersionNode->appendChild($this->_buildTextNode($doc, 'ResourceLink', $publication->getCoverImageUrl($context->getId(), $pubLocale)));

/* --- Publishing Detail --- */

Expand Down Expand Up @@ -707,15 +713,16 @@ function createProductNode($doc, $submission, $publicationFormat) {
$supplyDetailNode = $doc->createElementNS($deployment->getNamespace(), 'SupplyDetail');
$productSupplyNode->appendChild($supplyDetailNode);

$supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
$supplyDetailNode->appendChild($supplierNode);
if (isset($supplier)) {
$supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
$supplyDetailNode->appendChild($supplierNode);

$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierRole', $supplier->getRole()));
$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierName', $supplier->getName()));
if ($supplier->getPhone()) {
$supplierNode->appendChild($this->_buildTextNode($doc, 'TelephoneNumber', $supplier->getPhone()));
}

if ($supplier->getEmail()) {
$supplierNode->appendChild($this->_buildTextNode($doc, 'EmailAddress', $supplier->getEmail()));
}
Expand All @@ -735,12 +742,8 @@ function createProductNode($doc, $submission, $publicationFormat) {

$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '29')); // 29 -> Web page for full content
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->url($context->getPath(), 'catalog', 'book', $submissionBestId)));
unset($supplierNode);
unset($supplierWebsiteNode);

} else { // No suppliers specified, use the Press settings instead.
$supplierNode = $doc->createElementNS($deployment->getNamespace(), 'Supplier');
$supplyDetailNode->appendChild($supplierNode);

$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierRole', '09')); // Publisher supplying to end customers
$supplierNode->appendChild($this->_buildTextNode($doc, 'SupplierName', $context->getData('publisher')));
Expand All @@ -755,9 +758,9 @@ function createProductNode($doc, $submission, $publicationFormat) {
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Public website
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->url($context->getPath())));

unset($supplierNode);
unset($supplierWebsiteNode);
}
unset($supplierNode);
unset($supplierWebsiteNode);

if ($publicationFormat->getReturnableIndicatorCode() != '') {
$returnsNode = $doc->createElementNS($deployment->getNamespace(), 'ReturnsConditions');
Expand Down Expand Up @@ -892,5 +895,3 @@ function _buildTextNode($doc, $nodeName, $textContent) {
return $node;
}
}