PluginProbe
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools / 1.1.3
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools v1.1.3
1.5.5 1.5.4 trunk 1.0.0 1.0.1 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 All 47 releases
pixelavo / admin / class-diagnostic-data.php

class-diagnostic-data.php in Pixelavo – Server Side Tracking & Pixel + AI Ads Tools 1.1.3, at admin/class-diagnostic-data.php

518 lines 19.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Diagnostic data.
4 */
5
6 // If this file is accessed directly, exit.
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * Class.
13 */
14 if ( ! class_exists( 'Pixelavo_Diagnostic_Data' ) ) {
15 class Pixelavo_Diagnostic_Data {
16
17 /**
18 * Project name.
19 */
20 private $project_name;
21
22 /**
23 * Project type.
24 */
25 private $project_type;
26
27 /**
28 * Project version.
29 */
30 private $project_version;
31
32 /**
33 * Pro version Slug.
34 */
35 private $project_pro_slug;
36
37 /**
38 * Pro active.
39 */
40 private $project_pro_active;
41
42 /**
43 * Pro installed.
44 */
45 private $project_pro_installed;
46
47 /**
48 * Pro version.
49 */
50 private $project_pro_version;
51
52 /**
53 * Data center.
54 */
55 private $data_center;
56
57 /**
58 * Privacy policy.
59 */
60 private $privacy_policy;
61
62 /**
63 * Instance.
64 */
65 private static $_instance = null;
66
67 /**
68 * Get instance.
69 */
70 public static function get_instance() {
71 if ( is_null( self::$_instance ) ) {
72 self::$_instance = new self();
73 }
74
75 return self::$_instance;
76 }
77
78 /**
79 * Constructor.
80 */
81 private function __construct() {
82 $this->project_name = 'Pixelavo';
83 $this->project_type = 'wordpress-plugin';
84 $this->project_version = PIXELAVO_VERSION;
85 $this->data_center = 'https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjAwNTY1MDYzZTA0MzM1MjY1NTUzNyI_3D_pc';
86 $this->privacy_policy = 'https://hasthemes.com/privacy-policy/';
87
88 $this->project_pro_slug = 'pixelavo-pro/pixelavo-pro.php';
89 $this->project_pro_active = $this->is_pro_plugin_active();
90 $this->project_pro_installed = $this->is_pro_plugin_installed();
91 $this->project_pro_version = $this->get_pro_version();
92
93 if( get_option('pixelavo_diagnostic_data_agreed') === 'yes' || get_option('pixelavo_diagnostic_data_notice') === 'no' ){
94 return;
95 }
96
97 add_action( 'admin_notices', function () {
98 $this->show_notices();
99 }, 0 );
100
101 add_action('plugins_loaded', function(){
102 $agreed = ( isset( $_GET['pixelavo_diagnostic_data_agreed'] ) ? sanitize_key( $_GET['pixelavo_diagnostic_data_agreed'] ) : '' );
103
104 if( $agreed === 'yes' ){
105 $this->process_data( $agreed );
106 } elseif( $agreed === 'no' ) {
107 $this->process_data( $agreed );
108 }
109 }, 11);
110 }
111
112 /**
113 * Is capable user.
114 */
115 private function is_capable_user() {
116 $result = 'no';
117
118 if ( current_user_can( 'manage_options' ) ) {
119 $result = 'yes';
120 }
121
122 return $result;
123 }
124
125 /**
126 * Is show core notice.
127 */
128 private function is_show_core_notice() {
129 $result = get_option( 'pixelavo_diagnostic_data_notice', 'yes' );
130 $result = ( ( 'yes' === $result ) ? 'yes' : 'no' );
131
132 return $result;
133 }
134
135 /**
136 * Is pro active.
137 */
138 private function is_pro_plugin_active() {
139
140 $result = is_plugin_active( $this->project_pro_slug );
141 $result = ( ( true === $result ) ? 'yes' : 'no' );
142
143 return $result;
144 }
145
146 /**
147 * Is pro installed.
148 */
149 private function is_pro_plugin_installed() {
150
151 $plugins = get_plugins();
152 $result = ( isset( $plugins[ $this->project_pro_slug ] ) ? 'yes' : 'no' );
153
154 return $result;
155 }
156
157 /**
158 * Get pro version.
159 */
160 private function get_pro_version() {
161
162 $plugins = get_plugins();
163 $data = ( ( isset( $plugins[ $this->project_pro_slug ] ) && is_array( $plugins[ $this->project_pro_slug ] ) ) ? $plugins[ $this->project_pro_slug ] : array() );
164 $version = ( isset( $data['Version'] ) ? sanitize_text_field( $data['Version'] ) : '' );
165
166 return $version;
167 }
168
169 /**
170 * Process data.
171 */
172 private function process_data( $agreed ) {
173 $notice = 'no';
174
175 if ( 'yes' === $agreed ) {
176 $data = $this->get_data();
177
178 if ( ! empty( $data ) ) {
179 $response = $this->send_request( $data );
180
181 if ( is_wp_error( $response ) ) {
182 $agreed = 'no';
183 $notice = 'yes';
184 }
185 }
186 }
187
188 update_option( 'pixelavo_diagnostic_data_agreed', $agreed );
189 update_option( 'pixelavo_diagnostic_data_notice', $notice );
190 }
191
192 /**
193 * Get data.
194 */
195 private function get_data() {
196 $hash = md5( current_time( 'U', true ) );
197
198 $project = array(
199 'name' => $this->project_name,
200 'type' => $this->project_type,
201 'version' => $this->project_version,
202 'pro_active' => $this->project_pro_active,
203 'pro_installed' => $this->project_pro_installed,
204 'pro_version' => $this->project_pro_version,
205 );
206
207 $site_title = get_bloginfo( 'name' );
208 $site_description = get_bloginfo( 'description' );
209 $site_url = wp_parse_url( home_url(), PHP_URL_HOST );
210 $admin_email = get_option( 'admin_email' );
211
212 $admin_first_name = '';
213 $admin_last_name = '';
214 $admin_display_name = '';
215
216 $users = get_users( array(
217 'role' => 'administrator',
218 'orderby' => 'ID',
219 'order' => 'ASC',
220 'number' => 1,
221 'paged' => 1,
222 ) );
223
224 $admin_user = ( ( is_array( $users ) && isset( $users[0] ) && is_object( $users[0] ) ) ? $users[0] : null );
225
226 if ( ! empty( $admin_user ) ) {
227 $admin_first_name = ( isset( $admin_user->first_name ) ? $admin_user->first_name : '' );
228 $admin_last_name = ( isset( $admin_user->last_name ) ? $admin_user->last_name : '' );
229 $admin_display_name = ( isset( $admin_user->display_name ) ? $admin_user->display_name : '' );
230 }
231
232 $ip_address = $this->get_ip_address();
233
234 $data = array(
235 'hash' => $hash,
236 'project' => $project,
237 'site_title' => $site_title,
238 'site_description' => $site_description,
239 'site_address' => $site_url,
240 'site_url' => $site_url,
241 'admin_email' => $admin_email,
242 'admin_first_name' => $admin_first_name,
243 'admin_last_name' => $admin_last_name,
244 'admin_display_name' => $admin_display_name,
245 'server_info' => $this->get_server_info(),
246 'wordpress_info' => $this->get_wordpress_info(),
247 'users_count' => $this->get_users_count(),
248 'plugins_count' => $this->get_plugins_count(),
249 'ip_address' => $ip_address,
250 'country_name' => $this->get_country_from_ip( $ip_address ),
251 );
252
253 return $data;
254 }
255
256 /**
257 * Get server info.
258 */
259 private function get_server_info() {
260 global $wpdb;
261
262 $software = ( ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
263 $php_version = ( function_exists( 'phpversion' ) ? phpversion() : '' );
264 $mysql_version = ( method_exists( $wpdb, 'db_version' ) ? $wpdb->db_version() : '' );
265 $php_max_upload_size = size_format( wp_max_upload_size() );
266 $php_default_timezone = date_default_timezone_get();
267 $php_soap = ( class_exists( 'SoapClient' ) ? 'yes' : 'no' );
268 $php_fsockopen = ( function_exists( 'fsockopen' ) ? 'yes' : 'no' );
269 $php_curl = ( function_exists( 'curl_init' ) ? 'yes' : 'no' );
270
271 $server_info = array(
272 'software' => $software,
273 'php_version' => $php_version,
274 'mysql_version' => $mysql_version,
275 'php_max_upload_size' => $php_max_upload_size,
276 'php_default_timezone' => $php_default_timezone,
277 'php_soap' => $php_soap,
278 'php_fsockopen' => $php_fsockopen,
279 'php_curl' => $php_curl,
280 );
281
282 return $server_info;
283 }
284
285 /**
286 * Get wordpress info.
287 */
288 private function get_wordpress_info() {
289 $wordpress_info = array();
290
291 $memory_limit = ( defined( 'WP_MEMORY_LIMIT' ) ? WP_MEMORY_LIMIT : '' );
292 $debug_mode = ( ( defined('WP_DEBUG') && WP_DEBUG ) ? 'yes' : 'no' );
293 $locale = get_locale();
294 $version = get_bloginfo( 'version' );
295 $multisite = ( is_multisite() ? 'yes' : 'no' );
296 $theme_slug = get_stylesheet();
297
298 $wordpress_info = array(
299 'memory_limit' => $memory_limit,
300 'debug_mode' => $debug_mode,
301 'locale' => $locale,
302 'version' => $version,
303 'multisite' => $multisite,
304 'theme_slug' => $theme_slug,
305 );
306
307 $theme = wp_get_theme( $wordpress_info['theme_slug'] );
308
309 if ( is_object( $theme ) && ! empty( $theme ) && method_exists( $theme, 'get' ) ) {
310 $theme_name = $theme->get( 'Name' );
311 $theme_version = $theme->get( 'Version' );
312 $theme_uri = $theme->get( 'ThemeURI' );
313 $theme_author = $theme->get( 'Author' );
314
315 $wordpress_info = array_merge( $wordpress_info, array(
316 'theme_name' => $theme_name,
317 'theme_version' => $theme_version,
318 'theme_uri' => $theme_uri,
319 'theme_author' => $theme_author,
320 ) );
321 }
322
323 return $wordpress_info;
324 }
325
326 /**
327 * Get users count.
328 */
329 private function get_users_count() {
330 $users_count = array();
331
332 $users_count_data = count_users();
333
334 $total_users = ( isset( $users_count_data['total_users'] ) ? $users_count_data['total_users'] : 0 );
335 $avail_roles = ( isset( $users_count_data['avail_roles'] ) ? $users_count_data['avail_roles'] : array() );
336
337 $users_count['total'] = $total_users;
338
339 if ( is_array( $avail_roles ) && ! empty( $avail_roles ) ) {
340 foreach ( $avail_roles as $role => $count ) {
341 $users_count[ $role ] = $count;
342 }
343 }
344
345 return $users_count;
346 }
347
348 /**
349 * Get plugins count.
350 */
351 private function get_plugins_count() {
352 $total_plugins_count = 0;
353 $active_plugins_count = 0;
354 $inactive_plugins_count = 0;
355
356 $plugins = get_plugins();
357 $plugins = ( is_array( $plugins ) ? $plugins : array() );
358
359 $active_plugins = get_option( 'active_plugins', array() );
360 $active_plugins = ( is_array( $active_plugins ) ? $active_plugins : array() );
361
362 if ( ! empty( $plugins ) ) {
363 foreach ( $plugins as $key => $data ) {
364 if ( in_array( $key, $active_plugins, true ) ) {
365 $active_plugins_count++;
366 } else {
367 $inactive_plugins_count++;
368 }
369
370 $total_plugins_count++;
371 }
372 }
373
374 $plugins_count = array(
375 'total' => $total_plugins_count,
376 'active' => $active_plugins_count,
377 'inactive' => $inactive_plugins_count,
378 );
379
380 return $plugins_count;
381 }
382
383 /**
384 * Get IP Address
385 */
386 private function get_ip_address() {
387 $response = wp_remote_get( 'https://icanhazip.com/' );
388
389 if ( is_wp_error( $response ) ) {
390 return '';
391 }
392
393 $ip_address = wp_remote_retrieve_body( $response );
394 $ip_address = trim( $ip_address );
395
396 if ( ! filter_var( $ip_address, FILTER_VALIDATE_IP ) ) {
397 return '';
398 }
399
400 return $ip_address;
401 }
402
403 /**
404 * Get Country Form ID Address
405 */
406 private function get_country_from_ip( $ip_address ) {
407 $api_url = 'http://ip-api.com/json/' . $ip_address;
408
409 // Fetch data from the API
410 $response = wp_remote_get( $api_url );
411
412 if ( is_wp_error( $response ) ) {
413 return 'Error';
414 }
415
416 // Decode the JSON response
417 $data = json_decode( wp_remote_retrieve_body($response) );
418
419 if ($data && $data->status === 'success') {
420 return $data->country;
421 } else {
422 return 'Unknown';
423 }
424 }
425
426 /**
427 * Send request.
428 */
429 private function send_request( $data = array() ) {
430 if ( ! is_array( $data ) || empty( $data ) ) {
431 return;
432 }
433
434 $site_url = wp_parse_url( home_url(), PHP_URL_HOST );
435
436 $headers = array(
437 'user-agent' => $this->project_name . '/' . md5( $site_url ) . ';',
438 'Accept' => 'application/json',
439 );
440
441 $response = wp_remote_post( $this->data_center, array(
442 'method' => 'POST',
443 'timeout' => 30,
444 'redirection' => 5,
445 'httpversion' => '1.0',
446 'blocking' => false,
447 'headers' => $headers,
448 'body' => $data,
449 'cookies' => array(),
450 ) );
451
452 return $response;
453 }
454
455 /**
456 * Show notices.
457 */
458 private function show_notices() {
459 $action = isset($_GET['action'] ) ? sanitize_text_field($_GET['action'] ) : '';
460
461 if ( 'no' === $this->is_capable_user() || 'upload-plugin' == $action ) {
462 return;
463 }
464
465 if ( 'yes' === $this->is_show_core_notice() ) {
466 $this->show_core_notice();
467 }
468 }
469
470 /**
471 * Show core notice.
472 */
473 private function show_core_notice() {
474
475 /*
476 * translators: %1$s: project name
477 * translators: %2$s: strong start tag
478 * translators: %3$s: strong end tag
479 * translators: %4$s: a start tag with url
480 * translators: %5$s: a end tag
481 */
482 $message_l1 = sprintf( esc_html__( 'At %2$s%1$s%3$s, we prioritize continuous improvement and compatibility. To achieve this, we gather non-sensitive diagnostic information and details about plugin usage. This includes your site\'s URL, the versions of WordPress and PHP you\'re using, and a list of your installed plugins and themes. We also require your email address to provide you with exclusive discount coupons and updates. This data collection is crucial for ensuring that %2$s%1$s%3$s remains up-to-date and compatible with the most widely-used plugins and themes. Rest assured, your privacy is our priority – no spam, guaranteed. %4$sPrivacy Policy%5$s', 'pixelavo' ), esc_html( $this->project_name ), '<strong>', '</strong>', '<a target="_blank" href="' . esc_url( $this->privacy_policy ) . '">', '</a>', '<h4 class="pixelavo-diagnostic-data-title">', '</h4>' );
483
484 /*
485 * translators: %1$s: a start tag with url
486 * translators: %2$s: a end tag
487 */
488 $message_l2 = sprintf( esc_html__( 'Server information (Web server, PHP version, MySQL version), WordPress information, site name, site URL, number of plugins, number of users, your name, and email address. You can rest assured that no sensitive data will be collected or tracked. %1$sLearn more%2$s.', 'pixelavo' ), '<a target="_blank" href="' . esc_url( $this->privacy_policy ) . '">', '</a>' );
489
490 $button_text_1 = esc_html__( 'Count Me In', 'pixelavo' );
491 $button_link_1 = add_query_arg( array( 'pixelavo_diagnostic_data_agreed' => 'yes' ) );
492
493 $button_text_2 = esc_html__( 'No, Thanks', 'pixelavo' );
494 $button_link_2 = add_query_arg( array( 'pixelavo_diagnostic_data_agreed' => 'no' ) );
495 ?>
496 <div class="pixelavo-diagnostic-data-style"><style>.pixelavo-diagnostic-data-notice,.woocommerce-embed-page .pixelavo-diagnostic-data-notice{padding-top:.75em;padding-bottom:.75em;}.pixelavo-diagnostic-data-notice .pixelavo-diagnostic-data-buttons,.pixelavo-diagnostic-data-notice .pixelavo-diagnostic-data-list,.pixelavo-diagnostic-data-notice .pixelavo-diagnostic-data-message{padding:.25em 2px;margin:0;}.pixelavo-diagnostic-data-notice .pixelavo-diagnostic-data-list{display:none;color:#646970;}.pixelavo-diagnostic-data-notice .pixelavo-diagnostic-data-buttons{padding-top:.75em;}.pixelavo-diagnostic-data-notice .pixelavo-diagnostic-data-buttons .button{margin-right:5px;box-shadow:none;}.pixelavo-diagnostic-data-loading{position:relative;}.pixelavo-diagnostic-data-loading::before{position:absolute;content:"";width:100%;height:100%;top:0;left:0;background-color:rgba(255,255,255,.5);z-index:999;}.pixelavo-diagnostic-data-disagree{border-width:0px !important;background-color: transparent!important; padding: 0!important;}h4.pixelavo-diagnostic-data-title {margin: 0 0 10px 0;font-size: 1.04em;font-weight: 600;}</style></div>
497 <div class="pixelavo-diagnostic-data-notice notice notice-success">
498 <h4 class="pixelavo-diagnostic-data-title">
499 <?php
500 /* translators: %1$s: project name */
501 echo sprintf( esc_html__('🌟 Enhance Your %1$s Experience as a Valued Contributor!','pixelavo'), esc_html( $this->project_name ));
502 ?>
503 </h4>
504 <p class="pixelavo-diagnostic-data-message"><?php echo wp_kses_post( $message_l1 ); ?></p>
505 <p class="pixelavo-diagnostic-data-list"><?php echo wp_kses_post( $message_l2 ); ?></p>
506 <p class="pixelavo-diagnostic-data-buttons">
507 <a href="<?php echo esc_url( $button_link_1 ); ?>" class="pixelavo-diagnostic-data-button pixelavo-diagnostic-data-agree button button-primary"><?php echo esc_html( $button_text_1 ); ?></a>
508 <a href="<?php echo esc_url( $button_link_2 ); ?>" class="pixelavo-diagnostic-data-button pixelavo-diagnostic-data-disagree button button-secondary"><?php echo esc_html( $button_text_2 ); ?></a>
509 </p>
510 </div>
511 <?php
512 }
513
514 }
515
516 // Returns the instance.
517 Pixelavo_Diagnostic_Data::get_instance();
518 }