PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.7.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.7.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
← All changes | includes/Admin/Form/AdminFormHandler.php +245 -945 3.2.12.7.0 View file →
@@ -16,21 +16,19 @@
16 16 use BitCode\BitForm\Core\Database\IntegrationModel;
17 17 use BitCode\BitForm\Core\Database\ReportsModel;
18 18 use BitCode\BitForm\Core\Database\SuccessMessageModel;
19 19 use BitCode\BitForm\Core\Database\WorkFlowModel;
20 -use BitCode\BitForm\Core\Form\FormManager;
21 20 use BitCode\BitForm\Core\Integration\IntegrationHandler;
22 21 use BitCode\BitForm\Core\Messages\EmailTemplateHandler;
22 +use BitCode\BitForm\Core\Messages\PdfTemplateHandler;
23 23 use BitCode\BitForm\Core\Messages\SuccessMessageHandler;
24 -use BitCode\BitForm\Core\Migration\MigrationHelper;
25 24 use BitCode\BitForm\Core\Util\FileHandler;
26 25 use BitCode\BitForm\Core\Util\FormDuplicateHelper;
27 26 use BitCode\BitForm\Core\Util\HttpHelper;
28 27 use BitCode\BitForm\Core\Util\IpTool;
29 -use BitCode\BitForm\Core\Util\Log;
30 -use BitCode\BitForm\Core\Util\Utilities;
31 28 use BitCode\BitForm\Core\WorkFlow\WorkFlow;
32 29 use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler;
30 +use BitCode\BitFormPro\Admin\AppSetting\Pdf;
33 31 use WP_Error;
34 32
35 33 class AdminFormHandler
36 34 {
@@ -56,9 +54,9 @@
56 54 $form_content_raw = $templateProvider->getTemplate($templateName, $newFormId);
57 55 if (!$form_content_raw) {
58 56 return new WP_Error('template_empty', __('Template not found, by this name: ', 'bit-form') . $templateName);
59 57 } else {
60 - return wp_json_encode(
58 + return \json_encode(
61 59 [
62 60 'id' => 0,
63 61 'form_content' => $form_content_raw,
64 62 ]
@@ -71,12 +69,14 @@
71 69 $this->createFormStylesDirIfNotExists();
72 70
73 71 if (
74 72 file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
75 - && wp_is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
73 + && is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
76 74 ) {
77 - $filePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName;
78 - return FileHandler::writeFile($filePath, $styles);
75 + $createStyleFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName, 'w');
76 + fwrite($createStyleFile, $styles);
77 + fclose($createStyleFile);
78 + return true;
79 79 }
80 80 return false;
81 81 }
82 82
@@ -86,9 +86,9 @@
86 86 $sm_width = 400;
87 87 $lg_styles = '';
88 88 $md_styles = '';
89 89 $sm_styles = '';
90 - for ($i = 0; $i < count($layout->lg ?? []); $i++) {
90 + for ($i = 0; $i < count($layout->lg); $i++) {
91 91 $fld = $layout->lg[$i];
92 92
93 93 if ($fld->w < 10) {
94 94 $lay_row_height = 43;
@@ -152,12 +152,14 @@
152 152 $this->createFormStylesDirIfNotExists();
153 153
154 154 if (
155 155 file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
156 - && wp_is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
156 + && is_writable(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')
157 157 ) {
158 - $filePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName;
159 - return FileHandler::writeFile($filePath, $formStyle);
158 + $createStyleFile = fopen(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . $sheetName, 'w');
159 + fwrite($createStyleFile, $formStyle);
160 + fclose($createStyleFile);
161 + return true;
160 162 }
161 163 return false;
162 164 }
163 165
@@ -173,9 +175,10 @@
173 175
174 176 private function pdfFontDownload($fontName)
175 177 {
176 178 if (class_exists('\BitCode\BitFormPro\Admin\AppSetting\Pdf')) {
177 - \BitCode\BitFormPro\Admin\AppSetting\Pdf::getInstance()->fontsDownload($fontName);
179 + $pdf = new Pdf();
180 + $pdf->fontsDownload($fontName);
178 181 }
179 182 return false;
180 183 }
181 184
@@ -191,8 +194,17 @@
191 194 if ($formManager->isExist()) {
192 195 return new WP_Error('empty_form', __('Error Occurred, Please Reload', 'bit-form'));
193 196 }
194 197
198 + if (!class_exists('BitCode\\BitFormPro\\Plugin')) {
199 + if (!empty($workFlows) && count($workFlows) > 2) {
200 + return new WP_Error(
201 + 'free_limit',
202 + __('You are allowed to add maximum 2 workflows ', 'bit-form')
203 + );
204 + }
205 + }
206 +
195 207 if (isset($post->formStyle) && $post->formStyle) {
196 208 $sheetName = 'bitform-' . $post->form_id . '.css';
197 209 $this->saveStyleSheet($post->formStyle, $sheetName);
198 210 }
@@ -198,20 +210,18 @@
198 210 }
199 211
200 212 if (isset($post->layoutChanged) && $post->layoutChanged) {
201 213 $sheetName = 'bitform-layout-' . $post->form_id . '.css';
202 - $rowHeight = (int) $post->rowHeight;
214 + $rowHeight = (int)$post->rowHeight;
203 215 $this->saveLayoutStyleSheet($post->layout, $sheetName, $rowHeight);
204 216 }
205 217
206 218 $fields = wp_unslash($post->fields);
207 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
208 219 // $fields = $post->fields;
209 220 $layout = wp_unslash($post->layout);
210 - $nestedLayout = isset($post->nestedLayouts) ? wp_unslash($post->nestedLayouts) : (object) [];
221 + $nestedLayout = wp_unslash($post->nestedLayout);
211 222 $formInfo = wp_unslash($post->formInfo);
212 223 $form_name = wp_unslash($post->form_name);
213 - $form_name = strlen($form_name) > 50 ? substr($form_name, 0, 50) : $form_name;
214 224 $formSettings = (object) wp_unslash($post->formSettings);
215 225 $atomic_class_map = isset($post->atomicClassMap) ? wp_unslash($post->atomicClassMap) : [];
216 226 $breakpointSize = wp_unslash($post->breakpointSize);
217 227 $style = $post->style;
@@ -225,9 +235,8 @@
225 235
226 236 $mailTem = $formSettings->mailTem;
227 237 $pdfTem = $formSettings->pdfTem;
228 238 $integrations = $formSettings->integrations;
229 - $formPermissions = $formSettings->formPermissions;
230 239
231 240 $user_details = static::$ipTool->getUserDetail();
232 241 if (empty($fields) || empty($layout)) {
233 242 return new WP_Error(
@@ -240,12 +249,8 @@
240 249 'empty_form',
241 250 __('Form Name Should Be Within 50 Characters', 'bit-form')
242 251 );
243 252 }
244 - // Guard: never persist orphan fields (in fields but in no layout) — they
245 - // render nothing yet their validation rules block submission. Covers old
246 - // clients and hand-edited imports (importAForm funnels through here).
247 - $this->pruneOrphanFields($fields, $nestedLayout, $layout, null, $post);
248 253 $form_content = [
249 254 'fields' => $fields,
250 255 'layout' => $layout,
251 256 'nestedLayout' => $nestedLayout,
@@ -258,12 +263,8 @@
258 263 if (!empty($formSettings->theme)) {
259 264 $form_content = array_merge($form_content, ['theme' => $formSettings->theme]);
260 265 }
261 266
262 - if (!empty($formSettings->formPermissions)) {
263 - $form_content = array_merge($form_content, ['formPermissions' => $formSettings->formPermissions]);
264 - }
265 -
266 267 if (!empty($additional)) {
267 268 $form_content = array_merge($form_content, ['additional' => $additional]);
268 269 }
269 270 if (!empty($workFlows)) {
@@ -311,11 +312,10 @@
311 312 return $save_status;
312 313 } elseif (!$save_status) {
313 314 return false;
314 315 } else {
315 - FileHandler::createIndexFile(BITFORMS_UPLOAD_DIR . "/$save_status");
316 + wp_mkdir_p(BITFORMS_UPLOAD_DIR . "/$save_status");
316 317 $formID = $save_status;
317 - do_action('bitform_admin_form_changed');
318 318 $integartionIDForWorkflow = [];
319 319 // Confiramtion Message [start]
320 320 if (!empty($formSettings->confirmation->type->successMsg)) {
321 321 $successMessages = $formSettings->confirmation->type->successMsg;
@@ -322,13 +322,10 @@
322 322 $successMessageHandler = new SuccessMessageHandler($formID, $user_details);
323 323 foreach ($successMessages as $messageKey => $messageDetail) {
324 324 $savedID = $successMessageHandler->saveMessage($messageDetail);
325 325 if ($savedID) {
326 - $msgIdx = empty($messageDetail->id) ? $messageKey : wp_json_encode(['id' => $messageDetail->id]);
326 + $msgIdx = empty($messageDetail->id) ? $messageKey : \json_encode(['id' => $messageDetail->id]);
327 327 $integartionIDForWorkflow['successMsg'][$msgIdx] = $savedID;
328 - if (!empty($messageDetail->clRef)) {
329 - $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
330 - }
331 328 $messageDetail->id = $savedID;
332 329 $style = $this->updateSuccessMessageClassName($style, $messageKey, $savedID);
333 330 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
334 331 }
@@ -341,10 +338,10 @@
341 338 'builderSettings' => $builderSettings
342 339 ];
343 340 $update_status = static::$formModel->update(
344 341 [
345 - 'builder_helper_state' => \wp_json_encode($builder_helper_state),
346 - 'atomic_class_map' => $atomic_class_map,
342 + 'builder_helper_state' => \wp_json_encode($builder_helper_state),
343 + 'atomic_class_map' => $atomic_class_map,
347 344 ],
348 345 [
349 346 'id' => $formID,
350 347 ]
@@ -361,55 +358,31 @@
361 358 $emailTemplateHandler
362 359 = new EmailTemplateHandler($formID, $user_details);
363 360 foreach ($mailTem as $templateKey => $templateDetail) {
364 361 $savedID = $emailTemplateHandler->saveTemplate($templateDetail);
365 - if ($savedID && !is_wp_error($savedID)) {
366 - $tempIdx = empty($templateDetail->id) ? $templateKey : wp_json_encode(['id' => $templateDetail->id]);
362 + if ($savedID) {
363 + $tempIdx = empty($templateDetail->id) ? $templateKey : \json_encode(['id' => $templateDetail->id]);
367 364 $integartionIDForWorkflow['mailNotify'][$tempIdx] = $savedID;
368 - if (!empty($templateDetail->clRef)) {
369 - $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
370 - }
371 - // return the new id (and drop the temp ref) so the frontend reconciles the template
372 - $templateDetail->id = $savedID;
373 - unset($templateDetail->clRef);
374 365 }
375 366 }
376 367 }
377 368 // Email Template [end] */
369 + // if (!empty($pdfTem)) {
370 + // $pdfTemplateHandler = new PdfTemplateHandler($formID);
371 + // foreach ($pdfTem as $templateKey => $templateDetail) {
372 + // $savedID = $pdfTemplateHandler->save($templateDetail);
378 373
379 - // PDF Template [start]
380 - if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
381 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
382 - $workFlowString = '';
383 - if (!empty($workFlows)) {
384 - $workFlowString = wp_json_encode($workFlows);
385 - }
386 - foreach ($pdfTem as $templateDetail) {
387 - $savedID = $pdfTemplateHandler->save($templateDetail);
374 + // $pdfSetting = $templateDetail->setting;
388 375
389 - $pdfSetting = $templateDetail->setting;
390 -
391 - if (isset($pdfSetting->font->name) && !empty($pdfSetting->font->name)) {
392 - $this->pdfFontDownload($pdfSetting->font->name);
393 - }
394 - if (!empty($workFlowString)) {
395 - $workFlowString = str_replace('"pdfId":"{\"id\":\"' . $templateDetail->id . '\"}"', '"pdfId":"{\"id\":\"' . $savedID . '\"}"', $workFlowString);
396 - // Multi-PDF: remap ids inside "pdfIds":[...] segments only — email-template ids use
397 - // the same {\"id\":N} token shape, so a global replace would corrupt them.
398 - $workFlowString = preg_replace_callback(
399 - '/"pdfIds":\[[^\]]*\]/',
400 - function ($matches) use ($templateDetail, $savedID) {
401 - return str_replace('{\"id\":\"' . $templateDetail->id . '\"}', '{\"id\":\"' . $savedID . '\"}', $matches[0]);
402 - },
403 - $workFlowString
404 - );
405 - }
406 - }
407 - if (!empty($workFlowString) && !empty($workFlows)) {
408 - $workFlows = json_decode($workFlowString);
409 - }
410 - }
411 - // PDF Template [end] */
376 + // if( isset($pdfSetting->font->name) && !empty($pdfSetting->font->name)) {
377 + // $this->pdfFontDownload($pdfSetting->font->name);
378 + // }
379 + // // if ($savedID) {
380 + // // $tempIdx = empty($templateDetail->id) ? $templateKey : \json_encode(['id' => $templateDetail->id]);
381 + // // $integartionIDForWorkflow['mailNotify'][$tempIdx] = $savedID;
382 + // // }
383 + // }
384 + // }
412 385 //Integration [start] */
413 386 $integrationHandler = new IntegrationHandler($formID, $user_details);
414 387 if (!empty($formSettings->confirmation->type)) {
415 388 $allIntegrations = $formSettings->confirmation->type;
@@ -414,14 +387,8 @@
414 387 if (!empty($formSettings->confirmation->type)) {
415 388 $allIntegrations = $formSettings->confirmation->type;
416 389 foreach ($allIntegrations as $integrationType => $integrationGroup) {
417 390 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
418 - $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
419 - // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
420 - $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
421 - if (is_object($singleIntegrationDetail)) {
422 - unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
423 - }
424 391 if (empty($singleIntegrationDetail->details)) {
425 392 $integrationName = $singleIntegrationDetail->title;
426 393 unset($singleIntegrationDetail->title, $singleIntegrationDetail->id);
427 394
@@ -431,25 +398,14 @@
431 398 $integrationName = $singleIntegrationDetail->title;
432 399 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
433 400 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
434 401 }
435 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
436 - $integIdx = empty($singleIntegrationDetail->id) ? $savedID : wp_json_encode(['id' => $singleIntegrationDetail->id]);
402 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
403 + $integIdx = empty($singleIntegrationDetail->id) ? $savedID : \json_encode(['id' => $singleIntegrationDetail->id]);
437 404 $integartionIDForWorkflow[$integrationType][$integIdx] = $savedID;
438 - if (!empty($clRef) && 'redirectPage' === $integrationType) {
439 - $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
440 - }
441 405 }
442 406 }
443 407 }
444 - if (isset($formSettings->formAbandonment)) {
445 - $formAbandonment = $formSettings->formAbandonment;
446 -
447 - $integrationName = 'formAbandonment';
448 - $integrationType = 'formAbandonment';
449 - $abandonmentIntegDetails = wp_json_encode($formAbandonment);
450 - $integrationHandler->saveIntegration($integrationName, $integrationType, $abandonmentIntegDetails, 'formAbandonment');
451 - }
452 408 if (!empty($integrations)) {
453 409 foreach ($integrations as $singleIntegrationKey => $singleIntegrationDetail) {
454 410 $integrationName = $singleIntegrationDetail->name;
455 411 unset($singleIntegrationDetail->name);
@@ -456,11 +412,8 @@
456 412 $integrationType = $singleIntegrationDetail->type;
457 413 unset($singleIntegrationDetail->type);
458 414 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
459 415 unset($singleIntegrationDetail->id);
460 - // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
461 - $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
462 - unset($singleIntegrationDetail->__bf_cl_ref);
463 416 if (empty($singleIntegrationDetail->details)) {
464 417 $integrationDetails = !is_string($singleIntegrationDetail) ?
465 418 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
466 419 } else {
@@ -467,13 +420,10 @@
467 420 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
468 421 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
469 422 }
470 423 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
471 - $integIdx = empty($singleIntegrationDetailID) ? $singleIntegrationKey : wp_json_encode(['id' => $singleIntegrationDetailID]);
424 + $integIdx = empty($singleIntegrationDetailID) ? $singleIntegrationKey : \json_encode(['id' => $singleIntegrationDetailID]);
472 425 $integartionIDForWorkflow['integ'][$integIdx] = $savedID;
473 - if (!empty($clRef) && !is_wp_error($savedID)) {
474 - $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
475 - }
476 426 }
477 427 }
478 428 //Integrations [end]
479 429 //wrokFlows [start]
@@ -493,10 +443,10 @@
493 443 // }
494 444 }
495 445 //wrokFlows [end]
496 446 $details = [
497 - 'report_name' => __('All Entries', 'bit-form'),
498 - 'hiddenColumns' => ['__user_id', '__user_ip', '__referer', '__user_device', '__created_at', '__updated_at'],
447 + 'report_name' => 'All Entries',
448 + 'hiddenColumns' => [],
499 449 'pageSize' => 10,
500 450 'sortBy' => [],
501 451 'filters' => [],
502 452 'globalFilter' => '',
@@ -555,14 +505,13 @@
555 505 if (property_exists($post, 'builderSettings')) {
556 506 $builder_helper_state->builderSettings = $post->builderSettings;
557 507 }
558 508 if (property_exists($post, 'atomicClassMap')) {
559 - $atomic_class_map = \wp_json_encode((object) $post->atomicClassMap);
509 + $atomic_class_map = \wp_json_encode((object)$post->atomicClassMap);
560 510 }
561 511
562 512 if (property_exists($post, 'fields') && null !== $post->fields && property_exists($post, 'layout') && $post->layout) {
563 513 $fields = wp_unslash($post->fields);
564 - $fields = Helpers::replaceFieldsDefaultErrorMsg($fields);
565 514 $layout = wp_unslash($post->layout);
566 515 $nestedLayout = wp_unslash($post->nestedLayouts);
567 516 $formInfo = wp_unslash($post->formInfo);
568 517 $formID = wp_unslash($post->id);
@@ -573,9 +522,9 @@
573 522 $reports = wp_unslash($post->currentReport);
574 523 }
575 524
576 525 $mailTem = $formSettings->mailTem;
577 - $pdfTem = isset($formSettings->pdfTem) ? $formSettings->pdfTem : [];
526 + $pdfTem = $formSettings->pdfTem;
578 527 $integrations = $formSettings->integrations;
579 528
580 529 $user_details = static::$ipTool->getUserDetail();
581 530
@@ -582,10 +531,16 @@
582 531 if (empty($fields) || empty($layout) || is_null($formID)) {
583 532 return new WP_Error('empty_form', 'Can not update empty form.');
584 533 }
585 534
586 - // Guard: never persist orphan fields (see createNewForm). Fail closed.
587 - $this->pruneOrphanFields($fields, $nestedLayout, $layout, $formID, $post);
535 + if (!class_exists('BitCode\\BitFormPro\\Plugin')) {
536 + if (count($workFlows) > 2) {
537 + return new WP_Error(
538 + 'free_limit',
539 + __('You are allowed to add maximum 2 workflows ', 'bit-form')
540 + );
541 + }
542 + }
588 543
589 544 $form_content = [
590 545 'fields' => $fields,
591 546 'layout' => $layout,
@@ -602,12 +557,8 @@
602 557 } */
603 558 if (!empty($formSettings->theme)) {
604 559 $form_content = array_merge($form_content, ['theme' => $formSettings->theme]);
605 560 }
606 -
607 - if (!empty($formSettings->formPermissions)) {
608 - $form_content = array_merge($form_content, ['formPermissions' => $formSettings->formPermissions]);
609 - }
610 561 if (!empty($additional)) {
611 562 $form_content = array_merge($form_content, ['additional' => $additional]);
612 563 }
613 564 $integartionIDForWorkflow = [];
@@ -615,9 +566,8 @@
615 566 $newData['integation'] = 0;
616 567 $newData['mailTemplate'] = 0;
617 568 $newData['workflow'] = 0;
618 569 $newData['reports'] = 0;
619 - $newData['pdfTemplate'] = 0;
620 570 // Confiramtion Message [start]
621 571 if (!empty($formSettings->confirmation->type->successMsg)) {
622 572 $successMessages = $formSettings->confirmation->type->successMsg;
623 573 $successMessageHandler
@@ -627,11 +577,8 @@
627 577 $savedID = $successMessageHandler->saveMessage($messageDetail);
628 578 if ($savedID) {
629 579 $newData['settingConfiramation'] = 1;
630 580 $integartionIDForWorkflow['successMsg'][$messageKey] = $savedID;
631 - if (!empty($messageDetail->clRef)) {
632 - $integartionIDForWorkflow['confirmationCLRef'][$messageDetail->clRef] = $savedID;
633 - }
634 581 $messageDetail->id = $savedID;
635 582 $builder_helper_state->style = $this->updateSuccessMessageClassName($builder_helper_state->style, $messageKey, $savedID);
636 583 if (isset($atomic_class_map)) {
637 584 $atomic_class_map = $this->updateSuccessMessageClassName($atomic_class_map, $messageKey, $savedID);
@@ -656,29 +603,18 @@
656 603 $newData['mailTemplate'] = 2;
657 604 } else {
658 605 $newData['mailTemplate'] = 1;
659 606 $integartionIDForWorkflow['mailTem'][$templateKey] = $savedID;
660 - if (!empty($templateDetail->clRef)) {
661 - $integartionIDForWorkflow['emailCLRef'][$templateDetail->clRef] = $savedID;
662 - }
663 - // return the new id (and drop the temp ref) so the frontend reconciles the template
664 - $templateDetail->id = $savedID;
665 - unset($templateDetail->clRef);
666 607 }
667 608 } else {
668 - $updated = $emailTemplateHandler->updateTemplate($templateDetail);
669 - if (is_wp_error($updated) && 'db_error' === $updated->get_error_code()) {
670 - $newData['mailTemplate'] = 2;
671 - } elseif (0 === $newData['mailTemplate']) {
672 - $newData['mailTemplate'] = 1;
673 - }
609 + $emailTemplateHandler->updateTemplate($templateDetail);
674 610 }
675 611 }
676 612 }
677 613 // return $formSettings;
678 614 // Email Template [end] */
679 - if (!empty($pdfTem) && class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
680 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
615 + if (!empty($pdfTem)) {
616 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
681 617
682 618 foreach ($pdfTem as $templateKey => $templateDetail) {
683 619 if (isset($templateDetail->setting->font->name)) {
684 620 $this->pdfFontDownload($templateDetail->setting->font->name);
@@ -698,15 +634,8 @@
698 634 if (!empty($formSettings->confirmation->type)) {
699 635 $allIntegrations = $formSettings->confirmation->type;
700 636 foreach ($allIntegrations as $integrationType => $integrationGroup) {
701 637 foreach ($integrationGroup as $singleIntegrationKey => $singleIntegrationDetail) {
702 - // Redirect (and webhook) enable/disable toggle persists to the integration status column.
703 - $integrationStatus = isset($singleIntegrationDetail->status) ? (int) $singleIntegrationDetail->status : 1;
704 - // Inline-CL temp ref for a brand-new redirect (reconciled to the real id for workflow rows).
705 - $clRef = isset($singleIntegrationDetail->clRef) ? $singleIntegrationDetail->clRef : null;
706 - if (is_object($singleIntegrationDetail)) {
707 - unset($singleIntegrationDetail->status, $singleIntegrationDetail->clRef);
708 - }
709 638 if (empty($singleIntegrationDetail->details)) {
710 639 $integrationName = $singleIntegrationDetail->title;
711 640 unset($singleIntegrationDetail->title);
712 641 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
@@ -720,16 +649,13 @@
720 649 $integrationDetails = !is_string($singleIntegrationDetail->details) ?
721 650 wp_json_encode($singleIntegrationDetail->details) : $singleIntegrationDetail->details;
722 651 }
723 652 if (empty($singleIntegrationDetailID)) {
724 - $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
653 + $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
725 654 $newData['settingConfiramation'] = 1;
726 655 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
727 - if (!empty($clRef) && 'redirectPage' === $integrationType) {
728 - $integartionIDForWorkflow['redirectCLRef'][$clRef] = $savedID;
729 - }
730 656 } else {
731 - $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form', $integrationStatus);
657 + $integrationHandler->updateIntegration($singleIntegrationDetailID, $integrationName, $integrationType, $integrationDetails, 'form');
732 658 }
733 659 }
734 660 }
735 661 }
@@ -740,11 +666,8 @@
740 666 $integrationType = $singleIntegrationDetail->type;
741 667 unset($singleIntegrationDetail->type);
742 668 $singleIntegrationDetailID = empty($singleIntegrationDetail->id) ? null : $singleIntegrationDetail->id;
743 669 unset($singleIntegrationDetail->id);
744 - // Inline-CL temp ref for a brand-new integration (reconciled to the real id for workflow rows).
745 - $clRef = isset($singleIntegrationDetail->__bf_cl_ref) ? $singleIntegrationDetail->__bf_cl_ref : null;
746 - unset($singleIntegrationDetail->__bf_cl_ref);
747 670 if (empty($singleIntegrationDetail->details)) {
748 671 $integrationDetails = !is_string($singleIntegrationDetail) ?
749 672 wp_json_encode($singleIntegrationDetail) : $singleIntegrationDetail;
750 673 } else {
@@ -753,11 +676,8 @@
753 676 }
754 677 if (empty($singleIntegrationDetailID)) {
755 678 $savedID = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'form');
756 679 $integartionIDForWorkflow[$integrationType][$singleIntegrationKey] = $savedID;
757 - if (!empty($clRef) && !is_wp_error($savedID)) {
758 - $integartionIDForWorkflow['integrationCLRef'][$clRef] = $savedID;
759 - }
760 680 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
761 681 $newData['integation'] = 2;
762 682 } else {
763 683 $newData['integation'] = 1;
@@ -781,9 +701,8 @@
781 701 }
782 702 if ('oninput' === $workFlow->action_type || ('always' === $workFlow->action_type && 'cond' === $workFlow->action_behaviour)) {
783 703 $workFlowExist['oninput'] = true;
784 704 }
785 - // $integartionIDForWorkflow = apply_filters('bitform_filter_integration_id', $workFlow, $formID, $index);
786 705 if (empty($workFlow->id)) {
787 706 $savedID = $workFlowHandler->saveworkFlow($workFlow, $integartionIDForWorkflow, $index);
788 707 if (is_wp_error($savedID) && 'result_empty' !== $savedID->get_error_code()) {
789 708 $newData['workflow'] = 2;
@@ -810,19 +729,15 @@
810 729
811 730 $fieldNames['__user_id'] = __('User', 'bit-form');
812 731 $fieldNames['__user_ip'] = __('IP address', 'bit-form');
813 732 // $fieldNames['__user_location'] = __('');
814 - $fieldNames['__referer'] = __('Refer URL', 'bit-form');
815 - $fieldNames['__user_device'] = __('Device', 'bit-form');
816 - $fieldNames['__created_at'] = __('Created Time', 'bit-form');
817 - $fieldNames['__updated_at'] = __('Modified Time', 'bit-form');
733 + $fieldNames['__referer'] = __('Refer URL');
734 + $fieldNames['__user_device'] = __('Device');
735 + $fieldNames['__created_at'] = __('Created Time');
736 + $fieldNames['__updated_at'] = __('Modified Time');
818 737
819 738 $reportIsDefault = null;
820 - // The client posts currentReport as {} whenever its report atom has not resolved yet. That
821 - // is an empty stdClass, which empty() above treats as non-empty, so we reach here with
822 - // nothing to save — and writing the validated result would replace the stored report's
823 - // column order, hidden columns, page size and name with an empty list. Leave the row alone.
824 - if (isset($form_content['report_id']) && ReportsModel::isValidatableReport($reports)) {
739 + if (isset($form_content['report_id'])) {
825 740 $validDateReport = $reportsModel->validateReportFields($reports, $fieldNames);
826 741 if (isset($reports->isDefault)) {
827 742 $reportIsDefault = $reports->isDefault;
828 743 } else {
@@ -857,12 +772,12 @@
857 772 $abandonmentInteg = $abandonmentInteg[0];
858 773 }
859 774 if (isset($abandonmentInteg->id)) {
860 775 $abandonmentIntegID = $abandonmentInteg->id;
861 - $abandonmentIntegDetails = wp_json_encode($formAbandonment);
776 + $abandonmentIntegDetails = json_encode($formAbandonment);
862 777 $integrationHandler->updateIntegration($abandonmentIntegID, 'formAbandonment', 'formAbandonment', $abandonmentIntegDetails, 'formAbandonment');
863 778 } else {
864 - $abandonmentIntegDetails = wp_json_encode($formAbandonment);
779 + $abandonmentIntegDetails = json_encode($formAbandonment);
865 780 $integrationHandler->saveIntegration('formAbandonment', 'formAbandonment', $abandonmentIntegDetails, 'formAbandonment');
866 781 }
867 782 }
868 783 //form abandonment [end]
@@ -871,9 +786,9 @@
871 786 'form_name' => $form_name,
872 787 'form_content' => $form_content,
873 788 'user_id' => $user_details['id'],
874 789 'user_ip' => $user_details['ip'],
875 - 'builder_helper_state' => \wp_json_encode((object) $builder_helper_state),
790 + 'builder_helper_state' => \wp_json_encode((object)$builder_helper_state),
876 791 'generated_script_page_ids' => \wp_json_encode((object) []),
877 792 'user_device' => $user_details['device'],
878 793 'updated_at' => $user_details['time'],
879 794 ];
@@ -879,16 +794,15 @@
879 794 ];
880 795 if (isset($atomic_class_map)) {
881 796 $updateData['atomic_class_map'] = $atomic_class_map;
882 797 }
883 - $formUpdateVersion = get_option('bitform_form_update_version');
798 + $formUpdateVersion = get_option('bit-form_form_update_version');
884 799 if (!$formUpdateVersion) {
885 800 $formUpdateVersion = 1;
886 801 } else {
887 802 $formUpdateVersion = (int) $formUpdateVersion + 1;
888 803 }
889 - update_option('bitform_form_update_version', $formUpdateVersion);
890 - do_action('bitform_admin_form_changed');
804 + update_option('bit-form_form_update_version', $formUpdateVersion);
891 805
892 806 $update_status = static::$formModel->update(
893 807 $updateData,
894 808 [
@@ -906,9 +820,9 @@
906 820 }
907 821
908 822 $updated_data = $this->getAForm(['id' => $formID], null);
909 823
910 - if (0 === $newData['settingConfiramation'] && 0 === $newData['mailTemplate'] && 0 === $newData['integation'] && 0 === $newData['pdfTemplate']) {
824 + if (0 === $newData['settingConfiramation'] && 0 === $newData['mailTemplate'] && 0 === $newData['integation']) {
911 825 unset($updated_data['formSettings']);
912 826 }
913 827 if (0 === $newData['integation']) {
914 828 unset($updated_data['integrations']);
@@ -920,13 +834,13 @@
920 834 unset($updated_data['mailTem']);
921 835 } elseif (2 === $newData['mailTemplate']) {
922 836 $errorIN .= empty($errorIN) ? 'mailTemplate' : ', mailTemplate';
923 837 }
924 - if (0 === $newData['pdfTemplate']) {
925 - unset($updated_data['pdfTem']);
926 - } elseif (2 === $newData['pdfTemplate']) {
927 - $errorIN .= empty($errorIN) ? 'pdfTemplate' : ', pdfTemplate';
928 - }
838 + // if (0 === $newData['pdfTemplate']) {
839 + // unset($updated_data['pdfTem']);
840 + // } elseif (2 === $newData['pdfTemplate']) {
841 + // $errorIN .= empty($errorIN) ? 'pdfTemplate' : ', pdfTemplate';
842 + // }
929 843 if (0 === $newData['workflow']) {
930 844 unset($updated_data['workFlows']);
931 845 } elseif (2 === $newData['workflow']) {
932 846 $errorIN .= empty($errorIN) ? 'workflow' : ', workflow';
@@ -934,9 +848,8 @@
934 848 if (2 === $newData['reports']) {
935 849 $errorIN .= empty($errorIN) ? 'reports' : ', reports';
936 850 }
937 851 if (!empty($errorIN)) {
938 - /* translators: %s: comma-separated list of areas where error occurred */
939 852 $updated_data['message'] = sprintf(__('Error Occured in saving %s', 'bit-form'), $errorIN);
940 853 return new WP_Error('Form update Error.', $updated_data);
941 854 }
942 855 if (null !== $reportIsDefault) {
@@ -941,76 +854,30 @@
941 854 }
942 855 if (null !== $reportIsDefault) {
943 856 $updated_data['form_content']['is_default'] = $reportIsDefault;
944 857 }
945 - $updated_data['message'] = __('Form updated successfully.', 'bit-form');
858 + $updated_data['message'] = __('Form updated successfully.', 'bitform');
946 859 return $updated_data;
947 860 }
948 861 }
949 862
950 - /**
951 - * Drop orphan fields (present in `fields` but in no layout) from form_content
952 - * before persisting, and remove now-childless nestedLayout entries.
953 - *
954 - * Entry meta is NEVER touched here — only explicit user deletes clear meta
955 - * (see setEmptyMetaValue). Fail closed: an unusable/partial layout, or a
956 - * client that flagged a failed pre-save layout sync (->skipOrphanPrune),
957 - * prunes nothing. Pruned keys are logged, never silently dropped.
958 - *
959 - * @param object|array $fields by ref; orphan keys removed
960 - * @param object|null $nestedLayout by ref; stale container entries removed
961 - * @param array|object $layout raw layout (single or multi-step)
962 - * @param int|string|null $formID for logging ('new' when absent)
963 - * @param object $post raw request; honors ->skipOrphanPrune
964 - */
965 - private function pruneOrphanFields(&$fields, &$nestedLayout, $layout, $formID, $post)
966 - {
967 - $formLabel = $formID ? $formID : 'new';
968 - if (isset($post->skipOrphanPrune) && $post->skipOrphanPrune) {
969 - Log::debug_log('Bit Form: orphan prune skipped (client reported failed layout sync). FormID=' . $formLabel);
970 - return;
971 - }
972 - $orphanFldKeys = FormManager::computeOrphanFieldKeys($layout, $nestedLayout, $fields);
973 - // null = unusable/partial layout (fail closed); [] = nothing to prune
974 - if (!is_array($orphanFldKeys) || empty($orphanFldKeys)) {
975 - return;
976 - }
977 - Log::debug_log('Bit Form: pruning orphan fields (absent from every layout). FormID=' . $formLabel . ' keys=' . implode(',', $orphanFldKeys));
978 - foreach ($orphanFldKeys as $orphanKey) {
979 - if (is_object($fields)) {
980 - unset($fields->{$orphanKey});
981 - } elseif (is_array($fields)) {
982 - unset($fields[$orphanKey]);
983 - }
984 - }
985 - // prune stale nestedLayout entries — containers that no longer exist in fields
986 - if (is_object($nestedLayout)) {
987 - foreach (array_keys(get_object_vars($nestedLayout)) as $nKey) {
988 - $parentExists = is_object($fields) ? isset($fields->{$nKey}) : isset($fields[$nKey]);
989 - if (!$parentExists) {
990 - unset($nestedLayout->{$nKey});
991 - }
992 - }
993 - }
994 - }
995 -
996 863 public function setEmptyMetaValue($fieldkeys)
997 864 {
865 + $sqlEscaped = array_map(function ($fld) {
866 + return "'" . esc_sql($fld) . "'";
867 + }, $fieldkeys);
868 + $deletedFldKey = implode(',', $sqlEscaped);
998 869 global $wpdb;
999 - // Placeholders and arguments built dynamically from $fieldkeys; count matches at runtime.
1000 - $placeholders = implode(',', array_fill(0, \count($fieldkeys), '%s'));
1001 - $wpdb->query($wpdb->prepare(
1002 - "UPDATE `{$wpdb->prefix}bitforms_form_entrymeta` SET meta_value = %s WHERE meta_key IN ($placeholders)",
1003 - '',
1004 - ...$fieldkeys
1005 - ));
870 + $tablename = $wpdb->prefix . 'bitforms_form_entrymeta';
871 + $sql = $wpdb->prepare("UPDATE $tablename SET meta_value = %s WHERE meta_key IN ( " . $deletedFldKey . ')', '');
872 + $wpdb->query($sql);
1006 873 }
1007 874
1008 875 public function changeFormStatus($Request, $post)
1009 876 {
1010 877 if (isset($Request['status']) && $Request['id']) {
1011 - $status = sanitize_text_field(wp_unslash($Request['status']));
1012 - $id = absint(wp_unslash($Request['id']));
878 + $status = wp_unslash($Request['status']);
879 + $id = wp_unslash($Request['id']);
1013 880 } else {
1014 881 $status = wp_unslash($post->status);
1015 882 $id = wp_unslash($post->id);
1016 883 }
@@ -1044,10 +911,10 @@
1044 911
1045 912 public function changeBulkFormStatus($Request, $post)
1046 913 {
1047 914 if (isset($Request['status']) && $Request['formID']) {
1048 - $status = sanitize_text_field(wp_unslash($Request['status']));
1049 - $formID = array_map('absint', wp_unslash($Request['formID']));
915 + $status = wp_unslash($Request['status']);
916 + $formID = wp_unslash($Request['formID']);
1050 917 } else {
1051 918 $status = wp_unslash($post->status);
1052 919 $formID = wp_unslash($post->formID);
1053 920 }
@@ -1082,13 +949,9 @@
1082 949 public function getAllForm()
1083 950 {
1084 951 global $wpdb;
1085 952
1086 - // Direct query: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize table names.
1087 - $allForms = $wpdb->get_results("SELECT forms.id,forms.entries as fm_entries,forms.form_name,forms.status,forms.views,forms.created_at,COUNT(entries.id) as entries
1088 - FROM `{$wpdb->prefix}bitforms_form` as forms
1089 - LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id
1090 - GROUP BY forms.id");
953 + $allForms = $wpdb->get_results("SELECT forms.id,forms.entries as fm_entries,forms.form_name,forms.status,forms.views,forms.created_at,COUNT(entries.id) as entries FROM `{$wpdb->prefix}bitforms_form` as forms LEFT JOIN `{$wpdb->prefix}bitforms_form_entries` as entries ON forms.id = entries.form_id GROUP BY forms.id");
1091 954
1092 955 if (is_wp_error($allForms)) {
1093 956 return $allForms;
1094 957 } elseif (!$allForms) {
@@ -1099,10 +962,10 @@
1099 962 }
1100 963
1101 964 public function getAForm($Request, $post)
1102 965 {
1103 - if (!empty($Request['id'])) {
1104 - $formID = absint(wp_unslash($Request['id']));
966 + if (isset($Request['id'])) {
967 + $formID = wp_unslash($Request['id']);
1105 968 } else {
1106 969 $formID = wp_unslash($post->id);
1107 970 }
1108 971 // return $post->fields;
@@ -1121,9 +984,9 @@
1121 984 'nestedLayout' => !empty($form_content->nestedLayout) ? $form_content->nestedLayout : (object) [],
1122 985 'formInfo' => !empty($form_content->formInfo) ? $form_content->formInfo : (object) ['formName' => $formManager->getFormName()],
1123 986 'fields' => $form_content->fields,
1124 987 'form_name' => $formManager->getFormName(),
1125 - 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
988 + 'workFlowExist' => $form_content->workFlowExist,
1126 989 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1127 990 ];
1128 991 $successMessageHandler
1129 992 = new SuccessMessageHandler($formID);
@@ -1146,37 +1009,28 @@
1146 1009 if (!is_wp_error($emailTemplates)) {
1147 1010 foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1148 1011 $mailTem[] =
1149 1012 [
1150 - 'id' => $emailTemplatevalue->id,
1151 - 'title' => $emailTemplatevalue->title,
1152 - 'sub' => $emailTemplatevalue->sub,
1153 - 'body' => $emailTemplatevalue->body,
1154 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1155 - 'config' => !empty($emailTemplatevalue->config) ? json_decode($emailTemplatevalue->config) : (object) [],
1013 + 'id' => $emailTemplatevalue->id,
1014 + 'title' => $emailTemplatevalue->title,
1015 + 'sub' => $emailTemplatevalue->sub,
1016 + 'body' => $emailTemplatevalue->body,
1156 1017 ];
1157 1018 }
1158 1019 }
1159 1020 // get all pdf template
1160 - if (class_exists('\BitCode\BitFormPro\Core\Messages\PdfTemplateHandler')) {
1161 - $pdfTemplateHandler = new \BitCode\BitFormPro\Core\Messages\PdfTemplateHandler($formID);
1162 - $pdfTemplates = $pdfTemplateHandler->getAll();
1021 + $pdfTemplateHandler = new PdfTemplateHandler($formID);
1022 + $pdfTemplates = $pdfTemplateHandler->getAll();
1163 1023
1164 - if (!is_wp_error($pdfTemplates)) {
1165 - foreach ($pdfTemplates as $value) {
1166 - $pdfTem[] =
1167 - [
1168 - 'id' => $value->id,
1169 - 'title' => $value->title,
1170 - 'setting' => json_decode($value->setting),
1171 - 'pdf_config' => !empty($value->pdf_config) ? json_decode($value->pdf_config) : (object) [
1172 - 'status' => 1,
1173 - 'header' => '',
1174 - 'footer' => '',
1175 - ],
1176 - 'body' => $value->body,
1177 - ];
1178 - }
1024 + if (!is_wp_error($pdfTemplates)) {
1025 + foreach ($pdfTemplates as $value) {
1026 + $pdfTem[] =
1027 + [
1028 + 'id' => $value->id,
1029 + 'title' => $value->title,
1030 + 'setting' => json_decode($value->setting),
1031 + 'body' => $value->body,
1032 + ];
1179 1033 }
1180 1034 }
1181 1035
1182 1036 $integrationHandler = new IntegrationHandler($formID);
@@ -1184,11 +1038,10 @@
1184 1038 if (!is_wp_error($formIntegrations)) {
1185 1039 foreach ($formIntegrations as $integrationkey => $integrationValue) {
1186 1040 if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1187 1041 $integrationData = [
1188 - 'id' => $integrationValue->id,
1189 - 'title' => $integrationValue->integration_name,
1190 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1042 + 'id' => $integrationValue->id,
1043 + 'title' => $integrationValue->integration_name,
1191 1044 ];
1192 1045 if (!empty($integrationValue->integration_details)) {
1193 1046 $integration_details = (array) json_decode($integrationValue->integration_details);
1194 1047 $integrationData = array_merge($integration_details, $integrationData);
@@ -1214,26 +1067,11 @@
1214 1067 );
1215 1068 }
1216 1069 }
1217 1070 }
1218 -
1219 - // get form abandonment integration if exist
1220 - $formAbandonmentInteg = $integrationHandler->getAllIntegration('formAbandonment', 'formAbandonment');
1221 - if (!is_wp_error($formAbandonmentInteg) && !empty($formAbandonmentInteg)) {
1222 - $formAbandonmentInteg = $formAbandonmentInteg[0];
1223 - if (!empty($formAbandonmentInteg->integration_details)) {
1224 - $formAbandonment = json_decode($formAbandonmentInteg->integration_details);
1225 - } else {
1226 - $formAbandonment = (object) [];
1227 - }
1228 - } else {
1229 - $formAbandonment = (object) [];
1230 - }
1231 -
1232 1071 $settingsContent = [
1233 - 'formName' => $formManager->getFormName(),
1234 - 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1235 - 'formPermissions' => isset($form_content->formPermissions) ? $form_content->formPermissions : (object) [],
1072 + 'formName' => $formManager->getFormName(),
1073 + 'theme' => isset($form_content->theme) ? $form_content->theme : 'default',
1236 1074 // 'submitBtn' => $form_content->buttons,
1237 1075 ];
1238 1076
1239 1077 if (!empty($allConfirmation)) {
@@ -1292,24 +1130,8 @@
1292 1130 'pdfTem' => [],
1293 1131 ]
1294 1132 );
1295 1133 }
1296 -
1297 - if (!empty($formAbandonment)) {
1298 - $settingsContent = array_merge(
1299 - $settingsContent,
1300 - [
1301 - 'formAbandonment' => $formAbandonment,
1302 - ]
1303 - );
1304 - } else {
1305 - $settingsContent = array_merge(
1306 - $settingsContent,
1307 - [
1308 - 'formAbandonment' => (object) [],
1309 - ]
1310 - );
1311 - }
1312 1134 $formSettings = [
1313 1135 'formSettings' => $settingsContent,
1314 1136 ];
1315 1137 $data = [
@@ -1320,14 +1142,12 @@
1320 1142 'style' => $helper_states->style,
1321 1143 'themeVars' => $helper_states->themeVars,
1322 1144 'themeColors' => $helper_states->themeColors,
1323 1145 'builderSettings' => $helper_states->builderSettings,
1324 - 'customCode' => FrontEndScriptGenerator::getCustomCodes($formID),
1325 1146 'additional' => empty($form_content->additional) ? [
1326 1147 'enabled' => [
1327 1148 'blocked_ip' => false,
1328 1149 'restrict_form' => false,
1329 - 'onePerIp' => false,
1330 1150 ],
1331 1151 'settings' => [
1332 1152 'restrict_form' => [
1333 1153 'day' => [],
@@ -1342,8 +1162,9 @@
1342 1162 ],
1343 1163 'entry_limit' => null,
1344 1164 'blocked_ip' => [],
1345 1165 ],
1166 + 'onePerIp' => false,
1346 1167 ] : $form_content->additional,
1347 1168 'created_at' => $formManager->getFormMetaData()['created_at'],
1348 1169 'views' => $formManager->getFormMetaData()['views'],
1349 1170 'entries' => $formManager->getFormMetaData()['entries'],
@@ -1384,9 +1205,9 @@
1384 1205 } else {
1385 1206 $returnedReportData[$reportKey]->details = [];
1386 1207 }
1387 1208 if ('1' === (string) $reportData->isDefault) {
1388 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1209 + $returnedReportData[$reportKey]->details->report_name = 'All Entries';
1389 1210 }
1390 1211 }
1391 1212 $reports = ['reports' => $returnedReportData];
1392 1213 $data = array_merge($data, $reports);
@@ -1398,233 +1219,12 @@
1398 1219 return $data;
1399 1220 }
1400 1221 }
1401 1222
1402 - public function getAFormV1($Request, $post)
1403 - {
1404 - if (!empty($Request['id'])) {
1405 - $formID = absint(wp_unslash($Request['id']));
1406 - } else {
1407 - $formID = wp_unslash($post->id);
1408 - }
1409 - // return $post->fields;
1410 - if (is_null($formID)) {
1411 - return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1412 - }
1413 - $formManager = new AdminFormManager($formID);
1414 - if (!$formManager->isExist()) {
1415 - return new WP_Error('not_exists', __('Form is not exists.', 'bit-form'));
1416 - }
1417 - $form_content = $formManager->getFormContent();
1418 - if ($formManager->isExist()) {
1419 - $form_content_arr = [
1420 - 'layout' => $form_content->layout,
1421 - 'fields' => $form_content->fields,
1422 - 'form_name' => $formManager->getFormName(),
1423 - 'workFlowExist' => isset($form_content->workFlowExist) ? $form_content->workFlowExist : [],
1424 - 'report_id' => isset($form_content->report_id) ? $form_content->report_id : null
1425 - ];
1426 - $successMessageHandler
1427 - = new SuccessMessageHandler($formID);
1428 - $successMessages = $successMessageHandler->getAllMessage();
1429 - if (!is_wp_error($successMessages)) {
1430 - foreach ($successMessages as $sucessMessagekey => $sucessMessagevalue) {
1431 - $allConfirmation['type']['successMsg'][$sucessMessagekey] =
1432 - [
1433 - 'id' => $sucessMessagevalue->id,
1434 - 'title' => $sucessMessagevalue->message_title,
1435 - 'msg' => $sucessMessagevalue->message_content,
1436 - 'config' => !empty($sucessMessagevalue->message_config) ? json_decode($sucessMessagevalue->message_config) : (object) [],
1437 - ];
1438 - }
1439 - }
1440 - $emailTemplateHandler
1441 - = new EmailTemplateHandler($formID);
1442 - $emailTemplates = $emailTemplateHandler->getAllTemplate();
1443 - if (!is_wp_error($emailTemplates)) {
1444 - foreach ($emailTemplates as $emailTemplatekey => $emailTemplatevalue) {
1445 - $mailTem[] =
1446 - [
1447 - 'id' => $emailTemplatevalue->id,
1448 - 'title' => $emailTemplatevalue->title,
1449 - 'sub' => $emailTemplatevalue->sub,
1450 - 'body' => $emailTemplatevalue->body,
1451 - 'status' => isset($emailTemplatevalue->status) ? (int) $emailTemplatevalue->status : 1,
1452 - 'config' => !empty($emailTemplatevalue->config) ? json_decode($emailTemplatevalue->config) : (object) [],
1453 - ];
1454 - }
1455 - }
1456 - $integrationHandler = new IntegrationHandler($formID);
1457 - $formIntegrations = $integrationHandler->getAllIntegration('form');
1458 - if (!is_wp_error($formIntegrations)) {
1459 - foreach ($formIntegrations as $integrationkey => $integrationValue) {
1460 - if ('redirectPage' === $integrationValue->integration_type || 'webHooks' === $integrationValue->integration_type) {
1461 - $integrationData = [
1462 - 'id' => $integrationValue->id,
1463 - 'title' => $integrationValue->integration_name,
1464 - 'status' => isset($integrationValue->status) ? (int) $integrationValue->status : 1,
1465 - ];
1466 - if (!empty($integrationValue->integration_details)) {
1467 - // var_dump(json_decode($integrationValue->integration_details));
1468 - $integration_details = (array) json_decode($integrationValue->integration_details);
1469 - $integrationData = array_merge($integration_details, $integrationData);
1470 - } else {
1471 - $integration_details = [
1472 - 'url' => '',
1473 - ];
1474 - $integrationData = array_merge($integrationData, $integration_details);
1475 - }
1476 - $allConfirmation['type'][$integrationValue->integration_type][]
1477 - = $integrationData;
1478 - } else {
1479 - $integrationData = [
1480 - 'id' => $integrationValue->id,
1481 - 'name' => $integrationValue->integration_name,
1482 - 'type' => $integrationValue->integration_type,
1483 - ];
1484 - $integrations[] = array_merge(
1485 - $integrationData,
1486 - is_string($integrationValue->integration_details) ?
1487 - (array) json_decode($integrationValue->integration_details) :
1488 - $integrationValue->integration_details
1489 - );
1490 - }
1491 - }
1492 - }
1493 - $settingsContent = [
1494 - 'formName' => $formManager->getFormName(),
1495 - 'theme' => $form_content->theme,
1496 - // 'submitBtn' => $form_content->buttons,
1497 - ];
1498 -
1499 - if (!empty($allConfirmation)) {
1500 - $confirmation = [
1501 - 'confirmation' => $allConfirmation,
1502 - ];
1503 - } else {
1504 - $confirmation = [
1505 - 'confirmation' => ['type' => []],
1506 - ];
1507 - }
1508 - $settingsContent = array_merge($settingsContent, $confirmation);
1509 - if (!empty($integrations)) {
1510 - $settingsContent = array_merge(
1511 - $settingsContent,
1512 - [
1513 - 'integrations' => $integrations,
1514 - ]
1515 - );
1516 - } else {
1517 - $settingsContent = array_merge(
1518 - $settingsContent,
1519 - [
1520 - 'integrations' => []
1521 - ]
1522 - );
1523 - }
1524 - if (!empty($mailTem)) {
1525 - $settingsContent = array_merge(
1526 - $settingsContent,
1527 - [
1528 - 'mailTem' => $mailTem,
1529 - ]
1530 - );
1531 - } else {
1532 - $settingsContent = array_merge(
1533 - $settingsContent,
1534 - [
1535 - 'mailTem' => []
1536 - ]
1537 - );
1538 - }
1539 - $formSettings = [
1540 - 'formSettings' => $settingsContent,
1541 - ];
1542 - $data = [
1543 - 'id' => $formID,
1544 - 'form_name' => $formManager->getFormName(),
1545 - 'form_content' => $form_content_arr,
1546 - 'additional' => empty($form_content->additional) ? [
1547 - 'enabled' => [
1548 - 'blocked_ip' => false,
1549 - 'restrict_form' => false,
1550 - 'onePerIp' => false,
1551 - ],
1552 - 'settings' => [
1553 - 'restrict_form' => [
1554 - 'day' => [],
1555 - 'date' => [
1556 - 'from' => null,
1557 - 'to' => null,
1558 - ],
1559 - 'time' => [
1560 - 'from' => null,
1561 - 'to' => null,
1562 - ],
1563 - ],
1564 - 'entry_limit' => null,
1565 - 'blocked_ip' => [],
1566 - ],
1567 - ] : $form_content->additional,
1568 - 'created_at' => $formManager->getFormMetaData()['created_at'],
1569 - 'views' => $formManager->getFormMetaData()['views'],
1570 - 'entries' => $formManager->getFormMetaData()['entries'],
1571 - 'status' => $formManager->getFormMetaData()['status'],
1572 - ];
1573 - $data = array_merge($data, $formSettings);
1574 - $workFlowHandler = new WorkFlowHandler($formID);
1575 - $workFlows = ['workFlows' => $workFlowHandler->getAllworkFlowV1()];
1576 - $data = array_merge($data, $workFlows);
1577 - $reportsModel = new ReportsModel();
1578 - $returnedReportData = $reportsModel->get(
1579 - [
1580 - 'id',
1581 - 'details',
1582 - 'isDefault',
1583 - 'type',
1584 - ],
1585 - [
1586 - 'category' => 'form',
1587 - 'context' => $formID,
1588 - ]
1589 - );
1590 -
1591 - if (!is_wp_error($returnedReportData)) {
1592 - $fieldNames = [];
1593 - foreach ($formManager->getFieldLabel() as $key => $field) {
1594 - $fieldNames[$field['key']] = isset($field->lbl) ? $field->lbl : '';
1595 - }
1596 - if ($formManager->isGCLIDEnabled()) {
1597 - $fieldNames['GCLID'] = 'GCLID';
1598 - }
1599 - foreach ($returnedReportData as $reportKey => $reportData) {
1600 - $reportDetails = $reportsModel->validateReportFields($reportData, $fieldNames);
1601 - if (!empty($reportDetails) && is_string($reportDetails)) {
1602 - $returnedReportData[$reportKey]->details = json_decode($reportDetails);
1603 - } elseif (!empty($reportDetails)) {
1604 - $returnedReportData[$reportKey]->details = $reportDetails;
1605 - } else {
1606 - $returnedReportData[$reportKey]->details = [];
1607 - }
1608 - if ('1' === (string) $reportData->isDefault) {
1609 - $returnedReportData[$reportKey]->details->report_name = __('All Entries', 'bit-form');
1610 - }
1611 - }
1612 - $reports = ['reports' => $returnedReportData];
1613 - $data = array_merge($data, $reports);
1614 - }
1615 -
1616 - $formFields = $formManager->getFieldLabel();
1617 - $data = array_merge($data, ['Labels' => $formFields]);
1618 -
1619 - return $data;
1620 - }
1621 - }
1622 -
1623 1223 public function deleteAForm($Request, $post)
1624 1224 {
1625 - if (!empty($Request['id'])) {
1626 - $formID = absint(wp_unslash($Request['id']));
1225 + if (isset($Request['id'])) {
1226 + $formID = wp_unslash($Request['id']);
1627 1227 } else {
1628 1228 $formID = wp_unslash($post->id);
1629 1229 }
1630 1230 if (is_null($formID)) {
@@ -1629,31 +1229,22 @@
1629 1229 }
1630 1230 if (is_null($formID)) {
1631 1231 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1632 1232 }
1633 -
1634 - if (!filter_var($formID, FILTER_VALIDATE_INT)) {
1635 - return new WP_Error('invalid_form', __('Form id is invalid.', 'bit-form'));
1636 - }
1637 -
1638 1233 $delete_status = static::$formModel->delete(
1639 1234 [
1640 1235 'id' => $formID,
1641 1236 ]
1642 1237 );
1643 - do_action('bitform_admin_form_changed');
1644 1238
1645 - $successMessageModel = new SuccessMessageModel();
1239 + $successMessageModel
1240 + = new SuccessMessageModel();
1646 1241 $deleteMsgStatus = $successMessageModel->delete(['form_id' => $formID]);
1647 1242
1648 - $emailTemplateModel = new EmailTemplateModel();
1243 + $emailTemplateModel
1244 + = new EmailTemplateModel();
1649 1245 $deleteTemplateStatus = $emailTemplateModel->delete(['form_id' => $formID]);
1650 1246
1651 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1652 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1653 - $deletePdfTemplateStatus = $pdfTemplateModel->delete(['form_id' => $formID]);
1654 - }
1655 -
1656 1247 $integrationModel = new IntegrationModel();
1657 1248 $deleteIntegrationStatus = $integrationModel->delete(['form_id' => $formID]);
1658 1249
1659 1250 $workFlowModel = new WorkFlowModel();
@@ -1665,11 +1256,22 @@
1665 1256 $formEntryModel = new FormEntryModel();
1666 1257 $returnedEntries = $formEntryModel->get('id', ['form_id' => $formID]);
1667 1258 $entries = [];
1668 1259
1669 - // checked namespace exist
1670 - if (class_exists('\BitCode\BitFormPro\Admin\BfTable\Table')) {
1671 - \BitCode\BitFormPro\Admin\BfTable\Table::deleteTableByFormId($formID);
1260 + if (!is_wp_error($returnedEntries)) {
1261 + foreach ($returnedEntries as $entryKey => $entryInfo) {
1262 + $entries[] = $entryInfo->id;
1263 + }
1264 + global $wpdb;
1265 + $prefix = $wpdb->prefix;
1266 + if (count($entries) > 0) {
1267 + $deleteEntriesStatus = $formEntryModel->bulkDelete(
1268 + [
1269 + "`{$prefix}bitforms_form_entries`.`id`" => $entries,
1270 + "`{$prefix}bitforms_form_entries`.`form_id`" => $formID,
1271 + ]
1272 + );
1273 + }
1672 1274 }
1673 1275
1674 1276 $fileHandler = new FileHandler();
1675 1277 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
@@ -1677,54 +1279,36 @@
1677 1279 }
1678 1280 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
1679 1281 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID);
1680 1282 }
1681 - $formStylePath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles';
1682 -
1683 - $formCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css';
1684 - FileHandler::deleteIsFileExists($formCssPath);
1685 -
1686 - $layoutCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css';
1687 - FileHandler::deleteIsFileExists($layoutCssPath);
1688 -
1689 - $customCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.css';
1690 - FileHandler::deleteIsFileExists($customCssPath);
1691 -
1692 - $customJSPath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-scripts' . DIRECTORY_SEPARATOR . 'bitform-custom-' . $formID . '.js';
1693 - FileHandler::deleteIsFileExists($customJSPath);
1694 -
1695 - $conversationCssPath = $formStylePath . DIRECTORY_SEPARATOR . 'bitform-conversational-' . $formID . '.css';
1696 - FileHandler::deleteIsFileExists($conversationCssPath);
1697 -
1283 + if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css')) {
1284 + unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $formID . '.css');
1285 + }
1286 + if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css')) {
1287 + unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $formID . '.css');
1288 + }
1698 1289 return is_wp_error($delete_status) ? $delete_status : __('Form deleted successfully.', 'bit-form');
1699 1290 }
1700 1291
1701 1292 public function deleteBlukForm($Request, $post)
1702 1293 {
1703 - if (!empty($Request['formID'])) {
1704 - $formID = array_map('absint', wp_unslash($Request['formID']));
1294 + if (isset($Request['formID'])) {
1295 + $formID = wp_unslash($Request['formID']);
1705 1296 } else {
1706 1297 $formID = wp_unslash($post->formID);
1707 1298 }
1708 -
1709 1299 if (is_null($formID) || !is_array($formID)) {
1710 1300 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
1711 1301 }
1712 -
1713 - if (!Helpers::checkIsIntArr($formID)) {
1714 - return new WP_Error('invalid_form', __('Form id is invalid', 'bit-form'));
1715 - }
1716 -
1717 1302 $cssPath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1718 1303 foreach ($formID as $id) {
1719 - $formCssPath = $cssPath . 'bitform-' . $id . '.css';
1720 - FileHandler::deleteIsFileExists($formCssPath);
1721 -
1722 - $layoutPath = $cssPath . 'bitform-layout-' . $id . '.css';
1723 - FileHandler::deleteIsFileExists($layoutPath);
1724 -
1725 - $bitformCustomPath = $cssPath . 'bitform-' . $id . '-formid' . '.css';
1726 - FileHandler::deleteIsFileExists($bitformCustomPath);
1304 + unlink($cssPath . 'bitform-' . $id . '.css');
1305 + if (file_exists($cssPath . 'bitform-layout-' . $id . '.css')) {
1306 + unlink($cssPath . 'bitform-layout-' . $id . '.css');
1307 + }
1308 + if (file_exists($cssPath . 'bitform-' . $id . '-formid' . '.css')) {
1309 + unlink($cssPath . 'bitform-' . $id . '-formid' . '.css');
1310 + }
1727 1311 }
1728 1312 $delete_status = static::$formModel->bulkDelete(
1729 1313 [
1730 1314 'id' => $formID,
@@ -1729,26 +1313,16 @@
1729 1313 [
1730 1314 'id' => $formID,
1731 1315 ]
1732 1316 );
1733 - do_action('bitform_admin_form_changed');
1734 -
1735 - if (is_wp_error($delete_status)) {
1736 - wp_send_json_error($delete_status->get_error_message(), 400);
1737 - }
1738 -
1739 1317 $successMessageModel
1740 1318 = new SuccessMessageModel();
1741 1319 $deleteMsgStatus = $successMessageModel->bulkDelete(['form_id' => $formID]);
1742 1320
1743 - $emailTemplateModel = new EmailTemplateModel();
1321 + $emailTemplateModel
1322 + = new EmailTemplateModel();
1744 1323 $deleteTemplateStatus = $emailTemplateModel->bulkDelete(['form_id' => $formID]);
1745 1324
1746 - if (class_exists('\BitCode\BitFormPro\Core\Database\PdfTemplateModel')) {
1747 - $pdfTemplateModel = new \BitCode\BitFormPro\Core\Database\PdfTemplateModel();
1748 - $deletePdfTemplateStatus = $pdfTemplateModel->bulkDelete(['form_id' => $formID]);
1749 - }
1750 -
1751 1325 $integrationModel = new IntegrationModel();
1752 1326 $deleteIntegrationStatus = $integrationModel->bulkDelete(['form_id' => $formID]);
1753 1327
1754 1328 $workFlowModel = new WorkFlowModel();
@@ -1758,18 +1332,11 @@
1758 1332 $deleteReportStatus = $reportsModel->bulkDelete(['context' => $formID]);
1759 1333
1760 1334 $formEntryModel = new FormEntryModel();
1761 1335 $returnedEntries = $formEntryModel->get('id', ['form_id' => $formID]);
1762 -
1763 - if (class_exists('\BitCode\BitFormPro\Admin\BfTable\Table')) {
1764 - \BitCode\BitFormPro\Admin\BfTable\Table::deleteTableByBulkFormId($formID);
1765 - }
1766 -
1767 1336 $entries = [];
1768 1337 foreach ($returnedEntries as $entryKey => $entryInfo) {
1769 - if (!empty($entryInfo->id)) {
1770 - $entries[] = $entryInfo->id;
1771 - }
1338 + $entries[] = $entryInfo->id;
1772 1339 }
1773 1340 global $wpdb;
1774 1341 $prefix = $wpdb->prefix;
1775 1342 if (count($entries) > 0) {
@@ -1780,19 +1347,16 @@
1780 1347 ]
1781 1348 );
1782 1349 }
1783 1350
1784 - // delete entry log and details; table name interpolation only — $wpdb->prepare() parameterizes the form_id value.
1785 - $wpdb->query($wpdb->prepare(
1786 - "DELETE em, e FROM `{$prefix}bitforms_form_log_details` AS em JOIN `{$prefix}bitforms_form_entry_log` AS e ON em.log_id = e.id WHERE e.form_id = %d",
1787 - $formID
1788 - ));
1789 -
1790 1351 $fileHandler = new FileHandler();
1791 1352 foreach ($formID as $fId) {
1792 1353 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId)) {
1793 1354 $fileHandler->rmrf(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $fId);
1794 1355 }
1356 +
1357 + // unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-' . $fId . '.css');
1358 + // unlink(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . 'bitform-layout-' . $fId . '.css');
1795 1359 }
1796 1360
1797 1361 return is_wp_error($delete_status) ? $delete_status : __('Forms deleted successfully.', 'bit-form');
1798 1362 }
@@ -1834,15 +1398,21 @@
1834 1398 if (!is_wp_error($duplicateResponse) || (is_wp_error($duplicateResponse) && 'result_empty' === $duplicateResponse->get_error_code())) {
1835 1399 // duplicate stylesheet
1836 1400 $style_dir = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR;
1837 1401 // layout style copy
1838 - $styleStr = FileHandler::readFile($style_dir . 'bitform-layout-' . $oldFormId . '.css');
1402 + $mainFormLayStyle = fopen($style_dir . 'bitform-layout-' . $oldFormId . '.css', 'r');
1403 + $styleStr = fread($mainFormLayStyle, filesize($style_dir . 'bitform-layout-' . $oldFormId . '.css'));
1839 1404 $newStyle = str_replace(".bf$oldFormId-", ".bf$newFormId-", $styleStr);
1840 - FileHandler::writeFile($style_dir . "bitform-layout-$newFormId.css", $newStyle);
1405 + $createStyleFile = fopen($style_dir . "bitform-layout-$newFormId.css", 'w');
1406 + fwrite($createStyleFile, $newStyle);
1407 + fclose($createStyleFile);
1841 1408 // style copy
1842 - $styleStr = FileHandler::readFile($style_dir . 'bitform-' . $oldFormId . '.css');
1409 + $mainFormStyle = fopen($style_dir . 'bitform-' . $oldFormId . '.css', 'r');
1410 + $styleStr = fread($mainFormStyle, filesize($style_dir . 'bitform-' . $oldFormId . '.css'));
1843 1411 $newStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr);
1844 - FileHandler::writeFile($style_dir . "bitform-$newFormId.css", $newStyle);
1412 + $createStyleFile = fopen($style_dir . "bitform-$newFormId.css", 'w');
1413 + fwrite($createStyleFile, $newStyle);
1414 + fclose($createStyleFile);
1845 1415 $duplicatedForm = $this->getAForm(null, (object) ['id' => $newFormId]);
1846 1416 $duplicatedForm['message'] = __('Form duplicated successfully', 'bit-form');
1847 1417 return $duplicatedForm;
1848 1418 }
@@ -1855,15 +1425,15 @@
1855 1425 $newFormId = intval($post->newFormId);
1856 1426 if (!$oldFormId || empty($post->formDetail->fields) || empty($post->formDetail->layout)) {
1857 1427 return new WP_Error('invalid_form', __('Please import a valid json.', 'bit-form'));
1858 1428 }
1859 - $importtedForm = (array) $post->formDetail;
1429 + $importtedForm = (array)$post->formDetail;
1860 1430 $importtedForm['form_content']['fields'] = $importtedForm['fields'];
1861 1431 $importtedForm['form_content']['layout'] = $importtedForm['layout'];
1862 - $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayouts'];
1432 + $importtedForm['form_content']['nestedLayout'] = $importtedForm['nestedLayout'];
1863 1433 $importtedForm['form_content']['formInfo'] = $importtedForm['formInfo'];
1864 1434 unset($importtedForm['fields'], $importtedForm['layout'], $importtedForm['nestedLayout'], $importtedForm['formInfo']);
1865 - $formData = FormDuplicateHelper::createReplica((array) $importtedForm, $oldFormId, $newFormId);
1435 + $formData = FormDuplicateHelper::createReplica((array)$importtedForm, $oldFormId, $newFormId);
1866 1436
1867 1437 if (!empty($importtedForm['rowHeight'])) {
1868 1438 $formData->rowHeight = $importtedForm['rowHeight'];
1869 1439 }
@@ -1873,29 +1443,10 @@
1873 1443 $formData->layoutChanged = '-';
1874 1444 }
1875 1445 $importResponse = $this->createNewForm(null, $formData);
1876 1446
1877 - $customCode = [];
1878 - // add custom js
1879 - if (!empty($formData->customCode->customJs)) {
1880 - $customJsPath = 'form-scripts';
1881 - $fileName = 'bitform-custom-' . $newFormId . '.js';
1882 - $customCode['JavaScript'] = $formData->customCode->customJs;
1883 - Helpers::saveFile($customJsPath, $fileName, $formData->customCode->customJs, 'w');
1884 - }
1885 - // add custom css
1886 - if (!empty($formData->customCode->customCss)) {
1887 - $customCssPath = 'form-styles';
1888 - $fileName = 'bitform-custom-' . $newFormId . '.css';
1889 - $customCode['CSS'] = $formData->customCode->customCss;
1890 - Helpers::saveFile($customCssPath, $fileName, $formData->customCode->customCss, 'w');
1891 - }
1892 - if (!is_wp_error($importResponse)) {
1893 - $importResponse['customCode'] = $customCode;
1894 - }
1895 1447 if (!is_wp_error($importResponse) || (is_wp_error($importResponse) && 'result_empty' === $importResponse->get_error_code())) {
1896 1448 $responseData = $this->getAForm(null, (object) ['id' => $newFormId]);
1897 - $responseData['customCode'] = $customCode;
1898 1449 $responseData['message'] = __('Form imported successfully.', 'bit-form');
1899 1450 return $responseData;
1900 1451 }
1901 1452 return $importResponse;
@@ -1922,9 +1473,9 @@
1922 1473 // $formData->formStyle = str_replace("-$oldFormId", "-$newFormId", $styleStr);
1923 1474 // $formData->layoutChanged = '-';
1924 1475 // $formData->rowHeight = FormDuplicateHelper::calcRowHeight($styleStr, $oldFormId);
1925 1476
1926 - // $formJson = wp_json_encode($formData);
1477 + // $formJson = json_encode($formData);
1927 1478 // header('Content-Type: application/force-download');
1928 1479 // header('Content-Type: application/octet-stream');
1929 1480 // header('Content-Type: application/download');
1930 1481 // header('Content-Disposition: attachment; filename="bitform_export_' . $oldFormId . '.json"');
@@ -1950,9 +1501,9 @@
1950 1501 return new WP_Error('empty_form', __('Form does not exists.', 'bit-form'));
1951 1502 }
1952 1503
1953 1504 $newFormId = $oldFormId;
1954 - $duplicatedForm = $this->getAForm($Request, (object) ['id' => $oldFormId]);
1505 + $duplicatedForm = $this->getAForm($Request, (object)['id' => $oldFormId]);
1955 1506 $formData = FormDuplicateHelper::createReplica($duplicatedForm, $oldFormId, $newFormId);
1956 1507 // for custom css
1957 1508 $customCssPath = 'form-styles/bitform-custom-' . $newFormId . '.css';
1958 1509 $cssPath = Helpers::generatePathDirOrFile($customCssPath);
@@ -1972,10 +1523,10 @@
1972 1523 }
1973 1524
1974 1525 public function getFormEntryLabelAndCount($Request, $post)
1975 1526 {
1976 - if (!empty($Request['id'])) {
1977 - $id = absint(wp_unslash($Request['id']));
1527 + if (isset($Request['id'])) {
1528 + $id = wp_unslash($Request['id']);
1978 1529 } else {
1979 1530 $id = wp_unslash($post->id);
1980 1531 }
1981 1532 if (is_null($id)) {
@@ -2028,74 +1579,16 @@
2028 1579 $response['fieldDetails'] = $labels;
2029 1580 return $response;
2030 1581 }
2031 1582
2032 - /**
2033 - * Sanitize a request-supplied entry query condition before it reaches the Model
2034 - * layer. Only known entry-table columns are allowed as condition keys, operators
2035 - * are restricted to a safe allow-list ['form_id' => $id] when nothing valid remains.
2036 - *
2037 - * @param mixed $queryCondition
2038 - * @param int $id
2039 - * @return array
2040 - */
2041 - private function sanitizeEntryQueryCondition($queryCondition, $id)
2042 - {
2043 - $allowedColumns = [
2044 - 'id', 'form_id', 'status', 'created_at', 'updated_at',
2045 - 'user_id', 'user_ip', 'user_device', 'user_location', 'referer',
2046 - ];
2047 - $allowedOperators = ['=', '!=', '<>', '<', '>', '<=', '>=', 'LIKE', 'IN'];
2048 -
2049 - if (!is_array($queryCondition)) {
2050 - return ['form_id' => $id];
2051 - }
2052 -
2053 - $safe = [];
2054 - foreach ($queryCondition as $key => $value) {
2055 - if (!in_array($key, $allowedColumns, true)) {
2056 - continue;
2057 - }
2058 -
2059 - if (is_array($value)) {
2060 - // Never honour a request-supplied raw SQL fragment.
2061 - unset($value['raw']);
2062 -
2063 - if (array_key_exists('operator', $value) || array_key_exists('value', $value)) {
2064 - $operator = isset($value['operator']) && is_string($value['operator'])
2065 - ? strtoupper(trim($value['operator']))
2066 - : '=';
2067 - if (!in_array($operator, $allowedOperators, true)) {
2068 - $operator = '=';
2069 - }
2070 - $condValue = isset($value['value']) ? $value['value'] : '';
2071 - if (is_scalar($condValue)) {
2072 - $safe[$key] = ['operator' => $operator, 'value' => $condValue];
2073 - }
2074 - } else {
2075 - // IN-style list: keep scalar members only (bound by the Model).
2076 - $list = array_values(array_filter($value, 'is_scalar'));
2077 - if (!empty($list)) {
2078 - $safe[$key] = $list;
2079 - }
2080 - }
2081 - } elseif (is_scalar($value)) {
2082 - $safe[$key] = $value;
2083 - }
2084 - }
2085 -
2086 - return empty($safe) ? ['form_id' => $id] : $safe;
2087 - }
2088 -
2089 1583 public function getFormEntry($Request, $post)
2090 1584 {
2091 - if (!empty($Request['id'])) {
2092 - $id = absint(wp_unslash($Request['id']));
1585 + if (isset($Request['id'])) {
1586 + $id = wp_unslash($Request['id']);
2093 1587 $offset = isset($Request['offset']) ?
2094 1588 wp_unslash($Request['offset']) : 0;
2095 1589 $pageSize = isset($Request['pageSize']) ?
2096 1590 wp_unslash($Request['pageSize']) : 10;
2097 - $queryCondition = isset($Request['queryCondition']) ? wp_unslash($Request['queryCondition']) : ['form_id' => $id];
2098 1591 } else {
2099 1592 $id = wp_unslash($post->id);
2100 1593 $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : [];
2101 1594 $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : [];
@@ -2104,11 +1597,9 @@
2104 1597 $filters = isset($post->filters) ? wp_unslash($post->filters) : null;
2105 1598 $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null;
2106 1599 $pageSize = isset($post->pageSize) ?
2107 1600 wp_unslash($post->pageSize) : 10;
2108 - $queryCondition = isset($post->queryCondition) ? wp_unslash($post->queryCondition) : ['form_id' => $id];
2109 1601 }
2110 - $queryCondition = $this->sanitizeEntryQueryCondition($queryCondition, $id);
2111 1602 if (is_null($id)) {
2112 1603 return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
2113 1604 }
2114 1605 $formManager = new AdminFormManager($id);
@@ -2114,90 +1605,9 @@
2114 1605 $formManager = new AdminFormManager($id);
2115 1606 if (!$formManager->isExist()) {
2116 1607 return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
2117 1608 }
2118 - $formEntry = new FormEntryModel();
2119 - $entries = $formEntry->get(
2120 - 'id',
2121 - $queryCondition,
2122 - null,
2123 - null,
2124 - 'created_at',
2125 - 'DESC'
2126 - );
2127 - if (is_wp_error($entries)) {
2128 - if ('result_empty' === $entries->get_error_code()) {
2129 - return [
2130 - 'count' => 0,
2131 - 'entries' => [],
2132 - ];
2133 - }
2134 - return $entries;
2135 - }
2136 - $filter['field'] = $filters;
2137 - $filter['global'] = $globalFilter;
2138 1609
2139 - $formFields = $formManager->getFieldLabel(true);
2140 - $fieldDetails = $formManager->getFields();
2141 -
2142 - $entryMeta = new FormEntryMetaModel();
2143 - $formEntries = $entryMeta->getEntryMeta($formFields, $entries, $pageSize, $offset, $filter, $sortBy, $conditions, $dateBetweenFilter);
2144 - $customFieldHandler = new CustomFieldHandler();
2145 - $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
2146 - return $formEntries;
2147 - }
2148 -
2149 - public function getSingleEntry($formId, $entryId)
2150 - {
2151 - $formManager = new AdminFormManager($formId);
2152 - if (!$formManager->isExist()) {
2153 - return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
2154 - }
2155 -
2156 - $formFields = $formManager->getFieldLabel(true);
2157 - $fieldDetails = $formManager->getFields();
2158 - $entryMeta = new FormEntryMetaModel();
2159 - // $formEntry = new FormEntryModel();
2160 -
2161 - $entries = $entryMeta->getSingleEntryMeta($formFields, $entryId);
2162 -
2163 - if (!is_wp_error($entries)) {
2164 - return $entries[0];
2165 - }
2166 - return new WP_Error('entry_not_fonud', __('Entry Not Found!', 'bit-form'));
2167 -
2168 - // $customFieldHandler = new CustomFieldHandler();
2169 - // $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
2170 - // return $formEntries;
2171 - }
2172 -
2173 - public function getEntriesForReport($Request, $post)
2174 - {
2175 - if (!empty($Request['id'])) {
2176 - $id = absint(wp_unslash($Request['id']));
2177 - $offset = isset($Request['offset']) ?
2178 - wp_unslash($Request['offset']) : null;
2179 - $pageSize = isset($Request['pageSize']) ?
2180 - wp_unslash($Request['pageSize']) : null;
2181 - } else {
2182 - $id = wp_unslash($post->id);
2183 - $conditions = isset($post->conditions) ? wp_unslash($post->conditions) : [];
2184 - $dateBetweenFilter = isset($post->entriesFilterByDate) ? wp_unslash($post->entriesFilterByDate) : [];
2185 - $offset = isset($post->offset) ? wp_unslash($post->offset) : null;
2186 - $sortBy = isset($post->sortBy) ? wp_unslash($post->sortBy) : null;
2187 - $filters = isset($post->filters) ? wp_unslash($post->filters) : null;
2188 - $globalFilter = isset($post->globalFilter) ? wp_unslash($post->globalFilter) : null;
2189 - $pageSize = isset($post->pageSize) ?
2190 - wp_unslash($post->pageSize) : null;
2191 - }
2192 - if (is_null($id)) {
2193 - return new WP_Error('empty_form', __('Form id is empty.', 'bit-form'));
2194 - }
2195 - $formManager = new AdminFormManager($id);
2196 - if (!$formManager->isExist()) {
2197 - return new WP_Error('empty_form', __('Form does not exists', 'bit-form'));
2198 - }
2199 -
2200 1610 $formEntry = new FormEntryModel();
2201 1611 $entries = $formEntry->get(
2202 1612 'id',
2203 1613 [
@@ -2226,9 +1636,8 @@
2226 1636 $entryMeta = new FormEntryMetaModel();
2227 1637 $formEntries = $entryMeta->getEntryMeta($formFields, $entries, $pageSize, $offset, $filter, $sortBy, $conditions, $dateBetweenFilter);
2228 1638 $customFieldHandler = new CustomFieldHandler();
2229 1639 $formEntries = $customFieldHandler->updatedEntries($formEntries, $fieldDetails);
2230 - $formEntries['entries'] = Helpers::filterNullEntries($formEntries['entries']);
2231 1640 return $formEntries;
2232 1641 }
2233 1642
2234 1643 public function getExportEntry($post)
@@ -2235,9 +1644,8 @@
2235 1644 {
2236 1645 $formId = wp_unslash($post->formId);
2237 1646 $fileFormate = isset($post->fileFormate) ? wp_unslash($post->fileFormate) : null;
2238 1647 $limit = isset($post->limit) ? wp_unslash($post->limit) : null;
2239 - $entryCondition = isset($post->filter) ? wp_unslash($post->filter) : null;
2240 1648 $sortBy = isset($post->sort) ? wp_unslash($post->sort) : 'ASC';
2241 1649 $sortByField = isset($post->sortField) ? wp_unslash($post->sortField) : 'bitforms_form_entry_id';
2242 1650 $formFields = json_decode($post->selectedField);
2243 1651 if (is_null($formId)) {
@@ -2270,17 +1678,17 @@
2270 1678 return $entries;
2271 1679 }
2272 1680 $entryMeta = new FormEntryMetaModel();
2273 1681 $filter = [];
2274 - $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField, $offset, $entryCondition);
1682 + $formEntries = $entryMeta->getExportEntry($formFields, $entries, $formId, $fieldLabels, $limit, $sortBy, $sortByField);
2275 1683 return $formEntries;
2276 1684 }
2277 1685
2278 1686 public function deleteBlukFormEntries($Request, $post)
2279 1687 {
2280 - if (!empty($Request['formID'])) {
2281 - $formID = absint(wp_unslash($Request['formID']));
2282 - $entries = array_map('absint', wp_unslash($Request['entries']));
1688 + if (isset($Request['formID'])) {
1689 + $formID = wp_unslash($Request['formID']);
1690 + $entries = wp_unslash($Request['entries']);
2283 1691 } else {
2284 1692 $formID = wp_unslash($post->formID);
2285 1693 $entries = wp_unslash($post->entries);
2286 1694 }
@@ -2286,32 +1694,21 @@
2286 1694 }
2287 1695 if (is_null($formID) || !is_array($entries) || 0 === count($entries)) {
2288 1696 return new WP_Error('empty_form', __('Invalid Form ID or Entries ID.', 'bit-form'));
2289 1697 }
2290 -
2291 - if (!filter_var($formID, FILTER_VALIDATE_INT)) {
2292 - return new WP_Error('invalid_form', __('Form id is invalid.', 'bit-form'));
2293 - }
2294 -
2295 - if (!Helpers::checkIsIntArr($entries)) {
2296 - return new WP_Error('invalid_entries', __('Entries id is invalid', 'bit-form'));
2297 - }
2298 -
2299 1698 $formManager = new AdminFormManager($formID);
2300 1699 if (!$formManager->isExist()) {
2301 1700 return new WP_Error('empty_form', __('Form does not exist.', 'bit-form'));
2302 1701 }
2303 1702 $workFlowRunHelper = new WorkFlow($formID);
2304 -
2305 1703 $workFlowreturnedOnDelete = $workFlowRunHelper->executeOnDelete(
2306 1704 $formManager,
2307 1705 $formID,
2308 1706 $entries
2309 1707 );
2310 -
2311 1708 if (isset($workFlowreturnedOnDelete['entries'])) {
2312 1709 if (0 === count($workFlowreturnedOnDelete['entries'])) {
2313 - return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
1710 + return ['message' => __('Entry Deletetion prevented by workflow', 'bit-form')];
2314 1711 } elseif (count($workFlowreturnedOnDelete['entries']) === count($entries)) {
2315 1712 $message = __('Entry Deleted successfully', 'bit-form');
2316 1713 } else {
2317 1714 $result['prevented'] = array_diff($entries, $workFlowreturnedOnDelete['entries']);
@@ -2332,9 +1729,9 @@
2332 1729 );
2333 1730 if (file_exists(BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID)) {
2334 1731 $fileHandler = new FileHandler();
2335 1732 foreach ($entries as $enrtyKey => $entryID) {
2336 - $fileEntries = $fileHandler->getEntriesFileUploadDir($formID, $entryID);
1733 + $fileEntries = BITFORMS_UPLOAD_DIR . DIRECTORY_SEPARATOR . $formID . DIRECTORY_SEPARATOR . $entryID;
2337 1734 if (file_exists($fileEntries)) {
2338 1735 $fileHandler->rmrf($fileEntries);
2339 1736 }
2340 1737 }
@@ -2353,11 +1750,11 @@
2353 1750 }
2354 1751
2355 1752 public function duplicateFormEntry($Request, $post)
2356 1753 {
2357 - if (!empty($Request['formID'])) {
2358 - $formID = absint(wp_unslash($Request['formID']));
2359 - $entries = array_map('absint', wp_unslash($Request['entries']));
1754 + if (isset($Request['formID'])) {
1755 + $formID = wp_unslash($Request['formID']);
1756 + $entries = wp_unslash($Request['entries']);
2360 1757 } else {
2361 1758 $formID = wp_unslash($post->formID);
2362 1759 $entries = wp_unslash($post->entries);
2363 1760 }
@@ -2364,16 +1761,8 @@
2364 1761 if (is_null($formID) || !is_array($entries) || empty($entries)) {
2365 1762 return new WP_Error('empty_form', __('Form id or entries id is invalid', 'bit-form'));
2366 1763 }
2367 1764
2368 - if (!filter_var($formID, FILTER_VALIDATE_INT)) {
2369 - return new WP_Error('invalid_form', __('Form id is invalid', 'bit-form'));
2370 - }
2371 -
2372 - if (!Helpers::checkIsIntArr($entries)) {
2373 - return new WP_Error('invalid_entries', __('Entries id is invalid', 'bit-form'));
2374 - }
2375 -
2376 1765 $formManager = new AdminFormManager($formID);
2377 1766 if (!$formManager->isExist()) {
2378 1767 return new WP_Error('empty_form', __('Form does not exist', 'bit-form'));
2379 1768 }
@@ -2406,12 +1795,12 @@
2406 1795 );
2407 1796 if ($duplicate_status) {
2408 1797 $result['details'][$entryID] = $duplicatedEntryId;
2409 1798 $duplicate_count = $duplicate_count + 1;
2410 - if (file_exists(FileHandler::getEntriesFileUploadDir($formID, $entryID))) {
1799 + if (file_exists(BITFORMS_UPLOAD_DIR . "/$formID/$entryID")) {
2411 1800 $fileHandler->cpyr(
2412 - FileHandler::getEntriesFileUploadDir($formID, $entryID),
2413 - FileHandler::getEntriesFileUploadDir($formID, $duplicatedEntryId)
1801 + BITFORMS_UPLOAD_DIR . "/$formID/$entryID",
1802 + BITFORMS_UPLOAD_DIR . "/$formID/$duplicatedEntryId"
2414 1803 );
2415 1804 }
2416 1805 }
2417 1806 }
@@ -2428,11 +1817,11 @@
2428 1817 }
2429 1818
2430 1819 public function editFormEntry($Request, $post)
2431 1820 {
2432 - if (!empty($Request['formID'])) {
2433 - $formID = absint(wp_unslash($Request['formID']));
2434 - $entryID = absint(wp_unslash($Request['entryID']));
1821 + if (isset($Request['formID'])) {
1822 + $formID = wp_unslash($Request['formID']);
1823 + $entryID = wp_unslash($Request['entryID']);
2435 1824 } else {
2436 1825 $formID = wp_unslash($post->formID);
2437 1826 $entryID = wp_unslash($post->entryID);
2438 1827 }
@@ -2507,16 +1896,15 @@
2507 1896
2508 1897 public function updateFormEntry($Request, $post)
2509 1898 {
2510 1899 if (isset($Request['formID'], $Request['entryID'])) {
2511 - $formID = absint(wp_unslash($Request['formID']));
2512 - $entryID = absint(wp_unslash($Request['entryID']));
1900 + $formID = wp_unslash($Request['formID']);
1901 + $entryID = wp_unslash($Request['entryID']);
2513 1902 unset($Request['action'], $Request['formID'], $Request['entryID']);
2514 1903 }
2515 1904 $formManager = new AdminFormManager($formID);
2516 1905 $formManager->fieldNameReplaceOfPost();
2517 - // Called from AdminAjax handler; nonce already verified at AJAX entry before dispatch.
2518 - $updatedValue = is_array($post) ? $post : wp_unslash($_POST);
1906 + $updatedValue = wp_unslash($_POST);
2519 1907
2520 1908 if (is_null($updatedValue) || !is_array($updatedValue)) {
2521 1909 return new WP_Error('empty_data', __('Failed to update, Data is empty.', 'bit-form'));
2522 1910 }
@@ -2532,11 +1920,11 @@
2532 1920 }
2533 1921
2534 1922 public function getLogHistory($Request, $post)
2535 1923 {
2536 - if (!empty($Request['formID'])) {
2537 - $formID = absint(wp_unslash($Request['formID']));
2538 - $entryID = absint(wp_unslash($Request['entryID']));
1924 + if (isset($Request['formID'])) {
1925 + $formID = wp_unslash($Request['formID']);
1926 + $entryID = wp_unslash($Request['entryID']);
2539 1927 } else {
2540 1928 $formID = wp_unslash($post->formID);
2541 1929 $entryID = wp_unslash($post->entryID);
2542 1930 }
@@ -2556,10 +1944,10 @@
2556 1944 }
2557 1945
2558 1946 public function importDataStore($Request, $post)
2559 1947 {
2560 - if (!empty($Request['formID'])) {
2561 - $formID = absint(wp_unslash($Request['formID']));
1948 + if (isset($Request['formID'])) {
1949 + $formID = wp_unslash($Request['formID']);
2562 1950 } else {
2563 1951 $formID = wp_unslash($post->formID);
2564 1952 }
2565 1953 if (is_null($formID)) {
@@ -2571,14 +1959,10 @@
2571 1959 {
2572 1960 $pages = get_pages(['post_status' => 'publish', 'sort_column' => 'post_date', 'sort_order' => 'desc']);
2573 1961 $allPages = [];
2574 1962 foreach ($pages as $pageKey => $pageDetails) {
2575 - // $allPages[$pageKey]['title'] = $pageDetails->post_title;
2576 - // $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2577 - $allPages[] = (object) [
2578 - 'title' => $pageDetails->post_title,
2579 - 'url' => get_page_link($pageDetails->ID)
2580 - ];
1963 + $allPages[$pageKey]['title'] = $pageDetails->post_title;
1964 + $allPages[$pageKey]['url'] = get_page_link($pageDetails->ID);
2581 1965 }
2582 1966 return $allPages;
2583 1967 }
2584 1968
@@ -2583,11 +1967,11 @@
2583 1967 }
2584 1968
2585 1969 public function deleteAIntegration($Request, $post)
2586 1970 {
2587 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2588 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2589 - $id = absint(wp_unslash($Request['id']));
1971 + if (isset($Request['formID']) && $Request['id']) {
1972 + $formID = json_decode(wp_unslash($Request['formID']));
1973 + $id = wp_unslash($Request['id']);
2590 1974 } else {
2591 1975 $formID = wp_unslash($post->formID);
2592 1976 $id = wp_unslash($post->id);
2593 1977 }
@@ -2607,11 +1991,11 @@
2607 1991 }
2608 1992
2609 1993 public function deleteSuccessMessage($Request, $post)
2610 1994 {
2611 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2612 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2613 - $id = absint(wp_unslash($Request['id']));
1995 + if (isset($Request['formID']) && $Request['id']) {
1996 + $formID = json_decode(wp_unslash($Request['formID']));
1997 + $id = wp_unslash($Request['id']);
2614 1998 } else {
2615 1999 $formID = wp_unslash($post->formID);
2616 2000 $id = wp_unslash($post->id);
2617 2001 }
@@ -2630,11 +2014,11 @@
2630 2014 }
2631 2015
2632 2016 public function deleteAWorkflow($Request, $post)
2633 2017 {
2634 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2635 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2636 - $id = absint(wp_unslash($Request['id']));
2018 + if (isset($Request['formID']) && $Request['id']) {
2019 + $formID = json_decode(wp_unslash($Request['formID']));
2020 + $id = wp_unslash($Request['id']);
2637 2021 } else {
2638 2022 $formID = wp_unslash($post->formID);
2639 2023 $id = wp_unslash($post->id);
2640 2024 }
@@ -2652,11 +2036,11 @@
2652 2036 }
2653 2037
2654 2038 public function deleteAMailTemplate($Request, $post)
2655 2039 {
2656 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2657 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2658 - $id = absint(wp_unslash($Request['id']));
2040 + if (isset($Request['formID']) && $Request['id']) {
2041 + $formID = json_decode(wp_unslash($Request['formID']));
2042 + $id = wp_unslash($Request['id']);
2659 2043 } else {
2660 2044 $formID = wp_unslash($post->formID);
2661 2045 $id = wp_unslash($post->id);
2662 2046 }
@@ -2674,11 +2058,11 @@
2674 2058 }
2675 2059
2676 2060 public function duplicateAMailTemplate($Request, $post)
2677 2061 {
2678 - if (!empty($Request['formID']) && !empty($Request['id'])) {
2679 - $formID = absint(json_decode(wp_unslash($Request['formID'])));
2680 - $id = absint(wp_unslash($Request['id']));
2062 + if (isset($Request['formID']) && $Request['id']) {
2063 + $formID = json_decode(wp_unslash($Request['formID']));
2064 + $id = wp_unslash($Request['id']);
2681 2065 } else {
2682 2066 $formID = wp_unslash($post->formID);
2683 2067 $id = wp_unslash($post->id);
2684 2068 }
@@ -2684,17 +2068,8 @@
2684 2068 }
2685 2069 if (empty($formID) || empty($id)) {
2686 2070 return new WP_Error('empty_form', 'Invalid Form ID or Email Template ID.');
2687 2071 }
2688 -
2689 - if (false === filter_var($id, FILTER_VALIDATE_INT)) {
2690 - return new WP_Error('empty_form', 'Invalid Email Template ID.');
2691 - }
2692 -
2693 - if (false === filter_var($formID, FILTER_VALIDATE_INT)) {
2694 - return new WP_Error('empty_form', 'Invalid Form ID.');
2695 - }
2696 -
2697 2072 $emailTemplateHandler = new EmailTemplateHandler($formID);
2698 2073 $duplicate_status = $emailTemplateHandler->duplicateTemplate($id);
2699 2074 if (is_wp_error($duplicate_status)) {
2700 2075 return $duplicate_status;
@@ -2797,16 +2172,11 @@
2797 2172 } else {
2798 2173 $integrationID = $reCaptcha->id;
2799 2174 unset($reCaptcha->id);
2800 2175 }
2801 - $reCaptcha = wp_json_encode($reCaptcha);
2802 -
2803 - // $integrationName = 'google reCaptcha';
2804 - $integrationName = $post->integrationName;
2805 -
2806 - // $integrationType = 'v2' === $post->version ? 'gReCaptcha' : 'gReCaptchaV3';
2807 - $integrationType = $post->integrationType;
2808 -
2176 + $reCaptcha = json_encode($reCaptcha);
2177 + $integrationName = 'google reCaptcha';
2178 + $integrationType = 'v2' === $post->version ? 'gReCaptcha' : 'gReCaptchaV3';
2809 2179 $integrationDetails = $reCaptcha;
2810 2180 $user_details = static::$ipTool->getUserDetail();
2811 2181 $integrationHandler = new IntegrationHandler(0, $user_details);
2812 2182 $response = [];
@@ -2812,12 +2182,12 @@
2812 2182 $response = [];
2813 2183 if (empty($integrationID)) {
2814 2184 $captchaSaveStatus = $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'app');
2815 2185 $response['id'] = $captchaSaveStatus;
2816 - $response['message'] = __('reCAPTCHA saved successfully', 'bit-form');
2186 + $response['message'] = __('g-reCAPTCHA saved successfully', 'bit-form');
2817 2187 } else {
2818 2188 $captchaSaveStatus = $integrationHandler->updateIntegration($integrationID, $integrationName, $integrationType, $integrationDetails, 'app');
2819 - $response['message'] = __('reCAPTCHA updated successfully', 'bit-form');
2189 + $response['message'] = __('g-reCAPTCHA updated successfully', 'bit-form');
2820 2190 }
2821 2191
2822 2192 if (is_wp_error($captchaSaveStatus)) {
2823 2193 return $captchaSaveStatus;
@@ -2835,37 +2205,30 @@
2835 2205 }
2836 2206 if (is_string($paySetting)) {
2837 2207 $paySetting = json_decode($paySetting);
2838 2208 }
2839 -
2840 2209 $canSave = null;
2841 - switch ($paySetting->type) {
2842 - case 'PayPal':
2843 - $canSave = $this->addWebhookToPaypal($paySetting);
2844 - break;
2845 - case 'Razorpay':
2846 - $canSave = true;
2847 - break;
2848 - case 'Stripe':
2849 - $canSave = $this->addWebhookToStripe($paySetting);
2850 - break;
2851 - case 'Mollie':
2852 - $canSave = true;
2853 - break;
2854 - default:
2855 - $canSave = null;
2210 + // $checkedCanSave = [
2211 + // 'PayPal' => $this->addWebhookToPaypal($paySetting),
2212 + // 'Razorpay' => true,
2213 + // 'Stripe' => $this->addWebhookToStripe($paySetting),
2214 + // ];
2215 + // $canSave = $checkedCanSave[$paySetting->type];
2216 + if ('PayPal' === $paySetting->type) {
2217 + $canSave = $this->addWebhookToPaypal($paySetting);
2218 + } elseif ('Razorpay' === $paySetting->type) {
2219 + $canSave = true;
2220 + } elseif ('Stripe' === $paySetting->type) {
2221 + $canSave = $this->addWebhookToStripe($paySetting);
2856 2222 }
2857 2223 if (is_null($canSave)) {
2858 - return new WP_Error('stripe', __('Please re-check your Client ID & Secret', 'bit-form'));
2224 + return ['message' => __('Please re-check your Client ID & Secret', 'bit-form')];
2859 2225 }
2860 - $integrationID = null;
2861 - if (isset($paySetting->id)) {
2862 - $integrationID = $paySetting->id;
2863 - unset($paySetting->id);
2864 - }
2226 + $integrationID = $paySetting->id;
2227 + unset($paySetting->id);
2865 2228 $integrationName = $paySetting->name;
2866 2229 $integrationType = 'payments';
2867 - $paySetting = wp_json_encode($paySetting);
2230 + $paySetting = json_encode($paySetting);
2868 2231 $integrationDetails = $paySetting;
2869 2232 $user_details = static::$ipTool->getUserDetail();
2870 2233 $integrationHandler = new IntegrationHandler(0, $user_details);
2871 2234 $response = [];
@@ -2914,8 +2277,10 @@
2914 2277 }
2915 2278
2916 2279 private function addWebhookToStripe($paySetting)
2917 2280 {
2281 + // $transaction_mode = $paySetting->mode;
2282 + // $publishableKey = $paySetting->publishableKey;
2918 2283 $clientSecret = $paySetting->clientSecret;
2919 2284
2920 2285 $create_webhook_url = 'https://api.stripe.com/v1/webhook_endpoints';
2921 2286 $headers = [
@@ -2925,12 +2290,8 @@
2925 2290
2926 2291 $webhook_url = get_rest_url() . 'bitform/v1/payments/stripe';
2927 2292
2928 2293 $apiResponse = HttpHelper::get($create_webhook_url, '', $headers);
2929 -
2930 - if (isset($apiResponse->error)) {
2931 - return null;
2932 - }
2933 2294 $webhookList = $apiResponse->data;
2934 2295 $webhook_already_exist = false;
2935 2296
2936 2297 foreach ($webhookList as $webhook) {
@@ -2940,16 +2301,15 @@
2940 2301 }
2941 2302 }
2942 2303
2943 2304 $data = [
2944 - 'enabled_events[]' => 'payment_intent.succeeded',
2945 - 'url' => $webhook_url,
2305 + 'enabled_events[]' => 'payment_intent.succeeded',
2306 + 'url' => $webhook_url,
2946 2307 ];
2947 2308
2948 2309 if (!$webhook_already_exist) {
2949 2310 $webhook_response = HttpHelper::post($create_webhook_url, $data, $headers);
2950 2311 if (is_wp_error($webhook_response) || (isset($webhook_response->error) && $webhook_response->error)) {
2951 - Log::debug_log(['Stripe webhook creation failed' => $webhook_response]);
2952 2312 return null;
2953 2313 }
2954 2314 }
2955 2315 return true;
@@ -2992,70 +2352,10 @@
2992 2352 return true;
2993 2353 }
2994 2354 }
2995 2355
2996 - public function replaceAllFormsErrorMessagesByGlobalMessages()
2997 - {
2998 - try {
2999 - $formModel = new FormModel();
3000 - $allForms = $formModel->get(['id', 'form_content']);
3001 -
3002 - foreach ($allForms as $form) {
3003 - // Decode form_content JSON to stdClass
3004 - $formContent = \json_decode($form->form_content);
3005 - $fields = $formContent->fields ?? null;
3006 - // If decode fails, skip to next
3007 - if (!$fields) {
3008 - Log::debug_log("Form ID {$form->id}: invalid JSON in form_content");
3009 - continue;
3010 - }
3011 -
3012 - // Replace default error messages using your helper
3013 - $updatedFields = Helpers::replaceFieldsDefaultErrorMsg($fields);
3014 -
3015 - $formContent->fields = $updatedFields;
3016 - // Encode back to JSON
3017 - $updatedContent = \json_encode($formContent);
3018 -
3019 - if (false === $updatedContent) {
3020 - Log::debug_log("Form ID {$form->id}: JSON encoding failed");
3021 - continue;
3022 - }
3023 - // Update form content in DB
3024 - $formModel->update(
3025 - ['form_content' => $updatedContent], // data to update
3026 - ['id' => $form->id] // condition for update
3027 - );
3028 - }
3029 - } catch (\Exception $e) {
3030 - Log::debug_log([
3031 - 'message' => 'Error in updateAllFormsErrorMessagesWithGlobalMessages',
3032 - 'error' => $e->getMessage(),
3033 - ]);
3034 - }
3035 - }
3036 -
3037 2356 public function updateSuccessMessageClassName($str, $msgIdx, $msgId)
3038 2357 {
3039 2358 $TEMP_CONF_ID = '_tmp_' . $msgIdx . '_conf_id';
3040 2359 return str_replace($TEMP_CONF_ID, $msgId, $str);
3041 - }
3042 -
3043 - public function startMigrationProcess()
3044 - {
3045 - Utilities::duplicateDbTable('form', 'form_v1');
3046 - Utilities::duplicateDbTable('workflows', 'workflows_v1');
3047 - Utilities::duplicateDbTable('success_messages', 'success_messages_v1');
3048 - MigrationHelper::duplicateV1StyleFiles();
3049 - $all_forms = $this->getAllForm();
3050 - $v1FormContents = [];
3051 - $defaultStyleClass = MigrationHelper::getBitformDefaultStyleClass();
3052 - foreach ($all_forms as $form) {
3053 - $formContents = $this->getAFormV1(['id' => $form->id], ['id' => $form->id]);
3054 - $v1FormContents[] = $formContents;
3055 - FrontEndScriptGenerator::saveCssFile("{$form->id}", $defaultStyleClass);
3056 - FrontEndScriptGenerator::saveCssFile("{$form->id}-formid", $defaultStyleClass);
3057 - }
3058 - set_transient('bitforms_v1_form_contents', $v1FormContents);
3059 - update_option('bitforms_migrating_to_v2', true);
3060 2360 }
3061 2361 }