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 -72 3.3.12.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,16 +27,14 @@
29 27
30 28 $formHTML = $formViewObject->html;
31 29 $font = $formViewObject->font;
32 30 $bfGlobals = $formViewObject->bfGlobals;
33 - $configTag = isset($formViewObject->configTag) ? $formViewObject->configTag : '';
34 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
35 31
36 32 if (defined('BITAPPS_DEV') && BITAPPS_DEV) {
37 33 set_transient('bitform_form_preview', true);
38 34 $frontendFormHandler->generateJs($formID);
39 35 $title = 'BitForm Preview page';
40 - Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'configTag', 'formContent'));
36 + Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
41 37 }
42 38 }
43 39 }
44 40
@@ -43,73 +39,50 @@
43 39 }
44 40
45 41 private static function getCustomUrlFormId()
46 42 {
47 - $urlMap = get_transient('bitform_conversational_url_map');
48 - if (false === $urlMap) {
49 - $urlMap = self::buildConversationalUrlMap();
50 - set_transient('bitform_conversational_url_map', $urlMap, DAY_IN_SECONDS);
51 - }
52 -
53 - if (empty($urlMap)) {
54 - return null;
55 - }
56 -
57 - $currentUrl = get_site_url() . (isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '');
43 + $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
58 44 $parsedCurrentUrl = wp_parse_url($currentUrl);
45 + $formModel = new FormModel();
46 + $forms = $formModel->get(
47 + ['id', 'form_content']
48 + );
59 49
60 - foreach ($urlMap as $formID => $customUrlSlug) {
61 - $customUrl = get_site_url() . '/' . $customUrlSlug;
62 - $parsedCustomUrl = wp_parse_url($customUrl);
63 - $pathMatched = isset($parsedCustomUrl['path']) && $parsedCustomUrl['path'] === ($parsedCurrentUrl['path'] ?? '');
64 - if (!$pathMatched) {
65 - 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 + }
66 78 }
67 - if (!isset($parsedCustomUrl['query'])) {
68 - return $formID;
69 - }
70 - parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
71 - parse_str($parsedCurrentUrl['query'] ?? '', $parsedCurrentQueries);
72 - if (empty(array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries))) {
73 - return $formID;
74 - }
75 79 }
76 -
77 - return null;
78 80 }
79 81
80 - private static function buildConversationalUrlMap()
81 - {
82 - $formModel = new FormModel();
83 - $forms = $formModel->get(['id', 'form_content']);
84 - $urlMap = [];
85 - if (is_wp_error($forms) || !is_array($forms)) {
86 - return $urlMap;
87 - }
88 - foreach ($forms as $form) {
89 - $formContent = json_decode($form->form_content);
90 - if (empty($formContent->formInfo->standaloneSettings->active)) {
91 - continue;
92 - }
93 - if (empty($formContent->formInfo->conversationalSettings->enable)) {
94 - continue;
95 - }
96 - $standaloneSettings = $formContent->formInfo->standaloneSettings;
97 - if (empty($standaloneSettings->customUrl)) {
98 - continue;
99 - }
100 - $urlMap[$form->id] = $standaloneSettings->customUrl;
101 - }
102 - return $urlMap;
103 - }
104 -
105 82 public static function conversationalFormView()
106 83 {
107 - if (is_admin()) {
108 - return;
109 - }
110 - // Read-only: form ID and preview flag from query string for conversational form dispatch. No state mutation.
111 - $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'] : '';
112 85 $formType = 'conversational';
113 86 if (empty($formID)) {
114 87 $formID = self::getCustomUrlFormId();
115 88 }
@@ -118,16 +91,11 @@
118 91 return '';
119 92 }
120 93
121 94 $formID = intval($formID);
122 -
123 - $isPreview = isset($_GET['bf_preview']);
124 -
125 - ConversationalHelpers::setPreviewMode($isPreview);
126 -
127 95 $attr = ['type'=> $formType, 'form_id' => $formID, 'form_preview' => true];
128 96
129 - $FormManager = FormManager::getInstance($formID);
97 + $FormManager = new FormManager($formID);
130 98 $formContent = $FormManager->getFormContent();
131 99 if (empty($formContent->formInfo->conversationalSettings->enable)) {
132 100 return;
133 101 }
@@ -141,15 +109,13 @@
141 109
142 110 $formHTML = $formViewObject->html;
143 111 $font = $formViewObject->font;
144 112 $bfGlobals = $formViewObject->bfGlobals;
145 - $configTag = isset($formViewObject->configTag) ? $formViewObject->configTag : '';
146 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
147 113
148 114 set_transient('bitform_form_preview', true);
149 115 $frontendFormHandler->generateJs($formID, null, $formType);
150 116 $title = 'Bit Form';
151 - Render::view('views/conversational-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'configTag', 'isPreview', 'formContent'));
117 + Render::view('views/conversational-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
152 118
153 119 exit(200);
154 120 }
155 121 }