PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.7.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.7.0
V3.3.2 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 All 139 releases
← All changes | includes/Frontend/StandaloneFormView.php +41 -69 3.2.1 → 2.7.0 View file →
@@ -10,18 +10,13 @@
10 10 class StandaloneFormView
11 11 {
12 12 public static function preview()
13 13 {
14 - if (!(current_user_can('manage_options') || current_user_can('manage_bitform'))) {
15 - auth_redirect();
16 - return;
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)) {
14 + $requestUri = $_SERVER['REQUEST_URI'];
15 + $uri = explode('/', $requestUri);
16 +
17 + if (is_array($uri) && count($uri) > 0) {
18 + $formID = $uri[count($uri) - 1];
24 19 $attr = ['form_id' => $formID, 'form_preview' => true];
25 20
26 21 $frontendFormHandler = new FrontendFormHandler();
27 22 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
@@ -31,82 +26,60 @@
31 26 }
32 27 $formHTML = $formViewObject->html;
33 28 $font = $formViewObject->font;
34 29 $bfGlobals = $formViewObject->bfGlobals;
35 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
36 30
37 31 set_transient('bitform_form_preview', true);
38 32 $frontendFormHandler->generateJs($formID);
39 33 $title = 'BitForm Preview page';
40 - Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'formContent'));
34 + Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
41 35 }
42 36 }
43 37
44 38 private static function getCustomUrlFormId()
45 39 {
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'])) : '');
40 + $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
57 41 $parsedCurrentUrl = wp_parse_url($currentUrl);
42 + $formModel = new FormModel();
43 + $forms = $formModel->get(
44 + ['id', 'form_content']
45 + );
58 46
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;
47 + if (!is_wp_error($forms)) {
48 + foreach ($forms as $form) {
49 + $formID = $form->id;
50 + $formContent = json_decode($form->form_content);
51 + $isStandaloneActive = !empty($formContent->formInfo->standaloneSettings->active);
52 + if ($isStandaloneActive) {
53 + $standaloneSettings = $formContent->formInfo->standaloneSettings;
54 + $hasCustomUrl = !empty($standaloneSettings->customUrl);
55 + if (!$hasCustomUrl) {
56 + continue;
57 + }
58 + $customUrl = get_site_url() . '/' . $standaloneSettings->customUrl;
59 + $parsedCustomUrl = wp_parse_url($customUrl);
60 + $pathMatched = $parsedCustomUrl['path'] === $parsedCurrentUrl['path'];
61 + if (!$pathMatched) {
62 + continue;
63 + }
64 + if (!isset($parsedCustomUrl['query'])) {
65 + return $formID;
66 + }
67 + parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
68 + parse_str($parsedCurrentUrl['query'], $parsedCurrentQueries);
69 + $diff = array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries);
70 + if (empty($diff)) {
71 + return $formID;
72 + }
73 + }
65 74 }
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 75 }
75 -
76 - return null;
77 76 }
78 77
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 78 public static function standaloneFormView()
102 79 {
103 - if (is_admin()) {
104 - return;
105 - }
106 - // Read-only: form ID from query string for standalone view dispatch. No state mutation.
107 80 $hasBitFormParam = isset($_GET['bit-form']);
108 - $formID = isset($_GET['bit-form']) ? sanitize_text_field(wp_unslash($_GET['bit-form'])) : '';
81 + $formID = isset($_GET['bit-form']) ? $_GET['bit-form'] : '';
109 82
110 83 if (empty($formID)) {
111 84 $formID = self::getCustomUrlFormId();
112 85 }
@@ -117,9 +90,9 @@
117 90
118 91 $formID = intval($formID);
119 92 $attr = ['form_id' => $formID, 'form_preview' => true];
120 93
121 - $FormManager = FormManager::getInstance($formID);
94 + $FormManager = new FormManager($formID);
122 95 $formContent = $FormManager->getFormContent();
123 96 if (empty($formContent->formInfo->standaloneSettings->active)) {
124 97 return;
125 98 }
@@ -135,14 +108,13 @@
135 108
136 109 $formHTML = $formViewObject->html;
137 110 $font = $formViewObject->font;
138 111 $bfGlobals = $formViewObject->bfGlobals;
139 - $formContent = isset($formViewObject->formContent) ? $formViewObject->formContent : null;
140 112
141 113 set_transient('bitform_form_preview', true);
142 114 $frontendFormHandler->generateJs($formID);
143 115 $title = !empty($standaloneSettings->pageTitle) ? $standaloneSettings->pageTitle : 'Bit Form';
144 - Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals', 'formContent'));
116 + Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
145 117
146 118 exit(200);
147 119 }
148 120 }