PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / ajax / Ajax_TrendData.php

Ajax_TrendData.php in 404 Solution 4.3.0, at includes/ajax/Ajax_TrendData.php

40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * AJAX handler for the Trend Analytics endpoint.
9 *
10 * Returns daily 404/redirect activity for Chart.js charts on the Stats page.
11 */
12 class ABJ_404_Solution_Ajax_TrendData {
13
14 /** @return void */
15 public static function echoTrendData(): void {
16 if (!ABJ_404_Solution_AjaxRequestContractValidator::requireValidCurrentRequest('ajax-trend-data')) {
17 return;
18 }
19
20 abj_service('ajax_security_gate')->requireAdminWithNonce('abj404_trendData');
21
22 // Rate limiting: 60 requests per minute.
23 if (ABJ_404_Solution_Ajax_Php::consumeRateLimit('trend_data', 60, 60)) {
24 wp_send_json_error(array('message' => __('Rate limit exceeded. Please try again later.', '404-solution')), 429);
25 return; // @phpstan-ignore deadCode.unreachable
26 }
27
28 $daysRaw = isset($_GET['days']) ? intval($_GET['days']) : 30;
29 // Clamp to 1-90.
30 $days = max(1, min(90, $daysRaw));
31
32 /** @var ABJ_404_Solution_LogsRepositoryInterface $logsRepository */
33 $logsRepository = abj_service('logs_repository');
34 $data = $logsRepository->getDailyActivityTrend($days);
35
36 wp_send_json_success($data, 200);
37 }
38
39 }
40