PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Frontend/ConversationalFormView.php +38 -70 3.2.22.15.3 View file →
@@ -5,16 +5,14 @@
5 5 use BitCode\BitForm\Core\Database\FormModel;
6 6 use BitCode\BitForm\Core\Form\FormManager;
7 7 use BitCode\BitForm\Core\Util\Render;
8 8 use BitCode\BitForm\Frontend\Form\FrontendFormHandler;
9 -use BitCode\BitForm\Frontend\Form\View\Conversational\ConversationalHelpers;
10 9
11 10 class ConversationalFormView
12 11 {
13 12 public static function preview()
14 13 {
15 - // Read-only: REQUEST_URI used to extract form ID from URL path for view dispatch. No state mutation.
16 - $requestUri = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '';
14 + $requestUri = $_SERVER['REQUEST_URI'];
17 15 $uri = explode('/', $requestUri);
18 16
19 17 if (is_array($uri) && count($uri) > 0) {
20 18 $formID = $uri[count($uri) - 1];
@@ -29,15 +27,14 @@
29 27
30 28 $formHTML = $formViewObject->html;
31 29 $font = $formViewObject->font;
32 30 $bfGlobals = $formViewObject->bfGlobals;
33 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
34 31
35 32 if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
36 33 set_transient('bitform_form_preview', true);
37 34 $frontendFormHandler->generateJs($formID);
38 35 $title = 'BitForm Preview page';
39 - Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'formContent'));
36 + Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
40 37 }
41 38 }
42 39 }
43 40
@@ -42,73 +39,50 @@
42 39 }
43 40
44 41 private static function getCustomUrlFormId()
45 42 {
46 - $urlMap = get_transient('bitform_conversational_url_map');
47 - if (false === $urlMap) {
48 - $urlMap = self::buildConversationalUrlMap();
49 - set_transient('bitform_conversational_url_map', $urlMap, DAY_IN_SECONDS);
50 - }
51 -
52 - if (empty($urlMap)) {
53 - return null;
54 - }
55 -
56 - $currentUrl = get_site_url() . (isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '');
43 + $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
57 44 $parsedCurrentUrl = wp_parse_url($currentUrl);
45 + $formModel = new FormModel();
46 + $forms = $formModel->get(
47 + ['id', 'form_content']
48 + );
58 49
59 - foreach ($urlMap as $formID => $customUrlSlug) {
60 - $customUrl = get_site_url() . '/' . $customUrlSlug;
61 - $parsedCustomUrl = wp_parse_url($customUrl);
62 - $pathMatched = isset($parsedCustomUrl['path']) && $parsedCustomUrl['path'] === ($parsedCurrentUrl['path'] ?? '');
63 - if (!$pathMatched) {
64 - continue;
50 + if (!is_wp_error($forms)) {
51 + foreach ($forms as $form) {
52 + $formID = $form->id;
53 + $formContent = json_decode($form->form_content);
54 + $isStandaloneActive = !empty($formContent->formInfo->standaloneSettings->active);
55 + $isConversationalActive = !empty($formContent->formInfo->conversationalSettings->enable);
56 + if ($isStandaloneActive && $isConversationalActive) {
57 + $standaloneSettings = $formContent->formInfo->standaloneSettings;
58 + $hasCustomUrl = !empty($standaloneSettings->customUrl);
59 + if (!$hasCustomUrl) {
60 + continue;
61 + }
62 + $customUrl = get_site_url() . '/' . $standaloneSettings->customUrl;
63 + $parsedCustomUrl = wp_parse_url($customUrl);
64 + $pathMatched = $parsedCustomUrl['path'] === $parsedCurrentUrl['path'];
65 + if (!$pathMatched) {
66 + continue;
67 + }
68 + if (!isset($parsedCustomUrl['query'])) {
69 + return $formID;
70 + }
71 + parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
72 + parse_str($parsedCurrentUrl['query'], $parsedCurrentQueries);
73 + $diff = array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries);
74 + if (empty($diff)) {
75 + return $formID;
76 + }
77 + }
65 78 }
66 - if (!isset($parsedCustomUrl['query'])) {
67 - return $formID;
68 - }
69 - parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
70 - parse_str($parsedCurrentUrl['query'] ?? '', $parsedCurrentQueries);
71 - if (empty(array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries))) {
72 - return $formID;
73 - }
74 79 }
75 -
76 - return null;
77 80 }
78 81
79 - private static function buildConversationalUrlMap()
80 - {
81 - $formModel = new FormModel();
82 - $forms = $formModel->get(['id', 'form_content']);
83 - $urlMap = [];
84 - if (is_wp_error($forms) || !is_array($forms)) {
85 - return $urlMap;
86 - }
87 - foreach ($forms as $form) {
88 - $formContent = json_decode($form->form_content);
89 - if (empty($formContent->formInfo->standaloneSettings->active)) {
90 - continue;
91 - }
92 - if (empty($formContent->formInfo->conversationalSettings->enable)) {
93 - continue;
94 - }
95 - $standaloneSettings = $formContent->formInfo->standaloneSettings;
96 - if (empty($standaloneSettings->customUrl)) {
97 - continue;
98 - }
99 - $urlMap[$form->id] = $standaloneSettings->customUrl;
100 - }
101 - return $urlMap;
102 - }
103 -
104 82 public static function conversationalFormView()
105 83 {
106 - if (is_admin()) {
107 - return;
108 - }
109 - // Read-only: form ID and preview flag from query string for conversational form dispatch. No state mutation.
110 - $formID = isset($_GET['bit-conversational-form']) ? sanitize_text_field(wp_unslash($_GET['bit-conversational-form'])) : '';
84 + $formID = isset($_GET['bit-conversational-form']) ? $_GET['bit-conversational-form'] : '';
111 85 $formType = 'conversational';
112 86 if (empty($formID)) {
113 87 $formID = self::getCustomUrlFormId();
114 88 }
@@ -117,16 +91,11 @@
117 91 return '';
118 92 }
119 93
120 94 $formID = intval($formID);
121 -
122 - $isPreview = isset($_GET['bf_preview']);
123 -
124 - ConversationalHelpers::setPreviewMode($isPreview);
125 -
126 95 $attr = ['type'=> $formType, 'form_id' => $formID, 'form_preview' => true];
127 96
128 - $FormManager = FormManager::getInstance($formID);
97 + $FormManager = new FormManager($formID);
129 98 $formContent = $FormManager->getFormContent();
130 99 if (empty($formContent->formInfo->conversationalSettings->enable)) {
131 100 return;
132 101 }
@@ -140,14 +109,13 @@
140 109
141 110 $formHTML = $formViewObject->html;
142 111 $font = $formViewObject->font;
143 112 $bfGlobals = $formViewObject->bfGlobals;
144 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
145 113
146 114 set_transient('bitform_form_preview', true);
147 115 $frontendFormHandler->generateJs($formID, null, $formType);
148 116 $title = 'Bit Form';
149 - Render::view('views/conversational-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'isPreview', 'formContent'));
117 + Render::view('views/conversational-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
150 118
151 119 exit(200);
152 120 }
153 121 }