-
Notifications
You must be signed in to change notification settings - Fork 1
/
ThothPlugin.inc.php
149 lines (123 loc) · 5.11 KB
/
ThothPlugin.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
<?php
/**
* @file plugins/generic/thoth/ThothPlugin.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Copyright (c) 2024 Lepidus Tecnologia
* Copyright (c) 2024 Thoth
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ThothPlugin
*
* @ingroup plugins_generic_thoth
*
* @brief Plugin for integration with Thoth for communication and synchronization of book data between the two platforms
*/
use APP\plugins\generic\thoth\classes\APIKeyEncryption;
use PKP\core\JSONMessage;
import('lib.pkp.classes.plugins.GenericPlugin');
import('plugins.generic.thoth.classes.ThothBadgeRender');
import('plugins.generic.thoth.classes.ThothNotification');
import('plugins.generic.thoth.classes.ThothRegister');
import('plugins.generic.thoth.classes.ThothUpdater');
import('plugins.generic.thoth.lib.thothAPI.exceptions.ThothException');
class ThothPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
$thothRegister = new ThothRegister($this);
HookRegistry::register('Schema::get::submission', [$thothRegister, 'addWorkIdToSchema']);
HookRegistry::register('Schema::get::eventLog', [$thothRegister, 'addReasonToSchema']);
HookRegistry::register('Form::config::before', [$thothRegister, 'addImprintField']);
HookRegistry::register('Publication::validatePublish', [$thothRegister, 'validateRegister']);
HookRegistry::register('TemplateManager::display', [$thothRegister, 'addResources']);
HookRegistry::register('Publication::publish', [$thothRegister, 'registerOnPublish']);
HookRegistry::register('LoadHandler', [$thothRegister, 'setupHandler']);
HookRegistry::register('APIHandler::endpoints', [$thothRegister, 'addThothEndpoint']);
$thothUpdater = new ThothUpdater($this);
HookRegistry::register('Publication::edit', [$thothUpdater, 'updateWork']);
$thothBadgeRender = new ThothBadgeRender($this);
HookRegistry::register('TemplateManager::display', [$thothBadgeRender, 'addThothBadge']);
$thothNotification = new ThothNotification($this);
HookRegistry::register('TemplateManager::display', [$thothNotification, 'addNotificationScript']);
}
return $success;
}
public function getDisplayName()
{
return __('plugins.generic.thoth.name');
}
public function getDescription()
{
return __('plugins.generic.thoth.description');
}
public function getActions($request, $verb)
{
$parentActions = parent::getActions($request, $verb);
if (!$this->getEnabled()) {
return $parentActions;
}
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
$linkAction = new LinkAction(
'settings',
new AjaxModal(
$router->url(
$request,
null,
null,
'manage',
null,
[
'verb' => 'settings',
'plugin' => $this->getName(),
'category' => 'generic'
]
),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
);
array_unshift($parentActions, $linkAction);
return $parentActions;
}
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
$this->import('ThothSettingsForm');
$form = new ThothSettingsForm($this, $context->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));
}
return parent::manage($args, $request);
}
public function getThothClient($contextId = null)
{
$contextId = $contextId ?? Application::get()->getRequest()->getContext()->getId();
$email = $this->getSetting($contextId, 'email');
$password = $this->getSetting($contextId, 'password');
if (!$email || !$password) {
throw new ThothException('Credentials not configured', 0);
}
$password = APIKeyEncryption::decryptString($password);
$testEnvironment = $this->getSetting($contextId, 'testEnvironment');
import('plugins.generic.thoth.lib.thothAPI.ThothClient');
$thothClient = new ThothClient($testEnvironment);
$thothClient->login($email, $password);
return $thothClient;
}
}