-
Notifications
You must be signed in to change notification settings - Fork 19
/
TexturePlugin.inc.php
272 lines (237 loc) · 7.76 KB
/
TexturePlugin.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
<?php
/**
* @file plugins/generic/texture/TexturePlugin.inc.php
*
* Copyright (c) 2003-2019 Simon Fraser University
* Copyright (c) 2003-2019 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class SubstancePlugin
* @ingroup plugins_generic_texture
*
* @brief Substance JATS editor plugin
*
*/
use PKP\linkAction\LinkAction;
use PKP\plugins\GenericPlugin;
use PKP\linkAction\request\OpenWindowAction;
use PKP\linkAction\request\PostAndRedirectAction;
define('DAR_MANIFEST_FILE', 'manifest.xml');
define('DAR_MANUSCRIPT_FILE', 'manuscript.xml');
define('TEXTURE_DAR_FILE_TYPE', 'dar');
define('TEXTURE_ZIP_FILE_TYPE', 'zip');
define('TEXTURE_HTML_FILE_TYPE', 'html');
/**
* Class TexturePlugin
*/
class TexturePlugin extends GenericPlugin {
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.texture.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.texture.description');
}
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled()) {
// Register callbacks.
HookRegistry::register('LoadHandler', array($this, 'callbackLoadHandler'));
HookRegistry::register('TemplateManager::fetch', array($this, 'templateFetchCallback'));
$this->_registerTemplateResource();
}
return true;
}
return false;
}
/**
* Get texture editor URL
* @param $request PKPRequest
* @return string
*/
function getTextureUrl($request) {
return $this->getPluginUrl($request) . '/texture';
}
/**
* Get plugin URL
* @param $request PKPRequest
* @return string
*/
function getPluginUrl($request) {
return $request->getBaseUrl() . '/' . $this->getPluginPath();
}
/**
* @param $hookName string The name of the invoked hook
* @param $args
* @return bool
* @see PKPPageRouter::route()
*/
public function callbackLoadHandler($hookName, $args) {
$page = $args[0];
$op = $args[1];
switch ("$page/$op") {
case 'texture/createGalley':
case 'texture/editor':
case 'texture/export':
case 'texture/extract':
case 'texture/json':
case 'texture/save':
case 'texture/createGalleyForm':
case 'texture/media':
define('HANDLER_CLASS', 'TextureHandler');
define('TEXTURE_PLUGIN_NAME', $this->getName());
$args[2] = $this->getPluginPath() . '/' . 'TextureHandler.inc.php';
break;
}
return false;
}
/**
* Adds additional links to submission files grid row
* @param $hookName string The name of the invoked hook
* @param $params array Hook parameters
*/
public function templateFetchCallback($hookName, $params) {
$request = $this->getRequest();
$router = $request->getRouter();
$dispatcher = $router->getDispatcher();
$templateMgr = $params[0];
$resourceName = $params[1];
if ($resourceName == 'controllers/grid/gridRow.tpl') {
$row = $templateMgr->getTemplateVars('row');
$data = $row->getData();
if (is_array($data) && (isset($data['submissionFile']))) {
$submissionFile = $data['submissionFile'];
$fileExtension = strtolower($submissionFile->getData('mimetype'));
// get stage ID
$stageId = (int)$request->getUserVar('stageId');
$fileStage = SUBMISSION_FILE_PRODUCTION_READY;
if (strtolower($fileExtension) == 'text/xml') {
$this->_editWithTextureAction($row, $dispatcher, $request, $submissionFile, $stageId);
//$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
//$this->_exportAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
} elseif (strtolower($fileExtension) == TEXTURE_DAR_FILE_TYPE) {
$this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_DAR_FILE_TYPE);
} elseif (strtolower($fileExtension) == TEXTURE_ZIP_FILE_TYPE) {
$this->_extractAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage, TEXTURE_ZIP_FILE_TYPE);
} elseif (strtolower($fileExtension) == TEXTURE_HTML_FILE_TYPE) {
$this->_createGalleyAction($row, $dispatcher, $request, $submissionFile, $stageId, $fileStage);
}
}
}
}
/**
* exports a dar archive
* @param $row SubmissionFilesGridRow
* @param Dispatcher $dispatcher
* @param PKPRequest $request
* @param $submissionFile SubmissionFile
* @param int $stageId
* @param int $fileStage
*/
private function _exportAction($row, Dispatcher $dispatcher, PKPRequest $request, $submissionFile, int $stageId, int $fileStage): void {
$row->addAction(new LinkAction(
'texture_export',
new OpenWindowAction(
$dispatcher->url($request, ROUTE_PAGE, null, 'texture', 'export', null,
array(
'submissionId' => $submissionFile->getData('submissionId'),
'submissionFileId' => $submissionFile->getData('id'),
'stageId' => $stageId
)
)
),
__('plugins.generic.texture.links.exportDarArchive'),
null
));
}
/**
* extracts a dar archive
* @param $row SubmissionFilesGridRow
* @param Dispatcher $dispatcher
* @param PKPRequest $request
* @param $submissionFile SubmissionFile
* @param int $stageId
* @param int $fileStage
* @param $zipType
*/
private function _extractAction($row, Dispatcher $dispatcher, PKPRequest $request, $submissionFile, int $stageId, int $fileStage, $zipType): void {
$stageId = (int)$request->getUserVar('stageId');
$zipLabel = ($zipType == TEXTURE_DAR_FILE_TYPE) ? 'plugins.generic.texture.links.extractDarArchive' : 'plugins.generic.texture.links.extractZipArchive';
$actionArgs = array(
'submissionId' => $submissionFile->getData('submissionId'),
'submissionFileId' => $submissionFile->getData('id'),
'stageId' => $stageId,
'zipType' => $zipType
);
$path = $dispatcher->url($request, ROUTE_PAGE, null, 'texture', 'extract', null, $actionArgs);
$pathRedirect = $dispatcher->url($request, ROUTE_PAGE, null, 'workflow', 'access', $actionArgs);
$row->addAction(new LinkAction(
'texture_import',
new PostAndRedirectAction($path, $pathRedirect),
__($zipLabel),
null
));
}
/**
* Adds edit with Texture action to files grid
* @param $row SubmissionFilesGridRow
* @param Dispatcher $dispatcher
* @param PKPRequest $request
* @param $submissionFile SubmissionFile
* @param int $stageId
*/
private function _editWithTextureAction($row, Dispatcher $dispatcher, PKPRequest $request, $submissionFile, int $stageId): void {
$row->addAction(new LinkAction(
'texture_editor',
new OpenWindowAction(
$dispatcher->url($request, ROUTE_PAGE, null, 'texture', 'editor', null,
array(
'submissionId' => $submissionFile->getData('submissionId'),
'submissionFileId' => $submissionFile->getData('id'),
'stageId' => $stageId
)
)
),
__('plugins.generic.texture.links.editWithTexture'),
null
));
}
/**
* Adds create galley action to files grid
* @param $row SubmissionFilesGridRow
* @param Dispatcher $dispatcher
* @param PKPRequest $request
* @param $submissionFile SubmissionFile
* @param int $stageId
*/
private function _createGalleyAction($row, Dispatcher $dispatcher, PKPRequest $request, $submissionFile, int $stageId, int $fileStage): void {
$actionArgs = array(
'submissionId' => $submissionFile->getData('submissionId'),
'stageId' => $stageId,
'fileStage' => $fileStage,
'submissionFileId' => $submissionFile->getData('id')
);
$row->addAction(new LinkAction(
'createGalleyForm',
new AjaxModal(
$dispatcher->url(
$request, ROUTE_PAGE, null,
'texture',
'createGalleyForm', null,
$actionArgs
),
__('submission.layout.newGalley')
),
__('plugins.generic.texture.links.createGalley'),
null
));
}
}