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
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.7.0, at includes/Frontend/StandaloneFormView.php

121 lines 3.8 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 $requestUri = $_SERVER['REQUEST_URI'];
15 $uri = explode('/', $requestUri);
16
17 if (is_array($uri) && count($uri) > 0) {
18 $formID = $uri[count($uri) - 1];
19 $attr = ['form_id' => $formID, 'form_preview' => true];
20
21 $frontendFormHandler = new FrontendFormHandler();
22 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
23 if ('string' === gettype($formViewObject)) {
24 Render::view('views/form-not-found');
25 exit;
26 }
27 $formHTML = $formViewObject->html;
28 $font = $formViewObject->font;
29 $bfGlobals = $formViewObject->bfGlobals;
30
31 set_transient('bitform_form_preview', true);
32 $frontendFormHandler->generateJs($formID);
33 $title = 'BitForm Preview page';
34 Render::view('views/preview-page', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
35 }
36 }
37
38 private static function getCustomUrlFormId()
39 {
40 $currentUrl = get_site_url() . $_SERVER['REQUEST_URI'];
41 $parsedCurrentUrl = wp_parse_url($currentUrl);
42 $formModel = new FormModel();
43 $forms = $formModel->get(
44 ['id', 'form_content']
45 );
46
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 }
74 }
75 }
76 }
77
78 public static function standaloneFormView()
79 {
80 $hasBitFormParam = isset($_GET['bit-form']);
81 $formID = isset($_GET['bit-form']) ? $_GET['bit-form'] : '';
82
83 if (empty($formID)) {
84 $formID = self::getCustomUrlFormId();
85 }
86
87 if (empty($formID)) {
88 return '';
89 }
90
91 $formID = intval($formID);
92 $attr = ['form_id' => $formID, 'form_preview' => true];
93
94 $FormManager = new FormManager($formID);
95 $formContent = $FormManager->getFormContent();
96 if (empty($formContent->formInfo->standaloneSettings->active)) {
97 return;
98 }
99
100 $standaloneSettings = $formContent->formInfo->standaloneSettings;
101
102 $frontendFormHandler = new FrontendFormHandler();
103 $formViewObject = $frontendFormHandler->handleFrontendRenderRequest($attr);
104 if ('string' === gettype($formViewObject)) {
105 Render::view('views/form-not-found');
106 exit;
107 }
108
109 $formHTML = $formViewObject->html;
110 $font = $formViewObject->font;
111 $bfGlobals = $formViewObject->bfGlobals;
112
113 set_transient('bitform_form_preview', true);
114 $frontendFormHandler->generateJs($formID);
115 $title = !empty($standaloneSettings->pageTitle) ? $standaloneSettings->pageTitle : 'Bit Form';
116 Render::view('views/standalone-form', compact('formID', 'title', 'formHTML', 'font', 'bfGlobals'));
117
118 exit(200);
119 }
120 }
121