← All changes
|
includes/Admin/Form/FrontEndScriptGenerator.php
+183
-131
3.2.2
→
2.17.6
View file →
| @@ -1,14 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Admin\Form; |
| 4 | 4 | |
| 5 | -if (!defined('ABSPATH')) { | |
| 6 | - exit; | |
| 7 | -} | |
| 8 | - | |
| 5 | +use BitCode\BitForm\Admin\Form\InitJs\Paypal; | |
| 6 | +use BitCode\BitForm\Admin\Form\InitJs\Razorpay; | |
| 7 | +use BitCode\BitForm\Admin\Form\InitJs\Recaptcha; | |
| 8 | +use BitCode\BitForm\Admin\Form\InitJs\RecaptchaV3; | |
| 9 | +use BitCode\BitForm\Admin\Form\InitJs\ScriptLoader; | |
| 10 | +use BitCode\BitForm\Admin\Form\InitJs\Stripe; | |
| 11 | +use BitCode\BitForm\Admin\Form\InitJs\Turnstile; | |
| 9 | 12 | use BitCode\BitForm\Core\Util\FileHandler; |
| 10 | 13 | use BitCode\BitForm\Core\Util\Log; |
| 14 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 15 | +use BitCode\BitForm\Core\WorkFlow\WorkFlowHandler; | |
| 16 | +use BitCode\BitFormPro\Admin\FormSettings\FormAbandonment; | |
| 11 | 17 | use WP_Error; |
| 12 | 18 | |
| 13 | 19 | class FrontEndScriptGenerator |
| 14 | 20 | { |
| @@ -30,10 +36,11 @@ | ||
| 30 | 36 | |
| 31 | 37 | private static function generateBfGlobalObjJS($contentIds = []) |
| 32 | 38 | { |
| 33 | 39 | $contentidArray = wp_json_encode($contentIds); |
| 34 | - return ' if(!window.bf_globals){ window.bf_globals = {};} | |
| 35 | - ' . $contentidArray . '.forEach(function(contentId){ | |
| 40 | + return <<<GLOBALOBJ | |
| 41 | + if(!window.bf_globals){ window.bf_globals = {};} | |
| 42 | + $contentidArray.forEach(function(contentId){ | |
| 36 | 43 | const form = document.getElementById(contentId); |
| 37 | 44 | if(!form){ |
| 38 | 45 | delete window.bf_globals[contentId]; |
| 39 | 46 | return; |
| @@ -44,14 +51,15 @@ | ||
| 44 | 51 | window.bf_globals[contentId].inits = {}; |
| 45 | 52 | window.bf_globals[contentId].contentId = contentId; |
| 46 | 53 | } |
| 47 | 54 | |
| 48 | - });'; | |
| 55 | + }); | |
| 56 | +GLOBALOBJ; | |
| 49 | 57 | } |
| 50 | 58 | |
| 51 | 59 | private static function isValidationNeeded($fldData) |
| 52 | 60 | { |
| 53 | - $validationsToCheck = ['valid->req', 'valid->regexr', 'mn', 'mx', 'opt', 'err->invalid->show', 'err->notVerified->show']; | |
| 61 | + $validationsToCheck = ['valid->req', 'valid->regexr', 'mn', 'mx', 'opt', 'err->invalid->show']; | |
| 54 | 62 | foreach ($validationsToCheck as $property) { |
| 55 | 63 | $needValidation = Helpers::property_exists_nested($fldData, $property); |
| 56 | 64 | if ($needValidation) { |
| 57 | 65 | return true; |
| @@ -85,11 +93,8 @@ | ||
| 85 | 93 | |
| 86 | 94 | // for hidden Field when cache plugin on |
| 87 | 95 | $this->jsHiddenFieldScript(); |
| 88 | 96 | |
| 89 | - // for recaptcha v3 (form-level setting) | |
| 90 | - $this->jsRecaptchaV3Scripts(); | |
| 91 | - | |
| 92 | 97 | // for form abandonment scripts |
| 93 | 98 | $this->jsFormAbandonmentScripts(); |
| 94 | 99 | |
| 95 | 100 | // multi step form scripts |
| @@ -139,24 +144,55 @@ | ||
| 139 | 144 | } |
| 140 | 145 | |
| 141 | 146 | private function jsFormAbandonmentScripts() |
| 142 | 147 | { |
| 143 | - /** | |
| 144 | - * Add-ons can inject required script files here. | |
| 145 | - * | |
| 146 | - * @param array $files Array of file arrays: ['priority' => int, 'filename' => string] | |
| 147 | - * @param array $formContents | |
| 148 | - * @param array $fields | |
| 149 | - */ | |
| 150 | - $files = apply_filters('bitform_form_abandonment_script_files', [], $this->_formContents, $this->_fields); | |
| 151 | - if (empty($files) || !is_array($files)) { | |
| 148 | + if (!Utilities::isPro() || !class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) { | |
| 152 | 149 | return; |
| 153 | 150 | } |
| 154 | - foreach ($files as $jsFile) { | |
| 155 | - if (!empty($jsFile['filename']) && !empty($jsFile['priority'])) { | |
| 156 | - $this->addScriptInLoadedScriptsList($jsFile); | |
| 151 | + // check if any of the form has form abandonment enabled | |
| 152 | + $allFiles = []; | |
| 153 | + foreach ($this->_formContents as $formContent) { | |
| 154 | + $formAbandonmentSettings = FormAbandonment::getFormAbandonmentSettings($formContent->formId); | |
| 155 | + if (!empty($formAbandonmentSettings->saveFormDraft)) { | |
| 156 | + $neededFiles = ScriptFilePriorityManager::formAbandonmentNeededFiles('autoSave'); | |
| 157 | + $allFiles = array_merge($allFiles, $neededFiles); | |
| 158 | + break; | |
| 157 | 159 | } |
| 160 | + | |
| 161 | + $workflowHandler = new WorkFlowHandler($formContent->formId); | |
| 162 | + $allWorkflows = $workflowHandler->getAllworkFlow(); | |
| 163 | + foreach ($allWorkflows as $workflow) { | |
| 164 | + foreach ($workflow['conditions'] as $cond) { | |
| 165 | + if (!empty($cond->actions) && !empty($cond->actions->fields)) { | |
| 166 | + foreach ($cond->actions->fields as $fldAction) { | |
| 167 | + if (empty($fldAction->field) || empty($fldAction->action)) { | |
| 168 | + continue; | |
| 169 | + } | |
| 170 | + if ('_bf_form' === $fldAction->field && 'save_draft' === $fldAction->action) { | |
| 171 | + $neededFiles = ScriptFilePriorityManager::formAbandonmentNeededFiles(); | |
| 172 | + $allFiles = array_merge($allFiles, $neededFiles); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + } | |
| 176 | + } | |
| 177 | + } | |
| 158 | 178 | } |
| 179 | + if (isset($this->_fields['button'])) { | |
| 180 | + foreach ($this->_fields['button'] as $button) { | |
| 181 | + if ('save-draft' === $button['field']->btnTyp) { | |
| 182 | + $neededFiles = ScriptFilePriorityManager::formAbandonmentNeededFiles(); | |
| 183 | + $allFiles = array_merge($allFiles, $neededFiles); | |
| 184 | + break; | |
| 185 | + } | |
| 186 | + } | |
| 187 | + } | |
| 188 | + // | |
| 189 | + if (empty($allFiles)) { | |
| 190 | + return; | |
| 191 | + } | |
| 192 | + foreach ($allFiles as $jsFile) { | |
| 193 | + $this->addScriptInLoadedScriptsList($jsFile); | |
| 194 | + } | |
| 159 | 195 | } |
| 160 | 196 | |
| 161 | 197 | private function appendJs($script, $postId, $previewMode, $mode = 'a') |
| 162 | 198 | { |
| @@ -184,12 +220,22 @@ | ||
| 184 | 220 | |
| 185 | 221 | $script = ''; |
| 186 | 222 | foreach ($this->_loadedScriptsList as $scriptFileArr) { |
| 187 | 223 | $fileNam = $scriptFileArr['filename']; |
| 188 | - $fileContent = self::getFileFromAssetsJs($fileNam); | |
| 189 | - if ($fileContent) { | |
| 190 | - $script .= $fileContent; | |
| 224 | + if (!isset($scriptFileArr['scriptTyp']) || 'script' === $scriptFileArr['scriptTyp']) { | |
| 225 | + if (self::getFileFromAssetsJs($fileNam)) { | |
| 226 | + $script .= self::getFileFromAssetsJs($fileNam); | |
| 227 | + continue; | |
| 228 | + } | |
| 229 | + continue; | |
| 191 | 230 | } |
| 231 | + if ('custom' === $scriptFileArr['scriptTyp']) { | |
| 232 | + $fileInstance = $scriptFileArr['source'] . $fileNam; | |
| 233 | + if (!class_exists($fileInstance)) { | |
| 234 | + continue; | |
| 235 | + } // when class not found, skip load script | |
| 236 | + $script .= $fileInstance::init($scriptFileArr['fk'], $scriptFileArr['field'], $scriptFileArr['contentId']); | |
| 237 | + } | |
| 192 | 238 | } |
| 193 | 239 | return $script; |
| 194 | 240 | } |
| 195 | 241 | |
| @@ -197,12 +243,8 @@ | ||
| 197 | 243 | { |
| 198 | 244 | foreach ($this->_fields as $flds) { |
| 199 | 245 | foreach ($flds as $fld) { |
| 200 | 246 | $fldData = $fld['field']; |
| 201 | - // Corrupt/partial form JSON can produce a null field or one without typ. | |
| 202 | - if (!is_object($fldData)) { | |
| 203 | - continue; | |
| 204 | - } | |
| 205 | 247 | // for validation js files |
| 206 | 248 | if (self::isValidationNeeded($fldData)) { |
| 207 | 249 | $validation = $this->_validationJsFilesNeeded['validation']; |
| 208 | 250 | $this->addScriptInLoadedScriptsList($validation); |
| @@ -222,30 +264,18 @@ | ||
| 222 | 264 | |
| 223 | 265 | $validationScriptFileMapping = ScriptFilePriorityManager::validationScriptFileMapping($fldData->typ); |
| 224 | 266 | if ($validationScriptFileMapping) { |
| 225 | 267 | foreach ($validationScriptFileMapping as $key => $value) { |
| 226 | - $paths = $value['paths'] ?? []; | |
| 227 | - $hasMatchingPath = false; | |
| 228 | - foreach ($paths as $path) { | |
| 268 | + foreach ($value['paths'] as $path) { | |
| 229 | 269 | if (Helpers::property_exists_nested($fldData, $path)) { |
| 230 | - $hasMatchingPath = true; | |
| 231 | - break; // one match is enough | |
| 270 | + $file = $this->_validationJsFilesNeeded[$key]; | |
| 271 | + $this->addScriptInLoadedScriptsList($file); | |
| 232 | 272 | } |
| 233 | 273 | } |
| 234 | - | |
| 235 | - if (!$hasMatchingPath) { | |
| 236 | - continue; | |
| 237 | - } | |
| 238 | - | |
| 239 | - // Add the main script once | |
| 240 | - if (!empty($this->_validationJsFilesNeeded[$key])) { | |
| 241 | - $this->addScriptInLoadedScriptsList($this->_validationJsFilesNeeded[$key]); | |
| 242 | - } | |
| 243 | - | |
| 244 | - // Add dependencies once each | |
| 245 | - foreach (($value['dependencies'] ?? []) as $dep) { | |
| 246 | - if (!empty($this->_validationJsFilesNeeded[$dep])) { | |
| 247 | - $this->addScriptInLoadedScriptsList($this->_validationJsFilesNeeded[$dep]); | |
| 274 | + if (isset($value['dependencies'])) { | |
| 275 | + foreach ($value['dependencies'] as $dependency) { | |
| 276 | + $dependencyFile = $this->_validationJsFilesNeeded[$dependency]; | |
| 277 | + $this->addScriptInLoadedScriptsList($dependencyFile); | |
| 248 | 278 | } |
| 249 | 279 | } |
| 250 | 280 | } |
| 251 | 281 | } |
| @@ -254,9 +284,8 @@ | ||
| 254 | 284 | } |
| 255 | 285 | |
| 256 | 286 | private function jsFieldsNeededFile() |
| 257 | 287 | { |
| 258 | - $filePondPluginList = apply_filters('bitform_filepond_plugins_list', []); | |
| 259 | 288 | foreach ($this->_fields as $typ => $flds) { |
| 260 | 289 | if (!array_key_exists($typ, $this->_jsFilesNeeded)) { |
| 261 | 290 | continue; |
| 262 | 291 | } |
| @@ -266,30 +295,26 @@ | ||
| 266 | 295 | if ('advanced-file-up' === $typ) { |
| 267 | 296 | $configs = $fld['field']->config; |
| 268 | 297 | foreach ($configs as $configKey => $config) { |
| 269 | 298 | if ($configs->$configKey) { |
| 270 | - if (array_key_exists($configKey, $filePondPluginList)) { | |
| 271 | - $this->addScriptInLoadedScriptsList($filePondPluginList[$configKey]); | |
| 299 | + $filepondPlugin = ScriptFilePriorityManager::filePondPlugins($configKey); | |
| 300 | + if ($filepondPlugin) { | |
| 301 | + $this->addScriptInLoadedScriptsList($filepondPlugin); | |
| 272 | 302 | } |
| 273 | 303 | } |
| 274 | 304 | } |
| 275 | 305 | } |
| 276 | 306 | foreach ($fldScriptArr as $scriptFile) { |
| 277 | - if (isset($scriptFile['paths']) && is_array($scriptFile['paths'])) { | |
| 278 | - $pathMatched = false; | |
| 279 | - foreach ($scriptFile['paths'] as $path) { | |
| 280 | - if (Helpers::property_exists_nested($fld['field'], $path)) { | |
| 281 | - $pathMatched = true; | |
| 282 | - break; | |
| 283 | - } | |
| 284 | - } | |
| 285 | - if (!$pathMatched) { | |
| 286 | - continue; | |
| 287 | - } | |
| 288 | - } elseif (isset($scriptFile['path']) && !Helpers::property_exists_nested($fld['field'], $scriptFile['path'])) { | |
| 307 | + if (!isset($scriptFile['scriptTyp'])) { | |
| 308 | + $this->addScriptInLoadedScriptsList($scriptFile); | |
| 289 | 309 | continue; |
| 290 | 310 | } |
| 291 | - $this->addScriptInLoadedScriptsList($scriptFile); | |
| 311 | + if ('custom' === $scriptFile['scriptTyp'] && Helpers::property_exists_nested($fld['field'], $scriptFile['path'], true)) { | |
| 312 | + $scriptFile['field'] = $fld['field']; | |
| 313 | + $scriptFile['fk'] = $fld['fk']; | |
| 314 | + $scriptFile['contentId'] = $fld['contentId']; | |
| 315 | + $this->addScriptInLoadedScriptsList($scriptFile); | |
| 316 | + } | |
| 292 | 317 | } |
| 293 | 318 | } |
| 294 | 319 | } |
| 295 | 320 | } |
| @@ -333,10 +358,9 @@ | ||
| 333 | 358 | { |
| 334 | 359 | // for js file |
| 335 | 360 | $path = 'form-scripts'; |
| 336 | 361 | $fileName = "bitform-custom-$formId.js"; |
| 337 | - $filteredJs = Helpers::removeJsSingleLineComments($customCodes->JavaScript); | |
| 338 | - self::customCodeFileSaveOrDelete($filteredJs, $path, $fileName); | |
| 362 | + self::customCodeFileSaveOrDelete($customCodes->JavaScript, $path, $fileName); | |
| 339 | 363 | |
| 340 | 364 | // for css file |
| 341 | 365 | $path = 'form-styles'; |
| 342 | 366 | $fileName = "bitform-custom-$formId.css"; |
| @@ -369,31 +393,27 @@ | ||
| 369 | 393 | return $customCodes; |
| 370 | 394 | } |
| 371 | 395 | |
| 372 | 396 | private $fldContainersByType = [ |
| 373 | - 'address' => '.__$fk__-parent-fld-wrp', | |
| 374 | - 'select' => '.__$fk__-dpd-fld-wrp', | |
| 375 | - 'country' => '.__$fk__-country-fld-wrp', | |
| 376 | - 'currency' => '.__$fk__-currency-fld-wrp', | |
| 377 | - 'phone-number' => '.__$fk__-phone-fld-wrp', | |
| 378 | - 'file-up' => '.__$fk__-file-up-wrpr', | |
| 379 | - 'advanced-file-up' => '#filepond-__$fk__-container', | |
| 380 | - 'paypal' => '.__$fk__-paypal-wrp', | |
| 381 | - 'razorpay' => '.__$fk__-razorpay-wrp', | |
| 382 | - 'recaptcha' => '.__$fk__-recaptcha-wrp', | |
| 383 | - 'stripe' => '.__$fk__-stripe-fld', | |
| 384 | - 'mollie' => '.__$fk__-mollie-wrp', | |
| 385 | - 'repeater' => '.__$fk__-rpt-fld-wrp', | |
| 386 | - 'signature' => '.__$fk__-inp-fld-wrp', | |
| 387 | - 'rating' => '.__$fk__-inp-fld-wrp', | |
| 388 | - 'email-otp' => '.__$fk__-inp-fld-wrp', | |
| 389 | - 'hcaptcha' => '.__$fk__-h-captcha-wrp', | |
| 390 | - 'advanced-datetime' => '.__$fk__-advanced-datetime', | |
| 397 | + 'select' => '.__$fk__-dpd-fld-wrp', | |
| 398 | + 'country' => '.__$fk__-country-fld-wrp', | |
| 399 | + 'currency' => '.__$fk__-currency-fld-wrp', | |
| 400 | + 'phone-number' => '.__$fk__-phone-fld-wrp', | |
| 401 | + 'file-up' => '.__$fk__-file-up-wrpr', | |
| 402 | + 'advanced-file-up' => '#filepond-__$fk__-container', | |
| 403 | + 'paypal' => '.__$fk__-paypal-wrp', | |
| 404 | + 'razorpay' => '.__$fk__-razorpay-wrp', | |
| 405 | + 'recaptcha' => '.__$fk__-recaptcha-wrp', | |
| 406 | + 'stripe' => '.__$fk__-stripe-fld', | |
| 407 | + 'mollie' => '.__$fk__-mollie-wrp', | |
| 408 | + 'repeater' => '.__$fk__-rpt-fld-wrp', | |
| 409 | + 'signature' => '.__$fk__-inp-fld-wrp', | |
| 410 | + 'rating' => '.__$fk__-inp-fld-wrp', | |
| 391 | 411 | ]; |
| 392 | 412 | |
| 393 | 413 | private function generateFieldConfigsJs() |
| 394 | 414 | { |
| 395 | - $customFlds = ['address', 'select', 'country', 'currency', 'phone-number', 'file-up', 'advanced-file-up', 'paypal', 'razorpay', 'stripe', 'mollie', 'recaptcha', 'repeater', 'signature', 'rating', 'turnstile', 'hcaptcha', 'advanced-datetime', 'email-otp']; | |
| 415 | + $customFlds = ['select', 'country', 'currency', 'phone-number', 'file-up', 'advanced-file-up', 'paypal', 'razorpay', 'stripe', 'mollie', 'recaptcha', 'repeater', 'signature', 'rating', 'turnstile']; | |
| 396 | 416 | $allFieldTypes = array_keys($this->_fields); |
| 397 | 417 | $customFldsInForms = array_intersect($allFieldTypes, $customFlds); |
| 398 | 418 | $formContents = $this->_formContents; |
| 399 | 419 | $recaptchaV3Enabled = false; |
| @@ -415,10 +435,10 @@ | ||
| 415 | 435 | } |
| 416 | 436 | |
| 417 | 437 | $customFldConfigPaths = []; |
| 418 | 438 | |
| 419 | - $allConfs = ScriptFilePriorityManager::getAllFldConfs(); | |
| 420 | 439 | foreach ($customFldsInForms as $customFldTyp) { |
| 440 | + $allConfs = ScriptFilePriorityManager::getAllFldConfs(); | |
| 421 | 441 | if (isset($allConfs[$customFldTyp])) { |
| 422 | 442 | $customFldConfigPaths[$customFldTyp] = $allConfs[$customFldTyp]; |
| 423 | 443 | } else { |
| 424 | 444 | $customFldConfigPaths[$customFldTyp] = (object) []; |
| @@ -427,45 +447,95 @@ | ||
| 427 | 447 | |
| 428 | 448 | $customFldConfigPaths = wp_json_encode($customFldConfigPaths); |
| 429 | 449 | $containers = wp_json_encode($containers); |
| 430 | 450 | |
| 431 | - $script = ' const customFldConfigPaths = ' . $customFldConfigPaths . '; | |
| 432 | - const fldContainers = ' . $containers . '; | |
| 451 | + $scriptLoaderFields = ['paypal', 'razorpay', 'stripe', 'recaptcha', 'turnstile']; | |
| 452 | + $scriptLoadedNeeded = array_intersect($scriptLoaderFields, $customFldsInForms) || $recaptchaV3Enabled; | |
| 453 | + if ($scriptLoadedNeeded) { | |
| 454 | + $scriptLoaderJs = ScriptLoader::init(); | |
| 455 | + } else { | |
| 456 | + $scriptLoaderJs = ''; | |
| 457 | + } | |
| 458 | + | |
| 459 | + if (in_array('paypal', $customFldsInForms)) { | |
| 460 | + $paypalInitJs = Paypal::init(); | |
| 461 | + } else { | |
| 462 | + $paypalInitJs = ''; | |
| 463 | + } | |
| 464 | + | |
| 465 | + if (in_array('razorpay', $customFldsInForms)) { | |
| 466 | + $razorpayInitJs = Razorpay::init(); | |
| 467 | + } else { | |
| 468 | + $razorpayInitJs = ''; | |
| 469 | + } | |
| 470 | + | |
| 471 | + if (in_array('stripe', $customFldsInForms)) { | |
| 472 | + $stripeInitJs = Stripe::init(); | |
| 473 | + } else { | |
| 474 | + $stripeInitJs = ''; | |
| 475 | + } | |
| 476 | + | |
| 477 | + if (in_array('mollie', $customFldsInForms)) { | |
| 478 | + $mollieInitJs = Stripe::init(); | |
| 479 | + } else { | |
| 480 | + $mollieInitJs = ''; | |
| 481 | + } | |
| 482 | + | |
| 483 | + if (in_array('recaptcha', $customFldsInForms)) { | |
| 484 | + $recaptchaInitJs = Recaptcha::init(); | |
| 485 | + } else { | |
| 486 | + $recaptchaInitJs = ''; | |
| 487 | + } | |
| 488 | + | |
| 489 | + if (in_array('turnstile', $customFldsInForms)) { | |
| 490 | + $turnstileInitJs = Turnstile::init(); | |
| 491 | + } else { | |
| 492 | + $turnstileInitJs = ''; | |
| 493 | + } | |
| 494 | + | |
| 495 | + if ($recaptchaV3Enabled) { | |
| 496 | + $recaptchaV3InitJs = RecaptchaV3::init(); | |
| 497 | + } else { | |
| 498 | + $recaptchaV3InitJs = ''; | |
| 499 | + } | |
| 500 | + | |
| 501 | + $script = <<<FIELDCONFIGJS | |
| 502 | + const customFldConfigPaths = $customFldConfigPaths; | |
| 503 | + const fldContainers = $containers; | |
| 433 | 504 | |
| 505 | + $scriptLoaderJs; | |
| 506 | + | |
| 434 | 507 | function initAllCustomFlds (formContentId = null) { |
| 435 | 508 | const allContendIds = formContentId ? [formContentId] : Object.keys(bf_globals); |
| 436 | 509 | allContendIds.forEach((contentId) => { |
| 437 | 510 | const contentData = bf_globals[contentId]; |
| 438 | - if(!contentData?.inits) contentData.inits = {}; | |
| 439 | 511 | const flds = bf_globals[contentId]?.fields || {}; |
| 440 | 512 | const fldKeys = Object.keys(flds).reverse(); |
| 441 | 513 | fldKeys.forEach((fldKey) => { |
| 442 | 514 | const fldData = flds[fldKey]; |
| 443 | 515 | const fldType = fldData.typ; |
| 444 | - if(fldType === \'paypal\') { | |
| 445 | - initPaypalFld(contentId, fldKey, fldData, fldType); | |
| 446 | - } else if(fldType === \'razorpay\') { | |
| 447 | - initRazorpayFld(contentId, fldKey, fldType); | |
| 448 | - } else if(fldType === \'recaptcha\') { | |
| 449 | - initRecaptchaFld(contentId, fldKey, fldType); | |
| 450 | - } else if(fldType === \'turnstile\') { | |
| 451 | - initTurnstileFld(contentId, fldKey); | |
| 452 | - } else if(fldType === \'hcaptcha\') { | |
| 453 | - initHCaptchaFld(contentId, fldKey, fldType); | |
| 454 | - } else if(fldType === \'stripe\' || fldType === \'mollie\') { | |
| 455 | - initStripeFld(contentId, fldKey, fldType); | |
| 516 | + if(fldType === 'paypal') { | |
| 517 | + $paypalInitJs; | |
| 518 | + } else if(fldType === 'razorpay') { | |
| 519 | + $razorpayInitJs; | |
| 520 | + } else if(fldType === 'recaptcha') { | |
| 521 | + $recaptchaInitJs; | |
| 522 | + } else if(fldType === 'turnstile') { | |
| 523 | + $turnstileInitJs; | |
| 524 | + } else if(fldType === 'stripe') { | |
| 525 | + $stripeInitJs; | |
| 456 | 526 | } else if (customFldConfigPaths[fldType]) { |
| 457 | 527 | contentData.inits[fldKey] = getFldInstance(contentId, fldKey, fldType); |
| 458 | 528 | } |
| 459 | 529 | }); |
| 460 | - if(contentData.gRecaptchaVersion === \'v3\' && contentData.gRecaptchaSiteKey){ | |
| 461 | - initRecaptchaV3Fld(contentId, contentData); | |
| 530 | + if(contentData.gRecaptchaVersion === 'v3' && contentData.gRecaptchaSiteKey){ | |
| 531 | + $recaptchaV3InitJs; | |
| 462 | 532 | } |
| 463 | 533 | }); |
| 464 | 534 | }; |
| 465 | - function getFldInstance(contentId, fldKey, fldTyp, nestedSelector = \'\') { | |
| 466 | - const fldClass = this[\'bit_\'+fldTyp.replace(/-/g, \'_\')+\'_field\']; | |
| 467 | - const selector = \'#form-\'+contentId+\' \'+nestedSelector+fldContainers[fldTyp].replace("__$fk__", fldKey); | |
| 535 | + function getFldInstance(contentId, fldKey, fldTyp, nestedSelector = '') { | |
| 536 | + const fldClass = this['bit_'+fldTyp.replace(/-/g, '_')+'_field']; | |
| 537 | + const selector = '#form-'+contentId+' '+nestedSelector+fldContainers[fldTyp].replace("__\$fk__", fldKey); | |
| 468 | 538 | if(!fldClass || !bfSelect(selector)) return; |
| 469 | 539 | return new fldClass(selector, getFldConf(contentId, fldKey, fldTyp)); |
| 470 | 540 | }; |
| 471 | 541 | function getFldConf(contentId, fieldKey, fldTyp) { |
| @@ -486,13 +556,13 @@ | ||
| 486 | 556 | } else { |
| 487 | 557 | value = getDataFromNestedPath(fldData, fldPath.path); |
| 488 | 558 | } |
| 489 | 559 | } |
| 490 | - if (!value && "val" in fldPath) { | |
| 560 | + if (!value && fldPath.val) { | |
| 491 | 561 | value = fldPath.val; |
| 492 | - if(typeof value === \'string\') { | |
| 562 | + if(typeof value === 'string') { | |
| 493 | 563 | Object.entries(varData).forEach(([key, val]) => { |
| 494 | - value = value.replace("__$"+key+"__", val); | |
| 564 | + value = value.replace("__\$"+key+"__", val); | |
| 495 | 565 | }); |
| 496 | 566 | } |
| 497 | 567 | } |
| 498 | 568 | fldConf = setDataToNestedPath(fldConf, confPath, value); |
| @@ -518,9 +588,10 @@ | ||
| 518 | 588 | current = current[k]; |
| 519 | 589 | }); |
| 520 | 590 | current[lastKey] = value; |
| 521 | 591 | return current; |
| 522 | - }'; | |
| 592 | + } | |
| 593 | +FIELDCONFIGJS; | |
| 523 | 594 | |
| 524 | 595 | return $script; |
| 525 | 596 | } |
| 526 | 597 | |
| @@ -541,10 +612,8 @@ | ||
| 541 | 612 | $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['conditionalLogic']; |
| 542 | 613 | $this->addScriptInLoadedScriptsList($fileArr); |
| 543 | 614 | $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['resetPlaceholders']; |
| 544 | 615 | $this->addScriptInLoadedScriptsList($fileArr); |
| 545 | - $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['bfResetDefaultValue']; | |
| 546 | - $this->addScriptInLoadedScriptsList($fileArr); | |
| 547 | 616 | $fileArr = ScriptFilePriorityManager::validationAndOtherScriptFile()['validateFocusLost']; |
| 548 | 617 | $this->addScriptInLoadedScriptsList($fileArr); |
| 549 | 618 | $fileArr = ScriptFilePriorityManager::frontendScriptFile()['observeElm']; |
| 550 | 619 | $this->addScriptInLoadedScriptsList($fileArr); |
| @@ -558,29 +627,12 @@ | ||
| 558 | 627 | |
| 559 | 628 | private function jsHiddenFieldScript() |
| 560 | 629 | { |
| 561 | 630 | $appConfig = get_option('bitform_app_config'); |
| 562 | - $cacheTokenEnabled = true; | |
| 563 | - if (is_object($appConfig) && property_exists($appConfig, 'cache_plugin')) { | |
| 564 | - $cacheTokenEnabled = (bool) $appConfig->cache_plugin; | |
| 565 | - } elseif (is_array($appConfig) && array_key_exists('cache_plugin', $appConfig)) { | |
| 566 | - $cacheTokenEnabled = (bool) $appConfig['cache_plugin']; | |
| 567 | - } | |
| 568 | - if ($cacheTokenEnabled) { | |
| 631 | + if (Helpers::property_exists_nested($appConfig, 'cache_plugin', true)) { | |
| 569 | 632 | $fileArr = ScriptFilePriorityManager::frontendScriptFile()['hidden-token-field']; |
| 570 | 633 | $this->addScriptInLoadedScriptsList($fileArr); |
| 571 | 634 | return; |
| 572 | - } | |
| 573 | - } | |
| 574 | - | |
| 575 | - private function jsRecaptchaV3Scripts() | |
| 576 | - { | |
| 577 | - foreach ($this->_formContents as $content) { | |
| 578 | - if (isset($content->additional->enabled->recaptchav3) && $content->additional->enabled->recaptchav3) { | |
| 579 | - $this->addScriptInLoadedScriptsList(['priority' => 302, 'filename' => 'scriptLoader.min.js']); | |
| 580 | - $this->addScriptInLoadedScriptsList(['priority' => 303, 'filename' => 'initRecaptchaV3Fld.min.js']); | |
| 581 | - return; | |
| 582 | - } | |
| 583 | 635 | } |
| 584 | 636 | } |
| 585 | 637 | |
| 586 | 638 | public function dd($data, $exit = false) |