Skip to content

Commit f6308d1

Browse files
committed
pkp/pkp-lib#7272 Simultaneously Displaying Multilingual Metadata on the Article Landing Page
1 parent 9d37378 commit f6308d1

File tree

5 files changed

+136
-21
lines changed

5 files changed

+136
-21
lines changed

pages/preprint/PreprintHandler.php

+37
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ public function view($args, $request)
292292
$templateMgr->addHeader('canonical', '<link rel="canonical" href="' . $url . '">');
293293
}
294294

295+
$templateMgr->assign('pubLocData', $this->getPublicationLocaleData($publication, $context->getPrimaryLocale(), $preprint->getData('locale'), $templateMgr->getTemplateVars('activeTheme')->getOption('showMetadata') ?: []));
296+
295297
if (!Hook::call('PreprintHandler::view', [&$request, &$preprint, $publication])) {
296298
$templateMgr->display('frontend/pages/preprint.tpl');
297299
event(new UsageEvent(Application::ASSOC_TYPE_SUBMISSION, $context, $preprint));
@@ -411,4 +413,39 @@ public function userCanViewGalley($request)
411413
}
412414
return false;
413415
}
416+
417+
/**
418+
* For preprint details, format display data.
419+
*/
420+
protected function getPublicationLocaleData(\APP\publication\Publication $publication, string $contextPrimaryLocale, string $submissionLocale, array $metadataOpts): array
421+
{
422+
$titles = array_filter($publication->getTitles('html'));
423+
$primaryLocale = isset($titles[$contextPrimaryLocale]) ? $contextPrimaryLocale : $submissionLocale;
424+
$uiLocale = $contextPrimaryLocale;
425+
$getMData = fn ($opt) => empty(count($mdata = array_filter($publication->getData($opt) ?? []))) || in_array($opt, $metadataOpts)
426+
? $mdata
427+
: (isset($mdata[$primaryLocale]) ? [$primaryLocale => $mdata[$primaryLocale]] : [$fk = array_key_first($mdata) => $mdata[$fk]]);
428+
429+
$pubLocData = [
430+
'titles' => ['text' => in_array('title', $metadataOpts) ? array_filter($titles, fn ($locale) => $locale !== $primaryLocale, ARRAY_FILTER_USE_KEY) : []],
431+
'keywords' => ['text' => $getMData('keywords')],
432+
'abstract' => ['text' => $getMData('abstract')],
433+
];
434+
435+
foreach($pubLocData as $opt => &$item) {
436+
uksort($item['text'], fn ($a, $b) => $a === $primaryLocale ? -1 : ($b === $primaryLocale ? 1 : ($a < $b ? -1 : 1)));
437+
438+
$locales = array_keys($item['text']);
439+
$hasSameHeaderLocale = in_array($opt, $metadataOpts);
440+
$item['header'] = [];
441+
foreach($locales as $locale) {
442+
$item['header'][$locale] = $hasSameHeaderLocale ? $locale : $uiLocale;
443+
}
444+
}
445+
446+
$pubLocData['primaryTitle'] = $titles[$primaryLocale];
447+
$pubLocData['primaryLocale'] = $primaryLocale;
448+
449+
return $pubLocData;
450+
}
414451
}

plugins/themes/default/DefaultThemePlugin.php

+20
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ public function init()
125125
'default' => 'none',
126126
]);
127127

128+
$this->addOption('showMetadata', 'FieldOptions', [
129+
'label' => __('plugins.themes.default.option.metadata.label'),
130+
'description' => __('plugins.themes.default.option.metadata.description'),
131+
'options' => [
132+
[
133+
'value' => 'title',
134+
'label' => __('submission.title'),
135+
],
136+
[
137+
'value' => 'keywords',
138+
'label' => __('preprint.subject'),
139+
],
140+
[
141+
'value' => 'abstract',
142+
'label' => __('preprint.abstract'),
143+
],
144+
],
145+
'default' => [],
146+
]);
147+
128148
// Load primary stylesheet
129149
$this->addStyle('stylesheet', 'styles/index.less');
130150

plugins/themes/default/locale/en/locale.po

+6
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ msgstr "Downloads"
9292

9393
msgid "plugins.themes.default.displayStats.noStats"
9494
msgstr "Download data is not yet available."
95+
96+
msgid "plugins.themes.default.option.metadata.label"
97+
msgstr "Show submission metadata on the preprint landing page"
98+
99+
msgid "plugins.themes.default.option.metadata.description"
100+
msgstr "Select the metadata to show in an preprint's other languages."

plugins/themes/default/styles/objects/preprint_details.less

+31
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
margin: 0;
1515
}
1616

