PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
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 2.10.2 All 137 releases
bit-form / includes / Frontend / StandaloneFormView.php

StandaloneFormView.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.13, at includes/Frontend/StandaloneFormView.php

127 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend;
4
5 use BitCode\BitForm\Core\Database\FormModel;
6 use BitCode\BitForm\Core\Form\FormManager;
7 use BitCode\BitForm\Core\Util\Render;
8 use BitCode\BitForm\Frontend\Form\FrontendFormHandler;
9
10 class StandaloneFormView
11 {
12 public static function preview()
13 {
14 if (!(current_user_can('manage_options') || current_user_can('manage_bitform'))) {
15 auth_redirect();
16 return;
17 }
18 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- REQUEST_URI is parsed/compared, not output directly.
19 $requestUri = isset($_SERVER['REQUEST_URI']) ? wp_unslash($_SERVER['REQUEST_URI']) : '';
20 ('Request URI: ' . $requestUri);
21 $uri = explode('/', rtrim($requestUri, '/'));
22
23 if (is_array($uri) && count($uri) >= 3) {
24 $formID = $uri[2];
25 $attr = ['form_id' => $formID, 'form_preview' => true];
26
27 $frontendFormHandler = new FrontendFormHandler();
28 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
29 if ('string' === gettype($formViewObject)) {
30 Render::view('views/form-not-found');
31 exit;
32 }
33 $formHTML = $formViewObject->html;
34 $font = $formViewObject->font;
35 $bfGlobals = $formViewObject->bfGlobals;
36
37 set_transient('bitform_form_preview', true);
38 $frontendFormHandler->generateJs($formID);
39 $title = 'BitForm Preview page';
40 Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
41 }
42 }
43
44 private static function getCustomUrlFormId()
45 {
46 $currentUrl = get_site_url() . (isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '');
47 $parsedCurrentUrl = wp_parse_url($currentUrl);
48 $formModel = new FormModel();
49 $forms = $formModel->get(
50 ['id', 'form_content']
51 );
52
53 if (!is_wp_error($forms)) {
54 foreach ($forms as $form) {
55 $formID = $form->id;
56 $formContent = json_decode($form->form_content);
57 $isStandaloneActive = !empty($formContent->formInfo->standaloneSettings->active);
58 if ($isStandaloneActive) {
59 $standaloneSettings = $formContent->formInfo->standaloneSettings;
60 $hasCustomUrl = !empty($standaloneSettings->customUrl);
61 if (!$hasCustomUrl) {
62 continue;
63 }
64 $customUrl = get_site_url() . '/' . $standaloneSettings->customUrl;
65 $parsedCustomUrl = wp_parse_url($customUrl);
66 $pathMatched = $parsedCustomUrl['path'] === $parsedCurrentUrl['path'];
67 if (!$pathMatched) {
68 continue;
69 }
70 if (!isset($parsedCustomUrl['query'])) {
71 return $formID;
72 }
73 parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
74 parse_str($parsedCurrentUrl['query'], $parsedCurrentQueries);
75 $diff = array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries);
76 if (empty($diff)) {
77 return $formID;
78 }
79 }
80 }
81 }
82 }
83
84 public static function standaloneFormView()
85 {
86 $hasBitFormParam = isset($_GET['bit-form']);
87 $formID = isset($_GET['bit-form']) ? sanitize_text_field(wp_unslash($_GET['bit-form'])) : '';
88
89 if (empty($formID)) {
90 $formID = self::getCustomUrlFormId();
91 }
92
93 if (empty($formID)) {
94 return '';
95 }
96
97 $formID = intval($formID);
98 $attr = ['form_id' => $formID, 'form_preview' => true];
99
100 $FormManager = FormManager::getInstance($formID);
101 $formContent = $FormManager->getFormContent();
102 if (empty($formContent->formInfo->standaloneSettings->active)) {
103 return;
104 }
105
106 $standaloneSettings = $formContent->formInfo->standaloneSettings;
107
108 $frontendFormHandler = new FrontendFormHandler();
109 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
110 if ('string' === gettype($formViewObject)) {
111 Render::view('views/form-not-found');
112 exit;
113 }
114
115 $formHTML = $formViewObject->html;
116 $font = $formViewObject->font;
117 $bfGlobals = $formViewObject->bfGlobals;
118
119 set_transient('bitform_form_preview', true);
120 $frontendFormHandler->generateJs($formID);
121 $title = !empty($standaloneSettings->pageTitle) ? $standaloneSettings->pageTitle : 'Bit Form';
122 Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
123
124 exit(200);
125 }
126 }
127