PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.16.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.16.2
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 / BfAnalytics.php

BfAnalytics.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.16.2, at includes/BfAnalytics.php

173 lines 4.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;
4
5 use BitCode\BitForm\BitApps\WPTelemetry\Telemetry\Telemetry;
6
7 if (!\defined('ABSPATH')) {
8 exit;
9 }
10 class BfAnalytics
11 {
12 public function modifyTelemetryData()
13 {
14 global $wpdb;
15 $allForms = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}bitforms_form");
16
17 $bfInfo = [];
18 $formsArr = [];
19 foreach ($allForms as $form) {
20 $formData = [];
21 $formData['id'] = $form->id;
22 $formContent = json_decode($form->form_content, true);
23 $formData['fields'] = $this->fieldCount($formContent['fields']);
24 $formData['workflows'] = $this->countRow($form->id, 'bitforms_workflows');
25 $formData['pdfTemplate'] = $this->countRow($form->id, 'bitforms_pdf_template');
26 $formData['emailTemplate'] = $this->countRow($form->id, 'bitforms_email_template');
27 $formData['integrations'] = $this->getIntegrations($form->id);
28 $formData['formAbandonment'] = $this->getFormAbandonment($form->id);
29 $formData['doubleOptin'] = $this->getDoubleOptin($form->id);
30 $formData['tableView'] = $this->countRow($form->id, 'bitforms_frontend_views');
31 $formsArr[] = $formData;
32 }
33 $bfInfo['forms'] = $formsArr;
34 $bfInfo['totalForms'] = count($allForms);
35 $bfInfo['reCaptchaV3'] = $this->getReCaptchaV3();
36 $bfInfo['paymentGateway'] = $this->getPaymentGateway();
37 $bfInfo['smtp'] = $this->isSMTPExist();
38
39 return $bfInfo;
40 }
41
42 public function analyticsOptIn($permission)
43 {
44 if (true === $permission) {
45 Telemetry::report()->trackingOptIn();
46 return true;
47 }
48 Telemetry::report()->trackingOptOut();
49 return false;
50 }
51
52 public function isTrackingEnabled()
53 {
54 return (bool) Telemetry::report()->isTrackingAllowed();
55 }
56
57 private function fieldCount($fields)
58 {
59 $count = [];
60 foreach ($fields as $field) {
61 if (isset($count[$field['typ']])) {
62 $count[$field['typ']]++;
63 } else {
64 $count[$field['typ']] = 1;
65 }
66 }
67 return $count;
68 }
69
70 private function countRow($formId, $tablename)
71 {
72 global $wpdb;
73 $totalRow = $wpdb->get_results(
74 $wpdb->prepare(
75 "SELECT COUNT(*) as count FROM `{$wpdb->prefix}{$tablename}` WHERE form_id = %d;",
76 $formId
77 )
78 );
79 return $totalRow[0]->count || 0;
80 }
81
82 private function getIntegrations($formId)
83 {
84 global $wpdb;
85 $integrations = $wpdb->get_results(
86 $wpdb->prepare(
87 "SELECT integration_type FROM `{$wpdb->prefix}bitforms_integration` WHERE form_id = %d AND category='form';",
88 $formId
89 )
90 );
91
92 $integrationNameArr = array_map(function ($integration) {
93 return $integration->integration_type;
94 }, $integrations);
95
96 return $integrationNameArr;
97 }
98
99 private function getFormAbandonment($formId)
100 {
101 global $wpdb;
102 $formAbandonment = $wpdb->get_results(
103 $wpdb->prepare(
104 "SELECT integration_details FROM `{$wpdb->prefix}bitforms_integration` WHERE form_id = %d AND category='formAbandonment';",
105 $formId
106 )
107 );
108 if (count($formAbandonment) > 0) {
109 $formAbandonment = json_decode($formAbandonment[0]->integration_details, true);
110 } else {
111 $formAbandonment = (object)[];
112 }
113 return $formAbandonment;
114 }
115
116 private function getDoubleOptin($formId)
117 {
118 global $wpdb;
119 $doubleOptin = $wpdb->get_results(
120 $wpdb->prepare(
121 "SELECT integration_details FROM `{$wpdb->prefix}bitforms_integration` WHERE category='doubleOptin' AND form_id = %d;",
122 $formId
123 )
124 );
125 if (count($doubleOptin) > 0) {
126 return true;
127 }
128 return false;
129 }
130
131 private function getIntegType($integration_type)
132 {
133 global $wpdb;
134 return $wpdb->get_results(
135 $wpdb->prepare(
136 "SELECT integration_type, integration_details FROM `{$wpdb->prefix}bitforms_integration` WHERE integration_type=%s;",
137 $integration_type
138 )
139 );
140 }
141
142 private function getReCaptchaV3()
143 {
144 $name = $this->getIntegType('gReCaptchaV3');
145 if (count($name) > 0) {
146 return true;
147 }
148 return false;
149 }
150
151 private function getPaymentGateway()
152 {
153 $types = $this->getIntegType('payments');
154
155 $paymentTypeArr = array_map(function ($type) {
156 $integration_details = json_decode($type->integration_details, true);
157 return $integration_details['type'];
158 }, $types);
159
160 return $paymentTypeArr;
161 }
162
163 private function isSMTPExist()
164 {
165 $type = $this->getIntegType('smtp');
166
167 if (count($type) > 0) {
168 return true;
169 }
170 return false;
171 }
172 }
173