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

ConversationalFormView.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.13, at includes/Frontend/ConversationalFormView.php

124 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend;
4
5 use BitCode\BitForm\Core\Database\FormModel;
6 use BitCode\BitForm\Core\Form\FormManager;
7 use BitCode\BitForm\Core\Util\Render;
8 use BitCode\BitForm\Frontend\Form\FrontendFormHandler;
9
10 class ConversationalFormView
11 {
12 public static function preview()
13 {
14 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- REQUEST_URI is parsed/compared, not output directly.
15 $requestUri = isset($_SERVER['REQUEST_URI']) ? wp_unslash($_SERVER['REQUEST_URI']) : '';
16 $uri = explode('/', $requestUri);
17
18 if (is_array($uri) && count($uri) > 0) {
19 $formID = $uri[count($uri) - 1];
20 $attr = ['form_id' => $formID, 'form_preview' => true];
21
22 $frontendFormHandler = new FrontendFormHandler();
23 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
24 if ('string' === gettype($formViewObject)) {
25 Render::view('views/form-not-found');
26 exit;
27 }
28
29 $formHTML = $formViewObject->html;
30 $font = $formViewObject->font;
31 $bfGlobals = $formViewObject->bfGlobals;
32
33 if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
34 set_transient('bitform_form_preview', true);
35 $frontendFormHandler->generateJs($formID);
36 $title = 'BitForm Preview page';
37 Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
38 }
39 }
40 }
41
42 private static function getCustomUrlFormId()
43 {
44 $currentUrl = get_site_url() . (isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '');
45 $parsedCurrentUrl = wp_parse_url($currentUrl);
46 $formModel = new FormModel();
47 $forms = $formModel->get(
48 ['id', 'form_content']
49 );
50
51 if (!is_wp_error($forms)) {
52 foreach ($forms as $form) {
53 $formID = $form->id;
54 $formContent = json_decode($form->form_content);
55 $isStandaloneActive = !empty($formContent->formInfo->standaloneSettings->active);
56 $isConversationalActive = !empty($formContent->formInfo->conversationalSettings->enable);
57 if ($isStandaloneActive && $isConversationalActive) {
58 $standaloneSettings = $formContent->formInfo->standaloneSettings;
59 $hasCustomUrl = !empty($standaloneSettings->customUrl);
60 if (!$hasCustomUrl) {
61 continue;
62 }
63 $customUrl = get_site_url() . '/' . $standaloneSettings->customUrl;
64 $parsedCustomUrl = wp_parse_url($customUrl);
65 $pathMatched = $parsedCustomUrl['path'] === $parsedCurrentUrl['path'];
66 if (!$pathMatched) {
67 continue;
68 }
69 if (!isset($parsedCustomUrl['query'])) {
70 return $formID;
71 }
72 parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
73 parse_str($parsedCurrentUrl['query'], $parsedCurrentQueries);
74 $diff = array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries);
75 if (empty($diff)) {
76 return $formID;
77 }
78 }
79 }
80 }
81 }
82
83 public static function conversationalFormView()
84 {
85 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Template rendering, reading URL parameter for form ID.
86 $formID = isset($_GET['bit-conversational-form']) ? sanitize_text_field(wp_unslash($_GET['bit-conversational-form'])) : '';
87 $formType = 'conversational';
88 if (empty($formID)) {
89 $formID = self::getCustomUrlFormId();
90 }
91
92 if (empty($formID)) {
93 return '';
94 }
95
96 $formID = intval($formID);
97 $attr = ['type'=> $formType, 'form_id' => $formID, 'form_preview' => true];
98
99 $FormManager = FormManager::getInstance($formID);
100 $formContent = $FormManager->getFormContent();
101 if (empty($formContent->formInfo->conversationalSettings->enable)) {
102 return;
103 }
104
105 $frontendFormHandler = new FrontendFormHandler();
106 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
107 if ('string' === gettype($formViewObject)) {
108 Render::view('views/form-not-found');
109 exit;
110 }
111
112 $formHTML = $formViewObject->html;
113 $font = $formViewObject->font;
114 $bfGlobals = $formViewObject->bfGlobals;
115
116 set_transient('bitform_form_preview', true);
117 $frontendFormHandler->generateJs($formID, null, $formType);
118 $title = 'Bit Form';
119 Render::view('views/conversational-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
120
121 exit(200);
122 }
123 }
124