PluginProbe
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools / 1.0.8
Pixelavo – Server Side Tracking & Pixel + AI Ads Tools v1.0.8
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.0.8, at admin/class-diagnostic-data.php

527 lines 21.3 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 add_action( 'admin_notices', function () {
94 $this->show_notices();
95 }, 0 );
96
97 add_action( 'wp_ajax_pixelavo_diagnostic_data', function () {
98 $this->process_data();
99 } );
100 }
101
102 /**
103 * Is capable user.
104 */
105 private function is_capable_user() {
106 $result = 'no';
107
108 if ( current_user_can( 'manage_options' ) ) {
109 $result = 'yes';
110 }
111
112 return $result;
113 }
114
115 /**
116 * Is show core notice.
117 */
118 private function is_show_core_notice() {
119 $result = get_option( 'pixelavo_diagnostic_data_notice', 'yes' );
120 $result = ( ( 'yes' === $result ) ? 'yes' : 'no' );
121
122 return $result;
123 }
124
125 /**
126 * Is pro active.
127 */
128 private function is_pro_plugin_active() {
129
130 $result = is_plugin_active( $this->project_pro_slug );
131 $result = ( ( true === $result ) ? 'yes' : 'no' );
132
133 return $result;
134 }
135
136 /**
137 * Is pro installed.
138 */
139 private function is_pro_plugin_installed() {
140
141 $plugins = get_plugins();
142 $result = ( isset( $plugins[ $this->project_pro_slug ] ) ? 'yes' : 'no' );
143
144 return $result;
145 }
146
147 /**
148 * Get pro version.
149 */
150 private function get_pro_version() {
151
152 $plugins = get_plugins();
153 $data = ( ( isset( $plugins[ $this->project_pro_slug ] ) && is_array( $plugins[ $this->project_pro_slug ] ) ) ? $plugins[ $this->project_pro_slug ] : array() );
154 $version = ( isset( $data['Version'] ) ? sanitize_text_field( $data['Version'] ) : '' );
155
156 return $version;
157 }
158
159 /**
160 * Process data.
161 */
162 private function process_data() {
163
164 $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
165
166 if ( ! wp_verify_nonce( $nonce, 'pixelavo_diagnostic_data_nonce' ) ) {
167 $errormessage = array(
168 'message' => __('Nonce Varification fail','pixelavo')
169 );
170 wp_send_json_error( $errormessage );
171 }
172
173 $agreed = ( isset( $_POST['agreed'] ) ? sanitize_key( $_POST['agreed'] ) : 'no' );
174 $agreed = ( ( 'yes' === $agreed ) ? 'yes' : 'no' );
175
176 $notice = 'no';
177
178 if ( 'yes' === $agreed ) {
179 $data = $this->get_data();
180
181 if ( ! empty( $data ) ) {
182 $response = $this->send_request( $data );
183
184 if ( is_wp_error( $response ) ) {
185 $agreed = 'no';
186 $notice = 'yes';
187 }
188 }
189 }
190
191 update_option( 'pixelavo_diagnostic_data_agreed', $agreed );
192 update_option( 'pixelavo_diagnostic_data_notice', $notice );
193
194 $response = array(
195 'success' => $agreed,
196 'notice' => $notice,
197 );
198
199 if ( 'yes' === $agreed ) {
200 $response['thanks_notice'] = $this->get_thanks_notice();
201 }
202
203 wp_send_json( $response );
204 }
205
206 /**
207 * Get data.
208 */
209 private function get_data() {
210 $hash = md5( current_time( 'U', true ) );
211
212 $project = array(
213 'name' => $this->project_name,
214 'type' => $this->project_type,
215 'version' => $this->project_version,
216 'pro_active' => $this->project_pro_active,
217 'pro_installed' => $this->project_pro_installed,
218 'pro_version' => $this->project_pro_version,
219 );
220
221 $site_title = get_bloginfo( 'name' );
222 $site_description = get_bloginfo( 'description' );
223 $site_url = wp_parse_url( home_url(), PHP_URL_HOST );
224 $admin_email = get_option( 'admin_email' );
225
226 $admin_first_name = '';
227 $admin_last_name = '';
228 $admin_display_name = '';
229
230 $users = get_users( array(
231 'role' => 'administrator',
232 'orderby' => 'ID',
233 'order' => 'ASC',
234 'number' => 1,
235 'paged' => 1,
236 ) );
237
238 $admin_user = ( ( is_array( $users ) && isset( $users[0] ) && is_object( $users[0] ) ) ? $users[0] : null );
239
240 if ( ! empty( $admin_user ) ) {
241 $admin_first_name = ( isset( $admin_user->first_name ) ? $admin_user->first_name : '' );
242 $admin_last_name = ( isset( $admin_user->last_name ) ? $admin_user->last_name : '' );
243 $admin_display_name = ( isset( $admin_user->display_name ) ? $admin_user->display_name : '' );
244 }
245
246 $ip_address = $this->get_ip_address();
247
248 $data = array(
249 'hash' => $hash,
250 'project' => $project,
251 'site_title' => $site_title,
252 'site_description' => $site_description,
253 'site_address' => $site_url,
254 'site_url' => $site_url,
255 'admin_email' => $admin_email,
256 'admin_first_name' => $admin_first_name,
257 'admin_last_name' => $admin_last_name,
258 'admin_display_name' => $admin_display_name,
259 'server_info' => $this->get_server_info(),
260 'wordpress_info' => $this->get_wordpress_info(),
261 'users_count' => $this->get_users_count(),
262 'plugins_count' => $this->get_plugins_count(),
263 'ip_address' => $ip_address,
264 'country_name' => $this->get_country_from_ip( $ip_address ),
265 );
266
267 return $data;
268 }
269
270 /**
271 * Get server info.
272 */
273 private function get_server_info() {
274 global $wpdb;
275
276 $software = ( ( isset( $_SERVER['SERVER_SOFTWARE'] ) && ! empty( $_SERVER['SERVER_SOFTWARE'] ) ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
277 $php_version = ( function_exists( 'phpversion' ) ? phpversion() : '' );
278 $mysql_version = ( method_exists( $wpdb, 'db_version' ) ? $wpdb->db_version() : '' );
279 $php_max_upload_size = size_format( wp_max_upload_size() );
280 $php_default_timezone = date_default_timezone_get();
281 $php_soap = ( class_exists( 'SoapClient' ) ? 'yes' : 'no' );
282 $php_fsockopen = ( function_exists( 'fsockopen' ) ? 'yes' : 'no' );
283 $php_curl = ( function_exists( 'curl_init' ) ? 'yes' : 'no' );
284
285 $server_info = array(
286 'software' => $software,
287 'php_version' => $php_version,
288 'mysql_version' => $mysql_version,
289 'php_max_upload_size' => $php_max_upload_size,
290 'php_default_timezone' => $php_default_timezone,
291 'php_soap' => $php_soap,
292 'php_fsockopen' => $php_fsockopen,
293 'php_curl' => $php_curl,
294 );
295
296 return $server_info;
297 }
298
299 /**
300 * Get wordpress info.
301 */
302 private function get_wordpress_info() {
303 $wordpress_info = array();
304
305 $memory_limit = ( defined( 'WP_MEMORY_LIMIT' ) ? WP_MEMORY_LIMIT : '' );
306 $debug_mode = ( ( defined('WP_DEBUG') && WP_DEBUG ) ? 'yes' : 'no' );
307 $locale = get_locale();
308 $version = get_bloginfo( 'version' );
309 $multisite = ( is_multisite() ? 'yes' : 'no' );
310 $theme_slug = get_stylesheet();
311
312 $wordpress_info = array(
313 'memory_limit' => $memory_limit,
314 'debug_mode' => $debug_mode,
315 'locale' => $locale,
316 'version' => $version,
317 'multisite' => $multisite,
318 'theme_slug' => $theme_slug,
319 );
320
321 $theme = wp_get_theme( $wordpress_info['theme_slug'] );
322
323 if ( is_object( $theme ) && ! empty( $theme ) && method_exists( $theme, 'get' ) ) {
324 $theme_name = $theme->get( 'Name' );
325 $theme_version = $theme->get( 'Version' );
326 $theme_uri = $theme->get( 'ThemeURI' );
327 $theme_author = $theme->get( 'Author' );
328
329 $wordpress_info = array_merge( $wordpress_info, array(
330 'theme_name' => $theme_name,
331 'theme_version' => $theme_version,
332 'theme_uri' => $theme_uri,
333 'theme_author' => $theme_author,
334 ) );
335 }
336
337 return $wordpress_info;
338 }
339
340 /**
341 * Get users count.
342 */
343 private function get_users_count() {
344 $users_count = array();
345
346 $users_count_data = count_users();
347
348 $total_users = ( isset( $users_count_data['total_users'] ) ? $users_count_data['total_users'] : 0 );
349 $avail_roles = ( isset( $users_count_data['avail_roles'] ) ? $users_count_data['avail_roles'] : array() );
350
351 $users_count['total'] = $total_users;
352
353 if ( is_array( $avail_roles ) && ! empty( $avail_roles ) ) {
354 foreach ( $avail_roles as $role => $count ) {
355 $users_count[ $role ] = $count;
356 }
357 }
358
359 return $users_count;
360 }
361
362 /**
363 * Get plugins count.
364 */
365 private function get_plugins_count() {
366 $total_plugins_count = 0;
367 $active_plugins_count = 0;
368 $inactive_plugins_count = 0;
369
370 $plugins = get_plugins();
371 $plugins = ( is_array( $plugins ) ? $plugins : array() );
372
373 $active_plugins = get_option( 'active_plugins', array() );
374 $active_plugins = ( is_array( $active_plugins ) ? $active_plugins : array() );
375
376 if ( ! empty( $plugins ) ) {
377 foreach ( $plugins as $key => $data ) {
378 if ( in_array( $key, $active_plugins, true ) ) {
379 $active_plugins_count++;
380 } else {
381 $inactive_plugins_count++;
382 }
383
384 $total_plugins_count++;
385 }
386 }
387
388 $plugins_count = array(
389 'total' => $total_plugins_count,
390 'active' => $active_plugins_count,
391 'inactive' => $inactive_plugins_count,
392 );
393
394 return $plugins_count;
395 }
396
397 /**
398 * Get IP Address
399 */
400 private function get_ip_address() {
401 $response = wp_remote_get( 'https://icanhazip.com/' );
402
403 if ( is_wp_error( $response ) ) {
404 return '';
405 }
406
407 $ip_address = wp_remote_retrieve_body( $response );
408 $ip_address = trim( $ip_address );
409
410 if ( ! filter_var( $ip_address, FILTER_VALIDATE_IP ) ) {
411 return '';
412 }
413
414 return $ip_address;
415 }
416
417 /**
418 * Get Country Form ID Address
419 */
420 private function get_country_from_ip( $ip_address ) {
421 $api_url = 'http://ip-api.com/json/' . $ip_address;
422
423 // Fetch data from the API
424 $response = wp_remote_get( $api_url );
425
426 if ( is_wp_error( $response ) ) {
427 return 'Error';
428 }
429
430 // Decode the JSON response
431 $data = json_decode( wp_remote_retrieve_body($response) );
432
433 if ($data && $data->status === 'success') {
434 return $data->country;
435 } else {
436 return 'Unknown';
437 }
438 }
439
440 /**
441 * Send request.
442 */
443 private function send_request( $data = array() ) {
444 if ( ! is_array( $data ) || empty( $data ) ) {
445 return;
446 }
447
448 $site_url = wp_parse_url( home_url(), PHP_URL_HOST );
449
450 $headers = array(
451 'user-agent' => $this->project_name . '/' . md5( $site_url ) . ';',
452 'Accept' => 'application/json',
453 );
454
455 $response = wp_remote_post( $this->data_center, array(
456 'method' => 'POST',
457 'timeout' => 30,
458 'redirection' => 5,
459 'httpversion' => '1.0',
460 'blocking' => false,
461 'headers' => $headers,
462 'body' => $data,
463 'cookies' => array(),
464 ) );
465
466 return $response;
467 }
468
469 /**
470 * Show notices.
471 */
472 private function show_notices() {
473 $action = isset($_GET['action'] ) ? sanitize_text_field($_GET['action'] ) : '';
474
475 if ( 'no' === $this->is_capable_user() || 'upload-plugin' == $action ) {
476 return;
477 }
478
479 if ( 'yes' === $this->is_show_core_notice() ) {
480 $this->show_core_notice();
481 }
482 }
483
484 /**
485 * Show core notice.
486 */
487 private function show_core_notice() {
488
489 $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>' );
490
491 $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>' );
492
493 $button_text_1 = esc_html__( 'Count Me In', 'pixelavo' );
494 $button_link_1 = add_query_arg( array( 'pixelavo-diagnostic-data-agreed' => 1 ) );
495
496 $button_text_2 = esc_html__( 'No, Thanks', 'pixelavo' );
497 $button_link_2 = add_query_arg( array( 'pixelavo-diagnostic-data-agreed' => 0 ) );
498 ?>
499 <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>
500 <div class="pixelavo-diagnostic-data-notice notice notice-success">
501 <h4 class="pixelavo-diagnostic-data-title"><?php echo sprintf( esc_html__('🌟 Enhance Your %1$s Experience as a Valued Contributor!','pixelavo'), esc_html( $this->project_name )); ?></h4>
502 <p class="pixelavo-diagnostic-data-message"><?php echo wp_kses_post( $message_l1 ); ?></p>
503 <p class="pixelavo-diagnostic-data-list"><?php echo wp_kses_post( $message_l2 ); ?></p>
504 <p class="pixelavo-diagnostic-data-buttons">
505 <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>
506 <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>
507 </p>
508 </div>
509 <div class="pixelavo-diagnostic-data-script"><script type="text/javascript">;(function($){"use strict";function pixelavoDissmissThanksNotice(noticeWrap){$('.pixelavo-diagnostic-data-thanks .notice-dismiss').on('click',function(e){e.preventDefault();let thisButton=$(this),noticeWrap=thisButton.closest('.pixelavo-diagnostic-data-thanks');noticeWrap.fadeTo(100,0,function(){noticeWrap.slideUp(100,function(){noticeWrap.remove()})})})};$(".pixelavo-diagnostic-data-list-toogle").on("click",function(e){e.preventDefault();$(this).parents(".pixelavo-diagnostic-data-notice").find(".pixelavo-diagnostic-data-list").slideToggle("fast")});$(".pixelavo-diagnostic-data-button").on("click",function(e){e.preventDefault();let thisButton=$(this),noticeWrap=thisButton.closest(".pixelavo-diagnostic-data-notice"),agreed=thisButton.hasClass("pixelavo-diagnostic-data-agree")?"yes":"no",styleWrap=$(".pixelavo-diagnostic-data-style"),scriptWrap=$(".pixelavo-diagnostic-data-script");$.ajax({type:"POST",url:ajaxurl,data:{action:"pixelavo_diagnostic_data",agreed:agreed,nonce:'<?php echo wp_create_nonce( 'pixelavo_diagnostic_data_nonce' );?>'},beforeSend:function(){noticeWrap.addClass("pixelavo-diagnostic-data-loading")},success:function(response){response="object"===typeof response?response:{};let success=response.hasOwnProperty("success")?response.success:"no",notice=response.hasOwnProperty("notice")?response.notice:"no",thanks_notice=response.hasOwnProperty("thanks_notice")?response.thanks_notice:"";if("yes"===success){noticeWrap.replaceWith(thanks_notice);styleWrap.remove();scriptWrap.remove()}else if("no"===notice){noticeWrap.remove();styleWrap.remove();scriptWrap.remove()};noticeWrap.removeClass("pixelavo-diagnostic-data-loading");pixelavoDissmissThanksNotice()},error:function(){noticeWrap.removeClass("pixelavo-diagnostic-data-loading")},})})})(jQuery);</script></div>
510 <?php
511 }
512
513 /**
514 * Get thanks notice.
515 */
516 private function get_thanks_notice() {
517 $message = sprintf( esc_html__( 'Thank you very much for supporting %2$s%1$s%3$s.', 'pixelavo' ), $this->project_name, '<strong>', '</strong>' );
518 $notice = sprintf( '<div class="pixelavo-diagnostic-data-thanks notice notice-success is-dismissible"><p>%1$s</p><button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button></div>', wp_kses_post( $message ) );
519
520 return $notice;
521 }
522
523 }
524
525 // Returns the instance.
526 Pixelavo_Diagnostic_Data::get_instance();
527 }