diff --git a/pages/article/ArticleHandler.php b/pages/article/ArticleHandler.php index 07f6bfb8505..9e0a44ba94f 100644 --- a/pages/article/ArticleHandler.php +++ b/pages/article/ArticleHandler.php @@ -167,8 +167,8 @@ public function initialize($request, $args = []) $this->galley = $galley; break; - // In some cases, a URL to a galley may use the ID when it should use - // the urlPath. Redirect to the galley's correct URL. + // In some cases, a URL to a galley may use the ID when it should use + // the urlPath. Redirect to the galley's correct URL. } elseif (ctype_digit($galleyId) && $galley->getId() == $galleyId) { $request->redirect(null, $request->getRequestedPage(), $request->getRequestedOp(), [$submission->getBestId(), $galley->getBestGalleyId()]); } @@ -357,6 +357,8 @@ public function view($args, $request) $templateMgr->assign('purchaseArticleEnabled', true); } + $templateMgr->assign('pubLocaleData', $this->getPublicationLocaleData($publication, $context->getPrimaryLocale(), $article->getData('locale'), $templateMgr->getTemplateVars('activeTheme')->getOption('showMetadata') ?: [])); + if (!Hook::call('ArticleHandler::view', [&$request, &$issue, &$article, $publication])) { $templateMgr->display('frontend/pages/article.tpl'); event(new UsageEvent(Application::ASSOC_TYPE_SUBMISSION, $context, $article, null, null, $this->issue)); @@ -616,4 +618,43 @@ public function userCanViewGalley($request, $articleId, $galleyId = null) } return true; } + + /** + * For article details, format display data. + */ + protected function getPublicationLocaleData(\APP\publication\Publication $publication, string $contextPrimaryLocale, string $submissionLocale, array $metadataOpts): array + { + $titles = $publication->getTitles('html'); + $subtitles = $publication->getSubtitles('html'); + $primaryLocale = isset($titles[$contextPrimaryLocale]) ? $contextPrimaryLocale : $submissionLocale; + $uiLocale = $contextPrimaryLocale; + $getOtherTitles = fn (array $tt, string $opt): array => in_array($opt, $metadataOpts) ? array_filter($tt, fn (string $locale) => $locale !== $primaryLocale, ARRAY_FILTER_USE_KEY) : []; + $getMdata = fn (string $opt): array => 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]]); + $getText = fn (array $item, string $opt): array => [ + 'text' => $item, + 'headingLang' => collect($item)->map(fn ($_, string $locale): string => in_array($opt, $metadataOpts) ? $locale : $uiLocale)->toArray() + ]; + + $pubLocaleData = [ + 'title' => $getText($getOtherTitles($titles, 'title'), 'title'), + 'subtitle' => $getText($getOtherTitles($subtitles, 'title'), 'title'), + 'keywords' => $getText($getMdata('keywords'), 'keywords'), + 'abstract' => $getText($getMdata('abstract'), 'abstract'), + ]; + $pubLocaleData['languages'] = collect($pubLocaleData) + ->map(fn (array $item): array => array_keys($item['text'])) + ->flatten() + ->sort() + ->prepend($primaryLocale) + ->unique() + ->values() + ->toArray(); + $pubLocaleData['primaryTitle'] = $titles[$primaryLocale]; + $pubLocaleData['primarySubtitle'] = $subtitles[$primaryLocale] ?? null; + $pubLocaleData['primaryLocale'] = $primaryLocale; + + return $pubLocaleData; + } } diff --git a/plugins/themes/default/DefaultThemePlugin.php b/plugins/themes/default/DefaultThemePlugin.php index 6ebcb1f4424..399bdd4f1da 100644 --- a/plugins/themes/default/DefaultThemePlugin.php +++ b/plugins/themes/default/DefaultThemePlugin.php @@ -124,6 +124,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' => __('article.title'), + ], + [ + 'value' => 'keywords', + 'label' => __('article.subject'), + ], + [ + 'value' => 'abstract', + 'label' => __('article.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 c783e630ff5..ca1511b3132 100644 --- a/plugins/themes/default/locale/en/locale.po +++ b/plugins/themes/default/locale/en/locale.po @@ -98,3 +98,15 @@ msgstr "Next slide" msgid "plugins.themes.default.prevSlide" msgstr "Previous slide" + +msgid "plugins.themes.default.option.metadata.label" +msgstr "Show article metadata on the article landing page" + +msgid "plugins.themes.default.option.metadata.description" +msgstr "Select the article metadata to show in other languages." + +msgid "plugins.themes.default.submissionMetadataInLanguage" +msgstr "Article Metadata in English" + +msgid "plugins.themes.default.titleSubtitleSeparator" +msgstr " — " diff --git a/plugins/themes/default/styles/objects/article_details.less b/plugins/themes/default/styles/objects/article_details.less index d8c032b0a0d..3ebcc29fc4e 100644 --- a/plugins/themes/default/styles/objects/article_details.less +++ b/plugins/themes/default/styles/objects/article_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 > h2 { + padding: 0 @triple; + } + .item { .label { @@ -66,6 +70,14 @@ display: inline; font-size: @font-base; } + + &.page_locale_title { + margin-bottom: @triple; + } + + &.abstract { + margin-bottom: @quadruple; + } } .sub_item { diff --git a/templates/frontend/objects/article_details.tpl b/templates/frontend/objects/article_details.tpl index 4b6b1463e1b..0b4ddbc61b2 100755 --- a/templates/frontend/objects/article_details.tpl +++ b/templates/frontend/objects/article_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, * * @hook Templates::Article::Main [] * @hook Templates::Article::Details::Reference [] @@ -91,13 +92,12 @@ {/if} -