forked from ojsde/shariff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShariffPlugin.inc.php
195 lines (171 loc) · 5.54 KB
/
ShariffPlugin.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
<?php
/**
* @file plugins/generic/shariff/ShariffPlugin.inc.php
*
* Copyright (c) 2014-2017 Simon Fraser University
* Copyright (c) 2003-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class ShariffPlugin
* @ingroup plugins_block_shariff
*
* @brief Shariff plugin class
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class ShariffPlugin extends GenericPlugin {
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName() {
return __('plugins.generic.shariff.displayName');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.generic.shariff.description');
}
function register($category, $path) {
if (parent::register($category, $path)) {
if ($this->getEnabled()) {
$context = Request::getContext();
$contextId = $context->getId();
// display the buttons depending in the selected position
switch($this->getSetting($contextId, 'selectedPosition')){
case 'footer':
HookRegistry::register('Templates::Common::Footer::PageFooter', array($this, 'addShariffButtons'));
break;
case 'sidebar':
HookRegistry::register('PluginRegistry::loadCategory', array($this, 'callbackLoadCategory'));
break;
case 'submission':
HookRegistry::register('Templates::Article::Footer::PageFooter', array($this, 'addShariffButtons'));
HookRegistry::register('Templates::Catalog::Book::Details', array($this, 'addShariffButtons'));
}
}
return true;
}
return false;
}
/**
* Get the name of the settings file to be installed on new context
* creation.
* @return string
*/
function getContextSpecificPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
/**
* @copydoc PKPPlugin::getTemplatePath
*/
function getTemplatePath($inCore = false) {
return parent::getTemplatePath($inCore) . 'templates/';
}
/**
* Register as a block plugin, even though this is a generic plugin.
* This will allow the plugin to behave as a block plugin, i.e. to
* have layout tasks performed on it.
* @param $hookName string
* @param $args array
*/
function callbackLoadCategory($hookName, $args) {
$category =& $args[0];
$plugins =& $args[1];
switch ($category) {
case 'blocks':
$this->import('ShariffBlockPlugin');
$blockPlugin = new ShariffBlockPlugin($this->getName());
$plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath()] = $blockPlugin;
break;
}
return false;
}
/**
* Hook callback: Handle requests.
* @param $hookName string The name of the hook being invoked
* @param $args array The parameters to the invoked hook
*/
function addShariffButtons($hookName, $args) {
$template =& $args[1];
$output =& $args[2];
$request = $this->getRequest();
$context = $request->getContext();
$contextId = $context->getId();
// services
$selectedServices = $this->getSetting($contextId, 'selectedServices');
$preparedServices = array_map(create_function('$arrayElement', 'return \'"\'.$arrayElement.\'"\';'), $selectedServices);
$dataServicesString = implode(",", $preparedServices);
// theme
$selectedTheme = $this->getSetting($contextId, 'selectedTheme');
// orientation
$selectedOrientation = $this->getSetting($contextId, 'selectedOrientation');
// get language from system
$locale = AppLocale::getLocale();
$iso1Lang = AppLocale::getIso1FromLocale($locale);
// javascript, css and backend url
$requestedUrl = Request::getCompleteUrl();
$baseUrl = Request::getBaseUrl();
$jsUrl = $baseUrl .'/'. $this->getPluginPath().'/shariff.complete.js';
$cssUrl = $baseUrl .'/' . $this->getPluginPath() . '/' . 'shariff.complete.css';
$backendUrl = $baseUrl .'/'. 'shariff-backend';
$output .= '
<link rel="stylesheet" type="text/css" href="'.$cssUrl.'">
<div class="shariff pkp_footer_content" data-lang="'. $iso1Lang.'"
data-services="['.$dataServicesString.']"
data-backend-url="'.$backendUrl.'"
data-theme="'.$selectedTheme.'"
data-orientation="'.$selectedOrientation.'"
data-url="'. $requestedUrl .'">
</div>
<script src="'.$jsUrl.'"></script>';
return false;
}
/**
* @see Plugin::getActions()
*/
function getActions($request, $verb) {
$router = $request->getRouter();
import('lib.pkp.classes.linkAction.request.AjaxModal');
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'settings',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array('verb' => 'settings', 'plugin' => $this->getName(), 'category' => 'generic')),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
),
):array(),
parent::getActions($request, $verb)
);
}
/**
* @see Plugin::manage()
*/
function manage($args, $request) {
switch ($request->getUserVar('verb')) {
case 'settings':
AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_PKP_MANAGER);
$this->import('ShariffSettingsForm');
$form = new ShariffSettingsForm($this, $request->getContext()->getId());
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute();
$notificationManager = new NotificationManager();
$notificationManager->createTrivialNotification($request->getUser()->getId());
return new JSONMessage(true);
}
} else {
$form->initData();
}
return new JSONMessage(true, $form->fetch($request));
}
return parent::manage($args, $request);
}
}
?>