-
Notifications
You must be signed in to change notification settings - Fork 8
/
SettingsForm.inc.php
223 lines (182 loc) · 8.2 KB
/
SettingsForm.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
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
<?php
/**
* @file plugins/generic/markup/SettingsForm.inc.php
*
* Copyright (c) 2003-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class SettingsForm
* @ingroup plugins_generic_markup
*
* @brief Form for Document Markup gateway plugin settings
*/
import('lib.pkp.classes.form.Form');
define('MARKUP_CSL_STYLE_DEFAULT', 'chicago-author-date.csl');
define('MARKUP_CSL_STYLE_NAME_DEFAULT', 'Chicago Manual of Style (author-date)');
define('MARKUP_DOCUMENT_SERVER_URL_DEFAULT', 'http://pkp-udev.lib.sfu.ca/');
class SettingsForm extends Form {
/** @var $journalId int */
var $journalId;
/** @var $plugin object */
var $plugin;
/** @var $settings array */
var $settings;
/**
* Constructor
* @param $plugin object
* @param $journalId int
*/
function SettingsForm(&$plugin, $journalId) {
$this->journalId = $journalId;
$this->plugin =& $plugin;
$journal =& Request::getJournal();
parent::Form($plugin->getTemplatePath() . 'settingsForm.tpl');
// Validation checks for this form
$this->settings = array(
'cslStyle' => 'string',
'cslStyleName' => 'string',
'cssHeaderImageName' => 'string',
'reviewVersion' => 'bool',
'markupHostUser' => 'string',
'markupHostPass' => 'string',
'markupHostURL' => 'string'
);
}
/**
* Validate the form
*/
function validate() {
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidator($this, 'cslStyle', 'required', 'plugins.generic.markup.required.cslStyle'));
$this->addCheck(new FormValidator($this, 'cslStyleName', 'optional', 'plugins.generic.markup.optional.cslStyleName'));
$this->addCheck(new FormValidator($this, 'reviewVersion', 'optional', 'plugins.generic.markup.optional.reviewVersion'));
$this->addCheck(new FormValidator($this, 'markupHostUser', 'optional', 'plugins.generic.markup.optional.markupHostUrl'));
$this->addCheck(new FormValidator($this, 'markupHostPass', 'optional', 'plugins.generic.markup.optional.markupHostPass'));
$this->addCheck(new FormValidator($this, 'markupHostURL', 'required', 'plugins.generic.markup.required.markupHostURL'));
$this->addCheck(new FormValidatorCustom($this, 'cssHeaderImageName', 'optional', 'plugins.generic.markup.error', $this->_validateImage('cssHeaderImage'),true));
// Fall back on parent validation
return parent::validate();
}
/**
* Ensure attached header image is a .jpg or .png
*
* @param $imageName string form upload fieldname
*/
function _validateImage($imageName) {
if (isset($_FILES[$imageName])) {
$journal =& Request::getJournal();
import('classes.file.JournalFileManager');
$journalFileManager = new JournalFileManager($journal);
if ($journalFileManager->uploadedFileExists($imageName)) {
$type = $journalFileManager->getUploadedFileType($imageName);
$ext = $journalFileManager->getImageExtension($type);
if (!$ext || ($ext != ".png" && $ext != ".jpg")) {
$this->addError('coverPage', __('plugins.generic.markup.optional.cssHeaderImage'));
return false;
}
}
}
return true;
}
/**
* Initialize plugin settings form data.
*
* @var cslStyle string holds the file name (including .csl suffix) of the selected csl style
* @var cslStyleName string holds the plain english name of the above style (automatically generated by ajax driven menu
* @var cssHeaderImageName string holds name of banner image to appear at top of html and pdf articles.
* @var reviewVersion boolean indicates if a reviewer version of article (without author info) should be made
* @var markupHostUser string (optional)
* @var markupHostPass string (optional)
* @var markupHostURL string holds URL of document markup server (e.g. http://pkp-udev.lib.sfu.ca/ )
*/
function initData() {
$journal =& Request::getJournal();
$journalId = $this->journalId;
$plugin =& $this->plugin;
// User must at least load settings page for plugin to work with defaults.
if ($plugin->getSetting($journalId, 'cslStyle') == '') {
$plugin->updateSetting($journalId, 'cslStyle', MARKUP_CSL_STYLE_DEFAULT);
$plugin->updateSetting($journalId, 'cslStyleName', MARKUP_CSL_STYLE_NAME_DEFAULT);
}
if ($plugin->getSetting($journalId, 'markupHostURL') == '') {
$plugin->updateSetting($journalId, 'markupHostURL', MARKUP_DOCUMENT_SERVER_URL_DEFAULT);
}
$this->setData('cslStyle', $plugin->getSetting($journalId, 'cslStyle'));
$this->setData('cslStyleName', $plugin->getSetting($journalId, 'cslStyleName'));
// This field has content only if header image actually exists in the right folder.
import('classes.file.JournalFileManager');
$journalFileManager = new JournalFileManager($journal);
$folderCssImage = glob($journalFileManager->filesDir . 'css/article_header.{jpg,png}',GLOB_BRACE);
if (count($folderCssImage)) {
$this->setData('cssHeaderImageName', basename($folderCssImage[0]));
}
$this->setData('markupHostUser', $plugin->getSetting($journalId, 'markupHostUser'));
// Security note: Not sending markupHostPass to browser.
$this->setData('reviewVersion', $plugin->getSetting($journalId, 'reviewVersion'));
//User assigned but should never change (view only).
$this->setData('markupHostURL', $plugin->getSetting($journalId, 'markupHostURL'));
}
/**
* Populate and display settings form.
*
* @var curlSupport indicates whether or not php curl has been installed
* @var zipSupport indicates whether or not zip library has been installed
* @var php5Support indicates server running php 5.0+
*/
function display() {
$templateMgr =& TemplateManager::getManager();
// Signals indicating plugin compatibility
$templateMgr->assign('curlSupport', function_exists('curl_init') ? __('plugins.generic.markup.installed') : __('plugins.generic.markup.not_installed'));
$templateMgr->assign('zipSupport', extension_loaded('zlib') ? __('plugins.generic.markup.installed') : __('plugins.generic.markup.not_installed') );
$templateMgr->assign('php5Support', checkPhpVersion('5.0.0') ? __('plugins.generic.markup.installed') : __('plugins.generic.markup.not_installed') );
$templateMgr->assign('pathInfo', Request::isPathInfoEnabled() ? __('plugins.generic.markup.enabled') : __('plugins.generic.markup.disabled') );
parent::display();
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$this->readUserVars(array('cslStyle','cslStyleName','markupHostURL','markupHostUser','markupHostPass','reviewVersion','cssHeaderImage'));
}
/**
* Save settings.
*/
function execute() {
$plugin =& $this->plugin;
$journalId = $this->journalId;
$plugin->updateSetting($journalId, 'cslStyle', $this->getData('cslStyle'));
$plugin->updateSetting($journalId, 'cslStyleName', $this->getData('cslStyleName'));
// Ensure document server url has http:// ... / in it.
$markupHostURL = $this->getData('markupHostURL');
if (strlen($markupHostURL) > 0) {
if (substr($markupHostURL,0,4) != "http") $markupHostURL = "http://" . $markupHostURL;
if (substr($markupHostURL,-1) != '/') $markupHostURL .= '/';
}
$plugin->updateSetting($journalId, 'markupHostURL', $markupHostURL);
$markupHostUser = $this->getData('markupHostUser');
$plugin->updateSetting($journalId, 'markupHostUser', $markupHostUser);
if (strlen($markupHostUser) > 0) {
$markupHostPass = $this->getData('markupHostPass');
// Only update password if account exists and password exists.
if (strlen($markupHostPass) > 0) {
$plugin->updateSetting($journalId, 'markupHostPass', $markupHostPass);
}
}
else {
$plugin->updateSetting($journalId, 'markupHostPass','');
}
$plugin->updateSetting($journalId, 'reviewVersion', $this->getData('reviewVersion'));
// Upload article header image if given. Image suffix already validated above.
if (isset($_FILES['cssHeaderImage'])) {
import('classes.file.JournalFileManager');
$journal =& Request::getJournal();
$journalFileManager = new JournalFileManager($journal);
if ($journalFileManager->uploadedFileExists('cssHeaderImage') ) {
$type = $journalFileManager->getUploadedFileType('cssHeaderImage');
$ext = $journalFileManager->getImageExtension($type);
$journalFileManager->uploadFile('cssHeaderImage', '/css/article_header'.$ext);
}
}
}
}
?>