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

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

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