WP Statistics - Version 12.6.9

Version Description

  • Fixed: Hit counter issue in some servers that blocking some XMLHttpRequest request.
  • Improvement REST API.
Download this release

Release Info

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

Code changes from version 12.6.8 to 12.6.9

composer.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "require": {
3
- "php": ">=5.4",
4
- "geoip2/geoip2": "^2.9.0",
5
- "s1lentium/iptools": "^1.1.0",
6
- "whichbrowser/parser": "2.0.37",
7
- "jaybizzle/crawler-detect": "1.2.78",
8
- "erusev/parsedown": "^1.6"
9
- },
10
- "config": {
11
- "vendor-dir": "includes/vendor"
12
- }
13
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
composer.lock DELETED
@@ -1,481 +0,0 @@
1
- {
2
- "_readme": [
3
- "This file locks the dependencies of your project to a known state",
4
- "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
- "This file is @generated automatically"
6
- ],
7
- "content-hash": "6497ec3331bd44e9dbbb7e43066a0708",
8
- "packages": [
9
- {
10
- "name": "composer/ca-bundle",
11
- "version": "1.1.4",
12
- "source": {
13
- "type": "git",
14
- "url": "https://github.com/composer/ca-bundle.git",
15
- "reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d"
16
- },
17
- "dist": {
18
- "type": "zip",
19
- "url": "https://api.github.com/repos/composer/ca-bundle/zipball/558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
20
- "reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
21
- "shasum": ""
22
- },
23
- "require": {
24
- "ext-openssl": "*",
25
- "ext-pcre": "*",
26
- "php": "^5.3.2 || ^7.0"
27
- },
28
- "require-dev": {
29
- "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5",
30
- "psr/log": "^1.0",
31
- "symfony/process": "^2.5 || ^3.0 || ^4.0"
32
- },
33
- "type": "library",
34
- "extra": {
35
- "branch-alias": {
36
- "dev-master": "1.x-dev"
37
- }
38
- },
39
- "autoload": {
40
- "psr-4": {
41
- "Composer\\CaBundle\\": "src"
42
- }
43
- },
44
- "notification-url": "https://packagist.org/downloads/",
45
- "license": [
46
- "MIT"
47
- ],
48
- "authors": [
49
- {
50
- "name": "Jordi Boggiano",
51
- "email": "j.boggiano@seld.be",
52
- "homepage": "http://seld.be"
53
- }
54
- ],
55
- "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.",
56
- "keywords": [
57
- "cabundle",
58
- "cacert",
59
- "certificate",
60
- "ssl",
61
- "tls"
62
- ],
63
- "time": "2019-01-28T09:30:10+00:00"
64
- },
65
- {
66
- "name": "erusev/parsedown",
67
- "version": "1.7.3",
68
- "source": {
69
- "type": "git",
70
- "url": "https://github.com/erusev/parsedown.git",
71
- "reference": "6d893938171a817f4e9bc9e86f2da1e370b7bcd7"
72
- },
73
- "dist": {
74
- "type": "zip",
75
- "url": "https://api.github.com/repos/erusev/parsedown/zipball/6d893938171a817f4e9bc9e86f2da1e370b7bcd7",
76
- "reference": "6d893938171a817f4e9bc9e86f2da1e370b7bcd7",
77
- "shasum": ""
78
- },
79
- "require": {
80
- "ext-mbstring": "*",
81
- "php": ">=5.3.0"
82
- },
83
- "require-dev": {
84
- "phpunit/phpunit": "^4.8.35"
85
- },
86
- "type": "library",
87
- "autoload": {
88
- "psr-0": {
89
- "Parsedown": ""
90
- }
91
- },
92
- "notification-url": "https://packagist.org/downloads/",
93
- "license": [
94
- "MIT"
95
- ],
96
- "authors": [
97
- {
98
- "name": "Emanuil Rusev",
99
- "email": "hello@erusev.com",
100
- "homepage": "http://erusev.com"
101
- }
102
- ],
103
- "description": "Parser for Markdown.",
104
- "homepage": "http://parsedown.org",
105
- "keywords": [
106
- "markdown",
107
- "parser"
108
- ],
109
- "time": "2019-03-17T18:48:37+00:00"
110
- },
111
- {
112
- "name": "geoip2/geoip2",
113
- "version": "v2.9.0",
114
- "source": {
115
- "type": "git",
116
- "url": "https://github.com/maxmind/GeoIP2-php.git",
117
- "reference": "a807fbf65212eef5d8d2db1a1b31082b53633d77"
118
- },
119
- "dist": {
120
- "type": "zip",
121
- "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/a807fbf65212eef5d8d2db1a1b31082b53633d77",
122
- "reference": "a807fbf65212eef5d8d2db1a1b31082b53633d77",
123
- "shasum": ""
124
- },
125
- "require": {
126
- "maxmind-db/reader": "~1.0",
127
- "maxmind/web-service-common": "~0.5",
128
- "php": ">=5.4"
129
- },
130
- "require-dev": {
131
- "friendsofphp/php-cs-fixer": "2.*",
132
- "phpunit/phpunit": "4.*",
133
- "squizlabs/php_codesniffer": "3.*"
134
- },
135
- "type": "library",
136
- "autoload": {
137
- "psr-4": {
138
- "GeoIp2\\": "src"
139
- }
140
- },
141
- "notification-url": "https://packagist.org/downloads/",
142
- "license": [
143
- "Apache-2.0"
144
- ],
145
- "authors": [
146
- {
147
- "name": "Gregory J. Oschwald",
148
- "email": "goschwald@maxmind.com",
149
- "homepage": "http://www.maxmind.com/"
150
- }
151
- ],
152
- "description": "MaxMind GeoIP2 PHP API",
153
- "homepage": "https://github.com/maxmind/GeoIP2-php",
154
- "keywords": [
155
- "IP",
156
- "geoip",
157
- "geoip2",
158
- "geolocation",
159
- "maxmind"
160
- ],
161
- "time": "2018-04-10T15:32:59+00:00"
162
- },
163
- {
164
- "name": "jaybizzle/crawler-detect",
165
- "version": "v1.2.78",
166
- "source": {
167
- "type": "git",
168
- "url": "https://github.com/JayBizzle/Crawler-Detect.git",
169
- "reference": "0f91f34d375ddd5d7034b9eaf6b74acd0b2a0ed6"
170
- },
171
- "dist": {
172
- "type": "zip",
173
- "url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/0f91f34d375ddd5d7034b9eaf6b74acd0b2a0ed6",
174
- "reference": "0f91f34d375ddd5d7034b9eaf6b74acd0b2a0ed6",
175
- "shasum": ""
176
- },
177
- "require": {
178
- "php": ">=5.3.0"
179
- },
180
- "require-dev": {
181
- "phpunit/phpunit": "^4.8|^5.5|^6.5",
182
- "satooshi/php-coveralls": "1.*"
183
- },
184
- "type": "library",
185
- "autoload": {
186
- "psr-4": {
187
- "Jaybizzle\\CrawlerDetect\\": "src/"
188
- }
189
- },
190
- "notification-url": "https://packagist.org/downloads/",
191
- "license": [
192
- "MIT"
193
- ],
194
- "authors": [
195
- {
196
- "name": "Mark Beech",
197
- "email": "m@rkbee.ch",
198
- "role": "Developer"
199
- }
200
- ],
201
- "description": "CrawlerDetect is a PHP class for detecting bots/crawlers/spiders via the user agent",
202
- "homepage": "https://github.com/JayBizzle/Crawler-Detect/",
203
- "keywords": [
204
- "crawler",
205
- "crawler detect",
206
- "crawler detector",
207
- "crawlerdetect",
208
- "php crawler detect"
209
- ],
210
- "time": "2019-01-15T21:21:27+00:00"
211
- },
212
- {
213
- "name": "maxmind-db/reader",
214
- "version": "v1.4.1",
215
- "source": {
216
- "type": "git",
217
- "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git",
218
- "reference": "eb83d0ee1c1f9b8a340206302136bc81ee02ae74"
219
- },
220
- "dist": {
221
- "type": "zip",
222
- "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/eb83d0ee1c1f9b8a340206302136bc81ee02ae74",
223
- "reference": "eb83d0ee1c1f9b8a340206302136bc81ee02ae74",
224
- "shasum": ""
225
- },
226
- "require": {
227
- "php": ">=5.4"
228
- },
229
- "require-dev": {
230
- "friendsofphp/php-cs-fixer": "2.*",
231
- "phpunit/phpunit": "4.* || 5.*",
232
- "satooshi/php-coveralls": "1.0.*",
233
- "squizlabs/php_codesniffer": "3.*"
234
- },
235
- "suggest": {
236
- "ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
237
- "ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
238
- "ext-maxminddb": "A C-based database decoder that provides significantly faster lookups"
239
- },
240
- "type": "library",
241
- "autoload": {
242
- "psr-4": {
243
- "MaxMind\\Db\\": "src/MaxMind/Db"
244
- }
245
- },
246
- "notification-url": "https://packagist.org/downloads/",
247
- "license": [
248
- "Apache-2.0"
249
- ],
250
- "authors": [
251
- {
252
- "name": "Gregory J. Oschwald",
253
- "email": "goschwald@maxmind.com",
254
- "homepage": "http://www.maxmind.com/"
255
- }
256
- ],
257
- "description": "MaxMind DB Reader API",
258
- "homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php",
259
- "keywords": [
260
- "database",
261
- "geoip",
262
- "geoip2",
263
- "geolocation",
264
- "maxmind"
265
- ],
266
- "time": "2019-01-04T19:55:56+00:00"
267
- },
268
- {
269
- "name": "maxmind/web-service-common",
270
- "version": "v0.5.0",
271
- "source": {
272
- "type": "git",
273
- "url": "https://github.com/maxmind/web-service-common-php.git",
274
- "reference": "61a9836fa3bb1743ab89752bae5005d71e78c73b"
275
- },
276
- "dist": {
277
- "type": "zip",
278
- "url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/61a9836fa3bb1743ab89752bae5005d71e78c73b",
279
- "reference": "61a9836fa3bb1743ab89752bae5005d71e78c73b",
280
- "shasum": ""
281
- },
282
- "require": {
283
- "composer/ca-bundle": "^1.0.3",
284
- "ext-curl": "*",
285
- "ext-json": "*",
286
- "php": ">=5.4"
287
- },
288
- "require-dev": {
289
- "friendsofphp/php-cs-fixer": "2.*",
290
- "phpunit/phpunit": "4.*",
291
- "squizlabs/php_codesniffer": "3.*"
292
- },
293
- "type": "library",
294
- "autoload": {
295
- "psr-4": {
296
- "MaxMind\\Exception\\": "src/Exception",
297
- "MaxMind\\WebService\\": "src/WebService"
298
- }
299
- },
300
- "notification-url": "https://packagist.org/downloads/",
301
- "license": [
302
- "Apache-2.0"
303
- ],
304
- "authors": [
305
- {
306
- "name": "Gregory Oschwald",
307
- "email": "goschwald@maxmind.com"
308
- }
309
- ],
310
- "description": "Internal MaxMind Web Service API",
311
- "homepage": "https://github.com/maxmind/web-service-common-php",
312
- "time": "2018-02-12T22:31:54+00:00"
313
- },
314
- {
315
- "name": "psr/cache",
316
- "version": "1.0.1",
317
- "source": {
318
- "type": "git",
319
- "url": "https://github.com/php-fig/cache.git",
320
- "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
321
- },
322
- "dist": {
323
- "type": "zip",
324
- "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
325
- "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
326
- "shasum": ""
327
- },
328
- "require": {
329
- "php": ">=5.3.0"
330
- },
331
- "type": "library",
332
- "extra": {
333
- "branch-alias": {
334
- "dev-master": "1.0.x-dev"
335
- }
336
- },
337
- "autoload": {
338
- "psr-4": {
339
- "Psr\\Cache\\": "src/"
340
- }
341
- },
342
- "notification-url": "https://packagist.org/downloads/",
343
- "license": [
344
- "MIT"
345
- ],
346
- "authors": [
347
- {
348
- "name": "PHP-FIG",
349
- "homepage": "http://www.php-fig.org/"
350
- }
351
- ],
352
- "description": "Common interface for caching libraries",
353
- "keywords": [
354
- "cache",
355
- "psr",
356
- "psr-6"
357
- ],
358
- "time": "2016-08-06T20:24:11+00:00"
359
- },
360
- {
361
- "name": "s1lentium/iptools",
362
- "version": "v1.1.1",
363
- "source": {
364
- "type": "git",
365
- "url": "https://github.com/S1lentium/IPTools.git",
366
- "reference": "f6f8ab6132ca7443bd7cced1681f5066d725fd5f"
367
- },
368
- "dist": {
369
- "type": "zip",
370
- "url": "https://api.github.com/repos/S1lentium/IPTools/zipball/f6f8ab6132ca7443bd7cced1681f5066d725fd5f",
371
- "reference": "f6f8ab6132ca7443bd7cced1681f5066d725fd5f",
372
- "shasum": ""
373
- },
374
- "require": {
375
- "ext-bcmath": "*",
376
- "php": ">=5.4.0"
377
- },
378
- "require-dev": {
379
- "phpunit/phpunit": "~4.0",
380
- "satooshi/php-coveralls": "~1.0"
381
- },
382
- "type": "library",
383
- "autoload": {
384
- "psr-4": {
385
- "IPTools\\": "src/"
386
- }
387
- },
388
- "notification-url": "https://packagist.org/downloads/",
389
- "license": [
390
- "MIT"
391
- ],
392
- "authors": [
393
- {
394
- "name": "Safarov Alisher",
395
- "email": "alisher.safarov@outlook.com",
396
- "homepage": "https://github.com/S1lentium"
397
- }
398
- ],
399
- "description": "PHP Library for manipulating network addresses (IPv4 and IPv6)",
400
- "keywords": [
401
- "IP",
402
- "IP-Tools",
403
- "cidr",
404
- "ipv4",
405
- "ipv6",
406
- "network",
407
- "subnet"
408
- ],
409
- "time": "2018-09-19T06:15:53+00:00"
410
- },
411
- {
412
- "name": "whichbrowser/parser",
413
- "version": "v2.0.37",
414
- "source": {
415
- "type": "git",
416
- "url": "https://github.com/WhichBrowser/Parser-PHP.git",
417
- "reference": "9c6ad8eadc23294b1c66d92876c11f13c5d4cf48"
418
- },
419
- "dist": {
420
- "type": "zip",
421
- "url": "https://api.github.com/repos/WhichBrowser/Parser-PHP/zipball/9c6ad8eadc23294b1c66d92876c11f13c5d4cf48",
422
- "reference": "9c6ad8eadc23294b1c66d92876c11f13c5d4cf48",
423
- "shasum": ""
424
- },
425
- "require": {
426
- "php": ">=5.4.0",
427
- "psr/cache": "^1.0"
428
- },
429
- "require-dev": {
430
- "icomefromthenet/reverse-regex": "0.0.6.3",
431
- "phpunit/php-code-coverage": "^2.2|^3.0",
432
- "phpunit/phpunit": "^4.0|^5.0",
433
- "satooshi/php-coveralls": "^1.0",
434
- "squizlabs/php_codesniffer": "2.5.*",
435
- "symfony/yaml": ">=2.8"
436
- },
437
- "suggest": {
438
- "cache/array-adapter": "Allows testing of the caching functionality"
439
- },
440
- "type": "library",
441
- "autoload": {
442
- "psr-4": {
443
- "WhichBrowser\\": [
444
- "src/",
445
- "tests/src/"
446
- ]
447
- }
448
- },
449
- "notification-url": "https://packagist.org/downloads/",
450
- "license": [
451
- "MIT"
452
- ],
453
- "authors": [
454
- {
455
- "name": "Niels Leenheer",
456
- "email": "niels@leenheer.nl",
457
- "role": "Developer"
458
- }
459
- ],
460
- "description": "Useragent sniffing library for PHP",
461
- "homepage": "http://whichbrowser.net",
462
- "keywords": [
463
- "browser",
464
- "sniffing",
465
- "ua",
466
- "useragent"
467
- ],
468
- "time": "2018-10-02T09:26:41+00:00"
469
- }
470
- ],
471
- "packages-dev": [],
472
- "aliases": [],
473
- "minimum-stability": "stable",
474
- "stability-flags": [],
475
- "prefer-stable": false,
476
- "prefer-lowest": false,
477
- "platform": {
478
- "php": ">=5.4"
479
- },
480
- "platform-dev": []
481
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/classes/class-wp-statistics-frontend.php CHANGED
@@ -70,8 +70,19 @@ class WP_Statistics_Frontend {
70
  global $WP_Statistics;
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
 
@@ -86,9 +97,6 @@ class WP_Statistics_Frontend {
86
  */
87
  $params = array();
88
 
89
- //Set Url
90
- $params['base'] = rtrim( get_rest_url(), "/" );
91
-
92
  //Set Browser
93
  $result = $WP_Statistics->get_UserAgent();
94
  $params['browser'] = $result['browser'];
@@ -98,15 +106,9 @@ class WP_Statistics_Frontend {
98
  //set referred
99
  $params['referred'] = $WP_Statistics->get_Referred();
100
 
101
- //set prefix Rest
102
- $params['api'] = rtrim( rest_get_url_prefix(), "/" );
103
-
104
  //Set ip
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();
112
  $params['exclude'] = $check_exclude->exclusion_match;
@@ -146,15 +148,7 @@ class WP_Statistics_Frontend {
146
  $params['user_id'] = get_current_user_id();
147
  }
148
 
149
- //Fixed entity decode Html
150
- foreach ( (array) $params as $key => $value ) {
151
- if ( ! is_scalar( $value ) ) {
152
- continue;
153
- }
154
- $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
155
- }
156
-
157
- return json_encode( $params, JSON_UNESCAPED_SLASHES );
158
  }
159
 
160
  /**
70
  global $WP_Statistics;
71
 
72
  if ( $WP_Statistics->use_cache ) {
73
+
74
+ // Wp-Statistics HTML comment
75
  $this->html_comment();
76
+
77
+ // Prepare Params
78
+ $params = array_merge( array(
79
+ '_' => time(),
80
+ '_wpnonce' => wp_create_nonce( 'wp_rest' ),
81
+ WP_Statistics_Rest::_Argument => 'yes',
82
+ ), self::set_default_params() );
83
+
84
+ // Return to Page
85
+ echo '<script>var WP_Statistics_http = new XMLHttpRequest();WP_Statistics_http.open(\'GET\', \'' . add_query_arg( $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";
86
  }
87
  }
88
 
97
  */
98
  $params = array();
99
 
 
 
 
100
  //Set Browser
101
  $result = $WP_Statistics->get_UserAgent();
102
  $params['browser'] = $result['browser'];
106
  //set referred
107
  $params['referred'] = $WP_Statistics->get_Referred();
108
 
 
 
 
109
  //Set ip
110
  $params['ip'] = esc_html( $WP_Statistics->get_IP() );
111
 
 
 
 
112
  //exclude
113
  $check_exclude = new WP_Statistics_Hits();
114
  $params['exclude'] = $check_exclude->exclusion_match;
148
  $params['user_id'] = get_current_user_id();
149
  }
150
 
151
+ return $params;
 
 
 
 
 
 
 
 
152
  }
153
 
154
  /**
includes/classes/class-wp-statistics-rest.php CHANGED
@@ -11,8 +11,8 @@ class WP_Statistics_Rest {
11
  // Set Default Statistic Save method
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.
@@ -28,10 +28,35 @@ class WP_Statistics_Rest {
28
  }
29
  }
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  /*
32
  * Add Endpoint Route
33
  */
34
  public function register_routes() {
 
 
 
 
 
 
 
35
  // Get Hit
36
  register_rest_route( self::route, '/' . self::func, array(
37
  'methods' => \WP_REST_Server::READABLE,
@@ -40,20 +65,13 @@ class WP_Statistics_Rest {
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
 
@@ -70,14 +88,7 @@ class WP_Statistics_Rest {
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
-
79
- // If something has gone horribly wrong and $WP_Statistics isn't an object, bail out.
80
- // This seems to happen sometimes with WP Cron calls.
81
  if ( ! is_object( $WP_Statistics ) ) {
82
  return;
83
  }
@@ -103,6 +114,9 @@ class WP_Statistics_Rest {
103
  if ( $WP_Statistics->get_option( 'pages' ) ) {
104
  $h->Pages();
105
  }
 
 
 
106
  }
107
 
108
  /*
@@ -111,7 +125,7 @@ class WP_Statistics_Rest {
111
  static public function is_rest() {
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
  }
@@ -124,11 +138,12 @@ class WP_Statistics_Rest {
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 );
 
132
  }
133
 
134
  if ( isset( $data[ $params ] ) ) {
11
  // Set Default Statistic Save method
12
  const func = 'hit';
13
 
14
+ // Set Default Name
15
+ const _Argument = 'wp_statistics_hit_rest';
16
 
17
  /**
18
  * Setup an Wordpress REst Api action.
28
  }
29
  }
30
 
31
+ /**
32
+ * List Of Required Params
33
+ *
34
+ * @return array
35
+ */
36
+ public static function require_params_hit() {
37
+ return array(
38
+ 'browser',
39
+ 'platform',
40
+ 'version',
41
+ 'ip',
42
+ 'track_all',
43
+ 'timestamp',
44
+ 'page_uri',
45
+ 'user_id',
46
+ );
47
+ }
48
+
49
  /*
50
  * Add Endpoint Route
51
  */
52
  public function register_routes() {
53
+
54
+ // Create Require Params
55
+ $params = array();
56
+ foreach ( self::require_params_hit() as $p ) {
57
+ $params[ $p ] = array( 'required' => true );
58
+ }
59
+
60
  // Get Hit
61
  register_rest_route( self::route, '/' . self::func, array(
62
  'methods' => \WP_REST_Server::READABLE,
65
  return ( $WP_Statistics->get_option( 'use_cache_plugin' ) == 1 ? true : false );
66
  },
67
  'callback' => array( $this, 'hit' ),
68
+ 'args' => array_merge(
69
+ array( '_wpnonce' => array(
70
  'required' => true,
71
  'validate_callback' => function ( $value ) {
72
  return wp_verify_nonce( $value, 'wp_rest' );
73
  }
74
+ ) ), $params )
 
 
 
 
 
 
 
75
  ) );
76
  }
77
 
88
  return array( "rest-api-wp-statistics" => "OK" );
89
  }
90
 
91
+ // Check Isset global
 
 
 
 
 
 
 
92
  if ( ! is_object( $WP_Statistics ) ) {
93
  return;
94
  }
114
  if ( $WP_Statistics->get_option( 'pages' ) ) {
115
  $h->Pages();
116
  }
117
+
118
+ // Set Return
119
+ return new \WP_REST_Response( array( 'status' => true, 'message' => __( 'Visitor Hit was recorded successfully.', 'wp-statistics' ) ) );
120
  }
121
 
122
  /*
125
  static public function is_rest() {
126
  global $WP_Statistics;
127
 
128
+ if ( isset( $WP_Statistics ) and defined( 'REST_REQUEST' ) && REST_REQUEST and $WP_Statistics->use_cache ) {
129
  if ( isset( $_REQUEST[ self::_Argument ] ) ) {
130
  return true;
131
  }
138
  * Get Params Request
139
  */
140
  static public function params( $params ) {
141
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST and isset( $_REQUEST[ self::_Argument ] ) ) {
142
+ $data = array();
143
+ foreach ( $_REQUEST as $key => $value ) {
144
+ if ( ! in_array( $key, array( '_', '_wpnonce' ) ) ) {
145
+ $data[ $key ] = trim( $value );
146
+ }
147
  }
148
 
149
  if ( isset( $data[ $params ] ) ) {
includes/classes/class-wp-statistics.php CHANGED
@@ -370,13 +370,11 @@ class WP_Statistics {
370
  * Generate hash string
371
  */
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.
379
- if ( array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
 
 
380
  $key = $_SERVER['HTTP_USER_AGENT'];
381
  } else {
382
  $key = 'Unknown';
370
  * Generate hash string
371
  */
372
  public function get_hash_string() {
 
 
 
 
373
 
374
  // Check the user agent has exist.
375
+ if ( $this->restapi->is_rest() and trim( $this->restapi->params( 'ua' ) ) != "" ) {
376
+ $key = $this->restapi->params( 'ua' );
377
+ } else if ( array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
378
  $key = $_SERVER['HTTP_USER_AGENT'];
379
  } else {
380
  $key = 'Unknown';
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: analytics, wordpress analytics, stats, statistics, visit, visitors, hits,
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,6 +127,10 @@ http://yourwebsite.com/wp-json/wpstatistics/v1
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.
6
  Requires at least: 3.0
7
  Tested up to: 5.2.1
8
  Requires PHP: 5.6
9
+ Stable tag: 12.6.9
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.9 =
131
+ * Fixed: Hit counter issue in some servers that blocking some `XMLHttpRequest` request.
132
+ * Improvement REST API.
133
+
134
  = 12.6.8 =
135
  * Fixed: Coefficient per visitors.
136
  * Improvement www domain in Top Referring.
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.8
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.9
7
  * Author: VeronaLabs
8
  * Author URI: http://veronalabs.com/
9
  * Text Domain: wp-statistics