PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.13
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.13
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.13, at app/Modules/Track/TrackModule.php

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