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 |