| @@ -1,13 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form; |
| 4 | 4 | |
| 5 | -if (!defined('ABSPATH')) { | |
| 6 | - exit; | |
| 7 | -} | |
| 8 | - | |
| 9 | -use BitCode\BitForm\Admin\Form\AdminFormHandler; | |
| 10 | 5 | use BitCode\BitForm\Admin\Form\FrontEndScriptGenerator; |
| 11 | 6 | use BitCode\BitForm\Admin\Form\Helpers; |
| 12 | 7 | use BitCode\BitForm\Core\Database\FormEntryMetaModel; |
| 13 | 8 | use BitCode\BitForm\Core\Database\FormModel; |
| @@ -12,14 +7,15 @@ | ||
| 12 | 7 | use BitCode\BitForm\Core\Database\FormEntryMetaModel; |
| 13 | 8 | use BitCode\BitForm\Core\Database\FormModel; |
| 14 | 9 | use BitCode\BitForm\Core\Form\FormManager; |
| 15 | 10 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 16 | -use BitCode\BitForm\Core\Util\EscapingHelper; | |
| 17 | 11 | use BitCode\BitForm\Core\Util\FieldValueHandler; |
| 18 | 12 | use BitCode\BitForm\Core\Util\FileDownloadProvider; |
| 19 | 13 | use BitCode\BitForm\Core\Util\FrontendHelpers; |
| 20 | 14 | use BitCode\BitForm\Core\Util\SmartTags; |
| 15 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 21 | 16 | use BitCode\BitForm\Core\WorkFlow\WorkFlow; |
| 17 | +use BitCode\BitFormPro\Admin\FormSettings\FormAbandonment; | |
| 22 | 18 | |
| 23 | 19 | final class FrontendFormHandler |
| 24 | 20 | { |
| 25 | 21 | public function __construct() |
| @@ -53,9 +49,9 @@ | ||
| 53 | 49 | } |
| 54 | 50 | |
| 55 | 51 | private function getJSFileSrc($postId) |
| 56 | 52 | { |
| 57 | - $formUpdateVersion = get_option('bitform_form_update_version'); | |
| 53 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 58 | 54 | $formScriptSrc = BITFORMS_UPLOAD_BASE_URL . "/form-scripts/$postId/bitform-js-$postId.js?bfv=$formUpdateVersion"; |
| 59 | 55 | |
| 60 | 56 | return $formScriptSrc; |
| 61 | 57 | } |
| @@ -81,12 +77,12 @@ | ||
| 81 | 77 | $formIDs = []; |
| 82 | 78 | $previewMode = 'classic'; |
| 83 | 79 | $postId = ''; |
| 84 | 80 | |
| 85 | - $formUpdateVersion = get_option('bitform_form_update_version'); | |
| 81 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 86 | 82 | if ($formID) { |
| 87 | 83 | $formIDs[] = $formID; |
| 88 | - $FrontendFormManager = FrontendFormManager::getInstance($formID, 1); | |
| 84 | + $FrontendFormManager = new FrontendFormManager($formID, 1); | |
| 89 | 85 | $formInfo = $FrontendFormManager->getFormInfo(); |
| 90 | 86 | $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier()); |
| 91 | 87 | $formContent = $FrontendFormManager->getFormContentWithValue($this->getValuesFromQueryParams()); |
| 92 | 88 | $formContent->formId = $formID; |
| @@ -128,9 +124,9 @@ | ||
| 128 | 124 | return; |
| 129 | 125 | } |
| 130 | 126 | foreach ($bfFrontendFormIds as $index => $formId) { |
| 131 | 127 | $shortCodeCounter = $index + 1; |
| 132 | - $FrontendFormManager = FrontendFormManager::getInstance($formId, $shortCodeCounter); | |
| 128 | + $FrontendFormManager = new FrontendFormManager($formId, $shortCodeCounter); | |
| 133 | 129 | $formInfo = $FrontendFormManager->getFormInfo(); |
| 134 | 130 | $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier()); |
| 135 | 131 | $formContent = $FrontendFormManager->getFormContentWithValue($this->getValuesFromQueryParams()); |
| 136 | 132 | $formContent->formId = $formId; |
| @@ -153,11 +149,8 @@ | ||
| 153 | 149 | return; |
| 154 | 150 | } |
| 155 | 151 | |
| 156 | 152 | $frontendScriptGenObj->generateJsFile($formContents, $allFields, $contentIds, $postId, $formIDs, $previewMode); |
| 157 | - if ('preview' === $previewMode) { | |
| 158 | - return; | |
| 159 | - } | |
| 160 | 153 | wp_enqueue_script('bit-form-all-script-test', $this->getJSFileSrc($postId), [], $formUpdateVersion, true); |
| 161 | 154 | } |
| 162 | 155 | |
| 163 | 156 | private function deleteUnusedFormPageIds($postId, $formIDs) |
| @@ -185,15 +178,15 @@ | ||
| 185 | 178 | $formModel->update(['generated_script_page_ids' => wp_json_encode($generatedScriptPageIdsDecoded)], ['id' => $formId]); |
| 186 | 179 | } |
| 187 | 180 | } |
| 188 | 181 | if ($regenerateScriptFlag) { |
| 189 | - $formUpdateVersion = get_option('bitform_form_update_version'); | |
| 182 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 190 | 183 | if (!$formUpdateVersion) { |
| 191 | 184 | $formUpdateVersion = 1; |
| 192 | 185 | } else { |
| 193 | 186 | $formUpdateVersion = (int) $formUpdateVersion + 1; |
| 194 | 187 | } |
| 195 | - update_option('bitform_form_update_version', $formUpdateVersion); | |
| 188 | + update_option('bit-form_form_update_version', $formUpdateVersion); | |
| 196 | 189 | } |
| 197 | 190 | return $regenerateScriptFlag; |
| 198 | 191 | } |
| 199 | 192 | |
| @@ -206,9 +199,9 @@ | ||
| 206 | 199 | $postId = $post->ID; |
| 207 | 200 | $regenerateScriptFlag = false; |
| 208 | 201 | $formModel = new FormModel(); |
| 209 | 202 | foreach ($formsIds as $formId) { |
| 210 | - $formInstance = FormManager::getInstance($formId); | |
| 203 | + $formInstance = new FormManager($formId); | |
| 211 | 204 | if (!$formInstance->isExist()) { |
| 212 | 205 | continue; |
| 213 | 206 | } |
| 214 | 207 | $generatedPages = $formInstance->getFormData('generated_script_page_ids'); |
| @@ -238,11 +231,10 @@ | ||
| 238 | 231 | |
| 239 | 232 | private function addInlineScript($code, $handle = '', $position = 'after') |
| 240 | 233 | { |
| 241 | 234 | $scriptHandle = !empty($handle) ? $handle : 'bf-inline-script'; |
| 242 | - $formUpdateVersion = get_option('bitform_form_update_version'); | |
| 243 | 235 | if (!wp_script_is($scriptHandle)) { |
| 244 | - wp_register_script($scriptHandle, '', [], $formUpdateVersion, true); | |
| 236 | + wp_register_script($scriptHandle, '', [], '', true); | |
| 245 | 237 | wp_enqueue_script($scriptHandle); |
| 246 | 238 | } |
| 247 | 239 | wp_add_inline_script($scriptHandle, $code, $position); |
| 248 | 240 | } |
| @@ -249,11 +241,10 @@ | ||
| 249 | 241 | |
| 250 | 242 | private function addInlineStyle($code, $handle = '') |
| 251 | 243 | { |
| 252 | 244 | $styleHandle = !empty($handle) ? $handle : 'bf-inline-style'; |
| 253 | - $formUpdateVersion = get_option('bitform_form_update_version'); | |
| 254 | 245 | if (!wp_style_is($styleHandle)) { |
| 255 | - wp_register_style($styleHandle, '', [], $formUpdateVersion); | |
| 246 | + wp_register_style($styleHandle, '', [], '', true); | |
| 256 | 247 | wp_enqueue_style($styleHandle); |
| 257 | 248 | } |
| 258 | 249 | wp_add_inline_style($styleHandle, $code); |
| 259 | 250 | } |
| @@ -281,9 +272,9 @@ | ||
| 281 | 272 | } |
| 282 | 273 | |
| 283 | 274 | private function executeOnUserInput($formID, $shortCodeCounter, $fields) |
| 284 | 275 | { |
| 285 | - $FrontendFormManager = FrontendFormManager::getInstance($formID, $shortCodeCounter); | |
| 276 | + $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter); | |
| 286 | 277 | $previousValue = $this->getValuesFromQueryParams(); |
| 287 | 278 | $formContent = $FrontendFormManager->getFormContentWithValue($previousValue); |
| 288 | 279 | $customCodesExist = strpos(FrontEndScriptGenerator::getCustomCodes($formID)['JavaScript'], 'bfVars'); |
| 289 | 280 | if ($customCodesExist || (!empty($formContent->workFlowExist) && !empty($formContent->workFlowExist->oninput))) { |
| @@ -293,12 +284,11 @@ | ||
| 293 | 284 | } |
| 294 | 285 | |
| 295 | 286 | private function getValuesFromQueryParams() |
| 296 | 287 | { |
| 297 | - // Read-only: query string parsed to pre-fill form fields. Values are sanitized per field before use. | |
| 298 | 288 | $queryParamsValue = []; |
| 299 | 289 | if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { |
| 300 | - $reqField = sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])); | |
| 290 | + $reqField = $_SERVER['QUERY_STRING']; | |
| 301 | 291 | foreach (explode('&', $reqField) as $keyValue) { |
| 302 | 292 | // $pattern = '/([a-zA-Z0-9])([a-zA-Z])\=+/'; |
| 303 | 293 | $pattern = '/([^.]+)=(.*?)([^.]+)/'; |
| 304 | 294 | $matches = preg_match($pattern, $keyValue, $matchFormat); |
| @@ -325,11 +315,10 @@ | ||
| 325 | 315 | $formID = intval($atts['form_id']); |
| 326 | 316 | } |
| 327 | 317 | if (isset($atts['entry_id'])) { |
| 328 | 318 | $entryId = intval($atts['entry_id']); |
| 329 | - // Read-only: entry ID from query string for shortcode render. No state mutation. | |
| 330 | - } elseif (isset($_GET['bf_entry_id']) && !is_array($_GET['bf_entry_id'])) { | |
| 331 | - $entryId = intval(sanitize_text_field(wp_unslash($_GET['bf_entry_id']))); | |
| 319 | + } elseif (isset($_GET['bf_entry_id'])) { | |
| 320 | + $entryId = $_GET['bf_entry_id']; | |
| 332 | 321 | } else { |
| 333 | 322 | $entryId = false; |
| 334 | 323 | } |
| 335 | 324 | if (isset($atts['id'])) { |
| @@ -341,22 +330,24 @@ | ||
| 341 | 330 | return __('Form ID cannot be empty', 'bit-form'); |
| 342 | 331 | } |
| 343 | 332 | |
| 344 | 333 | if (!$this->isExist($formID)) { |
| 345 | - /* translators: %s: form ID */ | |
| 346 | 334 | return sprintf(__('#%s no. Form doesn\'t exists', 'bit-form'), $formID); |
| 347 | 335 | } |
| 348 | 336 | |
| 349 | - // Add-ons may detect whether the current visitor is resuming an abandoned entry. | |
| 350 | - $isAbandoned = (bool) apply_filters('bitform_is_abandoned_entry', false, $formID, $entryId, $atts); | |
| 337 | + // check for abandoned form entry id | |
| 338 | + $isAbandoned = false; | |
| 339 | + if (empty($entryId) && Utilities::isPro() && class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) { | |
| 340 | + $FormAbandonment = new FormAbandonment($formID); | |
| 341 | + $isAbandoned = $FormAbandonment->checkAbandonedFormEntryId(); | |
| 342 | + } | |
| 351 | 343 | |
| 352 | 344 | FrontendHelpers::setBfFrontendFormIds($formID); |
| 353 | 345 | $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 354 | 346 | $shortCodeCounter = count($bfFrontendFormIds); |
| 355 | - $FrontendFormManager = FrontendFormManager::getInstance($formID, $shortCodeCounter); | |
| 347 | + $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter); | |
| 356 | 348 | |
| 357 | 349 | if (!$FrontendFormManager->checkStatus()) { |
| 358 | - /* translators: %s: form ID */ | |
| 359 | 350 | return sprintf(__('#%s no. Form is not active', 'bit-form'), $formID); |
| 360 | 351 | } |
| 361 | 352 | ob_start(); |
| 362 | 353 | $this->loadAssets($formID, $formType); |
| @@ -366,11 +357,10 @@ | ||
| 366 | 357 | if ($font && !$formPreview) { |
| 367 | 358 | wp_enqueue_style('bf-google-font', $font, '1.0.0', true); |
| 368 | 359 | } |
| 369 | 360 | |
| 370 | - // Read-only: password reset token from URL for display-time validation. No state written until form is submitted. | |
| 371 | 361 | if (!empty($_GET['token']) && !empty($_GET['id'])) { |
| 372 | - $this->validPassowordResetToken(sanitize_text_field(wp_unslash($_GET['token'])), sanitize_text_field(wp_unslash($_GET['id'])), $formID); | |
| 362 | + $this->validPassowordResetToken($_GET['token'], $_GET['id'], $formID); | |
| 373 | 363 | } |
| 374 | 364 | |
| 375 | 365 | $previousValue = $this->getValuesFromQueryParams(); |
| 376 | 366 | $errorMessages = []; // delete |
| @@ -387,20 +377,13 @@ | ||
| 387 | 377 | $buttons = !empty($formContent->buttons) ? $formContent->buttons : ''; |
| 388 | 378 | $additional = $formContent->additional; |
| 389 | 379 | |
| 390 | 380 | // $workFlowRunType = $entryId ? 'edit' : 'create'; |
| 391 | - if ($entryId && (FrontendHelpers::is_current_user_can_access($formID, 'entryEditAccess'))) { | |
| 381 | + if ($entryId && (get_current_user_id() || is_admin())) { | |
| 382 | + // return sprintf(__('Sorry!, You cannot edit #%s no form.', 'bit-form'), $formID); | |
| 392 | 383 | $workFlowRunType = 'edit'; |
| 393 | - $adminFormHandler = new AdminFormHandler(); | |
| 394 | - $getEntry = $adminFormHandler->getSingleEntry($formID, $entryId); | |
| 395 | - if (FrontendHelpers::is_current_user_can_access($formID, 'entryEditAccess', '', $getEntry->__user_id)) { | |
| 396 | - $fields = $this->setFieldsValue($fields, $formID, $entryId); | |
| 397 | - } elseif (!$isAbandoned) { | |
| 398 | - $entryId = false; | |
| 399 | - $workFlowRunType = 'create'; | |
| 400 | - } | |
| 384 | + $fields = $this->setFieldsValue($fields, $formID, $entryId); | |
| 401 | 385 | } else { |
| 402 | - $entryId = false; | |
| 403 | 386 | $workFlowRunType = 'create'; |
| 404 | 387 | } |
| 405 | 388 | |
| 406 | 389 | // if ($entryId) { |
| @@ -413,11 +396,11 @@ | ||
| 413 | 396 | do_action('bitform_onload_fields', $fields, $formID); |
| 414 | 397 | $workFlowreturnedOnUserInput = $this->executeOnUserInput($formID, $shortCodeCounter, $fields); |
| 415 | 398 | |
| 416 | 399 | // test for form before remove |
| 417 | - $noLabelFieldTypes = ['decision-box', 'gdpr', 'html', 'shortcode', 'button', 'paypal', 'razorpay', 'recaptcha', 'turnstile', 'hcaptcha', 'stripe', 'spacer']; | |
| 400 | + $noLabel = ['decision-box', 'html', 'shortcode', 'button', 'paypal', 'razorpay', 'recaptcha']; | |
| 418 | 401 | foreach ($fields as $fldKey => $field) { |
| 419 | - if (!in_array($field->typ, $noLabelFieldTypes) && isset($field->lbl)) { | |
| 402 | + if (!in_array($field->typ, $noLabel) && isset($field->lbl)) { | |
| 420 | 403 | $lblReplaceToBackslash = str_replace('$_bf_$', '\\', $field->lbl); |
| 421 | 404 | $fields->{$fldKey}->lbl = FieldValueHandler::replaceSmartTagWithValue($lblReplaceToBackslash); |
| 422 | 405 | } |
| 423 | 406 | } |
| @@ -423,9 +406,9 @@ | ||
| 423 | 406 | } |
| 424 | 407 | $fieldsKey = $FrontendFormManager->getFieldsKey(); |
| 425 | 408 | |
| 426 | 409 | $captchaV3Settings = $FrontendFormManager->getCaptchaV3Settings(); |
| 427 | - if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings || $FrontendFormManager->getTurnstileSettings() || $FrontendFormManager->isFieldTypeExist('hcaptcha')) { | |
| 410 | + if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings || $FrontendFormManager->getTurnstileSettings()) { | |
| 428 | 411 | $integrationHandler = new IntegrationHandler(0); |
| 429 | 412 | $allFormIntegrations = $integrationHandler->getAllIntegration('app'); |
| 430 | 413 | if (!is_wp_error($allFormIntegrations)) { |
| 431 | 414 | foreach ($allFormIntegrations as $integration) { |
| @@ -448,17 +431,8 @@ | ||
| 448 | 431 | $integrationDetails = json_decode($integration->integration_details); |
| 449 | 432 | $turnstileSiteKey = $integrationDetails->siteKey; |
| 450 | 433 | } |
| 451 | 434 | |
| 452 | - if ( | |
| 453 | - $FrontendFormManager->isFieldTypeExist('hcaptcha') | |
| 454 | - && !is_null($integration->integration_type) | |
| 455 | - && 'hcaptcha' === $integration->integration_type | |
| 456 | - ) { | |
| 457 | - $integrationDetails = json_decode($integration->integration_details); | |
| 458 | - $hCaptchaSiteKey = $integrationDetails->siteKey; | |
| 459 | - } | |
| 460 | - | |
| 461 | 435 | if ($captchaV3Settings) { |
| 462 | 436 | if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) { |
| 463 | 437 | $integrationDetails = json_decode($integration->integration_details); |
| 464 | 438 | $integrationDetails->id = $integration->id; |
| @@ -472,11 +446,9 @@ | ||
| 472 | 446 | |
| 473 | 447 | if ($captchaV3Settings && !empty($reCAPTCHA->siteKey)) { |
| 474 | 448 | // DANGER: no matter what, DONT CHANGE THE SCRIPT ID OF THIS SCRIPT |
| 475 | 449 | $scriptId = BITFORMS_PREFIX . 'recaptcha'; |
| 476 | - // External Google reCAPTCHA script; version managed by URL query param. Loaded in header because | |
| 477 | - // standalone form views do not render wp_footer(), making footer enqueue unreliable. | |
| 478 | - wp_enqueue_script($scriptId, "https://www.google.com/recaptcha/api.js?render={$reCAPTCHA->siteKey}", [], null, false); | |
| 450 | + wp_enqueue_script($scriptId, "https://www.google.com/recaptcha/api.js?render={$reCAPTCHA->siteKey}"); | |
| 479 | 451 | } |
| 480 | 452 | |
| 481 | 453 | $configs = [ |
| 482 | 454 | 'bf_separator' => BITFORMS_BF_SEPARATOR, |
| @@ -533,10 +505,9 @@ | ||
| 533 | 505 | 'smartTags' => SmartTags::smartTags(SmartTags::getPostUserData()), |
| 534 | 506 | 'paymentCallbackUrl' => get_rest_url() . 'bitform/v1/payments/razorpay', |
| 535 | 507 | 'gRecaptchaSiteKey' => !empty($reCAPTCHA->siteKey) ? $reCAPTCHA->siteKey : null, |
| 536 | 508 | 'gRecaptchaVersion' => !empty($reCAPTCHAVersion) ? $reCAPTCHAVersion : null, |
| 537 | - 'turnstileSiteKey' => !empty($turnstileSiteKey) ? $turnstileSiteKey : null, | |
| 538 | - 'hCaptchaSiteKey' => !empty($hCaptchaSiteKey) ? $hCaptchaSiteKey : null, | |
| 509 | + 'turnstileSiteKey' => !empty($turnstileSiteKey) ? $turnstileSiteKey : null | |
| 539 | 510 | ]; |
| 540 | 511 | |
| 541 | 512 | if ($entryId) { |
| 542 | 513 | $bitFormFrontArr['entryId'] = $entryId; |
| @@ -553,9 +524,8 @@ | ||
| 553 | 524 | } |
| 554 | 525 | } |
| 555 | 526 | |
| 556 | 527 | $formInfo = $FrontendFormManager->getFormInfo(); |
| 557 | - $bitFormFrontArr['formName'] = $formInfo->formName ?? ''; | |
| 558 | 528 | if (is_array($layout) && count($layout) > 1) { |
| 559 | 529 | $multiStepSettings = isset($formInfo->multiStepSettings) ? $formInfo->multiStepSettings : null; |
| 560 | 530 | $newTempSettings = (object) [ |
| 561 | 531 | 'validateOnStepChange' => isset($multiStepSettings->validateOnStepChange) ? $multiStepSettings->validateOnStepChange : false, |
| @@ -581,24 +551,27 @@ | ||
| 581 | 551 | 'formAbandonment' => $formAbandonmentSettings |
| 582 | 552 | ]; |
| 583 | 553 | } |
| 584 | 554 | |
| 555 | + $bitFormsFront = apply_filters( | |
| 556 | + 'bitforms_localized_script', | |
| 557 | + $bitFormFrontArr | |
| 558 | + ); | |
| 559 | + | |
| 585 | 560 | $layout = wp_json_encode($layout); |
| 586 | 561 | $buttons = wp_json_encode($buttons); |
| 587 | 562 | $frontArr = wp_json_encode($bitFormFrontArr); |
| 588 | 563 | |
| 589 | - $bfGlobals = sprintf(' | |
| 564 | + $bfGlobals = <<<BFGLOBALS | |
| 590 | 565 | if(!window.bf_globals) { |
| 591 | 566 | window.bf_globals = {} |
| 592 | - } if(!window.bf_globals.%1$s) { | |
| 593 | - window.bf_globals.%1$s = {} | |
| 567 | + } if(!window.bf_globals.{$FormIdentifier}) { | |
| 568 | + window.bf_globals.{$FormIdentifier} = {} | |
| 594 | 569 | } |
| 595 | - if(document.getElementById("%1$s")) { | |
| 596 | - window.bf_globals.%1$s = { | |
| 597 | - ...window.bf_globals.%1$s, | |
| 598 | - ...%2$s | |
| 599 | - }; | |
| 600 | - }', $FormIdentifier, $frontArr); | |
| 570 | + if(document.getElementById('{$FormIdentifier}')) { | |
| 571 | + window.bf_globals.{$FormIdentifier} = {...window.bf_globals.{$FormIdentifier}, ...{$frontArr}}; | |
| 572 | + } | |
| 573 | +BFGLOBALS; | |
| 601 | 574 | |
| 602 | 575 | if ('conversational' === $formType |
| 603 | 576 | && isset($formContent->formInfo->conversationalSettings->enable) |
| 604 | 577 | && $formContent->formInfo->conversationalSettings->enable) { |
| @@ -613,37 +586,17 @@ | ||
| 613 | 586 | $formViewObject = new \stdClass(); |
| 614 | 587 | $formViewObject->html = $html; |
| 615 | 588 | $formViewObject->font = $font; |
| 616 | 589 | $formViewObject->bfGlobals = $bfGlobals; |
| 617 | - $formViewObject->formContent = $formContent; | |
| 618 | 590 | return $formViewObject; |
| 619 | 591 | } |
| 620 | - | |
| 621 | - $bfGlobalsHandle = 'bitform-bf-globals-' . sanitize_key($FormIdentifier); | |
| 622 | - $this->addInlineScript($bfGlobals, $bfGlobalsHandle, 'after'); | |
| 623 | - $this->emitShowPickerBridge(); | |
| 624 | - | |
| 625 | - echo wp_kses(trim($html), EscapingHelper::getFormAllowedHtml($formContent)); | |
| 592 | + $html .= <<<BFGLOBALSSCRIPT | |
| 593 | + <script id="bit-form-bf-globals-{$FormIdentifier}">{$bfGlobals}</script> | |
| 594 | +BFGLOBALSSCRIPT; | |
| 595 | + echo trim($html); | |
| 626 | 596 | return ob_get_clean(); |
| 627 | 597 | } |
| 628 | 598 | |
| 629 | - /** | |
| 630 | - * Delegated listener that opens the native picker on date/time inputs marked | |
| 631 | - * with data-bf-show-picker. Replaces the legacy hardcoded onclick attribute. | |
| 632 | - * Registered as inline script once per request via wp_add_inline_script so | |
| 633 | - * the markup never travels through wp_kses(). | |
| 634 | - */ | |
| 635 | - private function emitShowPickerBridge() | |
| 636 | - { | |
| 637 | - static $emitted = false; | |
| 638 | - if ($emitted) { | |
| 639 | - return; | |
| 640 | - } | |
| 641 | - $emitted = true; | |
| 642 | - $code = 'if(!window.__bfShowPickerBound){window.__bfShowPickerBound=true;document.addEventListener("click",function(e){var t=e.target;if(t&&t.matches&&t.matches("input[data-bf-show-picker=\"1\"]")&&typeof t.showPicker==="function"){try{t.showPicker();}catch(_){}}});}'; | |
| 643 | - $this->addInlineScript($code, 'bitform-show-picker-bridge', 'after'); | |
| 644 | - } | |
| 645 | - | |
| 646 | 599 | private function isExist($formID) |
| 647 | 600 | { |
| 648 | 601 | $formModel = new FormModel(); |
| 649 | 602 | $form = $formModel->get( |
| @@ -661,9 +614,8 @@ | ||
| 661 | 614 | } |
| 662 | 615 | |
| 663 | 616 | private function getFieldsValue($formID, $entryID) |
| 664 | 617 | { |
| 665 | - $FrontendFormManager = FrontendFormManager::getInstance($formID, 1); | |
| 666 | 618 | $formEntryModel = new FormEntryMetaModel(); |
| 667 | 619 | $metaValues = $formEntryModel->get( |
| 668 | 620 | [ |
| 669 | 621 | 'meta_key', |
| @@ -672,9 +624,8 @@ | ||
| 672 | 624 | [ |
| 673 | 625 | 'bitforms_form_entry_id' => $entryID, |
| 674 | 626 | ] |
| 675 | 627 | ); |
| 676 | - $formFields = $FrontendFormManager->getFields(); | |
| 677 | 628 | $fldsData = (object) []; |
| 678 | 629 | if (!is_wp_error($metaValues)) { |
| 679 | 630 | foreach ($metaValues as $metaValue) { |
| 680 | 631 | $metaKey = $metaValue->meta_key; |
| @@ -692,11 +643,8 @@ | ||
| 692 | 643 | if (!isset($fldsData->{$metaKey})) { |
| 693 | 644 | $fldsData->{$metaKey} = ''; |
| 694 | 645 | } |
| 695 | 646 | $fldsData->{$metaKey} = $metaVal; |
| 696 | - if (isset($formFields[$metaKey]['type']) && in_array($formFields[$metaKey]['type'], ['file-up', 'advanced-file-up'])) { | |
| 697 | - $fldsData->{$metaKey} = $metaValue->meta_value; | |
| 698 | - } | |
| 699 | 647 | } |
| 700 | 648 | } |
| 701 | 649 | |
| 702 | 650 | return $fldsData; |
| @@ -764,9 +712,9 @@ | ||
| 764 | 712 | $newFormId = $formID . '-formid'; |
| 765 | 713 | } else { |
| 766 | 714 | $newFormId = $formID; |
| 767 | 715 | } |
| 768 | - $formUpdateVersion = get_option('bitform_form_update_version'); | |
| 716 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 769 | 717 | if (!wp_style_is('bitform-style-' . $newFormId) && is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css')) { |
| 770 | 718 | wp_enqueue_style( |
| 771 | 719 | 'bitform-style-' . $newFormId, |
| 772 | 720 | BITFORMS_UPLOAD_BASE_URL . "/form-styles/bitform-{$newFormId}.css", |
| @@ -774,9 +722,9 @@ | ||
| 774 | 722 | $formUpdateVersion |
| 775 | 723 | ); |
| 776 | 724 | if ($isPageBuilder) { |
| 777 | 725 | $formStyle = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css'); |
| 778 | - echo '<style id="bitform-style-' . esc_attr((string) $newFormId) . '">' . wp_kses($formStyle, []) . '</style>'; | |
| 726 | + echo sprintf("<style id='bitform-style-{$newFormId}'>%s</style>", $formStyle); | |
| 779 | 727 | } |
| 780 | 728 | } |
| 781 | 729 | if (!wp_style_is('bitform-style-custom-' . $formID) && is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $formID . '.css')) { |
| 782 | 730 | wp_enqueue_style( |
| @@ -786,9 +734,9 @@ | ||
| 786 | 734 | $formUpdateVersion |
| 787 | 735 | ); |
| 788 | 736 | if ($isPageBuilder) { |
| 789 | 737 | $formStyle = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $formID . '.css'); |
| 790 | - echo '<style id="bitform-style-custom-' . esc_attr((string) $formID) . '">' . wp_kses($formStyle, []) . '</style>'; | |
| 738 | + echo sprintf("<style id='bitform-style-custom-{$formID}'>%s</style>", $formStyle); | |
| 791 | 739 | } |
| 792 | 740 | } |
| 793 | 741 | // load conversational form css |
| 794 | 742 | if ('conversational' === $fromType) { |