17+
> .page_locale_titles {
18+
margin: @double 0 @triple 0;
19+
20+
> p {
21+
font-size: @font-base;
22+
margin-top: 0;
23+
margin-bottom: @half;
24+
25+
&:last-of-type {
26+
margin-bottom: 0;
27+
}
28+
}
29+
}
30+
1731
> .subtitle {
1832
margin: 0;
1933
font-size: @font-base;
@@ -60,6 +74,23 @@
6074
font-size: @font-bump;
6175
font-weight: @bold;
6276
}
77+
78+
79+
&.keywords > section {
80+
margin-bottom: @base;
81+
82+
&:last-of-type {
83+
margin-bottom: 0;
84+
}
85+
}
86+
87+
&.abstracts .abstract {
88+
margin-bottom: @quadruple;
89+
90+
&:last-of-type {
91+
margin-bottom: 0;
92+
}
93+
}
6394
}
6495

6596
.sub_item {

templates/frontend/objects/preprint_details.tpl

+42-21
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* @uses $licenseUrl string URL to license. Only assigned if license should be
6464
* included with published submissions.
6565
* @uses $ccLicenseBadge string An image and text with details about the license
66+
* @uses $pubLocData array Array of formatted publication locale metadata: titles, abstracts, keywords,
6667
*}
6768
<article class="obj_preprint_details">
6869

@@ -108,13 +109,23 @@
108109
<span class="separator">{translate key="navigation.breadcrumbSeparator"}</span>
109110
<span class="preprint_version">{translate key="publication.version" version=$publication->getData('version')}</span>
110111

111-
<h1 class="page_title">
112-
{$publication->getLocalizedTitle(null, 'html')|strip_unsafe_html}
112+
<h1 class="page_title" lang="{$pubLocData.primaryLocale|replace:"_":"-"}">
113+
{$pubLocData.primaryTitle|strip_unsafe_html}
113114
</h1>
114115

115-
{if $publication->getLocalizedData('subtitle')}
116-
<h2 class="subtitle">
117-
{$publication->getLocalizedSubTitle(null, 'html')|strip_unsafe_html}
116+
{if !empty(count($pubLocData.titles.text))}
117+
<section class="page_locale_titles">
118+
{foreach from=$pubLocData.titles.text key=locale item=title}
119+
<p lang="{$locale|replace:"_":"-"}">
120+
{$title|strip_unsafe_html}
121+
</p>
122+
{/foreach}
123+
</section>
124+
{/if}
125+
126+
{if $publication->getData('subtitle', $pubLocData.primaryLocale)}
127+
<h2 class="subtitle" lang="{$pubLocData.primaryLocale|replace:"_":"-"}">
128+
{$publication->getData('subtitle', $pubLocData.primaryLocale)|strip_unsafe_html}
118129
</h2>
119130
{/if}
120131

@@ -168,25 +179,35 @@
168179
{/if}
169180

170181
{* Keywords *}
171-
{if !empty($publication->getLocalizedData('keywords'))}
172-
<section class="item keywords">
173-
<h2 class="label">
174-
{capture assign=translatedKeywords}{translate key="preprint.subject"}{/capture}
175-
{translate key="semicolon" label=$translatedKeywords}
176-
</h2>
177-
<span class="value">
178-
{foreach name="keywords" from=$publication->getLocalizedData('keywords') item="keyword"}
179-
{$keyword|escape}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator"}{/if}
180-
{/foreach}
181-
</span>
182-
</section>
182+
{if !empty(count($pubLocData.keywords.text))}
183+
<section class="item keywords">
184+
{foreach from=$pubLocData.keywords.text key=locale item=keywords}
185+
<section>
186+
<h2 class="label" lang="{$pubLocData.keywords.header[$locale]|replace:"_":"-"}">
187+
{capture assign=translatedKeywords}{translate key="preprint.subject" locale=$pubLocData.keywords.header[$locale]}{/capture}
188+
{translate key="semicolon" label=$translatedKeywords locale=$pubLocData.keywords.header[$locale]}
189+
</h2>
190+
<span class="value" lang="{$locale|replace:"_":"-"}">
191+
{foreach name="keywords" from=$keywords item="keyword"}
192+
{$keyword|escape}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator" locale=$pubLocData.keywords.header[$locale]}{/if}
193+
{/foreach}
194+
</span>
195+
</section>
196+
{/foreach}
197+
</section>
183198
{/if}
184199

185200
{* Abstract *}
186-
{if $publication->getLocalizedData('abstract')}
187-
<section class="item abstract">
188-
<h2 class="label">{translate key="common.abstract"}</h2>
189-
{$publication->getLocalizedData('abstract')|strip_unsafe_html}
201+
{if !empty(count($pubLocData.abstract.text))}
202+
<section class="item abstracts">
203+
{foreach from=$pubLocData.abstract.text key=locale item=abstract}
204+
<section class="abstract">
205+
<h2 class="label" lang="{$pubLocData.abstract.header[$locale]|replace:"_":"-"}">
206+
{translate key="preprint.abstract" locale=$pubLocData.abstract.header[$locale]}
207+
</h2>
208+
<span lang="{$locale|replace:"_":"-"}">{$abstract|strip_unsafe_html}</span>
209+
</section>
210+
{/foreach}
190211
</section>
191212
{/if}
192213

0 commit comments

Comments
 (0)