-
Notifications
You must be signed in to change notification settings - Fork 11
/
CoinsPlugin.php
140 lines (121 loc) · 4.63 KB
/
CoinsPlugin.php
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* @file CoinsPlugin.php
*
* Copyright (c) 2013-2023 Simon Fraser University
* Copyright (c) 2003-2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class CoinsPlugin
* @brief COinS plugin class
*/
namespace APP\plugins\generic\coins;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\config\Config;
use APP\core\Application;
use APP\template\TemplateManager;
class CoinsPlugin extends GenericPlugin {
/**
* Called as a plugin is registered to the registry
* @param $category String Name of category plugin was registered to
* @return boolean True iff plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path, $mainContextId = null) {
$success = parent::register($category, $path, $mainContextId);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {
Hook::add('Templates::Common::Footer::PageFooter', [$this, 'insertFooter']);
}
return $success;
}
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName() {
return __('plugins.generic.coins.displayName');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.generic.coins.description');
}
/**
* Insert COinS tag.
*/
function insertFooter(string $hookName, array $params) : bool
{
if (!$this->getEnabled()) return false;
$request = Application::get()->getRequest();
// Ensure that the callback is being called from a page COinS should be embedded in.
if (!in_array($request->getRequestedPage() . '/' . $request->getRequestedOp(), [
'article/view',
])) return false;
$smarty =& $params[1];
$output =& $params[2];
$templateMgr = TemplateManager::getManager($request);
$article = $templateMgr->getTemplateVars('article');
$journal = $templateMgr->getTemplateVars('currentJournal');
$issue = $templateMgr->getTemplateVars('issue');
$publication = $article->getCurrentPublication();
$vars = [
['ctx_ver', 'Z39.88-2004'],
['rft_id', $request->url(null, 'article', 'view', $article->getId())],
['rft_val_fmt', 'info:ofi/fmt:kev:mtx:journal'],
['rft.language', $article->getData('locale')],
['rft.genre', 'article'],
['rft.title', $journal->getLocalizedName()],
['rft.jtitle', $journal->getLocalizedName()],
['rft.atitle', $publication->getFullTitles()[$article->getData('locale')]],
['rft.artnum', $article->getBestId()],
['rft.stitle', $journal->getLocalizedSetting('abbreviation')],
];
if ($issue) {
$vars = array_merge($vars, [
['rft.volume', $issue->getVolume()],
['rft.issue', $issue->getNumber()],
]);
}
$authors = $publication->getData('authors');
if ($firstAuthor = $authors->first()) {
$vars = array_merge($vars, [
['rft.aulast', $firstAuthor->getFamilyName($article->getData('locale'))],
['rft.aufirst', $firstAuthor->getGivenName($article->getData('locale'))],
]);
}
$datePublished = $publication->getData('datePublished');
if (!$datePublished && $issue) {
$datePublished = $issue->getDatePublished();
}
if ($datePublished) {
$vars[] = ['rft.date', date('Y-m-d', strtotime($datePublished))];
}
foreach ($authors as $author) {
$vars[] = ['rft.au', $author->getFullName()];
}
if ($doi = $publication->getStoredPubId('doi')) {
$vars[] = ['rft_id', 'info:doi/' . $doi];
}
if ($publication->getData('pages')) {
$vars[] = ['rft.pages', $publication->getData('pages')];
}
if ($journal->getSetting('printIssn')) {
$vars[] = ['rft.issn', $journal->getSetting('printIssn')];
}
if ($journal->getSetting('onlineIssn')) {
$vars[] = ['rft.eissn', $journal->getSetting('onlineIssn')];
}
$title = '';
foreach ($vars as $entries) {
list($name, $value) = $entries;
$title .= $name . '=' . urlencode($value) . '&';
}
$title = htmlentities(substr($title, 0, -1));
$output .= "<span class=\"Z3988\" title=\"$title\"></span>\n";
return false;
}
}