| 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 |
use ABJ_404_Solution_AjaxSecurityTrait; |
| 14 |
|
| 15 |
/** @return void */ |
| 16 |
public static function echoTrendData(): void { |
| 17 |
self::requireAdminWithNonce('abj404_trendData'); |
| 18 |
|
| 19 |
// Rate limiting: 60 requests per minute. |
| 20 |
if (ABJ_404_Solution_Ajax_Php::checkRateLimit('trend_data', 60, 60)) { |
| 21 |
wp_send_json_error(array('message' => __('Rate limit exceeded. Please try again later.', '404-solution')), 429); |
| 22 |
return; // @phpstan-ignore deadCode.unreachable |
| 23 |
} |
| 24 |
|
| 25 |
$daysRaw = isset($_GET['days']) ? intval($_GET['days']) : 30; |
| 26 |
// Clamp to 1–90. |
| 27 |
$days = max(1, min(90, $daysRaw)); |
| 28 |
|
| 29 |
$abj404dao = abj_service('data_access'); |
| 30 |
$data = $abj404dao->getDailyActivityTrend($days); |
| 31 |
|
| 32 |
wp_send_json_success($data, 200); |
| 33 |
} |
| 34 |
|
| 35 |
} |
| 36 |
|