feat : sparklines 14j stats + filtre IPs LAN (v1.6.27)

- Admin stats : sparklines SVG par page (120×28 px, courbe + dégradé),
  carte « Pages les plus visitées » en pleine largeur
- AccessLogParser : données par jour (pages_by_day) sur 14 jours
- AccessLogParser : IPs privées/LAN exclues de la répartition réseau
- ArticleManager : suppression opérateur nullsafe superflu (PHPStan)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 18:20:19 +02:00
parent c2035314fb
commit ed3f8062da
6 changed files with 154 additions and 75 deletions
+38 -19
View File
@@ -73,7 +73,9 @@ function buildAutoSeoDesc(string $content, string $title = ''): string
{
require_once BASE_PATH . '/src/Parsedown.php';
$_pd = new Parsedown();
$_plain = trim((string)preg_replace('/\s+/', ' ',
$_plain = trim((string)preg_replace(
'/\s+/',
' ',
html_entity_decode(strip_tags($_pd->text($content)), ENT_QUOTES | ENT_HTML5, 'UTF-8')
));
if ($title !== '' && stripos($_plain, $title) === 0) {
@@ -85,7 +87,9 @@ function buildAutoSeoDesc(string $content, string $title = ''): string
function slugToSearchQuery(string $rawPath): string
{
return trim((string)preg_replace('/\s{2,}/', ' ', (string)preg_replace(
'/[^a-zA-ZÀ-ÿ0-9\s]/u', ' ', str_replace(['-', '_', '/'], ' ', $rawPath)
'/[^a-zA-ZÀ-ÿ0-9\s]/u',
' ',
str_replace(['-', '_', '/'], ' ', $rawPath)
)));
}
@@ -2512,7 +2516,7 @@ switch ($action) {
$allArticles = array_values(array_filter($allArticles, fn ($a) => !empty($a['featured'])));
}
$sortBy = in_array($_GET['sort'] ?? '', ['title', 'published', 'updated']) ? $_GET['sort'] : 'updated';
$sortBy = in_array($_GET['sort'] ?? '', ['title', 'published', 'updated'], true) ? $_GET['sort'] : 'updated';
$sortDir = ($_GET['dir'] ?? '') === 'asc' ? 'asc' : 'desc';
usort($allArticles, function ($a, $b) use ($sortBy, $sortDir) {
$cmp = match ($sortBy) {
@@ -2730,21 +2734,24 @@ switch ($action) {
$cutoff14 = strtotime('-14 days midnight') ?: (time() - 14 * 86400);
$tParser = new TrendingParser('/var/log/apache2', apacheAccessLog());
$accessParser = new AccessLogParser('/var/log/apache2', apacheAccessLog());
$topIps = array_slice($accessParser->stats()['ips'], 0, 200, true);
$accessStats = $accessParser->stats();
$topIps = array_slice($accessStats['ips'], 0, 200, true);
$asnMap = (new AsnLookup())->batchLookup(array_keys($topIps));
$statsRaw = [
'readable' => $accessParser->isReadable(),
'books' => $tParser->top($cutoff14, 20, ['/book/']),
'as' => AsnLookup::aggregateByAs($topIps, $asnMap),
'readable' => $accessParser->isReadable(),
'books' => $tParser->top($cutoff14, 20, ['/book/']),
'as' => AsnLookup::aggregateByAs($topIps, $asnMap),
'pages_by_day' => $accessStats['pages_by_day'] ?? [],
];
@file_put_contents($statsCacheFile, json_encode($statsRaw));
}
$adminData['stats_readable'] = $statsRaw['readable'];
$adminData['stats_books'] = $statsRaw['books'];
$adminData['stats_as'] = $statsRaw['as'];
$adminData['stats_as_groups'] = AsnLookup::applyGroups($statsRaw['as'], asGroups());
$adminData['as_groups'] = asGroups();
$adminData['stats_readable'] = $statsRaw['readable'];
$adminData['stats_books'] = $statsRaw['books'];
$adminData['stats_as'] = $statsRaw['as'];
$adminData['stats_as_groups'] = AsnLookup::applyGroups($statsRaw['as'], asGroups());
$adminData['as_groups'] = asGroups();
$adminData['stats_pages_by_day'] = $statsRaw['pages_by_day'] ?? [];
}
if ($tab === 'categories') {
@@ -2764,7 +2771,8 @@ switch ($action) {
try {
$st = $pdo->query('SELECT id, user_email, feed_url, label, created_at FROM rss_feeds ORDER BY created_at DESC');
$adminData['flux_feeds'] = $st->fetchAll(PDO::FETCH_ASSOC);
} catch (\Throwable) {}
} catch (\Throwable) {
}
}
}
@@ -2784,7 +2792,10 @@ switch ($action) {
}
if ($tab === 'ia') {
if (!isAdmin()) { http_response_code(403); exit; }
if (!isAdmin()) {
http_response_code(403);
exit;
}
require_once BASE_PATH . '/src/SiteSettings.php';
require_once BASE_PATH . '/src/Service/AiService.php';
$adminData['ai_provider'] = aiProvider();
@@ -2800,7 +2811,8 @@ switch ($action) {
case 'admin_save_ai_config':
requireAuth();
if (!isAdmin() || $_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(403); exit;
http_response_code(403);
exit;
}
require_once BASE_PATH . '/src/SiteSettings.php';
$allowedProviders = ['anthropic', 'claude_code'];
@@ -3439,7 +3451,8 @@ switch ($action) {
if ($pdo) {
try {
$pdo->prepare('DELETE FROM rss_feeds WHERE id = :id')->execute([':id' => $feedId]);
} catch (\Throwable) {}
} catch (\Throwable) {
}
}
}
header('Location: /admin/flux?deleted=1');
@@ -3541,7 +3554,9 @@ switch ($action) {
$_published[] = $_a;
}
}
if (empty($_published)) continue;
if (empty($_published)) {
continue;
}
$booksData[] = ['book' => $_bk, 'count' => count($_published), 'first' => $_published[0]];
}
unset($_bk, $_published, $_aSlug, $_a);
@@ -3864,9 +3879,13 @@ switch ($action) {
$_published[] = $_a;
}
}
if (empty($_published)) continue;
if (empty($_published)) {
continue;
}
$homeBooks[] = ['book' => $_bk, 'count' => count($_published), 'first' => $_published[0]];
if (count($homeBooks) >= 6) break;
if (count($homeBooks) >= 6) {
break;
}
}
unset($_bk, $_published, $_aSlug, $_a);
}