-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCitationManagerPlugin.php
executable file
·230 lines (198 loc) · 9.86 KB
/
CitationManagerPlugin.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
<?php
/**
* @file CitationManagerPlugin.php
*
* @copyright (c) 2021+ TIB Hannover
* @copyright (c) 2021+ Gazi Yücel
* @license Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class CitationManagerPlugin
* @brief Plugin for parsing Citations and submitting to Open Access websites.
*/
// todo: show citation manager tab only if $canAccessPublication && $metadataEnabled
namespace APP\plugins\generic\citationManager;
require_once(__DIR__ . '/vendor/autoload.php');
use APP\plugins\generic\citationManager\classes\DataModels\Citation\AuthorModel;
use APP\plugins\generic\citationManager\classes\DataModels\Metadata\PublicationMetadata;
use APP\plugins\generic\citationManager\classes\Db\PluginSchema;
use APP\plugins\generic\citationManager\classes\FrontEnd\ArticleView;
use APP\plugins\generic\citationManager\classes\Handlers\PluginAPIHandler;
use APP\plugins\generic\citationManager\classes\Helpers\ClassHelper;
use APP\plugins\generic\citationManager\classes\Helpers\LogHelper;
use APP\plugins\generic\citationManager\classes\PID\Doi;
use APP\plugins\generic\citationManager\classes\PID\GitHubIssue;
use APP\plugins\generic\citationManager\classes\PID\OpenAlex;
use APP\plugins\generic\citationManager\classes\PID\Orcid;
use APP\plugins\generic\citationManager\classes\PID\Wikidata;
use APP\plugins\generic\citationManager\classes\Settings\Actions;
use APP\plugins\generic\citationManager\classes\Settings\Manage;
use APP\plugins\generic\citationManager\classes\Workflow\SubmissionWizard;
use APP\plugins\generic\citationManager\classes\Workflow\WorkflowSave;
use APP\plugins\generic\citationManager\classes\Workflow\WorkflowTab;
use Application;
use Config;
use PKP\core\APIRouter;
use PKP\core\JSONMessage;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use Throwable;
define('CITATION_MANAGER_PLUGIN_NAME', basename(__FILE__, '.php'));
class CitationManagerPlugin extends GenericPlugin
{
/** @var string Whether show the structured or the raw citations */
public const CITATION_MANAGER_FRONTEND_SHOW_STRUCTURED = CITATION_MANAGER_PLUGIN_NAME . '_FrontEndShowStructured';
/** @var string Key for the journal metadata saved in journal */
public const CITATION_MANAGER_METADATA_JOURNAL = CITATION_MANAGER_PLUGIN_NAME . '_MetadataJournal';
/** @var string Key for the publication metadata saved in publication */
public const CITATION_MANAGER_METADATA_PUBLICATION = CITATION_MANAGER_PLUGIN_NAME . '_MetadataPublication';
/** @var string Key for the author metadata saved in author */
public const CITATION_MANAGER_METADATA_AUTHOR = CITATION_MANAGER_PLUGIN_NAME . '_MetadataAuthor';
/** @var string Key for structured citations saved in publications */
public const CITATION_MANAGER_CITATIONS_STRUCTURED = CITATION_MANAGER_PLUGIN_NAME . '_CitationsStructured';
/** @var string Key used for the form used in workflow and submission wizard */
public const CITATION_MANAGER_STRUCTURED_CITATIONS_FORM = CITATION_MANAGER_PLUGIN_NAME . '_StructuredCitationsForm';
/** @var string Wikidata username */
public const CITATION_MANAGER_WIKIDATA_USERNAME = CITATION_MANAGER_PLUGIN_NAME . '_Wikidata_Username';
/** @var string Wikidata password */
public const CITATION_MANAGER_WIKIDATA_PASSWORD = CITATION_MANAGER_PLUGIN_NAME . '_Wikidata_Password';
/** @var string GitHub handle / account used for Open Citations */
public const CITATION_MANAGER_OPEN_CITATIONS_OWNER = CITATION_MANAGER_PLUGIN_NAME . '_OpenCitations_Owner';
/** @var string GitHub repository used for Open Citations */
public const CITATION_MANAGER_OPEN_CITATIONS_REPOSITORY = CITATION_MANAGER_PLUGIN_NAME . '_OpenCitations_Repository';
/** @var string GitHub APi token used for Open Citations */
public const CITATION_MANAGER_OPEN_CITATIONS_TOKEN = CITATION_MANAGER_PLUGIN_NAME . '_OpenCitations_Token';
/** @var true Whether debugging mode is activated, careful with exposing secrets! */
public const isDebugMode = true;
/** @var true Whether testing mode. If this is enabled, classes in "tests/classes" are used. */
private bool $isTestMode = true;
/** @var array These are parameters which are used in templates in the front en backend. @see initPlugin() */
public array $templateParameters = [];
/** @copydoc Plugin::register */
public function register($category, $path, $mainContextId = null): bool
{
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled()) {
Hook::add('AcronPlugin::parseCronTab', function ($hookName, $args) {
$taskFilesPath =& $args[0];
$taskFilesPath[] = $this->getPluginPath() . DIRECTORY_SEPARATOR . 'scheduledTasks.xml';
return false;
});
$pluginSchema = new PluginSchema();
Hook::add('Schema::get::publication', function ($hookName, $args) use ($pluginSchema) {
$pluginSchema->addToSchemaPublication($hookName, $args);
});
Hook::add('Schema::get::author', function ($hookName, $args) use ($pluginSchema) {
$pluginSchema->addToSchemaAuthor($hookName, $args);
});
$this->initPlugin($category, $path, $mainContextId);
$submissionWizard = new SubmissionWizard($this);
Hook::add('Template::SubmissionWizard::Section', function ($hookName, $args) use ($submissionWizard) {
$submissionWizard->execute($hookName, $args);
});
$workflowTab = new WorkflowTab($this);
Hook::add('Template::Workflow', function ($hookName, $args) use ($workflowTab) {
$workflowTab->execute($hookName, $args);
});
$workflowSave = new WorkflowSave($this);
Hook::add('Publication::edit', function ($hookName, $args) use ($workflowSave) {
$workflowSave->execute($hookName, $args);
});
$articlePage = new ArticleView($this);
Hook::add('TemplateManager::display', function ($hookName, $args) use ($articlePage) {
$articlePage->execute($hookName, $args);
});
Hook::add('Dispatcher::dispatch', function ($hookName, $args) {
try {
$request = $args[0];
$router = $request->getRouter();
if ($router instanceof APIRouter
&& str_contains($request->getRequestPath(), 'api/v1/' . CITATION_MANAGER_PLUGIN_NAME)
) {
$handler = new PluginAPIHandler($this);
$router->setHandler($handler);
$handler->getApp()->run();
exit;
}
} catch (Throwable $ex) {
error_log(__METHOD__ . ' ' . $ex->getMessage());
}
return false;
});
}
return true;
}
return false;
}
/**
* Initializes this plugin
*
* @param $category
* @param $path
* @param $mainContextId
* @return void
*/
public function initPlugin($category, $path, $mainContextId = null): void
{
$request = $this->getRequest();
$context = $request->getContext();
$isTestMode = strtolower(Config::getVar(CITATION_MANAGER_PLUGIN_NAME, 'isTestMode'));
if (!empty($isTestMode) && ($isTestMode === 'true' || $isTestMode === '1'))
$this->isTestMode = true;
$apiBaseUrl = '';
if (!empty($context) && !empty($context->getData('urlPath'))) {
$apiBaseUrl = $request->getDispatcher()->url(
$request,
Application::ROUTE_API,
$context->getData('urlPath'),
'');
}
$this->templateParameters = [
'locale' => '',
'assetsUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath() . '/assets',
'apiBaseUrl' => $apiBaseUrl,
'journalMetadata' => '',
'authors' => '',
'authorModel' => json_encode(ClassHelper::getClassAsArrayNullAssigned(new AuthorModel())),
'publicationMetadata' => json_encode(ClassHelper::getClassAsArrayNullAssigned(new PublicationMetadata())),
'structuredCitations' => '',
'url' => [
'doi' => Doi::prefix,
'openAlex' => OpenAlex::prefix,
'openCitations' => GitHubIssue::prefix,
'orcid' => Orcid::prefix,
'wikidata' => Wikidata::prefix
]
];
}
/** @copydoc Plugin::getActions() */
public function getActions($request, $actionArgs): array
{
if (!$this->getEnabled()) return parent::getActions($request, $actionArgs);
$actions = new Actions($this);
return $actions->execute($request, $actionArgs, parent::getActions($request, $actionArgs));
}
/** @copydoc Plugin::manage() */
public function manage($args, $request): JSONMessage
{
$manage = new Manage($this);
return $manage->execute($args, $request);
}
/** @copydoc PKPPlugin::getDescription */
public function getDescription(): string
{
return __('plugins.generic.citationManager.description');
}
/** @copydoc PKPPlugin::getDisplayName */
public function getDisplayName(): string
{
return __('plugins.generic.citationManager.displayName');
}
public function getIsTestMode(): bool
{
return $this->isTestMode;
}
}
// For backwards compatibility -- expect this to be removed approx. OJS/OMP/OPS 3.6
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\citationManager\CitationManagerPlugin', '\CitationManagerPlugin');
}