WP Statistics - Version 5.4

Version Description

  • Fixed: GeoIP dependency code to ignore safe mode check in PHP 5.4 or newer.
  • Fixed: GeoIP dependency code to properly detect safe mode with PHP 5.3 or older.
  • Fixed: Browser information not recorded if GeoIP was not enabled.
  • Updated: get_IP code to better handle malformed IP addresses.
  • Updated: Persian (fa_IR) language.
  • Updated: Arabic (ar) language.
  • Updated: Chinese (zh_CN) language.
Download this release

Release Info

Developer GregRoss
Plugin Icon 128x128 WP Statistics
Version 5.4
Comparing to
See all releases

Code changes from version 5.3 to 5.4

includes/classes/hits.class.php CHANGED
@@ -2,10 +2,11 @@
2
  class Hits extends WP_Statistics {
3
 
4
  public $result = null;
 
 
5
  private $exclusion_match = FALSE;
6
  private $exclusion_reason = '';
7
  private $exclusion_record = FALSE;
8
- private $ip;
9
 
10
  public function __construct() {
11
 
@@ -168,15 +169,17 @@
168
  }
169
 
170
  public function Visitors() {
171
-
172
  // If we're a webcrawler or referral from ourselves or an excluded address don't record the visit.
173
  if( !$this->exclusion_match ) {
174
 
175
  $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip}'");
176
-
177
  if( !$this->result ) {
178
 
179
  if( get_option('wps_store_ua') == true ) { $ua = $_SERVER['HTTP_USER_AGENT']; } else { $ua = ''; }
 
 
180
 
181
  $this->db->insert(
182
  $this->tb_prefix . "statistics_visitor",
@@ -187,7 +190,7 @@
187
  'platform' => $agent['platform'],
188
  'version' => $agent['version'],
189
  'ip' => $this->ip,
190
- 'location' => '000',
191
  'UAString' => $ua
192
  )
193
  );
2
  class Hits extends WP_Statistics {
3
 
4
  public $result = null;
5
+ protected $ip;
6
+ protected $location = "000";
7
  private $exclusion_match = FALSE;
8
  private $exclusion_reason = '';
9
  private $exclusion_record = FALSE;
 
10
 
11
  public function __construct() {
12
 
169
  }
170
 
171
  public function Visitors() {
172
+
173
  // If we're a webcrawler or referral from ourselves or an excluded address don't record the visit.
174
  if( !$this->exclusion_match ) {
175
 
176
  $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip}'");
177
+
178
  if( !$this->result ) {
179
 
180
  if( get_option('wps_store_ua') == true ) { $ua = $_SERVER['HTTP_USER_AGENT']; } else { $ua = ''; }
181
+
182
+ $agent = $this->get_UserAgent();
183
 
184
  $this->db->insert(
185
  $this->tb_prefix . "statistics_visitor",
190
  'platform' => $agent['platform'],
191
  'version' => $agent['version'],
192
  'ip' => $this->ip,
193
+ 'location' => $this->location,
194
  'UAString' => $ua
195
  )
196
  );
includes/classes/hits.geoip.class.php CHANGED
@@ -3,228 +3,24 @@
3
 
4
  use GeoIp2\Database\Reader;
5
 
6
- class Hits extends WP_Statistics {
7
-
8
- public $result = null;
9
- private $exclusion_match = FALSE;
10
- private $exclusion_reason = '';
11
- private $exclusion_record = FALSE;
12
- private $ip;
13
-
14
  public function __construct() {
15
 
16
- global $wp_version;
17
-
18
  parent::__construct();
19
-
20
- $this->ip = $this->get_IP();
21
-
22
- if( get_option( 'wps_record_exclusions' ) == 1 ) {
23
- $this->exclusion_record = TRUE;
24
- }
25
-
26
- // The follow exclusion checks are done during the class construction so we don't have to execute them twice if we're tracking visits and visitors.
27
- //
28
- // Order of exclusion checks is:
29
- // 1 - robots
30
- // 2 - IP/Subnets
31
- // 3 - Self Referrals & login page
32
- // 4 - User roles
33
- //
34
-
35
- // Pull the robots from the database.
36
- $robots = explode( "\n", get_option('wps_robotlist') );
37
 
38
- // Check to see if we match any of the robots.
39
- foreach($robots as $robot) {
40
- $robot = trim($robot);
41
-
42
- // If the match case is less than 4 characters long, it might match too much so don't execute it.
43
- if(strlen($robot) > 3) {
44
- if(stripos($_SERVER['HTTP_USER_AGENT'], $robot) !== FALSE) {
45
- $this->exclusion_match = TRUE;
46
- $this->exclusion_reason = "robot";
47
- break;
48
- }
49
- }
50
- }
51
-
52
- if( !$this->exclusion_match ) {
53
- // Pull the subnets from the database.
54
- $subnets = explode( "\n", get_option('wps_exclude_ip') );
55
-
56
- // Check to see if we match any of the excluded addresses.
57
- foreach($subnets as $subnet ) {
58
- $subnet = trim($subnet);
59
-
60
- // The shortest ip address is 1.1.1.1, anything less must be a malformed entry.
61
- if(strlen($subnet) > 6) {
62
- if( $this->net_match( $subnet, $this->ip ) ) {
63
- $this->exclusion_match = TRUE;
64
- $this->exclusion_reason = "ip match";
65
- break;
66
- }
67
- }
68
  }
69
-
70
- // Check to see if we are being referred to ourselves.
71
- if( !$this->exclusion_match ) {
72
- if( $_SERVER['HTTP_USER_AGENT'] == "WordPress/" . $wp_version . "; " . get_home_url("/") ) { $this->exclusion_match = TRUE; $this->exclusion_reason = "self referral"; }
73
- if( $_SERVER['HTTP_USER_AGENT'] == "WordPress/" . $wp_version . "; " . get_home_url() ) { $this->exclusion_match = TRUE; $this->exclusion_reason = "self referral"; }
74
-
75
- if( get_option('wps_exclude_loginpage') == 1 ) {
76
- $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
77
- $host = $_SERVER['HTTP_HOST'];
78
- $script = $_SERVER['SCRIPT_NAME'];
79
-
80
- $currentURL = $protocol . '://' . $host . $script;
81
- $loginURL = wp_login_url();
82
-
83
- if( $currentURL == $loginURL ) { $this->exclusion_match = TRUE; $this->exclusion_reason = "login page";}
84
- }
85
-
86
- if( get_option('wps_exclude_adminpage') == 1 ) {
87
- $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
88
- $host = $_SERVER['HTTP_HOST'];
89
- $script = $_SERVER['SCRIPT_NAME'];
90
-
91
- $currentURL = $protocol . '://' . $host . $script;
92
- $adminURL = get_admin_url();
93
-
94
- $currentURL = substr( $currentURL, 0, strlen( $adminURL ) );
95
-
96
- if( $currentURL == $adminURL ) { $this->exclusion_match = TRUE; $this->exclusion_reason = "admin page";}
97
- }
98
-
99
- // Finally check to see if we are excluding based on the user role.
100
- if( !$this->exclusion_match ) {
101
-
102
- if( is_user_logged_in() ) {
103
- $current_user = wp_get_current_user();
104
-
105
- foreach( $current_user->roles as $role ) {
106
- $option_name = 'wps_exclude_' . str_replace(" ", "_", strtolower($role) );
107
- if( get_option($option_name) == TRUE ) {
108
- $this->exclusion_match = TRUE;
109
- $this->exclusion_reason = "user role";
110
- break;
111
- }
112
- }
113
- }
114
- }
115
  }
116
- }
117
- }
118
-
119
- // From: http://www.php.net/manual/en/function.ip2long.php
120
- //
121
-
122
- private function net_match($network, $ip) {
123
- // determines if a network in the form of 192.168.17.1/16 or
124
- // 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip
125
- $ip_arr = explode('/', $network);
126
-
127
- if( !isset( $ip_arr[1] ) ) { $ip_arr[1] = 0; }
128
-
129
- $network_long = ip2long($ip_arr[0]);
130
-
131
- $x = ip2long($ip_arr[1]);
132
- $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]);
133
- $ip_long = ip2long($ip);
134
-
135
- return ($ip_long & $mask) == ($network_long & $mask);
136
- }
137
-
138
- public function Visits() {
139
 
140
- // If we're a webcrawler or referral from ourselves or an excluded address don't record the visit.
141
- if( !$this->exclusion_match ) {
142
-
143
- $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visit ORDER BY `{$this->tb_prefix}statistics_visit`.`ID` DESC");
144
-
145
- if( substr($this->result->last_visit, 0, -1) != substr($this->Current_Date('Y-m-d H:i:s'), 0, -1) ) {
146
-
147
- if( $this->result->last_counter != $this->Current_Date('Y-m-d') ) {
148
-
149
- $this->db->insert(
150
- $this->tb_prefix . "statistics_visit",
151
- array(
152
- 'last_visit' => $this->Current_Date(),
153
- 'last_counter' => $this->Current_date('Y-m-d'),
154
- 'visit' => $this->coefficient
155
- )
156
- );
157
- } else {
158
-
159
- $this->db->update(
160
- $this->tb_prefix . "statistics_visit",
161
- array(
162
- 'last_visit' => $this->Current_Date(),
163
- 'visit' => $this->result->visit + $this->coefficient
164
- ),
165
- array(
166
- 'last_counter' => $this->result->last_counter
167
- )
168
- );
169
- }
170
- }
171
- }
172
- }
173
-
174
- public function Visitors() {
175
-
176
- // If we're a webcrawler or referral from ourselves or an excluded address don't record the visit.
177
- if( !$this->exclusion_match ) {
178
-
179
- $this->result = $this->db->get_row("SELECT * FROM {$this->tb_prefix}statistics_visitor WHERE `last_counter` = '{$this->Current_Date('Y-m-d')}' AND `ip` = '{$this->ip}'");
180
-
181
- if( !$this->result ) {
182
-
183
- if( get_option('wps_store_ua') == true ) { $ua = $_SERVER['HTTP_USER_AGENT']; } else { $ua = ''; }
184
-
185
- try
186
- {
187
- $upload_dir = wp_upload_dir();
188
- $reader = new Reader( $upload_dir['basedir'] . '/wp-statistics/GeoLite2-Country.mmdb' );
189
- $record = $reader->country( $this->ip );
190
- $location = $record->country->isoCode;
191
- }
192
- catch( Exception $e )
193
- {
194
- $location = "000";
195
- }
196
-
197
- $agent = $this->get_UserAgent();
198
-
199
- $this->db->insert(
200
- $this->tb_prefix . "statistics_visitor",
201
- array(
202
- 'last_counter' => $this->Current_date('Y-m-d'),
203
- 'referred' => $this->get_Referred(),
204
- 'agent' => $agent['browser'],
205
- 'platform' => $agent['platform'],
206
- 'version' => $agent['version'],
207
- 'ip' => $this->ip,
208
- 'location' => $location,
209
- 'UAString' => $ua
210
- )
211
- );
212
- }
213
- } else {
214
- if( $this->exclusion_record == TRUE ) {
215
- $this->result = $this->db->query("UPDATE {$this->tb_prefix}statistics_exclusions SET `count` = `count` + 1 WHERE `date` = '{$this->Current_Date('Y-m-d')}' AND `reason` = '{$this->exclusion_reason}'");
216
-
217
- if( !$this->result ) {
218
- $this->db->insert(
219
- $this->tb_prefix . "statistics_exclusions",
220
- array(
221
- 'date' => $this->Current_date('Y-m-d'),
222
- 'reason' => $this->exclusion_reason,
223
- 'count' => 1
224
- )
225
- );
226
- }
227
- }
228
- }
229
  }
230
  }
3
 
4
  use GeoIp2\Database\Reader;
5
 
6
+ class GeoIPHits extends Hits {
 
 
 
 
 
 
 
7
  public function __construct() {
8
 
 
 
9
  parent::__construct();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ try
12
+ {
13
+ $upload_dir = wp_upload_dir();
14
+ $reader = new Reader( $upload_dir['basedir'] . '/wp-statistics/GeoLite2-Country.mmdb' );
15
+ $record = $reader->country( $this->ip );
16
+ $location = $record->country->isoCode;
17
+ if( $location == "" ) { $location = "000"; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
+ catch( Exception $e )
20
+ {
21
+ $location = "000";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ $this->location = $location;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
26
  }
includes/classes/statistics.class.php CHANGED
@@ -82,7 +82,7 @@
82
  $temp_ip = $_SERVER['REMOTE_ADDR'];
83
 
84
  // Check to see if any of the HTTP headers are set to identify the remote user.
85
- // These often given better results as they can identify the remote user even through firewalls etc,
86
  // but are sometimes used in SQL injection attacks.
87
  if (getenv('HTTP_CLIENT_IP')) {
88
  $temp_ip = getenv('HTTP_CLIENT_IP');
82
  $temp_ip = $_SERVER['REMOTE_ADDR'];
83
 
84
  // Check to see if any of the HTTP headers are set to identify the remote user.
85
+ // These often give better results as they can identify the remote user even through firewalls etc,
86
  // but are sometimes used in SQL injection attacks.
87
  if (getenv('HTTP_CLIENT_IP')) {
88
  $temp_ip = getenv('HTTP_CLIENT_IP');
includes/functions/geoip-populate.php CHANGED
@@ -23,6 +23,7 @@
23
  try {
24
  $record = $reader->country( $item->ip );
25
  $location = $record->country->isoCode;
 
26
  } catch( Exception $e ) {
27
  $location = "000";
28
  }
23
  try {
24
  $record = $reader->country( $item->ip );
25
  $location = $record->country->isoCode;
26
+ if( $location == "" ) { $location = "000"; }
27
  } catch( Exception $e ) {
28
  $location = "000";
29
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mostafa.s1990
3
  Donate link: http://mostafa-soufi.ir/donate/
4
  Tags: statistics, stats, visit, visitors, chart, browser, blog, today, yesterday, week, month, yearl, total, post, page, sidebar, summary, feedburner, hits, pagerank, google, alexa, live visit
5
  Requires at least: 3.0
6
- Tested up to: 3.9
7
- Stable tag: 5.3
8
  License: GPL2
9
 
10
  Complete statistics for your blog.
@@ -219,9 +219,10 @@ No.
219
  * As the webcrawler code is now working, you'll probably see a significant change in the "Unknown" browser category and the number of hits your site gets.
220
 
221
  == Changelog ==
222
- = 5.? =
223
  * Fixed: GeoIP dependency code to ignore safe mode check in PHP 5.4 or newer.
224
  * Fixed: GeoIP dependency code to properly detect safe mode with PHP 5.3 or older.
 
225
  * Updated: get_IP code to better handle malformed IP addresses.
226
  * Updated: Persian (fa_IR) language.
227
  * Updated: Arabic (ar) language.
3
  Donate link: http://mostafa-soufi.ir/donate/
4
  Tags: statistics, stats, visit, visitors, chart, browser, blog, today, yesterday, week, month, yearl, total, post, page, sidebar, summary, feedburner, hits, pagerank, google, alexa, live visit
5
  Requires at least: 3.0
6
+ Tested up to: 3.9.1
7
+ Stable tag: 5.4
8
  License: GPL2
9
 
10
  Complete statistics for your blog.
219
  * As the webcrawler code is now working, you'll probably see a significant change in the "Unknown" browser category and the number of hits your site gets.
220
 
221
  == Changelog ==
222
+ = 5.4 =
223
  * Fixed: GeoIP dependency code to ignore safe mode check in PHP 5.4 or newer.
224
  * Fixed: GeoIP dependency code to properly detect safe mode with PHP 5.3 or older.
225
+ * Fixed: Browser information not recorded if GeoIP was not enabled.
226
  * Updated: get_IP code to better handle malformed IP addresses.
227
  * Updated: Persian (fa_IR) language.
228
  * Updated: Arabic (ar) language.
wp-statistics.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Wordpress Statistics
4
  Plugin URI: http://mostafa-soufi.ir/blog/wordpress-statistics
5
  Description: Complete statistics for your blog.
6
- Version: 5.3
7
  Author: Mostafa Soufi
8
  Author URI: http://mostafa-soufi.ir/
9
  Text Domain: wp_statistics
@@ -15,7 +15,7 @@ License: GPL2
15
  date_default_timezone_set( get_option('timezone_string') );
16
  }
17
 
18
- define('WP_STATISTICS_VERSION', '5.3');
19
  define('WP_STATISTICS_REQUIRED_GEOIP_PHP_VERSION', '5.3.0');
20
  define('WPS_EXPORT_FILE_NAME', 'wp-statistics');
21
 
@@ -47,10 +47,10 @@ License: GPL2
47
  include_once dirname( __FILE__ ) . '/includes/classes/statistics.class.php';
48
  include_once dirname( __FILE__ ) . '/includes/classes/useronline.class.php';
49
 
 
 
50
  if( get_option('wps_geoip') && wp_statistics_geoip_supported() ) {
51
  include_once dirname( __FILE__ ) . '/includes/classes/hits.geoip.class.php';
52
- } else {
53
- include_once dirname( __FILE__ ) . '/includes/classes/hits.class.php';
54
  }
55
 
56
  include_once dirname( __FILE__ ) . '/widget.php';
@@ -80,7 +80,12 @@ License: GPL2
80
 
81
  function wp_statistics_shutdown_action() {
82
  $o = new Useronline();
83
- $h = new Hits();
 
 
 
 
 
84
 
85
  if( get_option('wps_useronline') )
86
  $o->Check_online();
@@ -372,7 +377,7 @@ License: GPL2
372
  // Download
373
  $TempFile = download_url( $download_url );
374
  if (is_wp_error( $TempFile ) ) {
375
- $result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error downloading GeoIP database from: %s', 'wp_statistics'), $download_url) . "</strong></p></div>";
376
  }
377
  else {
378
  // Ungzip File
3
  Plugin Name: Wordpress Statistics
4
  Plugin URI: http://mostafa-soufi.ir/blog/wordpress-statistics
5
  Description: Complete statistics for your blog.
6
+ Version: 5.4
7
  Author: Mostafa Soufi
8
  Author URI: http://mostafa-soufi.ir/
9
  Text Domain: wp_statistics
15
  date_default_timezone_set( get_option('timezone_string') );
16
  }
17
 
18
+ define('WP_STATISTICS_VERSION', '5.4');
19
  define('WP_STATISTICS_REQUIRED_GEOIP_PHP_VERSION', '5.3.0');
20
  define('WPS_EXPORT_FILE_NAME', 'wp-statistics');
21
 
47
  include_once dirname( __FILE__ ) . '/includes/classes/statistics.class.php';
48
  include_once dirname( __FILE__ ) . '/includes/classes/useronline.class.php';
49
 
50
+ include_once dirname( __FILE__ ) . '/includes/classes/hits.class.php';
51
+
52
  if( get_option('wps_geoip') && wp_statistics_geoip_supported() ) {
53
  include_once dirname( __FILE__ ) . '/includes/classes/hits.geoip.class.php';
 
 
54
  }
55
 
56
  include_once dirname( __FILE__ ) . '/widget.php';
80
 
81
  function wp_statistics_shutdown_action() {
82
  $o = new Useronline();
83
+
84
+ if( class_exists( 'GeoIPHits' ) ) {
85
+ $h = new GeoIPHits();
86
+ } else {
87
+ $h = new Hits();
88
+ }
89
 
90
  if( get_option('wps_useronline') )
91
  $o->Check_online();
377
  // Download
378
  $TempFile = download_url( $download_url );
379
  if (is_wp_error( $TempFile ) ) {
380
+ $result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error downloading GeoIP database from %s: %s', 'wp_statistics'), $download_url, $TempFile->get_error_message() ) . "</strong></p></div>";
381
  }
382
  else {
383
  // Ungzip File