From eeaeedd2128971cbdd29307cc9e54e85384d7e1f Mon Sep 17 00:00:00 2001 From: jyhein <124268211+jyhein@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:40:26 +0300 Subject: [PATCH] pkp/pkp-lib#7272 Simultaneously Displaying Multilingual Metadata on the Article Landing Page --- pages/catalog/CatalogBookHandler.php | 37 ++++++++++++ plugins/themes/default/DefaultThemePlugin.php | 20 +++++++ plugins/themes/default/locale/en/locale.po | 6 ++ .../styles/objects/monograph_full.less | 31 ++++++++++ templates/frontend/objects/monograph_full.tpl | 57 ++++++++++++------- 5 files changed, 132 insertions(+), 19 deletions(-) diff --git a/pages/catalog/CatalogBookHandler.php b/pages/catalog/CatalogBookHandler.php index 320335593f8..07678da1102 100755 --- a/pages/catalog/CatalogBookHandler.php +++ b/pages/catalog/CatalogBookHandler.php @@ -298,6 +298,8 @@ public function book($args, $request) $templateMgr->addHeader('canonical', ''); } + $templateMgr->assign('pubLocData', $this->getPublicationLocaleData($this->publication, $request->getContext()->getPrimaryLocale(), $submission->getData('locale'), $templateMgr->getTemplateVars('activeTheme')->getOption('showMetadata') ?: [])); + // Display if (!Hook::call('CatalogBookHandler::book', [&$request, &$submission, &$this->publication, &$this->chapter])) { $templateMgr->display('frontend/pages/book.tpl'); @@ -605,4 +607,39 @@ protected function getChaptersFirstPublishedDate(Submission $submission, Chapter return null; } + + /** + * For book details, format display data. + */ + protected function getPublicationLocaleData(\APP\publication\Publication $publication, string $contextPrimaryLocale, string $submissionLocale, array $metadataOpts): array + { + $titles = array_filter($publication->getFullTitles('html')); + $primaryLocale = isset($titles[$contextPrimaryLocale]) ? $contextPrimaryLocale : $submissionLocale; + $uiLocale = $contextPrimaryLocale; + $getMData = fn ($opt) => empty(count($mdata = array_filter($publication->getData($opt) ?? []))) || in_array($opt, $metadataOpts) + ? $mdata + : (isset($mdata[$primaryLocale]) ? [$primaryLocale => $mdata[$primaryLocale]] : [$fk = array_key_first($mdata) => $mdata[$fk]]); + + $pubLocData = [ + 'titles' => ['text' => in_array('title', $metadataOpts) ? array_filter($titles, fn ($locale) => $locale !== $primaryLocale, ARRAY_FILTER_USE_KEY) : []], + 'keywords' => ['text' => $getMData('keywords')], + 'abstract' => ['text' => $getMData('abstract')], + ]; + + foreach($pubLocData as $opt => &$item) { + uksort($item['text'], fn ($a, $b) => $a === $primaryLocale ? -1 : ($b === $primaryLocale ? 1 : ($a < $b ? -1 : 1))); + + $locales = array_keys($item['text']); + $hasSameHeaderLocale = in_array($opt, $metadataOpts); + $item['header'] = []; + foreach($locales as $locale) { + $item['header'][$locale] = $hasSameHeaderLocale ? $locale : $uiLocale; + } + } + + $pubLocData['primaryTitle'] = $titles[$primaryLocale]; + $pubLocData['primaryLocale'] = $primaryLocale; + + return $pubLocData; + } } diff --git a/plugins/themes/default/DefaultThemePlugin.php b/plugins/themes/default/DefaultThemePlugin.php index 56b1ad7a204..91d736e40ba 100644 --- a/plugins/themes/default/DefaultThemePlugin.php +++ b/plugins/themes/default/DefaultThemePlugin.php @@ -126,6 +126,26 @@ public function init() 'default' => 'none', ]); + $this->addOption('showMetadata', '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' => __('submission.synopsis'), + ], + ], + '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 cd597a3564f..551476e6a95 100644 --- a/plugins/themes/default/locale/en/locale.po +++ b/plugins/themes/default/locale/en/locale.po @@ -95,3 +95,9 @@ msgstr "Downloads" msgid "plugins.themes.default.displayStats.noStats" msgstr "Download data is not yet available." + +msgid "plugins.themes.default.option.metadata.label" +msgstr "Show submission metadata on the book landing page" + +msgid "plugins.themes.default.option.metadata.description" +msgstr "Select the metadata to show in an books's other languages." diff --git a/plugins/themes/default/styles/objects/monograph_full.less b/plugins/themes/default/styles/objects/monograph_full.less index 057bc84e016..54d585993da 100644 --- a/plugins/themes/default/styles/objects/monograph_full.less +++ b/plugins/themes/default/styles/objects/monograph_full.less @@ -22,6 +22,20 @@ margin-bottom: @quadruple; } + > .locale_titles { + margin: @double 0 @triple 0; + + > p { + font-size: @font-base; + margin-top: 0; + margin-bottom: @half; + + &:last-of-type { + margin-bottom: 0; + } + } + } + .main_entry { .item { @@ -30,6 +44,23 @@ &:first-child { padding-top: 0; } + + + &.keywords > div { + margin-bottom: @triple; + + &:last-of-type { + margin-bottom: 0; + } + } + + &.abstracts .abstract { + margin-bottom: @quadruple; + + &:last-of-type { + margin-bottom: 0; + } + } } .label { diff --git a/templates/frontend/objects/monograph_full.tpl b/templates/frontend/objects/monograph_full.tpl index b00a5ab5af9..c8616607d1e 100644 --- a/templates/frontend/objects/monograph_full.tpl +++ b/templates/frontend/objects/monograph_full.tpl @@ -71,6 +71,7 @@ * @uses $licenseUrl string The URL which provides license information. * @uses $ccLicenseBadge string An HTML string containing a CC license image and * text. Only appears when license URL matches a known CC license. + * @uses $pubLocData array Array of formatted publication locale metadata: titles, abstracts, keywords, *}
+ {$title|strip_unsafe_html} +
+ {/foreach} +