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/StandaloneFormView.php +41 -65 3.1.02.15.3 View file →
@@ -14,14 +14,13 @@
14 14 if (!(current_user_can('manage_options') || current_user_can('manage_bitform'))) {
15 15 auth_redirect();
16 16 return;
17 17 }
18 - // $requestUri = isset($_SERVER['REQUEST_URI']) ? wp_unslash($_SERVER['REQUEST_URI']) : '';
19 - // ('Request URI: ' . $requestUri);
20 - // $uri = explode('/', rtrim($requestUri, '/'));
21 - // Read-only: form ID from query string for view dispatch. No state mutation.
22 - $formID = isset($_REQUEST['bitform-form-view']) && is_scalar($_REQUEST['bitform-form-view']) ? intval(sanitize_text_field(wp_unslash($_REQUEST['bitform-form-view']))) : null;
23 - if (!is_array($formID) && is_numeric($formID)) {
18 + $requestUri = esc_url($_SERVER['REQUEST_URI']);
19 + $uri = explode('/', $requestUri);
20 +
21 + if (is_array($uri) && count($uri) > 0) {
22 + $formID = $uri[count($uri) - 1];
24 23 $attr = ['form_id' => $formID, 'form_preview' => true];
25 24
26 25 $frontendFormHandler = new FrontendFormHandler();
27 26 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
@@ -31,82 +30,60 @@
31 30 }
32 31 $formHTML = $formViewObject->html;
33 32 $font = $formViewObject->font;
34 33 $bfGlobals = $formViewObject->bfGlobals;
35 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
36 34
37 35 set_transient('bitform_form_preview', true);
38 36 $frontendFormHandler->generateJs($formID);
39 37 $title = 'BitForm Preview page';
40 - Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'formContent'));
38 + Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
41 39 }
42 40 }
43 41
44 42 private static function getCustomUrlFormId()
45 43 {
46 - $urlMap = get_transient('bitform_standalone_url_map');
47 - if (false === $urlMap) {
48 - $urlMap = self::buildStandaloneUrlMap();
49 - set_transient('bitform_standalone_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'])) : '');
44 + $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
57 45 $parsedCurrentUrl = wp_parse_url($currentUrl);
46 + $formModel = new FormModel();
47 + $forms = $formModel->get(
48 + ['id', 'form_content']
49 + );
58 50
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;
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 + if ($isStandaloneActive) {
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 buildStandaloneUrlMap()
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 - $standaloneSettings = $formContent->formInfo->standaloneSettings;
93 - if (empty($standaloneSettings->customUrl)) {
94 - continue;
95 - }
96 - $urlMap[$form->id] = $standaloneSettings->customUrl;
97 - }
98 - return $urlMap;
99 - }
100 -
101 82 public static function standaloneFormView()
102 83 {
103 - if (is_admin()) {
104 - return;
105 - }
106 - // Read-only: form ID from query string for standalone view dispatch. No state mutation.
107 84 $hasBitFormParam = isset($_GET['bit-form']);
108 - $formID = isset($_GET['bit-form']) ? sanitize_text_field(wp_unslash($_GET['bit-form'])) : '';
85 + $formID = isset($_GET['bit-form']) ? $_GET['bit-form'] : '';
109 86
110 87 if (empty($formID)) {
111 88 $formID = self::getCustomUrlFormId();
112 89 }
@@ -117,9 +94,9 @@
117 94
118 95 $formID = intval($formID);
119 96 $attr = ['form_id' => $formID, 'form_preview' => true];
120 97
121 - $FormManager = FormManager::getInstance($formID);
98 + $FormManager = new FormManager($formID);
122 99 $formContent = $FormManager->getFormContent();
123 100 if (empty($formContent->formInfo->standaloneSettings->active)) {
124 101 return;
125 102 }
@@ -135,14 +112,13 @@
135 112
136 113 $formHTML = $formViewObject->html;
137 114 $font = $formViewObject->font;
138 115 $bfGlobals = $formViewObject->bfGlobals;
139 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
140 116
141 117 set_transient('bitform_form_preview', true);
142 118 $frontendFormHandler->generateJs($formID);
143 119 $title = !empty($standaloneSettings->pageTitle) ? $standaloneSettings->pageTitle : 'Bit Form';
144 - Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'formContent'));
120 + Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
145 121
146 122 exit(200);
147 123 }
148 124 }