PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.1
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Fallback / Field.php

Field.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.9.1, at includes/Core/Fallback/Field.php

261 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Fallback;
4
5 use BitCode\BitForm\Admin\Form\AdminFormHandler;
6 use BitCode\BitForm\Core\Database\FormModel;
7
8 class Field
9 {
10 public function buttonValidsObject()
11 {
12 $formModel = new FormModel();
13 $forms = $formModel->get(
14 ['id', 'form_content']
15 );
16
17 if (!is_wp_error($forms)) {
18 foreach ($forms as $form) {
19 $formID = $form->id;
20 $formContent = json_decode($form->form_content);
21 $fields = $formContent->fields;
22
23 foreach ($fields as $fldKey => $fldData) {
24 if ('button' === $fldData->typ && !isset($fldData->valid)) {
25 $fldData->valid = (object) [];
26 }
27 $fields->{$fldKey} = $fldData;
28 }
29
30 $formContent->fields = $fields;
31
32 $formModel->update(
33 [
34 'form_content' => wp_json_encode($formContent),
35 ],
36 [
37 'id' => $formID,
38 ]
39 );
40 }
41 }
42 }
43
44 public function addButton()
45 {
46 // if version is lower or equal than 1.3.13
47 $formModel = new FormModel();
48 $forms = $formModel->get(
49 ['id', 'form_content'],
50 [
51 'form_content' => ['operator' => 'LIKE', 'value' => '%\"buttons\":%'],
52 ]
53 );
54 if (!is_wp_error($forms)) {
55 $adminFormHandler = new AdminFormHandler();
56 foreach ($forms as $form) {
57 $formID = $form->id;
58 $formContent = json_decode($form->form_content);
59 $fields = json_encode($formContent->fields);
60 if (isset($formContent->buttons)) {
61 if (false === strpos($fields, '"btnTyp":"submit"')) {
62 $align = isset($formContent->buttons->align) ? $formContent->buttons->align : 'right';
63 $btnSiz = isset($formContent->buttons->btnSiz) ? $formContent->buttons->btnSiz : 'md';
64 $fulW = isset($formContent->buttons->fulW) ? $formContent->buttons->fulW : false;
65 $btnData = [
66 'typ' => 'button',
67 'btnSiz' => $btnSiz,
68 'fulW' => $fulW,
69 ];
70 $newID = 0;
71 foreach ($formContent->fields as $key => $value) {
72 $oldID = \preg_replace('/bf?\d+-(\d+)-?/', '$1', $key);
73 if ($oldID > $newID) {
74 $newID = $oldID;
75 }
76 }
77 $newID = $newID + 1;
78 $sBtnID = "bf${formID}-${newID}";
79 $lY = 0;
80 $mY = 0;
81 $sY = 0;
82 foreach ($formContent->layout->lg as $lg) {
83 if ($lg->y > $lY) {
84 $lY = $lg->y;
85 }
86 }
87 $lY = $lY + $lg->h + 1;
88 foreach ($formContent->layout->md as $md) {
89 if ($md->y > $mY) {
90 $mY = $md->y;
91 }
92 }
93 $mY = $mY + $md->h + 1;
94 foreach ($formContent->layout->sm as $sm) {
95 if ($sm->y > $sY) {
96 $sY = $sm->y;
97 }
98 }
99 $sY = $sY + $sm->h + 1;
100 if (isset($formContent->buttons->rstBtnTxt)) {
101 $newID += 1;
102 $rBtnID = "bf${formID}-${newID}";
103
104 if ($fulW) {
105 $btnData['btnTyp'] = 'submit';
106 $btnData['align'] = $align;
107 $btnData['txt'] = $formContent->buttons->subBtnTxt;
108 $formContent->fields->{$sBtnID} = (object) $btnData;
109 $rBtnData = $btnData;
110 $rBtnData['btnTyp'] = 'reset';
111 $rBtnData['align'] = $align;
112 $rBtnData['txt'] = $formContent->buttons->rstBtnTxt;
113 $formContent->fields->{$rBtnID} = (object) $rBtnData;
114 } else {
115 $btnData['btnTyp'] = 'submit';
116 $btnData['align'] = 'right';
117 $btnData['txt'] = $formContent->buttons->subBtnTxt;
118 $formContent->fields->{$sBtnID} = (object) $btnData;
119 $rBtnData = $btnData;
120 $rBtnData['btnTyp'] = 'reset';
121 $rBtnData['align'] = 'left';
122 $rBtnData['txt'] = $formContent->buttons->rstBtnTxt;
123 $formContent->fields->{$rBtnID} = (object) $rBtnData;
124 }
125 $subBtnLay = [
126 'h' => 2,
127 'i' => $sBtnID,
128 'minH' => 2,
129 'x' => 0,
130 'y' => 1000,
131 ];
132
133 $subBtnLay['w'] = 3;
134 $subBtnLay['y'] = $lY;
135
136 $formContent->layout->lg[] = (object) $subBtnLay;
137
138 $subBtnLay['w'] = 2;
139 $subBtnLay['y'] = $mY;
140
141 $formContent->layout->md[] = (object) $subBtnLay;
142
143 $subBtnLay['w'] = 1;
144 $subBtnLay['y'] = $sY;
145
146 $formContent->layout->sm[] = (object) $subBtnLay;
147
148 $subBtnLay['i'] = $rBtnID;
149 $subBtnLay['x'] = 3;
150 $subBtnLay['w'] = 3;
151 $subBtnLay['y'] = $lY;
152
153 $formContent->layout->lg[] = (object) $subBtnLay;
154
155 $subBtnLay['x'] = 2;
156 $subBtnLay['w'] = 2;
157 $subBtnLay['y'] = $mY;
158
159 $formContent->layout->md[] = (object) $subBtnLay;
160
161 $subBtnLay['w'] = 1;
162 $subBtnLay['x'] = 1;
163 $subBtnLay['y'] = $sY;
164
165 $formContent->layout->sm[] = (object) $subBtnLay;
166 } else {
167 $btnData['btnTyp'] = 'submit';
168 $btnData['txt'] = $formContent->buttons->subBtnTxt;
169 $btnData['align'] = $align;
170 $formContent->fields->{$sBtnID} = (object) $btnData;
171
172 $subBtnLay = [
173 'h' => 2,
174 'i' => $sBtnID,
175 'minH' => 2,
176 'x' => 0,
177 'w' => 6,
178 ];
179
180 $subBtnLay['y'] = $lY;
181
182 $formContent->layout->lg[] = (object) $subBtnLay;
183
184 $subBtnLay['y'] = $mY;
185
186 $formContent->layout->md[] = (object) $subBtnLay;
187
188 $subBtnLay['y'] = $sY;
189
190 $formContent->layout->sm[] = (object) $subBtnLay;
191 }
192 }
193 $adminFormHandler->saveLayoutStyleSheet($formContent->layout, 'bitform-layout-' . $formID . '.css');
194 unset($formContent->buttons);
195 $formModel->update(
196 [
197 'form_content' => wp_json_encode($formContent),
198 ],
199 [
200 'id' => $formID,
201 ]
202 );
203 }
204 }
205 }
206 }
207
208 public function phoneNumberMissingPattern()
209 {
210 $formModel = new FormModel();
211 $forms = $formModel->get(
212 ['id', 'form_content']
213 );
214
215 if (!is_wp_error($forms)) {
216 $missingPatterns = [
217 'CA' => '(?:2(?:04|[23]6|[48]9|50|63)|3(?:06|43|54|6[578]|82)|4(?:03|1[68]|[26]8|3[178]|50|74)|5(?:06|1[49]|48|79|8[147])|6(?:04|[18]3|39|47|72)|7(?:0[59]|42|53|78|8[02])|8(?:[06]7|19|25|73)|90[25])[2-9]$_bf_$d{6}',
218 'CL' => '2(?:1982[0-6]|3314[05-9])$_bf_$d{3}|(?:2(?:1(?:160|962)|3(?:2$_bf_$d$_bf_$d|3(?:[03467]$_bf_$d|1[0-35-9]|2[1-9]|5[0-24-9]|8[0-3])|600)|646[59])|80[1-9]$_bf_$d$_bf_$d|9(?:3(?:[0-57-9]$_bf_$d$_bf_$d|6(?:0[02-9]|[1-9]$_bf_$d))|6(?:[0-8]$_bf_$d$_bf_$d|9(?:[02-79]$_bf_$d|1[05-9]))|7[1-9]$_bf_$d$_bf_$d|9(?:[03-9]$_bf_$d$_bf_$d|1(?:[0235-9]$_bf_$d|4[0-24-9])|2(?:[0-79]$_bf_$d|8[0-46-9]))))$_bf_$d{4}|(?:22|3[2-5]|[47][1-35]|5[1-3578]|6[13-57]|8[1-9]|9[2458])$_bf_$d{7}',
219 'DK' => '(?:[2-7]$_bf_$d|8[126-9]|9[1-46-9])$_bf_$d{6}',
220 'GU' => '671(?:3(?:00|3[39]|4[349]|55|6[26])|4(?:00|56|7[1-9]|8[02-46-9])|5(?:55|6[2-5]|88)|6(?:3[2-578]|4[24-9]|5[34]|78|8[235-9])|7(?:[0479]7|2[0167]|3[45]|8[7-9])|8(?:[2-57-9]8|6[48])|9(?:2[29]|6[79]|7[1279]|8[7-9]|9[78]))$_bf_$d{4}',
221 'MP' => '670(?:2(?:3[3-7]|56|8[4-8])|32[1-38]|4(?:33|8[348])|5(?:32|55|88)|6(?:64|70|82)|78[3589]|8[3-9]8|989)$_bf_$d{4}',
222 'PR' => '(?:787|939)[2-9]$_bf_$d{6}',
223 'US' => '5056(?:[0-35-9]$_bf_$d|4[46])$_bf_$d{4}|(?:4722|505[2-57-9])$_bf_$d{6}|(?:2(?:0[1-35-9]|1[02-9]|2[03-589]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])|3(?:0[1-57-9]|1[02-9]|2[01356]|3[0-24679]|4[167]|5[0-2]|6[014]|8[056])|4(?:0[124-9]|1[02-579]|2[3-5]|3[0245]|4[023578]|58|6[349]|7[0589]|8[04])|5(?:0[1-47-9]|1[0235-8]|20|3[0149]|4[01]|5[179]|6[1-47]|7[0-5]|8[0256])|6(?:0[1-35-9]|1[024-9]|2[03689]|[34][016]|5[01679]|6[0-279]|78|8[0-29])|7(?:0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[0-59]|8[156])|8(?:0[1-68]|1[02-8]|2[068]|3[0-2589]|4[03578]|5[046-9]|6[02-5]|7[028])|9(?:0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[01357-9]|5[12469]|7[0-389]|8[04-69]))[2-9]$_bf_$d{6}',
224 'VI' => '340(?:2(?:0[0-368]|2[06-8]|4[49]|77)|3(?:32|44)|4(?:2[23]|44|7[34]|89)|5(?:1[34]|55)|6(?:2[56]|4[23]|77|9[023])|7(?:1[2-57-9]|2[57]|7$_bf_$d)|884|998)$_bf_$d{4}'
225 ];
226
227 foreach ($forms as $form) {
228 $formID = $form->id;
229 $formContent = json_decode($form->form_content);
230 $fields = $formContent->fields;
231
232 foreach ($fields as $fldKey => $fldData) {
233 if ('phone-number' === $fldData->typ) {
234 $options = $fldData->options;
235 $optCount = count($options);
236 for ($i = 0; $i < $optCount; $i++) {
237 $opt = $options[$i];
238 if (!isset($opt->ptrn) && isset($missingPatterns[$opt->i])) {
239 $options[$i]->ptrn = $missingPatterns[$opt->i];
240 }
241 }
242 $fldData->options = $options;
243 $fields->{$fldKey} = $fldData;
244 }
245 }
246
247 $formContent->fields = $fields;
248
249 $formModel->update(
250 [
251 'form_content' => wp_json_encode($formContent),
252 ],
253 [
254 'id' => $formID,
255 ]
256 );
257 }
258 }
259 }
260 }
261