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 / Admin / Form / ScriptFilePriorityManager.php

ScriptFilePriorityManager.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Admin/Form/ScriptFilePriorityManager.php

359 lines 16.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\Admin\Form;
4
5 class ScriptFilePriorityManager {
6 public static function jsFile() {
7 /**
8 * file load priority
9 * first priority status code 100
10 * sub status code link 101,102
11 * second priority status code 200
12 * sub status code link 201,202, 203
13 * continue..........
14 * priority = 100 range for helper file
15 * priority = 200 range for field file
16 * priority = 300 range for script file
17 * priority = 400 range for custom script file
18 * priority = 500 range for js init for custom field file
19 * priority = 600 range for js init for CDN field file
20 * Priority = 700 range for validation js file
21 * priority = 800 range for conditional js file
22 * @array [fieldType] => [
23 * priority => 'choose one of the priority status code',
24 * filename => 'fileName',
25 * scriptTyp => 'script' or 'init' or 'custom' by default script
26 * source => 'filePath' or 'url' or 'cdn' or className or customClassName by scriptTyp && by default it will be 'filePath'=> 'assets/js/fileName.js'',
27 * fk => 'field key'
28 * field => 'field object'
29 * ]
30
31 * final priority
32 helper js
33 common js
34 custom field script js
35 init for custom field js
36 inti for CDN field js
37 validation js
38 confirmation js
39 conditional js
40 submit js
41 custom js
42 */
43 $initSource = '\\BitCode\\BitForm\\Admin\\Form\\InitJs\\';
44 $customSource = '\\BitCode\\BitForm\\Admin\\Form\\ExtraFieldJS\\';
45 return [
46 'helperScript' => [
47 ['priority' => 101, 'filename' => 'bfSelect.min.js'],
48 ['priority' => 101, 'filename' => 'bfReset.min.js'],
49 ['priority' => 101, 'filename' => 'setBFMsg.min.js'],
50 ['priority' => 101, 'filename' => 'scrollToFld.min.js'],
51 ['priority' => 101, 'filename' => 'bfValidationErrMsg.min.js'],
52 ['priority' => 101, 'filename' => 'setHiddenFld.min.js'],
53 ['priority' => 101, 'filename' => 'submit-form.min.js'],
54 ['priority' => 101, 'filename' => 'setStyleProperty.min.js']
55 ],
56 'country' => [
57 ['priority' => 101, 'filename' => 'observeElm.min.js'],
58 ['priority' => 201, 'filename' => 'bit-virtualized-list.min.js'],
59 ['priority' => 301, 'filename' => 'bit-country-field.min.js'],
60 ['priority' => 501, 'filename' => 'Country', 'scriptTyp' => 'init', 'source' => $initSource],
61 ['priority' => 201, 'filename' => 'customFieldsReset.min.js'],
62 ['priority' => 101, 'filename' => 'observeElm.min.js'],
63 ],
64 'currency' => [
65 ['priority' => 101, 'filename' => 'observeElm.min.js'],
66 ['priority' => 201, 'filename' => 'bit-virtualized-list.min.js'],
67 ['priority' => 301, 'filename' => 'bit-currency-field.min.js'],
68 ['priority' => 501, 'filename' => 'Currency', 'scriptTyp' => 'init', 'source' => $initSource],
69 ['priority' => 201, 'filename' => 'customFieldsReset.min.js'],
70 ['priority' => 101, 'filename' => 'observeElm.min.js'],
71 ],
72 'select' => [
73 ['priority' => 101, 'filename' => 'observeElm.min.js'],
74 ['priority' => 301, 'filename' => 'bit-dropdown-field.min.js'],
75 ['priority' => 501, 'filename' => 'Select', 'scriptTyp' => 'init', 'source' => $initSource],
76 ['priority' => 201, 'filename' => 'customFieldsReset.min.js'],
77 ['priority' => 101, 'filename' => 'observeElm.min.js'],
78 ],
79 'advanced-file-up' => [
80 ['priority' => 101, 'filename' => 'observeElm.min.js'],
81 ['priority' => 202, 'filename' => 'bit-filepond.min.js'],
82 ['priority' => 301, 'filename' => 'bit-advance-file-upload-field.min.js'],
83 ['priority' => 501, 'filename' => 'AdvancedFileUpload', 'scriptTyp' => 'init', 'source' => $initSource],
84 ['priority' => 101, 'filename' => 'advancedFileHandle.min.js'],
85 ['priority' => 201, 'filename' => 'customFieldsReset.min.js'],
86 ],
87 'file-up' => [
88 ['priority' => 301, 'filename' => 'bit-file-up-field.min.js'],
89 ['priority' => 501, 'filename' => 'FileUpload', 'scriptTyp' => 'init', 'source' => $initSource],
90 ['priority' => 201, 'filename' => 'customFieldsReset.min.js'],
91 ],
92 'phone-number' => [
93 ['priority' => 101, 'filename' => 'observeElm.min.js'],
94 ['priority' => 201, 'filename' => 'bit-virtualized-list.min.js'],
95 ['priority' => 301, 'filename' => 'bit-phone-number-field.min.js'],
96 ['priority' => 501, 'filename' => 'PhoneNumber', 'scriptTyp' => 'init', 'source' => $initSource],
97 ['priority' => 201, 'filename' => 'customFieldsReset.min.js'],
98 ['priority' => 101, 'filename' => 'observeElm.min.js'],
99 ],
100 'paypal' => [
101 ['priority' => 101, 'filename' => 'paymentSubmitResponse.min.js'],
102 ['priority' => 301, 'filename' => 'bit-paypal-field.min.js'],
103 ['priority' => 601, 'filename' => 'Paypal', 'scriptTyp' => 'init', 'source' => $initSource],
104 ],
105 'razorpay' => [
106 ['priority' => 101, 'filename' => 'paymentSubmitResponse.min.js'],
107 ['priority' => 301, 'filename' => 'bit-razorpay-field.min.js'],
108 ['priority' => 601, 'filename' => 'Razorpay', 'scriptTyp' => 'init', 'source' => $initSource],
109 ],
110 'radio' => [
111 ['priority' => 301, 'filename' => 'OtherOptionJS', 'scriptTyp' => 'custom', 'source' => $customSource],
112 ],
113 'check' => [
114 ['priority' => 301, 'filename' => 'OtherOptionJS', 'scriptTyp' => 'custom', 'source' => $customSource],
115 ['priority' => 301, 'filename' => 'CheckDisableOnMax', 'scriptTyp' => 'custom', 'source' => $customSource],
116 ],
117 'recaptcha' => [
118 ['priority' => 301, 'filename' => 'bit-recaptcha-field.min.js'],
119 ['priority' => 601, 'filename' => 'Recaptcha', 'scriptTyp' => 'init', 'source' => $initSource],
120 ],
121 'decision-box' => [
122 ['priority' => 101, 'filename' => 'decisionFldHandle.min.js'],
123 ]
124 ];
125 }
126
127 public static function filePondPlugins($plugin) {
128 $plugins = [
129 'allowFileSizeValidation' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-file-validate-size.min.js'],
130 'allowFileTypeValidation' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-file-validate-type.min.js'],
131 'allowImageCrop' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-crop.min.js'],
132 'allowImagePreview' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-preview.min.js'],
133 'allowImageResize' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-resize.min.js'],
134 'allowImageTransform' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-transform.min.js'],
135 'allowImageValidateSize' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-image-validate-size.min.js'],
136 'allowPreview' => ['priority' => 201, 'filename' => 'bit-filepond-plugin-media-preview.min.js'],
137 ];
138 if (array_key_exists($plugin, $plugins)) {
139 return $plugins[$plugin];
140 }
141
142 return false;
143 }
144
145 public static function fieldMissingConfigsProps($fieldType, $field) {
146 // key is config path, value is field path
147 // var is for variable value
148 // path is for field path
149 // val is for static value
150 $configs = [
151 'select' => [
152 'fieldKey' => ['var' => 'fieldKey'],
153 'options' => ['path' => 'optionsList'],
154 'placeholder' => ['path' => 'ph'],
155 'classNames' => ['path' => 'customClasses'],
156 'attributes' => ['path' => 'customAttributes'],
157 'defaultValue' => ['path' => 'val', 'val' => isset($field->config->defaultValue) ? $field->config->defaultValue : ''],
158 'separator' => ['val' => BITFORMS_BF_SEPARATOR],
159 'mn' => ['path' => 'mn', 'val' => 0],
160 'mx' => ['path' => 'mx', 'val' => 0],
161 'disableOnMax' => ['path' => 'valid->disableOnMax', 'val' => false],
162 ],
163 'country' => [
164 'fieldKey' => ['var' => 'fieldKey'],
165 'options' => ['path' => 'options'],
166 'placeholder' => ['path' => 'ph'],
167 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/countries/'],
168 'classNames' => ['path' => 'customClasses'],
169 'attributes' => ['path' => 'customAttributes'],
170 'defaultValue' => ['path' => 'val', 'val' => isset($field->config->defaultValue) ? $field->config->defaultValue : ''],
171 ],
172 'currency' => [
173 'fieldKey' => ['var' => 'fieldKey'],
174 'options' => ['path' => 'options'],
175 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/currencies/'],
176 'classNames' => ['path' => 'customClasses'],
177 'attributes' => ['path' => 'customAttributes'],
178 'defaultValue' => ['path' => 'val', 'val' => isset($field->config->defaultValue) ? $field->config->defaultValue : ''],
179 ],
180 'phone-number' => [
181 'fieldKey' => ['var' => 'fieldKey'],
182 'options' => ['path' => 'options'],
183 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/countries/'],
184 'classNames' => ['path' => 'customClasses'],
185 'attributes' => ['path' => 'customAttributes']
186 ],
187 'file-up' => [
188 'fieldKey' => ['var' => 'fieldKey'],
189 'maxSizeErrMsg' => ['path' => isset($field->err->maxSize->msg) ? 'err->maxSize->msg' : 'err->maxSize->dflt'],
190 'minFileErrMsg' => ['path' => isset($field->err->minFile->msg) ? 'err->minFile->msg' : 'err->minFile->dflt'],
191 'maxFileErrMsg' => ['path' => isset($field->err->maxFile->msg) ? 'err->maxFile->msg' : 'err->maxFile->dflt'],
192 'assetsURL' => ['val' => BITFORMS_ROOT_URI . '/static/file-upload/'],
193 'classNames' => ['path' => 'customClasses'],
194 'attributes' => ['path' => 'customAttributes']
195 ],
196 'paypal' => [
197 'payIntegID' => ['path' => 'payIntegID'],
198 'style' => ['path' => 'style'],
199 'currency' => ['path' => 'currency', 'val' => 'USD'],
200 'amount' => ['path' => 'amount', 'val' => 0],
201 'amountFld' => ['path' => 'amountFld', 'val' => ''],
202 'shipping' => ['path' => 'shipping', 'val' => 0],
203 'shippingVal' => ['path' => 'shippingFld', 'val' => ''],
204 'tax' => ['path' => 'tax', 'val' => 0],
205 'taxVal' => ['path' => 'taxFld', 'val' => ''],
206 'description' => ['path' => 'description', 'val' => ''],
207 'descFld' => ['path' => 'descFld', 'val' => ''],
208 'payType' => ['path' => 'payType', 'val' => 'payment'],
209 'planId' => ['path' => 'planId', 'val' => ''],
210 'locale' => ['path' => 'locale', 'val' => 'en_US'],
211 'disableFunding' => ['path' => 'disableFunding', 'val' => ''],
212 ],
213 'advanced-file-up' => [
214 'fieldKey' => ['var' => 'fieldKey'],
215 'formID' => ['var' => 'formID'],
216 'configSetting' => ['path' => 'config'],
217 'ajaxURL' => ['val' => admin_url('admin-ajax.php')],
218 'nonce' => ['val' => wp_create_nonce('bitforms_save')],
219 'uploadFileToServer' => ['val' => 1],
220 ],
221 'razorpay' => [
222 'fieldKey' => ['var' => 'fieldKey'],
223 'options' => ['path' => 'options'],
224 'payIntegID' => ['path' => 'payIntegID'],
225 'payType' => ['path' =>'payType', 'val' => ''],
226 ],
227 ];
228
229 return isset($configs[$fieldType]) ? $configs[$fieldType] : [];
230 }
231
232 public static function frontendScriptFile() {
233 return [
234 'observeElm' => ['priority' => 101, 'filename' => 'observeElm.min.js'],
235 'hidden-token-field' => ['priority' => 300, 'filename' => 'hidden-token-field.min.js'],
236 ];
237 }
238
239 public static function validationScriptFile() {
240 return [
241 'checkFldValidation' => ['priority' => 701, 'filename' => 'checkFldValidation.min.js'],
242 'checkMinMaxOptions' => ['priority' => 702, 'filename' => 'checkMinMaxOptions.min.js'],
243 'customOptionValidation' => ['priority' => 702, 'filename' => 'customOptionValidation.min.js'],
244 'dcsnbxFldValidation' => ['priority' => 702, 'filename' => 'dcsnbxFldValidation.min.js'],
245 'emailFldValidation' => ['priority' => 702, 'filename' => 'emailFldValidation.min.js'],
246 'fileupFldValidation' => ['priority' => 702, 'filename' => 'fileupFldValidation.min.js'],
247 'advanceFileupFldValidation' => ['priority' => 702, 'filename' => 'advanceFileUpFldValidation.min.js'],
248 'phoneNumberFldValidation' => ['priority' => 702, 'filename' => 'phoneNumberFldValidation.min.js'],
249 'generateBackslashPattern' => ['priority' => 700, 'filename' => 'generateBackslashPattern.min.js'],
250 'nmbrFldValidation' => ['priority' => 702, 'filename' => 'nmbrFldValidation.min.js'],
251 'regexPatternValidation' => ['priority' => 701, 'filename' => 'regexPatternValidation.min.js'], // load before generateBackslashPattern file, then load regexPatternValidation
252 'requiredFldValidation' => ['priority' => 700, 'filename' => 'requiredFldValidation.min.js'],
253 'urlFldValidation' => ['priority' => 702, 'filename' => 'urlFldValidation.min.js'],
254 'validation' => ['priority' => 705, 'filename' => 'validateForm.min.js'], // last priority for validation script
255 'conditionalLogic' => ['priority' => 705, 'filename' => 'bit-conditionals.min.js'], // last priority for validation script
256 'validateFocusLost' => ['priority' => 706, 'filename' => 'validate-focus.min.js'], // last priority for validation script
257 ];
258 }
259
260 public static function validationCommonFunction() {
261 $commonFunctions = [
262 'requiredFldValidation' => [
263 'fields' => ['text', 'email'] // string { all} or array {field name} of field types
264 ],
265 'commonFuncion2' => [
266 'notFields' => ['text', 'email'],
267 'dependencies' => ['someDependsOnThisField'],
268 'paths' => ['path1', 'path2'],
269 ],
270 ];
271
272 return $commonFunctions;
273 }
274
275 public static function validationScriptFileMapping($fieldType) {
276 $textTypeField = ['text', 'password', 'username', 'url', 'date', 'datetime-local', 'time', 'month', 'week', 'color'];
277 if (in_array($fieldType, $textTypeField)) {
278 $fieldType = 'text';
279 }
280 $fields =
281 [
282 'text' => [
283 'regexPatternValidation' => [
284 'paths' => ['valid->regexr'],
285 'dependencies' => [
286 'generateBackslashPattern'
287 ]
288 ]
289 ],
290 'email' => [
291 'emailFldValidation' => [
292 'paths' => ['err->invalid->show'],
293 'dependencies' => [
294 'generateBackslashPattern'
295 ]
296 ],
297 ],
298 'number' => [
299 'nmbrFldValidation' => [
300 'paths' => ['mn', 'mx']
301 ]
302 ],
303 'radio' => [
304 'customOptionValidation' => [
305 'paths' => ['valid->otherOptReq'],
306 ]
307 ],
308 'check' => [
309 'checkMinMaxOptions' => [
310 'paths' => ['mn', 'mx'],
311 'dependencies' => [
312 'checkFldValidation'
313 ]
314 ],
315 'customOptionValidation' => [
316 'paths' => ['valid->otherOptReq'],
317 ]
318 ],
319 'select' => [
320 'checkMinMaxOptions' => [
321 'paths' => ['mn', 'mx'],
322 'dependencies' => [
323 'checkFldValidation'
324 ]
325 ],
326 ],
327 'url' => [
328 'urlFldValidation' => [
329 'paths' => ['err->invalid->show'],
330 'dependencies' => [
331 'generateBackslashPattern'
332 ]
333 ]
334 ],
335 'decision-box' => [
336 'dcsnbxFldValidation' => [
337 'paths' => ['valid->req']
338 ]
339 ],
340 'file-up' => [
341 'fileupFldValidation' => [
342 'paths' => ['valid->req']
343 ]
344 ],
345 'advanced-file-up' => [
346 'advanceFileupFldValidation' => [
347 'paths' => ['valid->req']
348 ]
349 ],
350 'phone-number' => [
351 'phoneNumberFldValidation' => [
352 'paths' => ['err->invalid->show'],
353 ]
354 ],
355 ];
356 return isset($fields[$fieldType]) ? $fields[$fieldType] : [];
357 }
358 }
359