forked from RBoelter/citations
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCitationsPlugin.inc.php
156 lines (143 loc) · 4.61 KB
/
CitationsPlugin.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
<?php
import('lib.pkp.classes.plugins.GenericPlugin');
class CitationsPlugin extends GenericPlugin
{
/**
* @return string plugin name
*/
public function getDisplayName()
{
return __('plugins.generic.citations.title');
}
/**
* @return string plugin description
*/
public function getDescription()
{
return __('plugins.generic.citations.desc');
}
public function register($category, $path, $mainContextId = NULL)
{
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->addStyleSheet(
'citations',
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/css/citations.css'
);
HookRegistry::register('Templates::Article::Details', array($this, 'citationsContent'));
HookRegistry::register('Templates::Preprint::Details', array($this, 'citationsContent'));
HookRegistry::register('LoadHandler', array($this, 'setPageHandler'));
}
return $success;
}
private function getPubId($smarty) {
$application = Application::getName();
switch($application){
case 'ojs2':
$submission = $smarty->getTemplateVars('article');
break;
case 'ops':
$submission = $smarty->getTemplateVars('preprint');
break;
}
return $submission->getStoredPubId('doi');
}
public function citationsContent($hookName, $args)
{
$request = Application::get()->getRequest();
$smarty =& $args[1];
$output =& $args[2];
$pubId = $this->getPubId($smarty);
$contextId = $request->getContext()->getId();
$settings = json_decode($this->getSetting($contextId, 'settings'), true);
if ($pubId != null && $pubId != '' && $settings) {
$smarty->assign(array(
'citationsImagePath' => $request->getBaseUrl() . '/' . $this->getPluginPath() . '/images/',
'citationsId' => $pubId,
'citationsProvider' => $settings['provider'] != null ? $settings['provider'] : 'all',
'citationsShowGoogle' => $settings['showGoogle'] ? $settings['showGoogle'] : 0,
'citationsShowPmc' => $settings['showPmc'] ? $settings['showPmc'] : 0,
'citationsShowTotal' => $settings['showTotal'] != null ? $settings['showTotal'] : false,
'citationsShowList' => $settings['showList'] != null ? $settings['showList'] : false,
'citationsMaxHeight' => $settings['maxHeight'] != null ? intval($settings['maxHeight']) : 0,
'citationsArgsList' => array(
'citationsId' => $pubId,
'citationsShowList' => $settings['showList'] != null ? $settings['showList'] : false,
'citationsProvider' => $settings['provider'] != null ? $settings['provider'] : 'all'
)
));
$smarty->addJavaScript(
'citations',
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/citations.js'
);
$output .= $smarty->fetch($this->getTemplateResource('citations.tpl'));
}
}
public function setPageHandler($hookName, $params)
{
$page = $params[0];
if ($this->getEnabled() && $page === 'citations') {
$this->import('classes/CitationsHandler');
define('HANDLER_CLASS', 'CitationsHandler');
return true;
}
return false;
}
/**
* Add settings button to plugin
* @param $request
* @param array $verb
* @return array
*/
public function getActions($request, $verb)
{
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
return array_merge(
$this->getEnabled() ? array(
new LinkAction(
'settings',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
),
) : array(),
parent::getActions($request, $verb)
);
}
/**
* Manage Settings
* @param array $args
* @param PKPRequest $request
* @return JSONMessage
*/
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('citationsProviderOptions', [
'all' => 'plugins.generic.citations.options.all',
'scopus' => 'plugins.generic.citations.options.scopus',
'crossref' => 'plugins.generic.citations.options.crossref'
]);
$this->import('CitationsSettingsForm');
$form = new CitationsSettingsForm($this);
if (!$request->getUserVar('save')) {
$form->initData();
return new JSONMessage(true, $form->fetch($request));
}
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
}
return parent::manage($args, $request);
}
}