PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.4
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.4, at includes/Frontend/StandaloneFormView.php

126 lines 4.0 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 $requestUri = esc_url($_SERVER['REQUEST_URI']);
19
20 $uri = explode('/', rtrim($requestUri, '/'));
21
22 if (is_array($uri) && count($uri) >= 3) {
23 $formID = $uri[2];
24 $attr = ['form_id' => $formID, 'form_preview' => true];
25
26 $frontendFormHandler = new FrontendFormHandler();
27 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
28 if ('string' === gettype($formViewObject)) {
29 Render::view('views/form-not-found');
30 exit;
31 }
32 $formHTML = $formViewObject->html;
33 $font = $formViewObject->font;
34 $bfGlobals = $formViewObject->bfGlobals;
35
36 set_transient('bitform_form_preview', true);
37 $frontendFormHandler->generateJs($formID);
38 $title = 'BitForm Preview page';
39 Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
40 }
41 }
42
43 private static function getCustomUrlFormId()
44 {
45 $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
46 $parsedCurrentUrl = wp_parse_url($currentUrl);
47 $formModel = new FormModel();
48 $forms = $formModel->get(
49 ['id', 'form_content']
50 );
51
52 if (!is_wp_error($forms)) {
53 foreach ($forms as $form) {
54 $formID = $form->id;
55 $formContent = json_decode($form->form_content);
56 $isStandaloneActive = !empty($formContent->formInfo->standaloneSettings->active);
57 if ($isStandaloneActive) {
58 $standaloneSettings = $formContent->formInfo->standaloneSettings;
59 $hasCustomUrl = !empty($standaloneSettings->customUrl);
60 if (!$hasCustomUrl) {
61 continue;
62 }
63 $customUrl = get_site_url() . '/' . $standaloneSettings->customUrl;
64 $parsedCustomUrl = wp_parse_url($customUrl);
65 $pathMatched = $parsedCustomUrl['path'] === $parsedCurrentUrl['path'];
66 if (!$pathMatched) {
67 continue;
68 }
69 if (!isset($parsedCustomUrl['query'])) {
70 return $formID;
71 }
72 parse_str($parsedCustomUrl['query'], $parsedCustomQueries);
73 parse_str($parsedCurrentUrl['query'], $parsedCurrentQueries);
74 $diff = array_diff_assoc($parsedCustomQueries, $parsedCurrentQueries);
75 if (empty($diff)) {
76 return $formID;
77 }
78 }
79 }
80 }
81 }
82
83 public static function standaloneFormView()
84 {
85 $hasBitFormParam = isset($_GET['bit-form']);
86 $formID = isset($_GET['bit-form']) ? $_GET['bit-form'] : '';
87
88 if (empty($formID)) {
89 $formID = self::getCustomUrlFormId();
90 }
91
92 if (empty($formID)) {
93 return '';
94 }
95
96 $formID = intval($formID);
97 $attr = ['form_id' => $formID, 'form_preview' => true];
98
99 $FormManager = FormManager::getInstance($formID);
100 $formContent = $FormManager->getFormContent();
101 if (empty($formContent->formInfo->standaloneSettings->active)) {
102 return;
103 }
104
105 $standaloneSettings = $formContent->formInfo->standaloneSettings;
106
107 $frontendFormHandler = new FrontendFormHandler();
108 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
109 if ('string' === gettype($formViewObject)) {
110 Render::view('views/form-not-found');
111 exit;
112 }
113
114 $formHTML = $formViewObject->html;
115 $font = $formViewObject->font;
116 $bfGlobals = $formViewObject->bfGlobals;
117
118 set_transient('bitform_form_preview', true);
119 $frontendFormHandler->generateJs($formID);
120 $title = !empty($standaloneSettings->pageTitle) ? $standaloneSettings->pageTitle : 'Bit Form';
121 Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
122
123 exit(200);
124 }
125 }
126