-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathTexturePlugin.php
More file actions
executable file
·121 lines (105 loc) · 2.9 KB
/
Copy pathTexturePlugin.php
File metadata and controls
executable file
·121 lines (105 loc) · 2.9 KB
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
<?php
/**
* @file plugins/generic/texture/TexturePlugin.php
*
* Copyright (c) 2003-2025 Simon Fraser University
* Copyright (c) 2003-2025 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class TexturePlugin
*
* @ingroup plugins_generic_texture
*
* @brief Texture editor plugin
*/
namespace APP\plugins\generic\texture;
use APP\core\Application;
use APP\core\Request;
use APP\plugins\generic\texture\classes\handlers\TextureHandler;
use APP\template\TemplateManager;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\security\Role;
class TexturePlugin extends GenericPlugin
{
public const PLUGIN_URL = 'texture';
public const DAR_MANIFEST_FILE = 'manifest.xml';
public const DAR_MANUSCRIPT_FILE = 'manuscript.xml';
public const FILE_TYPE_DAR = 'dar';
public const FILE_TYPE_ZIP = 'zip';
public const FILE_TYPE_HTML = 'html';
public const AUTHORIZED_ROLES = [
Role::ROLE_ID_MANAGER,
Role::ROLE_ID_SUB_EDITOR,
Role::ROLE_ID_ASSISTANT,
Role::ROLE_ID_REVIEWER,
Role::ROLE_ID_AUTHOR
];
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null): bool
{
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled()) {
Hook::add('LoadHandler', $this->setPageHandler(...));
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$userRoleIds = array_map(fn($role) => $role->getId(),
$request->getUser()?->getRoles($request->getContext()?->getId()) ?? []);
if (!empty($userRoleIds) && !empty(array_intersect($userRoleIds, TexturePlugin::AUTHORIZED_ROLES))) {
$this->addResources($templateMgr, $request);
}
}
return true;
}
return false;
}
/**
* Callback load handler.
* @see PKPPageRouter::route()
*/
public function setPageHandler($hookName, $args): bool
{
$page =& $args[0];
$handler =& $args[3];
if ($this->getEnabled() && $page === self::PLUGIN_URL) {
$handler = new TextureHandler($this);
return true;
}
return false;
}
/**
* Add resources
*/
public function addResources(TemplateManager $templateMgr, Request $request): void
{
$templateMgr->addJavaScript(
'TexturePluginJs',
"{$request->getBaseUrl()}/{$this->getPluginPath()}/public/build/build.iife.js",
[
'inline' => false,
'contexts' => ['backend'],
'priority' => TemplateManager::STYLE_SEQUENCE_LAST
]
);
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName(): string
{
return __('plugins.generic.texture.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription(): string
{
return __('plugins.generic.texture.description');
}
}
// For backwards compatibility -- expect this to be removed approx. OJS/OMP/OPS 3.6
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\texture\TexturePlugin', '\TexturePlugin');
}