forked from pkp/texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexturePlugin.inc.php
141 lines (125 loc) · 3.52 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
<?php
/**
* @file plugins/generic/texture/SubstancePlugin.inc.php
*
* Copyright (c) 2003-2018 Simon Fraser University
* Copyright (c) 2003-2018 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
*
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class TexturePlugin extends GenericPlugin {
/**
* @copydoc Plugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.texture.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.texture.description');
}
/**
* Register the plugin
*
* @param $category string Plugin category
* @param $path string Plugin path
*
* @return bool True on successful registration false otherwise
*/
function register($category, $path) {
if (parent::register($category, $path)) {
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();
}
/**
* @see PKPPageRouter::route()
*/
public function callbackLoadHandler($hookName, $args) {
$page = $args[0];
$op = $args[1];
switch ("$page/$op") {
case 'texture/editor':
case 'texture/json':
case 'texture/save':
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 $args array Hook parameters
*/
public function templateFetchCallback($hookName, $params) {
$request = $this->getRequest();
$router = $request->getRouter();
$dispatcher = $router->getDispatcher();
$journal = $request->getJournal();
$journalId = $journal->getId();
$templateMgr = $params[0];
$resourceName = $params[1];
if ($resourceName == 'controllers/grid/gridRow.tpl') {
$row = $templateMgr->get_template_vars('row');
$data = $row->getData();
if (is_array($data) && (isset($data['submissionFile']))) {
$submissionFile = $data['submissionFile'];
$fileExtension = strtolower($submissionFile->getExtension());
// get stage ID
$stage = $submissionFile->getFileStage();
$stageId = (int) $request->getUserVar('stageId');
if (strtolower($fileExtension) == 'xml') {
import('lib.pkp.classes.linkAction.request.OpenWindowAction');
$row->addAction(new LinkAction(
'editor',
new OpenWindowAction(
$dispatcher->url($request, ROUTE_PAGE, null, 'texture', 'editor', null,
array(
'submissionId' => $submissionFile->getSubmissionId(),
'fileId' => $submissionFile->getFileId(),
'stageId' => $stageId
)
)
),
__('plugins.generic.texture.links.editWithTexture'),
null
));
}
}
}
}
}