This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrereviewPlugin.inc.php
435 lines (374 loc) · 13.5 KB
/
PrereviewPlugin.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
import('lib.pkp.classes.plugins.GenericPlugin');
//PREREVIEW SITE
define('PREREVIEW_API_CHECK', 'https://prereview.org/api/v2/preprints/');
define('PREREVIEW_URL', 'https://prereview.org/preprints/');
class PrereviewPlugin extends GenericPlugin {
public function register($category, $path, $mainContextId = NULL) {
// Register the plugin even when it is not enabled
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
$request = Application::get()->getRequest();
//Include javascript and css
$url = $request->getBaseUrl() . '/' . $this->getPluginPath() . '/css/prereview.css';
$urlj = $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/prereview.js';
$templateMgr = TemplateManager::getManager($request);
$templateMgr->addStyleSheet('callbackSharingDisplay', $url);
$templateMgr->addJavaScript('callbackSharingDisplay', $urlj);
// Do something when the plugin is enabled
HookRegistry::register('Schema::get::publication', array($this, 'addToSchema')); //Add schema for radiobuttons
HookRegistry::register('Templates::Preprint::Details', array($this, 'callbackSharingDisplay')); // Include information in detail view of OPS
HookRegistry::register('submissionsubmitstep4form::display', array($this, 'handleFormDisplaySubmission'));//Include form to submmisions
HookRegistry::register('submissionsubmitstep4form::execute', array($this, 'handleFormExecute'));//Save form
HookRegistry::register('Template::Workflow::Publication', array($this, 'publicationTemplateData'));//Include form to publications
HookRegistry::register('LoadComponentHandler', array($this, 'setupGridHandler'));
}
return $success;
}
/**
* @param $hookName string The name of the hook being invoked
* @param $args array The parameters to the invoked hook
*/
function setupGridHandler($hookName, $params) {
$component =& $params[0];
if ($component == 'plugins.generic.prereviewPlugin.controllers.grid.PrereviewGridHandler') {
import($component);
PrereviewGridHandler::setPlugin($this);
return true;
}
return false;
}
/**
* Provide a name for this plugin
*
* The name will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*/
public function getDisplayName() {
return 'PREreview';
}
/**
* Provide a description for this plugin
*
* The description will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*/
public function getDescription() {
return __('plugins.generic.prereview.description');
}
/**
* @copydoc Plugin::getActions()
*/
function getActions($request, $actionArgs) {
// Get the existing actions
$actions = parent::getActions($request, $actionArgs);
if (!$this->getEnabled()) {
return $actions;
}
// Create a LinkAction that will call the plugin's
// `manage` method with the `settings` verb.
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
$linkAction = 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
);
// Add the LinkAction to the existing actions.
// Make it the first action to be consistent with
// other plugins.
array_unshift($actions, $linkAction);
return $actions;
}
/**
* @see Plugin::manage()
*/
function manage($args, $request) {
switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
$this->import('PrereviewSettingsForm');
$form = new PrereviewSettingsForm($this, $context);
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));
}
return parent::manage($args, $request);
}
function callbackSharingDisplay($hookName, $params) {
$templateMgr = $params[1];
$output =& $params[2];
$request = $this->getRequest();
$context = $request->getContext();
$result=array();
$showRevisions = $this->_getPluginSetting($context, 'showRevisions');
$idPreprint=$request->getRouter()->getHandler()->preprint->_data['id'];
$idPreprint=((int) $idPreprint);
$doi = $this->getDoi($idPreprint);
$doi_result = "doi-".str_replace("/", "-", strtolower($doi));
$url= PREREVIEW_API_CHECK . $doi_result;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
$datos = json_decode($result);
$fullrev=array();
$i=0;
$datos_fullreview=$datos->data[0]->fullReviews;
$datos_rapidreview=$datos->data[0]->rapidReviews;
foreach($datos_fullreview as $fr){
$fullrev[$i]=array(
'id' =>$i,
'name'=> $fr->authors[0]->name,
'content' =>$fr->drafts[0]->contents,
);
$i++;
}
$templateMgr->assign(
array(
'status' => $datos->status,
'url' => PREREVIEW_URL.$doi_result,
'numFullReviews' => count($datos_fullreview),
'numRapidReviews' => count($datos_rapidreview),
'numRequests' => count($datos->data[0]->requests),
'fullReviews' =>$fullrev,
'showReviews' =>$showRevisions,
'showrevisionsLong' =>$showrevisionsLong,
'rapidReviews' =>$this->getRapidReviews($datos_rapidreview),
'authorization'=>$this->getPrereviewSetting($idPreprint)->setting_value,
)
);
$output .= $templateMgr->fetch($this->getTemplateResource('prereview.tpl'));
return false;
}
function handleFormDisplaySubmission($hookName, $args) {
$request = PKPApplication::get()->getRequest();
$context = $request->getContext();
$templateMgr = TemplateManager::getManager($request);
switch ($hookName) {
case 'submissionsubmitstep4form::display':
$authorForm =& $args[0];
$supportedSubmissionLocales = $context->getSupportedSubmissionLocales();
$localeNames = AppLocale::getAllLocales();
$locales = array_map(function($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
}, $supportedSubmissionLocales);
$templateMgr->registerFilter("output", array($this, 'metadataForm'));
break;
}
return false;
}
function handleFormExecute($hookName, $params) {
$props =& $params[0];
$request = Application::get()->getRequest();
$this->import('PrereviewPluginDAO');
$prereview = new PrereviewPluginDAO();
DAORegistry::registerDAO('PrereviewPluginDAO', $prereview);
$id=$props->submission->_data['id'];
$request=$_POST['prereview:authorization'];
if(empty($request))
$request='no';
$preDao = DAORegistry::getDAO('PrereviewPluginDAO');
$preDao->insert($id, 'prereview:authorization', $request);
}
/**
* Output adds prereview authorization form.
*
* @param $output string
* @param $templateMgr TemplateManager
* @return string
*/
function metadataForm($output, $templateMgr) {
if (preg_match('/<input[^>]+name="submissionId"[^>]*>/', $output, $matches, PREG_OFFSET_CAPTURE)) {
$match = $matches[0][0];
$offset = $matches[0][1];
$templateMgr->assign('data', $output);
$newOutput = substr($output, 0, $offset + strlen($match));
$newOutput .= $templateMgr->fetch($this->getTemplateResource('request.tpl'));
$newOutput .= substr($output, $offset + strlen($match));
$output = $newOutput;
$templateMgr->unregisterFilter('output', array($this, 'metadataForm'));
}
return $output;
}
/**
* @param string $hookname
* @param array $args [string, TemplateManager]
*/
function publicationTemplateData(string $hookname, array $args): void {
/**
* @var $templateMgr TemplateManager
* @var $submission Submission
* @var $submissionFileDao SubmissionFileDAO
* @var $submissionFile SubmissionFile
*/
$templateMgr = $args[1];
$request = $this->getRequest();
$context = $request->getContext();
$submission = $templateMgr->getTemplateVars('submission');
$latestPublication = $submission->getLatestPublication();
$latestPublicationApiUrl = $request->getDispatcher()->url($request, ROUTE_API, $context->getData('urlPath'), 'submissions/' . $submission->getId() . '/publications/' . $latestPublication->getId());
$supportedSubmissionLocales = $context->getSupportedSubmissionLocales();
$localeNames = AppLocale::getAllLocales();
$locales = array_map(function($localeKey) use ($localeNames) {
return ['key' => $localeKey, 'label' => $localeNames[$localeKey]];
}, $supportedSubmissionLocales);
$smarty =& $args[1];
$output =& $args[2];
$submission = $smarty->get_template_vars('submission');
$smarty->assign([
'submissionId' => $submission->getId(),
'publication' => $this->getPrereviewSetting($submission->getId())->setting_value,
]);
$output .= sprintf(
$smarty->fetch($this->getTemplateResource('workflowPrereview.tpl'))
);
}
function getRapidReviews($rapidReviews){
for ($l = 0; $l < count($rapidReviews); $l++) {
$ynNovel[$l] = $rapidReviews[$l]->ynNovel;
$ynFuture[$l] = $rapidReviews[$l]->ynFuture;
$ynReproducibility[$l] = $rapidReviews[$l]->ynReproducibility;
$ynMethods[$l] = $rapidReviews[$l]->ynMethods;
$ynCoherent[$l] = $rapidReviews[$l]->ynCoherent;
$ynLimitations[$l] = $rapidReviews[$l]->ynLimitations;
$ynEthics[$l] = $rapidReviews[$l]->ynEthics;
$ynNewData[$l] = $rapidReviews[$l]->ynNewData;
$ynAvailableData[$l] = $rapidReviews[$l]->ynAvailableData;
$ynAvailableCode[$l] = $rapidReviews[$l]->ynAvailableCode;
$ynRecommend[$l] = $rapidReviews[$l]->ynRecommend;
$ynPeerReview[$l] = $rapidReviews[$l]->ynPeerReview;
}
$rapidrev=array(
'ynNovel'=>$this->getValues($ynNovel),
'ynFuture'=>$this->getValues($ynFuture),
'ynReproducibility'=>$this->getValues($ynReproducibility),
'ynMethods'=>$this->getValues($ynMethods),
'ynCoherent'=>$this->getValues($ynCoherent),
'ynLimitations'=>$this->getValues($ynLimitations),
'ynEthics'=>$this->getValues($ynEthics),
'ynNewData'=>$this->getValues($ynNewData),
'ynAvailableData'=>$this->getValues($ynAvailableData),
'ynAvailableCode'=>$this->getValues($ynAvailableCode),
'ynRecommend'=>$this->getValues($ynRecommend),
'ynPeerReview'=>$this->getValues($ynPeerReview),
);
return $rapidrev;
}
function getValues($value) {
$yes = 0;
$no = 0;
$unsure = 0;
$na = 0;
$result = "";
$total = (100 / count($value));
for ($v = 0; $v < count($value); $v++) {
switch ($value[$v]) {
case "yes":
$yes = $yes + $total;
break;
case "no":
$no = $no + $total;
break;
case "unsure":
$unsure = $unsure + $total;
break;
case "N/A":
$na = $na + $total;
break;
}
}
if ($yes != 0) {
$result = $result . '<div class="yes" style="width:' . $yes . '%;"><p>' . $yes . '%</p></div>';
}
if ($unsure != 0) {
$result = $result . '<div class="unsure" style="width:' . $unsure . '%;"><p>' . $unsure . '%</p></div>';
}
if ($na != 0) {
$result = $result . '<div class="na" style="width:' . $na . '%;"><p>' . $na . '%</p></div>';
}
if ($no != 0) {
$result = $result . '<div class="no" style="width:' . $no . '%;"><p>' . $no . '%</p></div>';
}
return $result;
}
public function addToSchema($hookName, $args) {
$schema = $args[0];
$propId = '{
"type": "string",
"apiSummary": true,
"validation": [
"nullable"
]
}';
$schema->properties->{'prereview:authorization'} = json_decode($propId);
}
/**
* Get context wide setting. If the context or the setting does not exist,
* get the site wide setting.
* @param $context Context
* @param $name Setting name
* @return mixed
*/
function _getPluginSetting($context, $name) {
$pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO');
if ($context && $pluginSettingsDao->settingExists($context->getId(), $this->getName(), $name)) {
return $this->getSetting($context->getId(), $name);
} else {
return $this->getSetting(CONTEXT_ID_NONE, $name);
}
}
function _getSubmissionSetting($id, $name) {
$this->import('PrereviewPluginDAO');
$prereview = new PrereviewPluginDAO();
DAORegistry::registerDAO('PrereviewPluginDAO', $prereview);
$preDao = DAORegistry::getDAO('PrereviewPluginDAO');
$result= $preDao->_getPrereviewData($id, $name);
return $result;
}
function getPrereviewSetting($id) {
$this->import('PrereviewPluginDAO');
$prereview = new PrereviewPluginDAO();
DAORegistry::registerDAO('PrereviewPluginDAO', $prereview);
$preDao = DAORegistry::getDAO('PrereviewPluginDAO');
$result= $preDao->getDataPrereview($id);
return $result;
}
function getInstallMigration() {
$this->import('PrereviewSchemaMigration');
return new PrereviewSchemaMigration();
}
public function getDoi($id) {
import('classes.submission.Submission');
$submission = Services::get('submission')->get($id);
$submission = $submission->getData('publications')[0]->getData('pub-id::doi');
return $submission;
}
}