-
Notifications
You must be signed in to change notification settings - Fork 12
/
FormSettings.php
189 lines (163 loc) · 4.85 KB
/
FormSettings.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
<?php
/**
* Copyright (c) 2017 Bastian Germann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Cforms2;
class FormSettings
{
private static $forms = array();
private $ind;
private $pre;
private function __construct($index_form, $index_prefix)
{
$this->ind = $index_form;
$this->pre = $index_prefix;
}
public function name()
{
return Settings::instance()->get($this->ind, $this->pre . 'fname');
}
// core
public function getDefaultEnctype()
{
return Settings::instance()->get($this->ind, $this->pre . 'formaction');
}
public function getDontClear()
{
return Settings::instance()->get($this->ind, $this->pre . 'dontclear');
}
public function getCustomNames()
{
return Settings::instance()->get($this->ind, $this->pre . 'customnames');
}
public function getExtraVar()
{
return substr(Settings::instance()->get($this->ind, $this->pre . 'tellafriend'), 0, 1) === '3';
}
public function getHide()
{
return Settings::instance()->get($this->ind, $this->pre . 'hide');
}
private function convertFormatToTime($formatted_date)
{
if (trim($formatted_date) === '') {
return 0;
}
$time = str_replace('/', '.', $formatted_date) . sprintf(' %+d', get_option('gmt_offset'));
$time = strtotime($time);
if ($time === false) {
return 0;
}
return $time;
}
public function getStartDateTime()
{
return $this->convertFormatToTime($this->getStartDate());
}
private function getStartDate()
{
return Settings::instance()->get($this->ind, $this->pre . 'startdate');
}
public function getEndDateTime()
{
return $this->convertFormatToTime($this->getEndDate());
}
private function getEndDate()
{
return Settings::instance()->get($this->ind, $this->pre . 'enddate');
}
public function getRedirect()
{
return Settings::instance()->get($this->ind, $this->pre . 'redirect');
}
public function getRedirectPage()
{
return Settings::instance()->get($this->ind, $this->pre . 'redirect_page');
}
public function getAction()
{
return Settings::instance()->get($this->ind, $this->pre . 'action');
}
public function getActionPage()
{
$url = Settings::instance()->get($this->ind, $this->pre . 'action_page');
return $url === 'http://' ? '' : $url;
}
// fileupload
public function getUploadExtensions()
{
return Settings::instance()->get($this->ind, $this->pre . 'upload_ext');
}
public function getUploadSize()
{
return (int) Settings::instance()->get($this->ind, $this->pre . 'upload_size');
}
public function getNoAttachments()
{
return Settings::instance()->get($this->ind, $this->pre . 'noattachments');
}
/**
* Converts a natural number to the corresponding form ID.
*
* @param int $no a natural number
* @return string the cformsII form ID
*/
private static function formId($no)
{
if ($no < 2) {
return '';
}
return strval($no);
}
/**
* Returns the settings object of the form with ID $id. If it does not exist returns null.
*
* @param mixed $id a cformsII form ID
* @return FormSettings
*/
public static function form($id)
{
if (is_int($id)) {
$id = FormSettings::formId($id);
}
if (isset(FormSettings::$forms[$id])) {
return FormSettings::$forms[$id];
} elseif (Settings::instance()->get("form{$id}")) {
FormSettings::$forms[$id] = new FormSettings("form{$id}", "cforms{$id}_");
return FormSettings::$forms[$id];
}
return null;
}
/**
* @return array associative array of FormSettings instances
*/
public static function forms()
{
$no = 1;
while (FormSettings::form($no) != null) {
$no += 1;
}
return FormSettings::$forms;
}
/**
* Resets the static fields.
*/
public static function reset()
{
FormSettings::$forms = array();
Settings::reset();
}
}