forked from ulsdevteam/pkp-formHoneypot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormHoneypotSettingsForm.inc.php
90 lines (73 loc) · 2.37 KB
/
FormHoneypotSettingsForm.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
<?php
/**
* @file plugins/generic/formHoneypot/FormHoneypotSettingsForm.inc.php
*
* Copyright (c) University of Pittsburgh
* Distributed under the GNU GPL v2 or later. For full terms see the LICENSE file.
*
* @class FormHoneypotSettingsForm
* @ingroup plugins_generic_formHoneypot
*
* @brief Form for journal managers to modify Form Honeypot plugin settings
*/
import('lib.pkp.classes.form.Form');
class FormHoneypotSettingsForm extends Form {
/** @var $contextId int */
var $_contextId;
/** @var $plugin object */
var $_plugin;
/**
* Constructor
* @param $plugin object
* @param $journalId int
*/
function __construct($plugin, $contextId) {
$this->_contextId = $contextId;
$this->_plugin = $plugin;
if (method_exists($plugin, 'getTemplateResource')) {
// OJS 3.1.2 and later
parent::__construct($plugin->getTemplateResource('settingsForm.tpl'));
} else {
// OJS 3.1.1 and earlier
parent::__construct($plugin->getTemplatePath() . 'settingsForm.tpl');
}
$this->addCheck(new FormValidatorCustom($this, 'formHoneypotMinimumTime', FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.formHoneypot.manager.settings.minimumTimeNumber', create_function('$s', 'return ($s === "0" || $s > 0);')));
$this->addCheck(new FormValidatorCustom($this, 'formHoneypotMaximimTime', FORM_VALIDATOR_OPTIONAL_VALUE, 'plugins.generic.formHoneypot.manager.settings.maximumTimeNumber', create_function('$s', 'return ($s === "0" || $s > 0);')));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}
/**
* Initialize form data.
*/
function initData() {
$plugin = $this->_plugin;
foreach (array_keys($this->_plugin->settingNames) as $k) {
$this->setData($k, $plugin->getSetting($this->_contextId, $k));
}
}
/**
* Fetch the form.
* @copydoc Form::fetch()
*/
function fetch($request) {
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->_plugin->getName());
return parent::fetch($request);
}
/**
* Assign form data to user-submitted data.
*/
function readInputData() {
$this->readUserVars(array_keys($this->_plugin->settingNames));
}
/**
* Save settings.
*/
function execute() {
$contextId = $this->_contextId;
foreach ($this->_plugin->settingNames as $k => $v) {
$this->_plugin->updateSetting($contextId, $k, $this->getData($k), $v);
}
}
}
?>