PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
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.0, at includes/Core/Fallback/Field.php

205 lines 6.4 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 public function buttonValidsObject() {
10 $formModel = new FormModel();
11 $forms = $formModel->get(
12 ['id', 'form_content']
13 );
14
15 if (!is_wp_error($forms)) {
16 foreach ($forms as $form) {
17 $formID = $form->id;
18 $formContent = json_decode($form->form_content);
19 $fields = $formContent->fields;
20
21 foreach ($fields as $fldKey => $fldData) {
22 if ('button' === $fldData->typ && !isset($fldData->valid)) {
23 $fldData->valid = (object) [];
24 }
25 $fields->{$fldKey} = $fldData;
26 }
27
28 $formContent->fields = $fields;
29
30 $formModel->update(
31 [
32 'form_content' => wp_json_encode($formContent),
33 ],
34 [
35 'id' => $formID,
36 ]
37 );
38 }
39 }
40 }
41
42 public function addButton() {
43 // if version is lower or equal than 1.3.13
44 $formModel = new FormModel();
45 $forms = $formModel->get(
46 ['id', 'form_content'],
47 [
48 'form_content' => ['operator' => 'LIKE', 'value' => '%\"buttons\":%'],
49 ]
50 );
51 if (!is_wp_error($forms)) {
52 $adminFormHandler = new AdminFormHandler();
53 foreach ($forms as $form) {
54 $formID = $form->id;
55 $formContent = json_decode($form->form_content);
56 $fields = json_encode($formContent->fields);
57 if (isset($formContent->buttons)) {
58 if (false === strpos($fields, '"btnTyp":"submit"')) {
59 $align = isset($formContent->buttons->align) ? $formContent->buttons->align : 'right';
60 $btnSiz = isset($formContent->buttons->btnSiz) ? $formContent->buttons->btnSiz : 'md';
61 $fulW = isset($formContent->buttons->fulW) ? $formContent->buttons->fulW : false;
62 $btnData = [
63 'typ' => 'button',
64 'btnSiz' => $btnSiz,
65 'fulW' => $fulW,
66 ];
67 $newID = 0;
68 foreach ($formContent->fields as $key => $value) {
69 $oldID = \preg_replace('/bf?\d+-(\d+)-?/', '$1', $key);
70 if ($oldID > $newID) {
71 $newID = $oldID;
72 }
73 }
74 $newID = $newID + 1;
75 $sBtnID = "bf${formID}-${newID}";
76 $lY = 0;
77 $mY = 0;
78 $sY = 0;
79 foreach ($formContent->layout->lg as $lg) {
80 if ($lg->y > $lY) {
81 $lY = $lg->y;
82 }
83 }
84 $lY = $lY + $lg->h + 1;
85 foreach ($formContent->layout->md as $md) {
86 if ($md->y > $mY) {
87 $mY = $md->y;
88 }
89 }
90 $mY = $mY + $md->h + 1;
91 foreach ($formContent->layout->sm as $sm) {
92 if ($sm->y > $sY) {
93 $sY = $sm->y;
94 }
95 }
96 $sY = $sY + $sm->h + 1;
97 if (isset($formContent->buttons->rstBtnTxt)) {
98 $newID += 1;
99 $rBtnID = "bf${formID}-${newID}";
100
101 if ($fulW) {
102 $btnData['btnTyp'] = 'submit';
103 $btnData['align'] = $align;
104 $btnData['txt'] = $formContent->buttons->subBtnTxt;
105 $formContent->fields->{$sBtnID} = (object) $btnData;
106 $rBtnData = $btnData;
107 $rBtnData['btnTyp'] = 'reset';
108 $rBtnData['align'] = $align;
109 $rBtnData['txt'] = $formContent->buttons->rstBtnTxt;
110 $formContent->fields->{$rBtnID} = (object) $rBtnData;
111 } else {
112 $btnData['btnTyp'] = 'submit';
113 $btnData['align'] = 'right';
114 $btnData['txt'] = $formContent->buttons->subBtnTxt;
115 $formContent->fields->{$sBtnID} = (object) $btnData;
116 $rBtnData = $btnData;
117 $rBtnData['btnTyp'] = 'reset';
118 $rBtnData['align'] = 'left';
119 $rBtnData['txt'] = $formContent->buttons->rstBtnTxt;
120 $formContent->fields->{$rBtnID} = (object) $rBtnData;
121 }
122 $subBtnLay = [
123 'h' => 2,
124 'i' => $sBtnID,
125 'minH' => 2,
126 'x' => 0,
127 'y' => 1000,
128 ];
129
130 $subBtnLay['w'] = 3;
131 $subBtnLay['y'] = $lY;
132
133 $formContent->layout->lg[] = (object) $subBtnLay;
134
135 $subBtnLay['w'] = 2;
136 $subBtnLay['y'] = $mY;
137
138 $formContent->layout->md[] = (object) $subBtnLay;
139
140 $subBtnLay['w'] = 1;
141 $subBtnLay['y'] = $sY;
142
143 $formContent->layout->sm[] = (object) $subBtnLay;
144
145 $subBtnLay['i'] = $rBtnID;
146 $subBtnLay['x'] = 3;
147 $subBtnLay['w'] = 3;
148 $subBtnLay['y'] = $lY;
149
150 $formContent->layout->lg[] = (object) $subBtnLay;
151
152 $subBtnLay['x'] = 2;
153 $subBtnLay['w'] = 2;
154 $subBtnLay['y'] = $mY;
155
156 $formContent->layout->md[] = (object) $subBtnLay;
157
158 $subBtnLay['w'] = 1;
159 $subBtnLay['x'] = 1;
160 $subBtnLay['y'] = $sY;
161
162 $formContent->layout->sm[] = (object) $subBtnLay;
163 } else {
164 $btnData['btnTyp'] = 'submit';
165 $btnData['txt'] = $formContent->buttons->subBtnTxt;
166 $btnData['align'] = $align;
167 $formContent->fields->{$sBtnID} = (object) $btnData;
168
169 $subBtnLay = [
170 'h' => 2,
171 'i' => $sBtnID,
172 'minH' => 2,
173 'x' => 0,
174 'w' => 6,
175 ];
176
177 $subBtnLay['y'] = $lY;
178
179 $formContent->layout->lg[] = (object) $subBtnLay;
180
181 $subBtnLay['y'] = $mY;
182
183 $formContent->layout->md[] = (object) $subBtnLay;
184
185 $subBtnLay['y'] = $sY;
186
187 $formContent->layout->sm[] = (object) $subBtnLay;
188 }
189 }
190 $adminFormHandler->saveLayoutStyleSheet($formContent->layout, 'bitform-layout-' . $formID . '.css');
191 unset($formContent->buttons);
192 $formModel->update(
193 [
194 'form_content' => wp_json_encode($formContent),
195 ],
196 [
197 'id' => $formID,
198 ]
199 );
200 }
201 }
202 }
203 }
204 }
205