PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 5.2.9
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v5.2.9
6.2.14 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 All 196 releases
fluentform / app / Modules / Track / TrackModule.php

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

184 lines 6.3 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\App\Http\Controllers\AdminNoticeController;
6
7 //Could not Find any Usage any where
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
16 private $adminNotice;
17
18 public function __construct()
19 {
20 $this->adminNotice = new AdminNoticeController();
21 }
22
23 public function initTrack()
24 {
25 if ($this->adminNotice->shouldShowNotice('track_data_notice') && $this->isLocalhost()) {
26 $this->showInitialConsent();
27 }
28 }
29
30 public function showInitialConsent()
31 {
32 $notice = $this->getInitialNotice();
33 $this->adminNotice->addNotice($notice);
34 }
35
36 public function rejectTrack()
37 {
38 $notice_name = sanitize_text_field(wpFluentForm('request')->get('notice_name'));
39 $action_type = sanitize_text_field(wpFluentForm('request')->get('action_type'));
40
41 $notificationPref = get_option($this->initialConsentKey, []);
42
43 if ('permanent' == $action_type) {
44 $notificationPref[$notice_name] = [
45 'status' => 'no',
46 'email_subscribed' => 'no',
47 'timestamp' => time(),
48 'temp_disabled' => false,
49 ];
50 } else {
51 $notificationPref[$notice_name] = [
52 'status' => 'no',
53 'email_subscribed' => 'no',
54 'timestamp' => time(),
55 'temp_disabled' => true,
56 ];
57 }
58
59 update_option($this->initialConsentKey, $notificationPref, 'no');
60 }
61
62 public function sendInitialInfo()
63 {
64 $email_enabled = sanitize_text_field(wpFluentForm('request')->get('email_enabled'));
65 $notice_name = sanitize_text_field(wpFluentForm('request')->get('notice_name'));
66
67 $notificationPref = get_option($this->initialConsentKey, []);
68
69 $notificationPref[$notice_name] = [
70 'status' => 'yes',
71 'email_subscribed' => ($email_enabled) ? 'yes' : 'no',
72 'timestamp' => time(),
73 ];
74
75 update_option($this->initialConsentKey, $notificationPref, 'no');
76
77 $logData = $this->getLogData();
78 $logData['email_subscribed'] = $email_enabled;
79
80 try {
81 wp_remote_post(
82 $this->apiUrl,
83 [
84 'body' => [
85 'plugin_log_id' => 1,
86 'plugin' => 'fluentform',
87 'data' => $logData,
88 ],
89 ]
90 );
91 } catch (\Exception $exception) {
92 // ...
93 }
94 }
95
96 private function getLogData()
97 {
98 global $wpdb;
99 //WP_DEBUG
100 if (defined('WP_DEBUG') && WP_DEBUG) {
101 $debug = 1;
102 } else {
103 $debug = 0;
104 }
105
106 //WPLANG
107 if (defined('WPLANG') && WPLANG) {
108 $lang = WPLANG;
109 } else {
110 $lang = 'default';
111 }
112
113 $ip_address = '';
114
115 $server = wpFluentForm('request')->server();
116
117 if (array_key_exists('SERVER_ADDR', $server)) {
118 $ip_address = sanitize_text_field($server['SERVER_ADDR']);
119 } elseif (array_key_exists('LOCAL_ADDR', $server)) {
120 $ip_address = sanitize_text_field($server['LOCAL_ADDR']);
121 }
122
123 $host_name = gethostbyaddr($ip_address);
124
125 $active_plugins = (array) get_option('active_plugins', []);
126 $current_user = wp_get_current_user();
127 if (!empty($current_user->user_email)) {
128 $email = $current_user->user_email;
129 } else {
130 $email = get_option('admin_email');
131 }
132
133 $data = [
134 'version' => FLUENTFORM_VERSION,
135 'wp_version' => get_bloginfo('version'),
136 'multisite_enabled' => is_multisite(),
137 'server_type' => sanitize_text_field($server['SERVER_SOFTWARE']),
138 'php_version' => phpversion(),
139 'mysql_version' => $wpdb->db_version(),
140 'wp_memory_limit' => WP_MEMORY_LIMIT,
141 'wp_debug_mode' => $debug,
142 'wp_lang' => $lang,
143 'wp_max_upload_size' => size_format(wp_max_upload_size()),
144 'php_max_post_size' => ini_get('post_max_size'),
145 'hostname' => $host_name,
146 'smtp' => ini_get('SMTP'),
147 'smtp_port' => ini_get('smtp_port'),
148 'active_plugins' => $active_plugins,
149 'email' => $email,
150 'display_name' => $current_user->display_name,
151 'ip_address' => $ip_address,
152 'domain' => site_url(),
153 ];
154
155 return $data;
156 }
157
158 public function getInitialNotice()
159 {
160 return [
161 'name' => 'track_data_notice',
162 'title' => __('Want to make Fluent Forms better with just one click?', 'fluentform'),
163 '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',
164 'links' => [
165 [
166 'href' => admin_url('admin.php?page=fluent_forms'),
167 'btn_text' => 'Yes, I want to make Fluent Forms Better',
168 'btn_atts' => 'class="button-primary ff_track_yes" data-notice_name="track_data_notice"',
169 ],
170 [
171 'href' => admin_url('admin.php?page=fluent_forms'),
172 'btn_text' => 'No, Please don\'t collect errors or other data',
173 'btn_atts' => 'class="button-secondary ff_nag_cross" data-notice_type="permanent" data-notice_name="track_data_notice"',
174 ],
175 ],
176 ];
177 }
178
179 private function isLocalhost()
180 {
181 return in_array(sanitize_text_field(wpFluentForm('request')->server('REMOTE_ADDR')), ['127.0.0.1', '::1']);
182 }
183 }
184