diff --git a/pages/preprint/PreprintHandler.php b/pages/preprint/PreprintHandler.php index 96b8207f85..0fc00f4d6a 100644 --- a/pages/preprint/PreprintHandler.php +++ b/pages/preprint/PreprintHandler.php @@ -23,6 +23,7 @@ use APP\facades\Repo; use APP\handler\Handler; use APP\observers\events\UsageEvent; +use APP\publication\Publication; use APP\security\authorization\OpsServerMustPublishPolicy; use APP\template\TemplateManager; use Firebase\JWT\JWT; @@ -169,6 +170,7 @@ public function initialize($request, $args = []) * * @param array $args * @param \APP\core\Request $request + * * @hook PreprintHandler::view [[&$request, &$preprint, $publication]] * @hook PreprintHandler::view::galley [[&$request, &$this->galley, &$preprint, $publication]] */ @@ -294,6 +296,13 @@ public function view($args, $request) $templateMgr->addHeader('canonical', ''); } + $templateMgr->assign('pubLocaleData', $this->getPublicationLocaleData( + $publication, + $context->getPrimaryLocale(), + $templateMgr->getTemplateVars('activeTheme')->getOption('showMultilingualMetadata') ?: [], + $templateMgr->getTemplateVars('activeTheme')->getOption('showMetadata') ?: [] + )); + if (!Hook::call('PreprintHandler::view', [&$request, &$preprint, $publication])) { $templateMgr->display('frontend/pages/preprint.tpl'); event(new UsageEvent(Application::ASSOC_TYPE_SUBMISSION, $context, $preprint)); @@ -330,6 +339,7 @@ public function view($args, $request) * * @param array $args * @param Request $request + * * @hook PreprintHandler::download [[$this->preprint, &$this->galley, &$this->submissionFileId]] * @hook FileManager::downloadFileFinished [[&$returner]] */ @@ -415,4 +425,38 @@ public function userCanViewGalley($request) } return false; } + + /** + * Format multilingual publication data for template: + * Default data at least includes in one language: full title, title, subtitle, keywords, abstract + * showMultilingualMetadataOpts adds multilingual metadata: title (by default includes fullTitle and subtitle), keywords, abstract, etc. + * showMetadataOpts: additional metadata + */ + protected function getPublicationLocaleData(Publication $publication, string $contextPrimaryLocale, array $showMultilingualMetadataOpts, array $showMetadataOpts): array + { + $titles = collect([ + 'title' => $publication->getTitles('html'), + 'subtitle' => $publication->getSubtitles('html'), + 'fullTitle' => $publication->getFullTitles('html'), + ]); + $metadataOpts = collect(['keywords', 'abstract'])->concat($showMetadataOpts)->diff($titles->keys())->unique()->values(); + $multilingualOpts = collect($showMultilingualMetadataOpts) + ->when(in_array('title', $showMultilingualMetadataOpts), fn ($m) => $m->concat(['subtitle', 'fullTitle'])->unique()->values()); + $primaryLocale = isset($titles->get('title')[$contextPrimaryLocale]) ? $contextPrimaryLocale : $publication->getData('locale'); + + $getText = fn (array $item, string $opt): array => [ + $opt => [ + 'text' => ($text = array_filter($item, fn (string $locale) => $multilingualOpts->contains($opt) || $locale === $primaryLocale, ARRAY_FILTER_USE_KEY)), + 'headingLang' => collect($text)->map(fn ($_, string $locale): string => $locale === $primaryLocale ? $contextPrimaryLocale : $locale)->toArray() + ], + ]; + + $pubLocaleData = $titles->mapWithKeys($getText) + ->union($metadataOpts->mapWithKeys(fn (string $opt): array => $getText($publication->getData($opt) ?? [], $opt))); + return $pubLocaleData + ->put('languages', $pubLocaleData->map(fn (array $item): array => array_keys($item['text'])) + ->flatten()->sort()->prepend($primaryLocale)->unique()->values()) + ->put('primaryLocale', $primaryLocale) + ->toArray(); + } } diff --git a/plugins/themes/default/DefaultThemePlugin.php b/plugins/themes/default/DefaultThemePlugin.php index f75dfd5091..a10a60b99f 100755 --- a/plugins/themes/default/DefaultThemePlugin.php +++ b/plugins/themes/default/DefaultThemePlugin.php @@ -125,6 +125,26 @@ public function init() 'default' => 'none', ]); + $this->addOption('showMultilingualMetadata', 'FieldOptions', [ + 'label' => __('plugins.themes.default.option.metadata.label'), + 'description' => __('plugins.themes.default.option.metadata.description'), + 'options' => [ + [ + 'value' => 'title', + 'label' => __('submission.title'), + ], + [ + 'value' => 'keywords', + 'label' => __('common.keywords'), + ], + [ + 'value' => 'abstract', + 'label' => __('common.abstract'), + ], + ], + 'default' => [], + ]); + // Load primary stylesheet $this->addStyle('stylesheet', 'styles/index.less'); diff --git a/plugins/themes/default/locale/en/locale.po b/plugins/themes/default/locale/en/locale.po index 22f90fc34b..723bf3a97f 100644 --- a/plugins/themes/default/locale/en/locale.po +++ b/plugins/themes/default/locale/en/locale.po @@ -97,4 +97,16 @@ msgid "plugins.themes.default.nextSlide" msgstr "Next slide" msgid "plugins.themes.default.prevSlide" -msgstr "Previous slide" \ No newline at end of file +msgstr "Previous slide" + +msgid "plugins.themes.default.option.metadata.label" +msgstr "Show preprint metadata on the preprint landing page" + +msgid "plugins.themes.default.option.metadata.description" +msgstr "Select the preprint metadata to show in other languages." + +msgid "plugins.themes.default.submissionMetadataInLanguage" +msgstr "Preprint Metadata in English" + +msgid "plugins.themes.default.titleSubtitleSeparator" +msgstr " — " diff --git a/plugins/themes/default/styles/objects/preprint_details.less b/plugins/themes/default/styles/objects/preprint_details.less index 2cd82aa7f4..1eb3e7ffd6 100755 --- a/plugins/themes/default/styles/objects/preprint_details.less +++ b/plugins/themes/default/styles/objects/preprint_details.less @@ -37,7 +37,7 @@ margin-bottom: 0; } - > h2 + p { + > h2 + p, h3 + p { margin-top: 0; } } @@ -52,6 +52,10 @@ .main_entry { + .metadata > .page_metadata_title { + margin: 0; + } + .item { .label { @@ -118,8 +122,7 @@ } } - .item.doi, - .item.keywords { + .item.doi { padding-top: 0; } @@ -302,8 +305,7 @@ font-weight: @bold; } - &.doi .label, - &.keywords .label { + &.doi .label { display: inline; font-size: @font-base; } diff --git a/templates/frontend/objects/preprint_details.tpl b/templates/frontend/objects/preprint_details.tpl index 8d70c5a36d..a615874a23 100644 --- a/templates/frontend/objects/preprint_details.tpl +++ b/templates/frontend/objects/preprint_details.tpl @@ -64,6 +64,7 @@ * @uses $licenseUrl string URL to license. Only assigned if license should be * included with published submissions. * @uses $ccLicenseBadge string An image and text with details about the license + * @uses $pubLocaleData array Array of formatted publication locale metadata: titles, abstracts, keywords, *}
@@ -109,13 +110,12 @@ {translate key="navigation.breadcrumbSeparator"} {translate key="publication.version" version=$publication->getData('version')} -

