PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V-3.3.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV-3.3.0
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 / Theme / Fields / TurnstileField.php

TurnstileField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder V-3.3.0, at includes/Frontend/Form/View/Theme/Fields/TurnstileField.php

99 lines 3.4 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\Theme\Fields;
4
5 use BitCode\BitForm\Core\Integration\IntegrationHandler;
6 use BitCode\BitForm\Core\Util\Utilities;
7
8 class TurnstileField
9 {
10 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
11 {
12 $integrationHandler = new IntegrationHandler(0);
13 $allFormIntegrations = $integrationHandler->getAllIntegration('app', 'turnstileCaptcha');
14 if (is_wp_error($allFormIntegrations)) {
15 return '';
16 }
17 $row = Utilities::firstRow($allFormIntegrations);
18 $siteKey = Utilities::jsonObj($row->integration_details ?? '')->siteKey ?? '';
19 return self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $siteKey, $error = null, $value = null);
20 }
21
22 private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $siteKey, $error = null, $value = null)
23 {
24 $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map);
25 $theme = $field->config->theme;
26 $size = $field->config->size;
27 $language = $field->config->language;
28 $appearance = $field->config->appearance;
29
30 $interactiveCallback = '';
31 $dNone = '';
32 $script = '';
33
34 $fldKeyWithContentId = $fieldHelpers->getFieldKeyWithContentCount();
35 $fldKeyExceptHyphen = str_replace('-', '', $fldKeyWithContentId);
36
37 $beforeInteractiveCallback = '';
38 $afterInteractiveCallback = '';
39
40 if ('interaction-only' === $appearance) {
41 $beforeExcFuncName = 'bfBeforeInteractiveCallback' . $fldKeyExceptHyphen;
42 $afterExcFuncName = 'bfAfterInteractiveCallback' . $fldKeyExceptHyphen;
43 $dNone = 'd-none';
44 $beforeInteractiveCallback = 'data-before-interactive-callback="' . $beforeExcFuncName . '"';
45 $afterInteractiveCallback = 'data-after-interactive-callback="' . $afterExcFuncName . '"';
46 $script = sprintf(
47 '<script>
48 function %1$s() {
49 const bfTurnstileFldSelector = document.querySelector(\'.%2$s-turnstile-wrp\');
50 if (bfTurnstileFldSelector) bfTurnstileFldSelector.parentElement.classList.remove(\'d-none\');
51 }
52 function %3$s() {
53 const bfTurnstileFldSelector = document.querySelector(\'.%2$s-turnstile-wrp\');
54 if (bfTurnstileFldSelector) bfTurnstileFldSelector.parentElement.classList.add(\'d-none\');
55 }
56 </script>',
57 $beforeExcFuncName,
58 $fldKeyWithContentId,
59 $afterExcFuncName
60 );
61 }
62
63 return sprintf(
64 '%1$s
65 <div
66 %2$s
67 class="%3$s %4$s %5$s"
68 >
69 <div class="%6$s-turnstile-wrp">
70 <div
71 class="cf-turnstile"
72 %7$s
73 %8$s
74 data-appearance="%9$s"
75 data-language="%10$s"
76 data-theme="%11$s"
77 data-size="%12$s"
78 data-sitekey="%13$s"
79 >
80 </div>
81 </div>
82 </div>',
83 $script,
84 $fieldHelpers->getCustomAttributes('fld-wrp'),
85 $fieldHelpers->getAtomicCls('fld-wrp'),
86 $fieldHelpers->getCustomClasses('fld-wrp'),
87 $dNone,
88 $fldKeyWithContentId,
89 $beforeInteractiveCallback,
90 $afterInteractiveCallback,
91 $fieldHelpers->esc_attr($appearance),
92 $fieldHelpers->esc_attr($language),
93 $fieldHelpers->esc_attr($theme),
94 $fieldHelpers->esc_attr($size),
95 $fieldHelpers->esc_attr($siteKey)
96 );
97 }
98 }
99