PluginProbe ʕ •ᴥ•ʔ
Advanced Google reCAPTCHA / 5.40
Advanced Google reCAPTCHA v5.40
5.40 5.39 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35
advanced-google-recaptcha / libs / stats.php
advanced-google-recaptcha / libs Last commit date
admin.php 4 months ago ajax.php 4 months ago functions.php 1 month ago setup.php 3 months ago stats.php 4 months ago utility.php 4 months ago
stats.php
66 lines
1 <?php
2 /**
3 * WP Captcha
4 * https://getwpcaptcha.com/
5 * (c) WebFactory Ltd, 2022 - 2026, www.webfactoryltd.com
6 */
7
8 class WPCaptcha_Stats extends WPCaptcha
9 {
10 static public $stats_cutoff = 1;
11
12 /**
13 * Get statistics
14 *
15 * @since 5.0
16 *
17 * @param string $type locks|fails
18 * @param int $ndays period for statistics
19 * @return bool
20 */
21 static function get_stats($type = "locks", $ndays = 60)
22 {
23 global $wpdb;
24
25 $days = array();
26 for ($i = $ndays; $i >= 0; $i--){
27 $days[gmdate("Y-m-d", strtotime('-' . $i . ' days'))] = 0;
28 }
29
30 // phpcs:ignore db call warnings as we are using a custom table
31
32 if ($type == 'locks') {
33 $results = $wpdb->get_results("SELECT COUNT(*) as count,DATE_FORMAT(accesslock_date, '%Y-%m-%d') AS date FROM " . $wpdb->wpcatcha_accesslocks . " GROUP BY DATE_FORMAT(accesslock_date, '%Y%m%d')"); // phpcs:ignore
34 } else {
35 $results = $wpdb->get_results("SELECT COUNT(*) as count,DATE_FORMAT(login_attempt_date, '%Y-%m-%d') AS date FROM " . $wpdb->wpcatcha_login_fails . " GROUP BY DATE_FORMAT(login_attempt_date, '%Y%m%d')"); // phpcs:ignore
36 }
37
38 $total = 0;
39
40 foreach ($results as $day) {
41 if(array_key_exists($day->date, $days)){
42 $days[$day->date] = $day->count;
43 $total += $day->count;
44 }
45 }
46
47 if ($total < self::$stats_cutoff) {
48 $stats['days'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
49 $stats['count'] = array(3, 4, 67, 76, 45, 32, 134, 6, 65, 65, 56, 123, 156, 156, 123, 156, 67, 88, 54, 178);
50 $stats['total'] = $total;
51
52 return $stats;
53 }
54
55 $stats = array('days' => array(), 'count' => array(), 'total' => 0);
56 foreach ($days as $day => $count) {
57 $stats['days'][] = $day;
58 $stats['count'][] = $count;
59 $stats['total'] += $count;
60 }
61 $stats['period'] = $ndays;
62 return $stats;
63 } // get_stats
64
65 } // class
66