- {$publication->getLocalizedTitle(null, 'html')|strip_unsafe_html} +

+ {$pubLocaleData.title.text[$pubLocaleData.primaryLocale]|strip_unsafe_html}

- - {if $publication->getLocalizedData('subtitle')} -

- {$publication->getLocalizedSubTitle(null, 'html')|strip_unsafe_html} + {if isset($pubLocaleData.subtitle.text[$pubLocaleData.primaryLocale])} +

+ {$pubLocaleData.subtitle.text[$pubLocaleData.primaryLocale]|strip_unsafe_html}

{/if} @@ -168,28 +168,60 @@ {/if} - {* Keywords *} - {if !empty($publication->getLocalizedData('keywords'))} -
-

- {capture assign=translatedKeywords}{translate key="preprint.subject"}{/capture} - {translate key="semicolon" label=$translatedKeywords} -

- - {foreach name="keywords" from=$publication->getLocalizedData('keywords') item="keyword"} - {$keyword|escape}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator"}{/if} - {/foreach} - -
- {/if} + {* + * Show preprint keywords and abstract in ui, or submission, language by default. + * Show optional multilingual metadata: titles, keywords, abstracts. + *} + {foreach from=$pubLocaleData.languages item=lang} +
+ {assign "hLvl" "2"} + {* Multilingual metadata title *} + {if $lang !== $pubLocaleData.primaryLocale} + {assign "hLvl" "3"} + + {* Title in other language *} + {if isset($pubLocaleData.title.text[$lang])} +
+ + {translate key="submission.title" locale=$pubLocaleData.title.headingLang[$lang]} + +

+ {$pubLocaleData.title.text[$lang]|strip_tags} + {if isset($pubLocaleData.subtitle.text[$lang])} + {translate key="plugins.themes.default.titleSubtitleSeparator" locale=$pubLocaleData.title.headingLang[$lang]}{$pubLocaleData.subtitle.text[$lang]|strip_tags} + {/if} +

+
+ {/if} + {/if} - {* Abstract *} - {if $publication->getLocalizedData('abstract')} -
-

{translate key="common.abstract"}

- {$publication->getLocalizedData('abstract')|strip_unsafe_html} + {* Keywords *} + {if isset($pubLocaleData.keywords.text[$lang])} +
+ + {translate key="common.keywords" locale=$pubLocaleData.keywords.headingLang[$lang]} + +

+ {foreach from=$pubLocaleData.keywords.text[$lang] item="keyword"} + {$keyword|escape}{if !$keyword@last}{translate key="common.commaListSeparator" locale=$pubLocaleData.keywords.headingLang[$lang]}{/if} + {/foreach} +

+
+ {/if} + + {* Abstract *} + {if isset($pubLocaleData.abstract.text[$lang])} +
+ + {translate key="common.abstract" locale=$pubLocaleData.abstract.headingLang[$lang]} + +

{$pubLocaleData.abstract.text[$lang]|strip_tags}

+
+ {/if}
- {/if} + {/foreach} {call_hook name="Templates::Preprint::Main"}