-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHealthCheckPlugin.php
186 lines (163 loc) · 5.38 KB
/
HealthCheckPlugin.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
<?php
/**
* @file HealthCheckPlugin.php
*
* Copyright (c) 2017-2023 Simon Fraser University
* Copyright (c) 2017-2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class HealthCheckPlugin
* @brief Plugin class for the HealthCheck plugin.
*/
namespace APP\plugins\generic\healthCheck;
use APP\core\Application;
use APP\core\Request;
use PKP\core\JSONMessage;
use PKP\core\PKPString;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class HealthCheckPlugin extends GenericPlugin
{
/**
* @copydoc GenericPlugin::register()
*/
public function register($category, $path, $mainContextId = NULL)
{
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
// Display the publication statement on the article details page
Hook::add('Templates::Article::Main', [$this, 'addPublicationStatement']);
}
return $success;
}
/**
* Provide a name for this plugin
*
* The name will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*
* @return string
*/
public function getDisplayName()
{
return __('plugins.generic.healthCheck.displayName');
}
/**
* Provide a description for this plugin
*
* The description will appear in the Plugin Gallery where editors can
* install, enable and disable plugins.
*
* @return string
*/
public function getDescription()
{
return __('plugins.generic.healthCheck.description');
}
/**
* Add a settings action to the plugin's entry in the
* plugins list.
*
* @param Request $request
* @param array $actionArgs
* @return array
*/
public function getActions($request, $actionArgs)
{
// Get the existing actions
$actions = parent::getActions($request, $actionArgs);
// Only add the settings action when the plugin is enabled
if (!$this->getEnabled()) {
return $actions;
}
// Create a LinkAction that will make a request to the
// plugin's `manage` method with the `settings` verb.
$router = $request->getRouter();
$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
);
// Add the LinkAction to the existing actions.
// Make it the first action to be consistent with
// other plugins.
array_unshift($actions, $linkAction);
return $actions;
}
/**
* Load a form when the `settings` button is clicked and
* save the form when the user saves it.
*
* @param array $args
* @param Request $request
* @return JSONMessage
*/
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
// Load the custom form
$form = new HealthCheckSettingsForm($this);
// Fetch the form the first time it loads, before
// the user has tried to save it
if (!$request->getUserVar('save')) {
$form->initData();
return new JSONMessage(true, $form->fetch($request));
}
// Validate and save the form data
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
}
return parent::manage($args, $request);
}
/**
* Add the publication statement to the article details page.
*
* @param string $hookName string
* @param array $params [[
* @option array Additional parameters passed with the hook
* @option TemplateManager
* @option string The HTML output
* ]]
* @return boolean
*/
public function addPublicationStatement($hookName, $params)
{
// Get the publication statement for this journal or press
$context = Application::get()->getRequest()->getContext();
$contextId = $context ? $context->getId() : Application::CONTEXT_SITE;
$publicationStatement = $this->getSetting($contextId, 'publicationStatement');
// Do not modify the output if there is no publication statement
if (!$publicationStatement) {
return false;
}
// Add the publication statement to the output
$output = &$params[2];
$output .= '<p class="publication-statement">' . PKPString::stripUnsafeHtml($publicationStatement) . '</p>';
return false;
}
}
// For backwards compatibility -- expect this to be removed approx. OJS/OMP/OPS 3.6
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\healthCheck\HealthCheckPlugin', '\HealthCheckPlugin');
}