This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
forked from ddooley/ojs-markup
-
Notifications
You must be signed in to change notification settings - Fork 5
/
SettingsForm.inc.php
175 lines (150 loc) · 5.82 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
<?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', '674e1c66aa817a0713a410915ac1b298');
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 mixed Plugin object
* @param $journalId int JournalId
*/
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',
'markupHostPass' => 'string',
'markupHostURL' => 'string',
'markupHostUser' => 'string',
'overrideGalley' => 'bool',
'wantedFormats' => 'object',
);
}
/**
* Validate the form
*
* @return bool Whether or not the form validated
*/
function validate() {
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidator($this, 'cslStyle', 'required', 'plugins.generic.markup.required.cslStyle'));
$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 FormValidator($this, 'markupHostUser', 'optional', 'plugins.generic.markup.optional.markupHostUrl'));
$this->addCheck(new FormValidator($this, 'overrideGalley', 'required', 'plugins.generic.markup.required.overrideGalley'));
$this->addCheck(new FormValidator($this, 'wantedFormats', 'required', 'plugins.generic.markup.required.wantedFormats'));
return parent::validate();
}
/**
* Initialize plugin settings form
*
* @return void
*/
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);
}
if ($plugin->getSetting($journalId, 'markupHostURL') == '') {
$plugin->updateSetting($journalId, 'markupHostURL', MARKUP_DOCUMENT_SERVER_URL_DEFAULT);
}
$this->setData('cslStyle', $plugin->getSetting($journalId, 'cslStyle'));
$this->setData('markupHostUser', $plugin->getSetting($journalId, 'markupHostUser'));
$this->setData('markupHostURL', $plugin->getSetting($journalId, 'markupHostURL'));
$this->setData('overrideGalley', $plugin->getSetting($journalId, 'overrideGalley'));
$this->setData('wantedFormats', $plugin->getSetting($journalId, 'wantedFormats'));
}
/**
* Populate and display settings form
*
* @return void
*/
function display() {
$templateManager =& TemplateManager::getManager();
// Signals indicating plugin compatibility
$templateManager->assign('curlSupport', function_exists('curl_init') ? __('plugins.generic.markup.settings.installed') : __('plugins.generic.markup.settings.notInstalled'));
$templateManager->assign('zipSupport', extension_loaded('zlib') ? __('plugins.generic.markup.settings.installed') : __('plugins.generic.markup.settings.notInstalled'));
$templateManager->assign('php5Support', checkPhpVersion('5.0.0') ? __('plugins.generic.markup.settings.installed') : __('plugins.generic.markup.settings.notInstalled'));
$templateManager->assign('pathInfo', Request::isPathInfoEnabled() ? __('plugins.generic.markup.settings.enabled') : __('plugins.generic.markup.settings.disabled'));
$additionalHeadData = '<link rel="stylesheet" type="text/css" href="' . $this->plugin->getCssUrl() . 'settingsForm.css" />';
$additionalHeadData .= '<script type="text/javascript" src="' . $this->plugin->getJsUrl() . 'settingsForm.js" />';
$templateManager->assign('additionalHeadData', $additionalHeadData);
parent::display();
}
/**
* Assign form data to user-submitted data
*
* @return void
*/
function readInputData() {
$this->readUserVars(
array(
'cslStyle',
'markupHostPass',
'markupHostURL',
'markupHostUser',
'overrideGalley',
'wantedFormats',
)
);
}
/**
* Save settings
*
* @return void
*/
function execute() {
$plugin =& $this->plugin;
$journalId = $this->journalId;
$plugin->updateSetting($journalId, 'cslStyle', $this->getData('cslStyle'));
$markupHostURL = $this->getData('markupHostURL');
if ($markupHostURL) {
if (!parse_url($markupHostURL, PHP_URL_SCHEME)) {
$markupHostURL = 'http://' . $markupHostURL;
}
if (substr(parse_url($markupHostURL, PHP_URL_PATH), -1) != '/') {
$markupHostURL .= '/';
}
}
$plugin->updateSetting($journalId, 'markupHostURL', $markupHostURL);
$plugin->updateSetting($journalId, 'markupHostUser', $this->getData('markupHostUser'));
$plugin->updateSetting($journalId, 'markupHostPass', $this->getData('markupHostPass'));
$plugin->updateSetting($journalId, 'overrideGalley', $this->getData('overrideGalley'));
$plugin->updateSetting($journalId, 'wantedFormats', $this->getData('wantedFormats'));
}
/**
* Returns JournalFileManager instance
*
* @param $journal mixed Journal to get a fiel manager instance for
*
* @return mixed JournalFileManager instance
*/
function _getJournalFileManager($journal = null) {
if (!$journal) { $journal =& Request::getJournal(); }
import('classes.file.JournalFileManager');
return new JournalFileManager($journal);
}
}