PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.19
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.19
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Modules / Track / TrackModule.php

TrackModule.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.19, at app/Modules/Track/TrackModule.php

176 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Track;
4
5 use FluentForm\AdminNotice;
6 use FluentForm\App;
7 use FluentForm\Framework\Helpers\ArrayHelper;
8
9 class TrackModule
10 {
11 private $apiUrl = 'https://fluentform.com';
12 private $initialConsentKey = '_fluentform_notice_pref';
13 private $newsletterDelayTimeStamp = 172800; // 7 days
14
15 public function initTrack()
16 {
17 if (AdminNotice::shouldShowNotice('track_data_notice') && $this->isLocalhost()) {
18 $this->showInitialConsent();
19 }
20 }
21
22 public function showInitialConsent()
23 {
24 $notice = $this->getInitialNotice();
25 AdminNotice::addNotice($notice);
26 }
27
28 public function rejectTrack()
29 {
30 $notice_name = sanitize_text_field(wpFluentForm('request')->get('notice_name'));
31 $action_type = sanitize_text_field(wpFluentForm('request')->get('action_type'));
32
33 $notificationPref = get_option($this->initialConsentKey, []);
34
35 if ('permanent' == $action_type) {
36 $notificationPref[$notice_name] = [
37 'status' => 'no',
38 'email_subscribed' => 'no',
39 'timestamp' => time(),
40 'temp_disabled' => false,
41 ];
42 } else {
43 $notificationPref[$notice_name] = [
44 'status' => 'no',
45 'email_subscribed' => 'no',
46 'timestamp' => time(),
47 'temp_disabled' => true,
48 ];
49 }
50
51 update_option($this->initialConsentKey, $notificationPref, 'no');
52 }
53
54 public function sendInitialInfo()
55 {
56 $email_enabled = sanitize_text_field(wpFluentForm('request')->get('email_enabled'));
57 $notice_name = sanitize_text_field(wpFluentForm('request')->get('notice_name'));
58
59 $notificationPref = get_option($this->initialConsentKey, []);
60
61 $notificationPref[$notice_name] = [
62 'status' => 'yes',
63 'email_subscribed' => ($email_enabled) ? 'yes' : 'no',
64 'timestamp' => time(),
65 ];
66
67 update_option($this->initialConsentKey, $notificationPref, 'no');
68
69 $logData = $this->getLogData();
70 $logData['email_subscribed'] = $email_enabled;
71
72 try {
73 wp_remote_post(
74 $this->apiUrl,
75 [
76 'body' => [
77 'plugin_log_id' => 1,
78 'plugin' => 'fluentform',
79 'data' => $logData,
80 ],
81 ]
82 );
83 } catch (\Exception $exception) {
84 // ...
85 }
86 }
87
88 private function getLogData()
89 {
90 global $wpdb;
91 //WP_DEBUG
92 if (defined('WP_DEBUG') && WP_DEBUG) {
93 $debug = 1;
94 } else {
95 $debug = 0;
96 }
97
98 //WPLANG
99 if (defined('WPLANG') && WPLANG) {
100 $lang = WPLANG;
101 } else {
102 $lang = 'default';
103 }
104
105 $ip_address = '';
106
107 $server = wpFluentForm('request')->server();
108
109 if (array_key_exists('SERVER_ADDR', $server)) {
110 $ip_address = sanitize_text_field($server['SERVER_ADDR']);
111 } elseif (array_key_exists('LOCAL_ADDR', $server)) {
112 $ip_address = sanitize_text_field($server['LOCAL_ADDR']);
113 }
114
115 $host_name = gethostbyaddr($ip_address);
116
117 $active_plugins = (array) get_option('active_plugins', []);
118 $current_user = wp_get_current_user();
119 if (!empty($current_user->user_email)) {
120 $email = $current_user->user_email;
121 } else {
122 $email = get_option('admin_email');
123 }
124
125 $data = [
126 'version' => App::getVersion(),
127 'wp_version' => get_bloginfo('version'),
128 'multisite_enabled' => is_multisite(),
129 'server_type' => sanitize_text_field($server['SERVER_SOFTWARE']),
130 'php_version' => phpversion(),
131 'mysql_version' => $wpdb->db_version(),
132 'wp_memory_limit' => WP_MEMORY_LIMIT,
133 'wp_debug_mode' => $debug,
134 'wp_lang' => $lang,
135 'wp_max_upload_size' => size_format(wp_max_upload_size()),
136 'php_max_post_size' => ini_get('post_max_size'),
137 'hostname' => $host_name,
138 'smtp' => ini_get('SMTP'),
139 'smtp_port' => ini_get('smtp_port'),
140 'active_plugins' => $active_plugins,
141 'email' => $email,
142 'display_name' => $current_user->display_name,
143 'ip_address' => $ip_address,
144 'domain' => site_url(),
145 ];
146
147 return $data;
148 }
149
150 public function getInitialNotice()
151 {
152 return [
153 'name' => 'track_data_notice',
154 'title' => __('Want to make Fluent Forms better with just one click?', 'fluentform'),
155 'message' => 'We will collect a few server data if you permit us. It will help us troubleshoot any inconveniences you may face while using FluentForm, and guide us to add better features according to your usage. NO FORM SUBMISSION DATA WILL BE COLLECTED.<br/><input checked type="checkbox" id="ff-optin-send-email"> You can also send me Fluent Forms tips and tricks occasionally',
156 'links' => [
157 [
158 'href' => admin_url('admin.php?page=fluent_forms'),
159 'btn_text' => 'Yes, I want to make Fluent Forms Better',
160 'btn_atts' => 'class="button-primary ff_track_yes" data-notice_name="track_data_notice"',
161 ],
162 [
163 'href' => admin_url('admin.php?page=fluent_forms'),
164 'btn_text' => 'No, Please don\'t collect errors or other data',
165 'btn_atts' => 'class="button-secondary ff_nag_cross" data-notice_type="permanent" data-notice_name="track_data_notice"',
166 ],
167 ],
168 ];
169 }
170
171 private function isLocalhost()
172 {
173 return in_array(sanitize_text_field(wpFluentForm('request')->server('REMOTE_ADDR')), ['127.0.0.1', '::1']);
174 }
175 }
176