-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrcidProfileLinkPlugin.inc.php
169 lines (146 loc) · 4.7 KB
/
OrcidProfileLinkPlugin.inc.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* @file plugins/generic/orcidProfile/OrcidProfileLinkPlugin.inc.php
*
* Copyright (c) National Documentation Centre
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class OrcidProfilePluginView
* @ingroup plugins_generic_orcidProfileLink
*
* @brief ORCID Profile View plugin class
*/
import('lib.pkp.classes.plugins.GenericPlugin');
define('ORCID_PROFILE_URL_PREFIX', 'https://orcid.org/');
class OrcidProfileLinkPlugin extends GenericPlugin {
public $array = [];
/**
* 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) {
$success = parent::register($category, $path);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {
// Register callback for Smarty filters; add CSS
HookRegistry::register('TemplateManager::display', array(&$this, 'handleTemplateDisplay'));
}
return $success;
}
/**
* Hook callback: register output filter to add data citation to submission
* summaries; add data citation to reading tools' suppfiles and metadata views.
* @see TemplateManager::display()
*/
function handleTemplateDisplay($hookName, $args) {
$templateMgr =& $args[0];
$template =& $args[1];
$request =& PKPApplication::getRequest();
switch ($template) {
case 'article/article.tpl':
$templateMgr->register_outputfilter(array(&$this, 'templateArticleFilter'));
break;
}
return false;
}
/**
* Output filter adds ORCiD profile link to article view page.
* @param $output string
* @param $templateMgr TemplateManager
* @return $string
*/
function templateArticleFilter($output, &$templateMgr) {
if (preg_match('/<div id="authorString"+>/', $output, $matches, PREG_OFFSET_CAPTURE)) {
$offset = $matches[0][1];
// Make the author string with it's ORCID link.
$article = $templateMgr->get_template_vars('article');
$str = $this->getAuthorNameWithOrcid($article);
$templateMgr->assign(array(
'authorStringOrcid' => $str,
));
$newOutput = substr($output, 0, $offset);
$newOutput .= $templateMgr->fetch($this->getTemplatePath() . 'orcidArticle.tpl');
$newOutput .= substr($output, $offset);
$output = $newOutput;
}
$templateMgr->unregister_outputfilter('templateArticleFilter');
return $output;
}
function getAuthorNameWithOrcid($article) {
$authors = $article->getAuthors();
$str = '';
foreach($authors as $author) {
if (!empty($str)) {
$str .= ', ';
}
if ($author->getData('orcid') && $author->getData('orcid') != "") {
$str .= htmlspecialchars($author->getFullName()).' (<a target="_blank" href="'.$author->getData('orcid').'">'.$author->getData('orcid').'</a>)';
} else {
$str .= htmlspecialchars($author->getFullName());
}
}
return $str;
}
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.orcidProfileLink.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.orcidProfileLink.description');
}
/**
* Extend the {url ...} smarty to support this plugin.
*/
function smartyPluginUrl($params, &$smarty) {
$path = array($this->getCategory(), $this->getName());
if (is_array($params['path'])) {
$params['path'] = array_merge($path, $params['path']);
} elseif (!empty($params['path'])) {
$params['path'] = array_merge($path, array($params['path']));
} else {
$params['path'] = $path;
}
if (!empty($params['id'])) {
$params['path'] = array_merge($params['path'], array($params['id']));
unset($params['id']);
}
return $smarty->smartyUrl($params, $smarty);
}
/**
* Set the page's breadcrumbs, given the plugin's tree of items
* to append.
* @param $subclass boolean
*/
function setBreadcrumbs($isSubclass = false) {
$templateMgr =& TemplateManager::getManager();
$pageCrumbs = array(
array(
Request::url(null, 'user'),
'navigation.user'
),
array(
Request::url(null, 'manager'),
'user.role.manager'
)
);
if ($isSubclass) {
$pageCrumbs[] = array(
Request::url(null, 'manager', 'plugins'),
'manager.plugins'
);
$pageCrumbs[] = array(
Request::url(null, 'manager', 'plugins', 'generic'),
'plugins.categories.generic'
);
}
$templateMgr->assign('pageHierarchy', $pageCrumbs);
}
}
?>