feat : "Meilleures audiences" + admin/stats pages via flux RSS XML (v1.6.6)

- post_list.php : section AJAX qui lit /trending?period=1h en XML (DOMParser) — plus de rendu PHP
- admin_stats.php : colonne "Pages les plus visitées" chargée en AJAX depuis /trending?period=14d XML
- index.php/stats : suppression de topGrouped pour /post/ ; seuls /book/ et ASN restent côté serveur

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 20:08:24 +02:00
parent 1d05138329
commit 5cea473d17
5 changed files with 112 additions and 57 deletions
+47 -9
View File
@@ -155,19 +155,57 @@ function _renderCard(array $post, array $privateCats, array $allCats, \Parsedown
</section>
<?php endif; ?>
<?php /* ─── Tendances ───────────────────────────────────────────────────── */ ?>
<?php if (!empty($popularPosts)): ?>
<section class="home-section">
<?php /* ─── Meilleures audiences (AJAX — flux RSS XML /trending?period=1h) ── */ ?>
<section class="home-section" id="home-audiences-section" hidden>
<h2 class="home-section-title">
Meilleures audiences <span class="home-section-title-sub">· 1 heure</span>
</h2>
<div class="post-grid">
<?php foreach ($popularPosts as $_pp): ?>
<?php _renderCard($_pp, $privateCats ?? [], $allCats ?? [], $Parsedown); ?>
<?php endforeach; ?>
</div>
<div class="post-grid" id="home-audiences-grid"></div>
</section>
<?php endif; ?>
<script>
(function(){
var _g=[
'linear-gradient(135deg,#667eea 0%,#764ba2 100%)',
'linear-gradient(135deg,#f093fb 0%,#f5576c 100%)',
'linear-gradient(135deg,#4facfe 0%,#00f2fe 100%)',
'linear-gradient(135deg,#43e97b 0%,#38f9d7 100%)',
'linear-gradient(135deg,#fa709a 0%,#fee140 100%)',
'linear-gradient(135deg,#a18cd1 0%,#fbc2eb 100%)'
];
function _e(s){return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');}
fetch('/trending?period=1h')
.then(function(r){return r.ok?r.text():Promise.reject();})
.then(function(xml){
var doc=new DOMParser().parseFromString(xml,'application/xml');
var items=Array.from(doc.querySelectorAll('item')).slice(0,6);
if(!items.length)return;
var grid=document.getElementById('home-audiences-grid');
if(!grid)return;
grid.innerHTML=items.map(function(item,i){
var raw=(item.querySelector('title')||{textContent:''}).textContent;
var title=raw.replace(/\s*\(\d+\s+visiteurs?\)$/,'');
var link=((item.querySelector('link')||{}).textContent||'#').trim();
var pd=(item.querySelector('pubDate')||{textContent:''}).textContent;
var date='';
try{if(pd)date=new Date(pd).toLocaleDateString('fr-FR');}catch(e){}
var grad=_g[i%_g.length];
return '<article class="card">'
+'<div class="card-cover" style="background:'+grad+'"></div>'
+'<div class="card-body d-flex flex-column">'
+'<h2 class="card-title"><a href="'+_e(link)+'">'+_e(title)+'</a></h2>'
+'<div class="post-entry-meta mt-auto">'
+(date?'<span>'+_e(date)+'</span>':'')
+'<a href="'+_e(link)+'" class="post-entry-read">→ lire</a>'
+'</div></div>'
+'<a href="'+_e(link)+'" class="stretched-link"></a>'
+'</article>';
}).join('');
var s=document.getElementById('home-audiences-section');
if(s)s.hidden=false;
})
.catch(function(){});
})();
</script>
<?php /* ─── Récemment mis à jour ──────────────────────────────────────── */ ?>
<?php if (!empty($recentlyUpdated)): ?>