PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / -3.0.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v-3.0.1
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
bit-form / includes / Frontend / Form / View / Conversational / ConversationalHelpers.php

ConversationalHelpers.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder -3.0.1, at includes/Frontend/Form/View/Conversational/ConversationalHelpers.php

277 lines 11.7 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\Form\View\Conversational;
4
5 use BitCode\BitForm\Admin\Form\Helpers;
6
7 class ConversationalHelpers
8 {
9 private $_formId;
10 private $_conversationalSettings;
11 private $_stepListObject;
12 private static $_isPreviewMode = false;
13
14 public static function setPreviewMode(bool $isPreview): void
15 {
16 self::$_isPreviewMode = $isPreview;
17 }
18
19 public function __construct($formId, $conversationalSettings)
20 {
21 $this->_formId = $formId;
22 $this->_conversationalSettings = $conversationalSettings;
23 $this->_stepListObject = $this->_conversationalSettings->stepListObject;
24 }
25
26 public function getWelcomePageView()
27 {
28 $welcomePageSettings = $this->getMergedStepSettings('welcomePage');
29 $welcomeTitle = '';
30 $welcomePageMarkup = '';
31 $buttonMarkup = '';
32
33 if (!$welcomePageSettings->enable) {
34 return '';
35 }
36 if (!empty($welcomePageSettings->title)) {
37 $welcomeTitle =
38 ' <div class="bc' . $this->_formId . '-welcome-title">' . "\n"
39 . ' <h2>' . $welcomePageSettings->title . '</h2>' . "\n"
40 . ' </div>';
41 }
42
43 $startBtnPreIcn = $this->conversationalSettingsIcon($welcomePageSettings, 'startBtnPreIcn', 'btn-pre-icon', 'Start Button Pre Icon');
44 $startBtnSufIcn = $this->conversationalSettingsIcon($welcomePageSettings, 'startBtnSufIcn', 'btn-suf-icon', 'Start Button Suf Icon');
45
46 $startBtnText = !empty($welcomePageSettings->btnTxt) ? $welcomePageSettings->btnTxt : 'Start';
47
48 $stepHints = !empty($welcomePageSettings->stepHints) ? $welcomePageSettings->stepHints : '';
49
50 $buttonMarkup =
51 ' <div class="bc' . $this->_formId . '-step-btn-wrpr">' . "\n"
52 . ' <div class="bc' . $this->_formId . '-step-btn-inner-wrpr">' . "\n"
53 . ' <div class="bc' . $this->_formId . '-step-btn-cntnt">' . "\n"
54 . ' <button class="bc' . $this->_formId . '-start-btn bc' . $this->_formId . '-btn" type="button">' . "\n"
55 . ' ' . $startBtnPreIcn . "\n"
56 . ' ' . $startBtnText . "\n"
57 . ' ' . $startBtnSufIcn . "\n"
58 . ' </button>' . "\n"
59 . ' <span class="bc' . $this->_formId . '-step-hints">' . "\n"
60 . ' ' . $stepHints . "\n"
61 . ' </span>' . "\n"
62 . ' </div>' . "\n"
63 . ' </div>' . "\n"
64 . ' </div>';
65
66 $welcomePageMarkup =
67 ' <div class="bc' . $this->_formId . '-welcome-content">' . "\n"
68 . ' ' . $welcomeTitle . "\n"
69 . ' ' . $welcomePageSettings->content . "\n"
70 . ' ' . $buttonMarkup . "\n"
71 . ' </div>';
72 $imageContent = $this->conversationalSettingsIcon($welcomePageSettings, 'layoutImage', 'step-img', 'Background Image');
73 $welcomeLayout = $welcomePageSettings->layout;
74 $welcomeLayoutClsNames = "bc{$this->_formId}-welcome $welcomeLayout";
75 return $this->getStepLayout($this->_formId, $imageContent, $welcomePageMarkup, $welcomeLayout, $welcomeLayoutClsNames);
76 }
77
78 public function getNavigationView()
79 {
80 $navigationSettings = $this->_conversationalSettings->navigationSettings;
81 $formId = $this->_formId;
82 $progressLabelMarkup = '';
83 $progressBarMarkup = '';
84 $progressMarkup = '';
85 $brandingMarkup = '';
86 $navBtnMarkup = '';
87
88 $isPreview = self::$_isPreviewMode;
89
90 if ($navigationSettings->showProgressLabel || $isPreview) {
91 $hiddenCls = ($isPreview && !$navigationSettings->showProgressLabel) ? ' bc-live-hidden' : '';
92 $progressLabelMarkup =
93 ' <div class="bc' . $formId . '-progress-lbl-wrpr' . $hiddenCls . '">' . "\n"
94 . ' <span class="bc' . $formId . '-progress-lbl">' . "\n"
95 . ' ' . $navigationSettings->progressLabel . "\n"
96 . ' </span>' . "\n"
97 . ' </div>';
98 }
99
100 if ($navigationSettings->showProgressBar || $isPreview) {
101 $hiddenCls = ($isPreview && !$navigationSettings->showProgressBar) ? ' bc-live-hidden' : '';
102 $progressBarMarkup =
103 ' <div class="bc' . $formId . '-progress-bar-wrpr' . $hiddenCls . '">' . "\n"
104 . ' <div class="bc' . $formId . '-progress-bar">' . "\n"
105 . ' <div class="bc' . $formId . '-progress-fill" style="width: 0%"></div>' . "\n"
106 . ' </div>' . "\n"
107 . ' </div>';
108 }
109
110 if ($navigationSettings->showProgressBar || $navigationSettings->showProgressLabel || $isPreview) {
111 $progressMarkup =
112 ' <div class="bc' . $formId . '-progress-wrpr">' . "\n"
113 . ' <div class="bc' . $formId . '-progress-cntnt" >' . "\n"
114 . ' ' . $progressLabelMarkup . "\n"
115 . ' ' . $progressBarMarkup . "\n"
116 . ' </div>' . "\n"
117 . ' </div>';
118 }
119
120 if ($navigationSettings->showBranding || $isPreview) {
121 $hiddenCls = ($isPreview && !$navigationSettings->showBranding) ? ' bc-live-hidden' : '';
122 $brandingMarkup =
123 ' <div class="bc' . $formId . '-branding-wrpr' . $hiddenCls . '">' . "\n"
124 . ' <div class="bc' . $formId . '-branding-cntnt">' . "\n"
125 . ' <div class="bc' . $formId . '-branding-lbl">' . "\n"
126 . ' <span class="bc' . $formId . '-prowered-by-lbl">Powered by</span> <span class="bc' . $formId . '-bit-form-lbl">BitForm</span>' . "\n"
127 . ' </div>' . "\n"
128 . ' </div>' . "\n"
129 . ' </div>';
130 }
131
132 if ($navigationSettings->showNavigateBtn || $isPreview) {
133 $hiddenCls = ($isPreview && !$navigationSettings->showNavigateBtn) ? ' bc-live-hidden' : '';
134 $navBtnMarkup =
135 ' <div class="bc' . $formId . '-nav-btn-wrpr' . $hiddenCls . '">' . "\n"
136 . ' <div class="bc' . $formId . '-nav-btn-cntnt">' . "\n"
137 . ' <button class="bc' . $formId . '-nav-btn bc' . $formId . '-nav-btn-up" type="button">' . "\n"
138 . ' <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up"><line x1="12" y1="19" x2="12" y2="5"></line><polyline points="5 12 12 5 19 12"></polyline></svg>' . "\n"
139 . ' </button>' . "\n"
140 . ' <button class="bc' . $formId . '-nav-btn bc' . $formId . '-nav-btn-down" type="button">' . "\n"
141 . ' <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-up"><line x1="12" y1="19" x2="12" y2="5"></line><polyline points="5 12 12 5 19 12"></polyline></svg>' . "\n"
142 . ' </button>' . "\n"
143 . ' </div>' . "\n"
144 . ' </div>';
145 }
146 $navBtnContainer = '';
147 if ($navigationSettings->showNavigateBtn || $isPreview) {
148 $navBtnContainer =
149 ' <div class="bc' . $formId . '-nav-btn-container">' . "\n"
150 . ' ' . $navBtnMarkup . "\n"
151 . ' </div>';
152 }
153
154 if ($navigationSettings->show || $isPreview) {
155 $hiddenCls = ($isPreview && !$navigationSettings->show) ? ' bc-live-hidden' : '';
156 return
157 ' <div class="bc' . $formId . '-nav-wrpr' . $hiddenCls . '">' . "\n"
158 . ' <div class="bc' . $formId . '-nav-wrpr-cntnt">' . "\n"
159 . ' ' . $progressMarkup . "\n"
160 . ' ' . $navBtnContainer . "\n"
161 . ' </div>' . "\n"
162 . ' ' . $brandingMarkup . "\n"
163 . ' </div>';
164 }
165 return '';
166 }
167
168 public function getStepButtonsView($fieldData, $stepSettings)
169 {
170 $formId = $this->_formId;
171 $isFieldRequired = !empty($fieldData->valid->req) && $fieldData->valid->req;
172 $btnTxt = $isFieldRequired ? $stepSettings->nextBtnTxt : $stepSettings->btnTxt;
173 $btnPreIcn = $this->conversationalSettingsIcon($stepSettings, 'btnPreIcn', 'btn-pre-icon', 'Button Prefix Icon');
174 $btnSufIcn = $this->conversationalSettingsIcon($stepSettings, 'btnSufIcn', 'btn-suf-icon', 'Button Suffix Icon');
175 $hiddenClass = $isFieldRequired ? 'bc-grid-hide' : '';
176 $stepHints = !empty($stepSettings->stepHints) ? $stepSettings->stepHints : '';
177
178 $dataBtnTxt = esc_attr(!empty($stepSettings->btnTxt) ? $stepSettings->btnTxt : 'Skip');
179 $dataNextBtnTxt = esc_attr(!empty($stepSettings->nextBtnTxt) ? $stepSettings->nextBtnTxt : 'Next');
180
181 $btnWrapperMarkup =
182 ' <div class="' . $hiddenClass . ' bc' . $formId . '-step-btn-wrpr">' . "\n"
183 . ' <div class="bc' . $formId . '-step-btn-inner-wrpr">' . "\n"
184 . ' <div class="bc' . $formId . '-step-btn-cntnt">' . "\n"
185 . ' <button class="bc' . $formId . '-btn bc' . $formId . '-btn-ok" type="button"'
186 . ' data-btn-txt="' . $dataBtnTxt . '" data-next-btn-txt="' . $dataNextBtnTxt . '">' . "\n"
187 . ' ' . $btnPreIcn . "\n"
188 . ' ' . $btnTxt . "\n"
189 . ' ' . $btnSufIcn . "\n"
190 . ' </button>' . "\n"
191 . ' <span class="bc' . $formId . '-step-hints">' . "\n"
192 . ' ' . $stepHints . "\n"
193 . ' </span>' . "\n"
194 . ' </div>' . "\n"
195 . ' </div>' . "\n"
196 . ' </div>';
197
198 return $btnWrapperMarkup;
199 }
200
201 public static function getStepLayout($formID, $imageContent, $fieldContent, $layoutName, $layoutClassNames = '')
202 {
203 $imageContentWrapper =
204 ' <div class="bc' . $formID . '-step-img-cntnr">' . "\n"
205 . ' <picture class="bc' . $formID . '-step-img-wrpr">' . "\n"
206 . ' ' . $imageContent . "\n"
207 . ' </picture>' . "\n"
208 . ' </div>';
209 $noImageLayouts = ['normal-layout', 'centered-card-layout'];
210 $imageContentWrapper = in_array($layoutName, $noImageLayouts, true) ? '' : $imageContentWrapper;
211
212 return
213 ' <div class="bc' . $formID . '-step-wrapper bc' . $formID . '-step bc-step-deactive ' . $layoutClassNames . '">' . "\n"
214 . ' <div class="bc' . $formID . '-step-content">' . "\n"
215 . ' ' . $imageContentWrapper . "\n"
216 . ' <div class="bc' . $formID . '-step-fld-wrpr">' . "\n"
217 . ' ' . $fieldContent . "\n"
218 . ' </div>' . "\n"
219 . ' </div>' . "\n"
220 . ' </div>';
221 }
222
223 public function conversationalSettingsIcon($data, $icnPropName, $element, $alt = 'Image')
224 {
225 if (Helpers::property_exists_nested($data, $icnPropName, '', 1)) {
226 $url = esc_url($data->$icnPropName);
227 return
228 ' <img' . "\n"
229 . ' class="bc' . $this->_formId . '-' . $element . '"' . "\n"
230 . ' src="' . $url . '"' . "\n"
231 . ' alt=' . $alt . "\n"
232 . ' />';
233 }
234 return '';
235 }
236
237 public function filterConversationalAllowedFields($layout, $fields)
238 {
239 $ignoreFields = $this::getConversationalIgnoredFields();
240 $newLayouts = (object) ['lg' => []];
241 foreach ($layout->lg as $row) {
242 if (!in_array($fields->{$row->i}->typ, $ignoreFields)) {
243 $newLayouts->lg[] = $row;
244 }
245 }
246 return $newLayouts;
247 }
248
249 public static function getConversationalIgnoredFields()
250 {
251 return [
252 'button',
253 'divider',
254 'spacer',
255 'title',
256 'html',
257 'shortcode',
258 'recaptcha',
259 'turnstile',
260 'hcaptcha',
261 'image',
262 'stripe',
263 'paypal',
264 'razorpay',
265 ];
266 }
267
268 public function getMergedStepSettings($stepPropertyName)
269 {
270 $allStepsSettings = $this->_stepListObject->allSteps;
271 $stepSettings = !empty($this->_stepListObject->{$stepPropertyName}) ? $this->_stepListObject->{$stepPropertyName} : (object) [];
272 $mergedSettings = (object) array_merge((array) $allStepsSettings, (array) $stepSettings);
273
274 return $mergedSettings;
275 }
276 }
277