-
Notifications
You must be signed in to change notification settings - Fork 6
/
PublonsPlugin.inc.php
355 lines (296 loc) · 11.9 KB
/
PublonsPlugin.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
/**
* @file plugins/generic/publons/PublonsPlugin.inc.php
*
* Copyright (c) 2016 Publons Ltd.
* Distributed under the GNU GPL v2.
*
* @class PublonsPlugin
* @ingroup plugins_generic_publons
*
* @brief Publons plugin
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class PublonsPlugin extends GenericPlugin {
/**
* Called as a plugin is registered to the registry
* @param $category String Name of category plugin was registered to
* @return boolean True if plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled()) {
$this->import('classes.PublonsReviews');
$this->import('classes.PublonsReviewsDAO');
$publonsReviewsDao = new PublonsReviewsDAO();
DAORegistry::registerDAO('PublonsReviewsDAO', $publonsReviewsDao);
HookRegistry::register('TemplateManager::display', array(&$this, 'handleTemplateDisplay'));
HookRegistry::register('TemplateManager::fetch', array(&$this, 'handleTemplateFetch'));
HookRegistry::register ('LoadHandler', array(&$this, 'handleRequest'));
}
return true;
}
return false;
}
/**
* Get the symbolic name of this plugin
* @return string
*/
function getName() {
// This should not be used as this is an abstract class
return 'PublonsPlugin';
}
/**
* Get the display name of this plugin
* @return string
* @see Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.publons.displayName');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.generic.publons.description');
}
/**
* @see Plugin::getTemplatePath()
*/
function getTemplatePath($inCore = false) {
$bathPath = Core::getBaseDir();
return 'file:' . $bathPath . DIRECTORY_SEPARATOR . parent::getTemplatePath() . DIRECTORY_SEPARATOR;
}
/**
* @copydoc PKPPlugin::getInstallMigration()
* This function only work from OJS 3.3.0-6
*/
function getInstallMigration() {
$this->import('classes.PublonsSchemaMigration');
return new PublonsSchemaMigration();
}
/**
* Get the stylesheet for this plugin.
*/
function getStyleSheet() {
return $this->getPluginPath() . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR . 'publons.css';
}
/**
* @see Plugin::getActions()
*/
function getActions($request, $verb) {
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'connect',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array('verb' => 'connect', 'plugin' => $this->getName(), 'category' => 'generic')),
$this->getDisplayName()
),
__('plugins.generic.publons.settings.connection'),
null
),
// new LinkAction(
// 'settings',
// new AjaxModal(
// $router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
// $this->getDisplayName()
// ),
// __('plugins.generic.publons.settings.published'),
// null
// ),
):array(),
parent::getActions($request, $verb)
);
}
/**
* @see GenericPlugin::manage()
*/
function manage($args, $request) {
AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER);
$templateMgr = TemplateManager::getManager($request);
$templateMgr->register_function('plugin_url', array($this, 'smartyPluginUrl'));
$journal = $request->getJournal();
switch ($request->getUserVar('verb')) {
case 'connect':
$this->import('classes.form.publonsSettingsForm');
$form = new PublonsSettingsForm($this, $journal->getId());
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
} else {
$form->initData();
}
return new JSONMessage(true, $form->fetch($request));
// case 'settings':
// $publonsReviewsDao =& DAORegistry::getDAO('PublonsReviewsDAO');
// $reviewsByJournal =& $publonsReviewsDao->getPublonsReviewsByJournal($journal->getId());
// $this->import('classes.form.SettingsForm');
// $form = new SettingsForm($this, $journal->getId());
// $form->initData();
// $form->display();
// return true;
}
return parent::manage($args, $request);
}
function handleRequest($hookName, $params) {
$page =& $params[0];
$request = Application::getRequest();
AppLocale::requireComponents();
if ($page == 'reviewer' && $this->getEnabled()) {
$op =& $params[1];
if ($op == 'exportReview') {
define('HANDLER_CLASS', 'PublonsHandler');
$this->import('PublonsHandler');
PublonsHandler::setPlugin($this);
return true;
}
}
return false;
}
/**
* 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) {
if ($this->getEnabled()) {
$templateMgr =& $args[0];
$request = PKPApplication::getRequest();
// Assign our private stylesheet, for front and back ends.
$templateMgr->addStyleSheet(
'publons',
$request->getBaseUrl() . '/' . $this->getStyleSheet(),
array(
'contexts' => array('frontend', 'backend')
)
);
return false;
}
}
function handleTemplateFetch($hookName, $args) {
if ($this->getEnabled()) {
$templateMgr =& $args[0];
$template =& $args[1];
$filterName = '';
if ($template == 'reviewer/review/reviewCompleted.tpl'){
$filterName = 'completedSubmissionOutputFilter';
} elseif ($template == 'reviewer/review/step3.tpl') {
$filterName = 'step3SubmissionOutputFilter';
}
if ($filterName !== '') {
$templateMgr->registerFilter('output', array(&$this, $filterName));
}
}
return false;
}
function step3SubmissionOutputFilter($output, $templateMgr) {
$plugin =& PluginRegistry::getPlugin('generic', $this->getName());
$reviewerSubmissionDao =& DAORegistry::getDAO('ReviewerSubmissionDAO');
$reviewSubmission = $templateMgr->get_template_vars('submission');
$reviewId = $reviewSubmission->getReviewId();
$journalId = $reviewSubmission->getJournalId();
$auth_token = $plugin->getSetting($journalId, 'auth_token');
// Only display if the plugin has been setup
if ($auth_token){
preg_match_all('/<div class="section formButtons form_buttons ">/s', $output, $matches, PREG_OFFSET_CAPTURE);
preg_match('/id="publons-info"/s', $output, $done);
if (!is_null(array_values(array_slice($matches[0], -1))[0][1])){
$match = array_values(array_slice($matches[0], -1))[0][1];
$beforeInsertPoint = substr($output, 0, $match);
$afterInsertPoint = substr($output, $match - strlen($output));
$templateMgr =& TemplateManager::getManager();
$newOutput = $beforeInsertPoint;
if (empty($done)){
$newOutput .= $templateMgr->fetch($this->getTemplatePath() . 'publonsNotificationStep.tpl');
}
$newOutput .= $afterInsertPoint;
$output = $newOutput;
}
}
$templateMgr->unregisterFilter('output', 'step3SubmissionOutputFilter');
return $output;
}
/**
* Output filter adds publons export step to submission process.
* @param $output string
* @param $templateMgr TemplateManager
* @return $string
*/
function completedSubmissionOutputFilter($output, $templateMgr) {
$plugin =& PluginRegistry::getPlugin('generic', $this->getName());
$reviewerSubmissionDao =& DAORegistry::getDAO('ReviewerSubmissionDAO');
$reviewSubmission = $templateMgr->get_template_vars('submission');
$reviewId = $reviewSubmission->getReviewId();
$journalId = $reviewSubmission->getJournalId();
$auth_token = $plugin->getSetting($journalId, 'auth_token');
// Only display if the plugin has been setup
if ($auth_token){
$publonsReviewsDao =& DAORegistry::getDAO('PublonsReviewsDAO');
$published = $publonsReviewsDao->getPublonsReviewsIdByReviewId($reviewId);
$info_url = $this->getSetting($journalId, 'info_url');
$templateMgr =& TemplateManager::getManager();
$templateMgr->unregisterFilter('output', array(&$this, 'completedSubmissionOutputFilter'));
$request = Application::getRequest();
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
$templateMgr->assign(
'exportReviewAction',
new LinkAction(
'exportReview',
new AjaxModal(
$router->url($request, null, null, 'exportReview', array('reviewId' => $reviewId)),
__('plugins.generic.publons.settings.connection')
),
__('plugins.generic.publons.settings.connection'),
null
)
);
$templateMgr->assign('reviewId', $reviewId);
$templateMgr->assign('published', $published);
$templateMgr->assign('infoURL', $info_url);
$output .= $templateMgr->fetch($this->getTemplatePath() . 'publonsExportStep.tpl');
}
return $output;
}
/**
* Get whether we're running php 5
* @return boolean
*/
function php5Installed() {
return version_compare(PHP_VERSION, '5.0.0', '>=');
}
/**
* Get whether curl is available
* @return boolean
*/
function curlInstalled() {
return function_exists('curl_version');
}
/**
* @see Plugin::smartyPluginUrl()
*/
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);
}
}
?>