PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.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 2.10.2 All 137 releases
bit-form / includes / Core / Fallback / StylesFallback.php

StylesFallback.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.9.1, at includes/Core/Fallback/StylesFallback.php

128 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\Core\Fallback;
4
5 use BitCode\BitForm\Core\Database\FormModel;
6 use BitCode\BitForm\Core\Util\Utilities;
7 use Jcof\Jcof;
8
9 class StylesFallback
10 {
11 public function stripeFldButtonDisabled()
12 {
13 $stylesArray = [
14 '.__fk__-stripe-btn:disabled' => [
15 'background' => '#7ca5e7',
16 'transform' => 'none',
17 ],
18 '.__fk__-stripe-wrp .stripe-pay-btn:disabled'=> [
19 'background' => '#7ca5e7',
20 'transform' => 'none',
21 ]
22 ];
23
24 $this->addStyles('stripe', $stylesArray);
25 }
26
27 /**
28 * for adding fallback styles to field in form staticStyles object
29 *
30 * @param string $fieldType
31 * @param array $stylesArray
32 * @return void
33 */
34 private function addStyles(string $fieldType, array $stylesArray): void
35 {
36 $formModel = new FormModel();
37 $forms = $formModel->get(
38 ['id', 'form_content', 'builder_helper_state']
39 );
40
41 if (is_wp_error($forms)) {
42 return;
43 }
44 foreach ($forms as $form) {
45 $hasStyleChanged = false;
46 $formId = $form->id;
47 $builderHelperState = json_decode($form->builder_helper_state);
48 if (empty($builderHelperState->staticStyles)) {
49 continue;
50 }
51 $staticStyleState = $builderHelperState->staticStyles;
52 $staticStyleState = Jcof::parse($staticStyleState);
53
54 $formContent = json_decode($form->form_content);
55 $fields = $formContent->fields;
56
57 foreach ($fields as $fldKey => $fldData) {
58 if ($fieldType !== $fldData->typ) {
59 continue;
60 }
61 if (!isset($staticStyleState['staticStyles'])) {
62 $staticStyleState['staticStyles'] = [];
63 }
64
65 $newStyles = $this->replaceFldKey($fldKey, $stylesArray);
66
67 foreach ($newStyles as $newStyleKey => $newStyleValue) {
68 $staticStyleState['staticStyles'][$newStyleKey] = $newStyleValue;
69 }
70
71 $generatedStyleCSS = Utilities::styleGenerator($newStyles);
72 Utilities::appendCSS($formId, $generatedStyleCSS);
73 $hasStyleChanged = true;
74 }
75
76 if (!$hasStyleChanged) {
77 continue;
78 }
79
80 $staticStyleState = Jcof::stringify($staticStyleState);
81 $builderHelperState->staticStyles = $staticStyleState;
82 $formModel->update(
83 [
84 'builder_helper_state' => wp_json_encode($builderHelperState),
85 ],
86 [
87 'id' => $formId,
88 ]
89 );
90 }
91 }
92
93 /**
94 * @method for replacing __fk__ with field key in styles array keys
95 * @example: .__fk__-stripe-btn:disabled to .bk-1-stripe-btn:disabled
96 *
97 * @param string $fldKey
98 * @param array $stylesArray
99 * @return array $newStyleArray
100 */
101 private function replaceFldKey(string $fldKey, array $stylesArray): array
102 {
103 $newStyleArray = [];
104 foreach ($stylesArray as $key => $value) {
105 $key = str_replace('__fk__', $fldKey, $key);
106 $newStyleArray[$key] = $value;
107 }
108 return $newStyleArray;
109 }
110
111 public function signatureFldIframeStyle()
112 {
113 $signatureIframeStyle = [
114 '.__fk__-signature-iframe' => [
115 'position' => 'absolute',
116 'top' => 0,
117 'left' => 0,
118 'width' => '100%',
119 'height' => '100%',
120 'opacity' => 0,
121 'pointer-events'=> 'none',
122 'border' => 'none',
123 ]
124 ];
125
126 $this->addStyles('signature', $signatureIframeStyle);
127 }
128 }