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 -67 3.3.12.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,83 +30,60 @@
31 30 }
32 31 $formHTML = $formViewObject->html;
33 32 $font = $formViewObject->font;
34 33 $bfGlobals = $formViewObject->bfGlobals;
35 - $configTag = isset($formViewObject->configTag) ? $formViewObject->configTag : '';
36 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
37 34
38 35 set_transient('bitform_form_preview', true);
39 36 $frontendFormHandler->generateJs($formID);
40 37 $title = 'BitForm Preview page';
41 - Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'configTag', 'formContent'));
38 + Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
42 39 }
43 40 }
44 41
45 42 private static function getCustomUrlFormId()
46 43 {
47 - $urlMap = get_transient('bitform_standalone_url_map');
48 - if (false === $urlMap) {
49 - $urlMap = self::buildStandaloneUrlMap();
50 - set_transient('bitform_standalone_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'])) : '');
44 + $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
58 45 $parsedCurrentUrl = wp_parse_url($currentUrl);
46 + $formModel = new FormModel();
47 + $forms = $formModel->get(
48 + ['id', 'form_content']
49 + );
59 50
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;
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 + }
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 buildStandaloneUrlMap()
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 - $standaloneSettings = $formContent->formInfo->standaloneSettings;
94 - if (empty($standaloneSettings->customUrl)) {
95 - continue;
96 - }
97 - $urlMap[$form->id] = $standaloneSettings->customUrl;
98 - }
99 - return $urlMap;
100 - }
101 -
102 82 public static function standaloneFormView()
103 83 {
104 - if (is_admin()) {
105 - return;
106 - }
107 - // Read-only: form ID from query string for standalone view dispatch. No state mutation.
108 84 $hasBitFormParam = isset($_GET['bit-form']);
109 - $formID = isset($_GET['bit-form']) ? sanitize_text_field(wp_unslash($_GET['bit-form'])) : '';
85 + $formID = isset($_GET['bit-form']) ? $_GET['bit-form'] : '';
110 86
111 87 if (empty($formID)) {
112 88 $formID = self::getCustomUrlFormId();
113 89 }
@@ -118,9 +94,9 @@
118 94
119 95 $formID = intval($formID);
120 96 $attr = ['form_id' => $formID, 'form_preview' => true];
121 97
122 - $FormManager = FormManager::getInstance($formID);
98 + $FormManager = new FormManager($formID);
123 99 $formContent = $FormManager->getFormContent();
124 100 if (empty($formContent->formInfo->standaloneSettings->active)) {
125 101 return;
126 102 }
@@ -136,15 +112,13 @@
136 112
137 113 $formHTML = $formViewObject->html;
138 114 $font = $formViewObject->font;
139 115 $bfGlobals = $formViewObject->bfGlobals;
140 - $configTag = isset($formViewObject->configTag) ? $formViewObject->configTag : '';
141 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
142 116
143 117 set_transient('bitform_form_preview', true);
144 118 $frontendFormHandler->generateJs($formID);
145 119 $title = !empty($standaloneSettings->pageTitle) ? $standaloneSettings->pageTitle : 'Bit Form';
146 - Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'configTag', 'formContent'));
120 + Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
147 121
148 122 exit(200);
149 123 }
150 124 }