-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDoiInSummaryPlugin.inc.php
More file actions
76 lines (58 loc) · 2.09 KB
/
DoiInSummaryPlugin.inc.php
File metadata and controls
76 lines (58 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @file plugins/generic/doiInSummary/DoiInSummaryPlugin.inc.php
*
* Copyright (c) 2015-2023 Lepidus Tecnologia
* Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt.
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class DoiInSummaryPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
HookRegistry::register('Templates::Issue::Issue::Article', [$this, 'addDoiToArticleSummary']);
$this->addLocaleData();
$this->addDoiStyleSheet();
}
return $success;
}
public function getDisplayName(): string
{
return __('plugins.generic.doiInSummary.displayName');
}
public function getDescription(): string
{
return __('plugins.generic.doiInSummary.description');
}
public function addDoiToArticleSummary(string $hookName, array $args): bool
{
$templateMgr = &$args[1];
$output = &$args[2];
$submission = $templateMgr->getTemplateVars('article');
$doiUrl = $this->getArticleDoiUrl($submission);
if (!is_null($doiUrl)) {
$templateMgr->assign('doiUrl', $doiUrl);
$output .= $templateMgr->fetch($this->getTemplateResource('doi_summary.tpl'));
}
return false;
}
private function getArticleDoiUrl(Submission $article): ?string
{
$publication = $article->getCurrentPublication();
$doiObject = $publication->getData('doiObject');
if (is_null($doiObject)) {
return null;
}
$doiUrl = $doiObject->getData('resolvingUrl');
return $doiUrl;
}
private function addDoiStyleSheet(): void
{
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$url = $request->getBaseUrl() . '/' . $this->getPluginPath() . '/styles/doi.css';
$templateMgr->addStyleSheet('doiCSS', $url);
}
}