WP Statistics - Version 12.6.8

Version Description

  • Fixed: Coefficient per visitors.
  • Improvement www domain in Top Referring.
  • Improvement REST API.
Download this release

Release Info

Developer mostafa.s1990
Plugin Icon 128x128 WP Statistics
Version 12.6.8
Comparing to
See all releases

Code changes from version 12.6.7 to 12.6.8

includes/classes/class-wp-statistics-frontend.php CHANGED
@@ -71,7 +71,7 @@ class WP_Statistics_Frontend {
71
 
72
  if ( $WP_Statistics->use_cache ) {
73
  $this->html_comment();
74
- echo '<script>var WP_Statistics_http = new XMLHttpRequest();WP_Statistics_http.open(\'POST\', \'' . add_query_arg( array( '_' => time() ), path_join( get_rest_url(), WP_Statistics_Rest::route . '/' . WP_Statistics_Rest::func ) ) . '\', true);WP_Statistics_http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");WP_Statistics_http.send("' . WP_Statistics_Rest::_POST . '=" + JSON.stringify(' . self::set_default_params() . '));</script>' . "\n";
75
  }
76
  }
77
 
@@ -105,7 +105,7 @@ class WP_Statistics_Frontend {
105
  $params['ip'] = esc_html( $WP_Statistics->get_IP() );
106
 
107
  //set hash ip
108
- $params['hash_ip'] = $WP_Statistics->get_hash_string();
109
 
110
  //exclude
111
  $check_exclude = new WP_Statistics_Hits();
@@ -115,7 +115,7 @@ class WP_Statistics_Frontend {
115
  //User Agent String
116
  $params['ua'] = '';
117
  if ( array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
118
- $params['ua'] = $_SERVER['HTTP_USER_AGENT'];
119
  }
120
 
121
  //track all page
71
 
72
  if ( $WP_Statistics->use_cache ) {
73
  $this->html_comment();
74
+ echo '<script>var WP_Statistics_http = new XMLHttpRequest();WP_Statistics_http.open(\'GET\', \'' . add_query_arg( array( '_' => time(), '_wpnonce' => wp_create_nonce( 'wp_rest' ), WP_Statistics_Rest::_Argument => self::set_default_params() ), path_join( get_rest_url(), WP_Statistics_Rest::route . '/' . WP_Statistics_Rest::func ) ) . '\', true);WP_Statistics_http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");WP_Statistics_http.send(null);</script>' . "\n";
75
  }
76
  }
77
 
105
  $params['ip'] = esc_html( $WP_Statistics->get_IP() );
106
 
107
  //set hash ip
108
+ $params['hash_ip'] = esc_html( str_replace( '#hash#', '', $WP_Statistics->get_hash_string() ) );
109
 
110
  //exclude
111
  $check_exclude = new WP_Statistics_Hits();
115
  //User Agent String
116
  $params['ua'] = '';
117
  if ( array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
118
+ $params['ua'] = esc_html( $_SERVER['HTTP_USER_AGENT'] );
119
  }
120
 
121
  //track all page
includes/classes/class-wp-statistics-rest.php CHANGED
@@ -12,7 +12,7 @@ class WP_Statistics_Rest {
12
  const func = 'hit';
13
 
14
  // Set Default POST Name
15
- const _POST = 'wp_statistics_hit';
16
 
17
  /**
18
  * Setup an Wordpress REst Api action.
@@ -34,8 +34,26 @@ class WP_Statistics_Rest {
34
  public function register_routes() {
35
  // Get Hit
36
  register_rest_route( self::route, '/' . self::func, array(
37
- 'methods' => 'POST',
38
- 'callback' => array( $this, 'hit' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  ) );
40
  }
41
 
@@ -48,14 +66,13 @@ class WP_Statistics_Rest {
48
  /*
49
  * Check Is Test Service Request
50
  */
51
- if ( isset( $_POST['rest-api-wp-statistics'] ) ) {
52
-
53
  return array( "rest-api-wp-statistics" => "OK" );
54
  }
55
 
56
 
57
  //Check Auth Key Request
58
- if ( ! isset( $_POST[ self::_POST ] ) ) {
59
  return new WP_Error( 'error', 'You have no right to access', array( 'status' => 403 ) );
60
  }
61
 
@@ -95,7 +112,7 @@ class WP_Statistics_Rest {
95
  global $WP_Statistics;
96
 
97
  if ( isset( $WP_Statistics ) and $WP_Statistics->use_cache ) {
98
- if ( isset( $_POST[ self::_POST ] ) ) {
99
  return true;
100
  }
101
  }
@@ -107,8 +124,8 @@ class WP_Statistics_Rest {
107
  * Get Params Request
108
  */
109
  static public function params( $params ) {
110
- if ( isset( $_POST[ self::_POST ] ) ) {
111
- $data = wp_unslash( $_POST[ self::_POST ] );
112
 
113
  if ( ! empty( $data ) && is_string( $data ) && is_array( json_decode( $data, true ) ) && json_last_error() == 0 ) {
114
  $data = json_decode( $data, true );
12
  const func = 'hit';
13
 
14
  // Set Default POST Name
15
+ const _Argument = 'wp_statistics_hit';
16
 
17
  /**
18
  * Setup an Wordpress REst Api action.
34
  public function register_routes() {
35
  // Get Hit
36
  register_rest_route( self::route, '/' . self::func, array(
37
+ 'methods' => \WP_REST_Server::READABLE,
38
+ 'permission_callback' => function () {
39
+ global $WP_Statistics;
40
+ return ( $WP_Statistics->get_option( 'use_cache_plugin' ) == 1 ? true : false );
41
+ },
42
+ 'callback' => array( $this, 'hit' ),
43
+ 'args' => array(
44
+ '_wpnonce' => array(
45
+ 'required' => true,
46
+ 'validate_callback' => function ( $value ) {
47
+ return wp_verify_nonce( $value, 'wp_rest' );
48
+ }
49
+ ),
50
+ self::_Argument => array(
51
+ 'required' => true,
52
+ 'validate_callback' => function ( $value, $request, $key ) {
53
+ return ( json_decode( wp_unslash( $value ) ) !== null );
54
+ }
55
+ )
56
+ )
57
  ) );
58
  }
59
 
66
  /*
67
  * Check Is Test Service Request
68
  */
69
+ if ( isset( $_REQUEST['rest-api-wp-statistics'] ) ) {
 
70
  return array( "rest-api-wp-statistics" => "OK" );
71
  }
72
 
73
 
74
  //Check Auth Key Request
75
+ if ( ! isset( $_REQUEST[ self::_Argument ] ) ) {
76
  return new WP_Error( 'error', 'You have no right to access', array( 'status' => 403 ) );
77
  }
78
 
112
  global $WP_Statistics;
113
 
114
  if ( isset( $WP_Statistics ) and $WP_Statistics->use_cache ) {
115
+ if ( isset( $_REQUEST[ self::_Argument ] ) ) {
116
  return true;
117
  }
118
  }
124
  * Get Params Request
125
  */
126
  static public function params( $params ) {
127
+ if ( isset( $_REQUEST[ self::_Argument ] ) ) {
128
+ $data = wp_unslash( $_REQUEST[ self::_Argument ] );
129
 
130
  if ( ! empty( $data ) && is_string( $data ) && is_array( json_decode( $data, true ) ) && json_last_error() == 0 ) {
131
  $data = json_decode( $data, true );
includes/classes/class-wp-statistics.php CHANGED
@@ -209,6 +209,9 @@ class WP_Statistics {
209
  //Set Options
210
  $this->load_options();
211
 
 
 
 
212
  // Check the cache option is enabled.
213
  if ( $this->get_option( 'use_cache_plugin' ) == true ) {
214
  $this->use_cache = 1;
@@ -369,7 +372,7 @@ class WP_Statistics {
369
  public function get_hash_string() {
370
  // Check If Rest Request
371
  if ( $this->restapi->is_rest() ) {
372
- return $this->restapi->params( 'hash_ip' );
373
  }
374
 
375
  // Check the user agent has exist.
@@ -798,9 +801,10 @@ class WP_Statistics {
798
 
799
  //Check If Rest Api Request
800
  if ( $this->restapi->is_rest() ) {
801
- $this->ip = $this->restapi->params( 'ip' );
802
-
803
- return $this->ip;
 
804
  }
805
 
806
  // Check to see if we've already retrieved the IP address and if so return the last result.
@@ -813,7 +817,7 @@ class WP_Statistics {
813
 
814
  // Get User IP
815
  if ( isset( $_SERVER[ $ip_method ] ) ) {
816
- $this->ip = sanitize_text_field( $_SERVER[ $ip_method ] );
817
  }
818
 
819
  /**
209
  //Set Options
210
  $this->load_options();
211
 
212
+ //Set coefficient
213
+ $this->set_coefficient();
214
+
215
  // Check the cache option is enabled.
216
  if ( $this->get_option( 'use_cache_plugin' ) == true ) {
217
  $this->use_cache = 1;
372
  public function get_hash_string() {
373
  // Check If Rest Request
374
  if ( $this->restapi->is_rest() ) {
375
+ return '#hash#' . $this->restapi->params( 'hash_ip' );
376
  }
377
 
378
  // Check the user agent has exist.
801
 
802
  //Check If Rest Api Request
803
  if ( $this->restapi->is_rest() ) {
804
+ $this->ip = sanitize_text_field( $this->restapi->params( 'ip' ) );
805
+ if ( filter_var( $this->ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
806
+ return $this->ip;
807
+ }
808
  }
809
 
810
  // Check to see if we've already retrieved the IP address and if so return the last result.
817
 
818
  // Get User IP
819
  if ( isset( $_SERVER[ $ip_method ] ) ) {
820
+ $this->ip = esc_html( $_SERVER[ $ip_method ] );
821
  }
822
 
823
  /**
includes/log/log.php CHANGED
@@ -118,7 +118,7 @@ foreach ( array( 'exclusions' => 'exclusions', 'users_online' => 'online' ) as $
118
  $overview_ads = get_option( 'wp_statistics_overview_page_ads', false );
119
  if($overview_ads != false and is_array( $overview_ads ) and $overview_ads['ads']['ID'] != $overview_ads['view'] and $overview_ads['ads']['status'] == "yes") {
120
  ?>
121
- jQuery(`<div id="wps_overview_ads_postbox" class="postbox"><div class="inside"><div class="close-overview-ads"><span class="dashicons dashicons-dismiss"></span></div><a href="<?php echo( isset( $overview_ads['ads']['link'] ) ? $overview_ads['ads']['link'] : '' ); ?>" title="<?php echo( isset( $overview_ads['ads']['title'] ) ? $overview_ads['ads']['title'] : '' ); ?>" <?php echo( $overview_ads['ads']['_target'] == "yes" ? ' target="_blank"' : '' ); ?>><img src="<?php echo( isset( $overview_ads['ads']['image'] ) ? $overview_ads['ads']['image'] : '' ); ?>" alt="<?php echo( isset( $overview_ads['ads']['title'] ) ? $overview_ads['ads']['title'] : '' ); ?>"></a></div></div>`).insertAfter("#wps-postbox-container-2 #normal-sortables div.postbox:first");
122
  jQuery(document).on('click', '.close-overview-ads', function () {
123
  jQuery("#wps_overview_ads_postbox").fadeOut("normal");
124
  jQuery.ajax({
118
  $overview_ads = get_option( 'wp_statistics_overview_page_ads', false );
119
  if($overview_ads != false and is_array( $overview_ads ) and $overview_ads['ads']['ID'] != $overview_ads['view'] and $overview_ads['ads']['status'] == "yes") {
120
  ?>
121
+ jQuery(`<div id="wps_overview_ads_postbox" class="postbox"><div class="inside"><div class="close-overview-ads"><span class="dashicons dashicons-dismiss"></span></div><a href="<?php echo( isset( $overview_ads['ads']['link'] ) ? $overview_ads['ads']['link'] : '' ); ?>" title="<?php echo( isset( $overview_ads['ads']['title'] ) ? $overview_ads['ads']['title'] : '' ); ?>" <?php echo( $overview_ads['ads']['_target'] == "yes" ? ' target="_blank"' : '' ); ?>><img style="display: block;" src="<?php echo( isset( $overview_ads['ads']['image'] ) ? $overview_ads['ads']['image'] : '' ); ?>" alt="<?php echo( isset( $overview_ads['ads']['title'] ) ? $overview_ads['ads']['title'] : '' ); ?>"></a></div></div>`).insertAfter("#wps-postbox-container-2 #normal-sortables div.postbox:first");
122
  jQuery(document).on('click', '.close-overview-ads', function () {
123
  jQuery("#wps_overview_ads_postbox").fadeOut("normal");
124
  jQuery.ajax({
includes/log/top-referring.php CHANGED
@@ -54,7 +54,9 @@ if ( $referr ) {
54
  $where = '';
55
  $domain_name = rtrim( preg_replace( '/^https?:\/\//', '', get_site_url() ), " / " );
56
  foreach ( array( "http", "https", "ftp" ) as $protocol ) {
57
- $where = " AND `referred` NOT LIKE '{$protocol}://{$domain_name}%' ";
 
 
58
  }
59
 
60
  //Get List referred
54
  $where = '';
55
  $domain_name = rtrim( preg_replace( '/^https?:\/\//', '', get_site_url() ), " / " );
56
  foreach ( array( "http", "https", "ftp" ) as $protocol ) {
57
+ foreach ( array( '', 'www.' ) as $w3 ) {
58
+ $where = " AND `referred` NOT LIKE '{$protocol}://{$w3}{$domain_name}%' ";
59
+ }
60
  }
61
 
62
  //Get List referred
includes/log/widgets/referring.php CHANGED
@@ -9,7 +9,9 @@ function wp_statistics_generate_referring_postbox_content( $count = 10 ) {
9
  $where = '';
10
  $domain_name = rtrim( preg_replace( '/^https?:\/\//', '', get_site_url() ), " / " );
11
  foreach ( array( "http", "https", "ftp" ) as $protocol ) {
12
- $where = " AND `referred` NOT LIKE '{$protocol}://{$domain_name}%' ";
 
 
13
  }
14
  $result = $wpdb->get_results( "SELECT SUBSTRING_INDEX(REPLACE( REPLACE( referred, 'http://', '') , 'https://' , '') , '/', 1 ) as `domain`, count(referred) as `number` FROM {$wpdb->prefix}statistics_visitor WHERE `referred` REGEXP \"^(https?://|www\\.)[\.A-Za-z0-9\-]+\\.[a-zA-Z]{2,4}\" AND referred <> '' AND LENGTH(referred) >=12 {$where} GROUP BY domain ORDER BY `number` DESC LIMIT $count" );
15
  foreach ( $result as $items ) {
9
  $where = '';
10
  $domain_name = rtrim( preg_replace( '/^https?:\/\//', '', get_site_url() ), " / " );
11
  foreach ( array( "http", "https", "ftp" ) as $protocol ) {
12
+ foreach ( array( '', 'www.' ) as $w3 ) {
13
+ $where = " AND `referred` NOT LIKE '{$protocol}://{$w3}{$domain_name}%' ";
14
+ }
15
  }
16
  $result = $wpdb->get_results( "SELECT SUBSTRING_INDEX(REPLACE( REPLACE( referred, 'http://', '') , 'https://' , '') , '/', 1 ) as `domain`, count(referred) as `number` FROM {$wpdb->prefix}statistics_visitor WHERE `referred` REGEXP \"^(https?://|www\\.)[\.A-Za-z0-9\-]+\\.[a-zA-Z]{2,4}\" AND referred <> '' AND LENGTH(referred) >=12 {$where} GROUP BY domain ORDER BY `number` DESC LIMIT $count" );
17
  foreach ( $result as $items ) {
readme.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  === WP Statistics ===
2
  Contributors: mostafa.s1990, mehrshaddarzi, ghasemi71ir, GregRoss, dedidata
3
  Donate link: https://wp-statistics.com/donate/
@@ -5,7 +6,7 @@ Tags: analytics, wordpress analytics, stats, statistics, visit, visitors, hits,
5
  Requires at least: 3.0
6
  Tested up to: 5.2.1
7
  Requires PHP: 5.6
8
- Stable tag: 12.6.7
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -126,8 +127,14 @@ http://yourwebsite.com/wp-json/wpstatistics/v1
126
  To register, go to the Permalink page and update the permalink with press Save Changes.
127
 
128
  == Changelog ==
 
 
 
 
 
129
  = 12.6.7 =
130
  * Improvement and sanitize visitor's IP address.
 
131
  * Improved: Minor issues.
132
 
133
  = 12.6.6.1 =
1
+
2
  === WP Statistics ===
3
  Contributors: mostafa.s1990, mehrshaddarzi, ghasemi71ir, GregRoss, dedidata
4
  Donate link: https://wp-statistics.com/donate/
6
  Requires at least: 3.0
7
  Tested up to: 5.2.1
8
  Requires PHP: 5.6
9
+ Stable tag: 12.6.8
10
  License: GPLv3
11
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
12
 
127
  To register, go to the Permalink page and update the permalink with press Save Changes.
128
 
129
  == Changelog ==
130
+ = 12.6.8 =
131
+ * Fixed: Coefficient per visitors.
132
+ * Improvement www domain in Top Referring.
133
+ * Improvement REST API.
134
+
135
  = 12.6.7 =
136
  * Improvement and sanitize visitor's IP address.
137
+ * Improvement and sanitize parameters in `WP_Statistics_Rest::hit()`, Thanks Thomas Chauchefoin for the report.
138
  * Improved: Minor issues.
139
 
140
  = 12.6.6.1 =
wp-statistics.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WP Statistics
4
  * Plugin URI: https://wp-statistics.com/
5
  * Description: Complete WordPress Analytics and Statistics for your site!
6
- * Version: 12.6.7
7
  * Author: VeronaLabs
8
  * Author URI: http://veronalabs.com/
9
  * Text Domain: wp-statistics
3
  * Plugin Name: WP Statistics
4
  * Plugin URI: https://wp-statistics.com/
5
  * Description: Complete WordPress Analytics and Statistics for your site!
6
+ * Version: 12.6.8
7
  * Author: VeronaLabs
8
  * Author URI: http://veronalabs.com/
9
  * Text Domain: wp-statistics