-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebsiteSettingsTabHandler.inc.php
More file actions
228 lines (200 loc) · 6.13 KB
/
WebsiteSettingsTabHandler.inc.php
File metadata and controls
228 lines (200 loc) · 6.13 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
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
<?php
/**
* @file controllers/tab/settings/WebsiteSettingsTabHandler.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 WebsiteSettingsTabHandler
* @ingroup controllers_tab_settings
*
* @brief Handle AJAX operations for tabs on Website settings page.
*/
// Import the base Handler.
import('lib.pkp.controllers.tab.settings.ManagerSettingsTabHandler');
class WebsiteSettingsTabHandler extends ManagerSettingsTabHandler {
/**
* Constructor
*/
function __construct() {
$this->addRoleAssignment(ROLE_ID_MANAGER,
array(
'showFileUploadForm',
'uploadFile',
'saveFile',
'deleteFile',
'fetchFile',
'reloadLocalizedDefaultSettings'
)
);
parent::__construct();
$this->setPageTabs(array(
'appearance' => 'controllers.tab.settings.appearance.form.AppearanceForm',
'information' => 'lib.pkp.controllers.tab.settings.information.form.InformationForm',
'archiving' => 'lib.pkp.controllers.tab.settings.archiving.form.ArchivingForm',
'languages' => 'controllers/tab/settings/languages/languages.tpl',
'plugins' => 'controllers/tab/settings/plugins/plugins.tpl',
'announcements' => 'lib.pkp.controllers.tab.settings.announcements.form.AnnouncementSettingsForm',
'navigationMenus' => 'lib.pkp.controllers.tab.settings.navigationMenus.form.NavigationMenuSettingsForm'
));
}
/**
* @copydoc SettingsTabHandler::showTab()
*/
function showTab($args, $request) {
$workingContexts = $this->getWorkingContexts($request);
if ($workingContexts && $workingContexts->getCount() > 1) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('multipleContexts', true);
}
return parent::showTab($args, $request);
}
//
// Public methods.
//
/**
* Show the upload image form.
* @param $request Request
* @param $args array
* @return JSONMessage JSON object
*/
function showFileUploadForm($args, $request) {
$fileUploadForm = $this->_getFileUploadForm($request);
$fileUploadForm->initData($request);
return new JSONMessage(true, $fileUploadForm->fetch($request));
}
/**
* Upload a new file.
* @param $args array
* @param $request PKPRequest
* @return JSONMessage JSON object
*/
function uploadFile($args, $request) {
$fileUploadForm = $this->_getFileUploadForm($request);
$temporaryFileId = $fileUploadForm->uploadFile($request);
if ($temporaryFileId !== false) {
$json = new JSONMessage();
$json->setAdditionalAttributes(array(
'temporaryFileId' => $temporaryFileId
));
return $json;
} else {
return new JSONMessage(false, __('common.uploadFailed'));
}
}
/**
* Save an uploaded file.
* @param $args array
* @param $request PKPRequest
* @return JSONMessage JSON object
*/
function saveFile($args, $request) {
$fileUploadForm = $this->_getFileUploadForm($request);
$fileUploadForm->readInputData();
if ($fileUploadForm->validate()) {
if ($fileUploadForm->execute($request)) {
// Generate a JSON message with an event
$settingName = $request->getUserVar('fileSettingName');
return DAO::getDataChangedEvent($settingName);
}
}
return new JSONMessage(false, __('common.invalidFileType'));
}
/**
* Deletes a journal image.
* @param $args array
* @param $request PKPRequest
* @return string
*/
function deleteFile($args, $request) {
$settingName = $request->getUserVar('fileSettingName');
$tabForm = $this->getTabForm();
$tabForm->initData($request);
if ($request->checkCSRF() && $tabForm->deleteFile($settingName, $request)) {
return DAO::getDataChangedEvent($settingName);
} else {
return new JSONMessage(false);
}
}
/**
* Fetch a file that has been uploaded.
*
* @param $args array
* @param $request Request
* @return JSONMessage JSON object
*/
function fetchFile($args, $request) {
// Get the setting name.
$settingName = $args['settingName'];
// Try to fetch the file.
$tabForm = $this->getTabForm();
$tabForm->initData($request);
$renderedElement = $tabForm->renderFileView($settingName, $request);
$json = new JSONMessage();
if ($renderedElement == false) {
$json->setAdditionalAttributes(array('noData' => $settingName));
} else {
$json->setElementId($settingName);
$json->setContent($renderedElement);
}
return $json;
}
/**
* Reload the default localized settings for the journal
* @param $args array
* @param $request object
* @return JSONMessage JSON object
*/
function reloadLocalizedDefaultSettings($args, $request) {
// make sure the locale is valid
$locale = $request->getUserVar('localeToLoad');
if ( !AppLocale::isLocaleValid($locale) ) {
return new JSONMessage(false);
}
$journal = $request->getJournal();
$journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
$journalSettingsDao->reloadLocalizedDefaultSettings(
$journal->getId(), 'registry/journalSettings.xml',
array(
'indexUrl' => $request->getIndexUrl(),
'journalPath' => $journal->getData('path'),
'primaryLocale' => $journal->getPrimaryLocale(),
'journalName' => $journal->getName($journal->getPrimaryLocale())
),
$locale
);
// also reload the user group localizable data
$userGroupDao = DAORegistry::getDAO('UserGroupDAO');
$userGroupDao->installLocale($locale, $journal->getId());
return DAO::getDataChangedEvent();
}
//
// Private helper methods.
//
/**
* Returns a file upload form.
* @param $request Request
* @return Form
*/
function _getFileUploadForm($request) {
$settingName = $request->getUserVar('fileSettingName');
$fileType = $request->getUserVar('fileType');
switch ($fileType) {
case 'image':
import('lib.pkp.controllers.tab.settings.appearance.form.NewContextImageFileForm');
$fileUploadForm = new NewContextImageFileForm($settingName);
break;
case 'css':
import('lib.pkp.controllers.tab.settings.appearance.form.NewContextCssFileForm');
$fileUploadForm = new NewContextCssFileForm($settingName);
break;
default:
$fileUploadForm = null; // Suppress scrutinizer
assert(false);
break;
}
return $fileUploadForm;
}
}
?>