Código:
// ── Dashboard: actividad reciente ──
$hoy_inicio = mktime(0, 0, 0, date('n'), date('j'), date('Y'));
$semana_inicio = $hoy_inicio - (6 * 86400);
$u_hoy = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(user_id) FROM u_miembros WHERE user_registro >= '$hoy_inicio'"));
$u_sem = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(user_id) FROM u_miembros WHERE user_registro >= '$semana_inicio'"));
$p_hoy = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(post_id) FROM p_posts WHERE post_date >= '$hoy_inicio' AND post_status = '0'"));
$p_sem = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(post_id) FROM p_posts WHERE post_date >= '$semana_inicio' AND post_status = '0'"));
$c_hoy = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(cid) FROM p_comentarios WHERE c_date >= '$hoy_inicio' AND c_status = '0'"));
$c_sem = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(cid) FROM p_comentarios WHERE c_date >= '$semana_inicio' AND c_status = '0'"));
$grafica = []; $max_posts = 1;
for ($i = 6; $i >= 0; $i--) {
$dia_ini = mktime(0, 0, 0, date('n'), date('j') - $i, date('Y'));
$dia_fin = $dia_ini + 86400;
$total = db_exec('fetch_row', db_exec([__FILE__, __LINE__], 'query', "SELECT COUNT(post_id) FROM p_posts WHERE post_date >= '$dia_ini' AND post_date < '$dia_fin' AND post_status = '0'"));
$grafica[] = ['label' => date('D', $dia_ini)[0], 'total' => (int)$total[0]];
if ((int)$total[0] > $max_posts) $max_posts = (int)$total[0];
}
foreach ($grafica as &$g) { $g['pct'] = round($g['total'] / $max_posts * 100); }
$smarty->assign('tsAdminActivity', [
'usuarios_hoy' => (int)$u_hoy[0],
'usuarios_semana' => (int)$u_sem[0],
'posts_hoy' => (int)$p_hoy[0],
'posts_semana' => (int)$p_sem[0],
'comentarios_hoy' => (int)$c_hoy[0],
'comentarios_semana' => (int)$c_sem[0],
'grafica' => $grafica,
]);
// ────────────────────────────────────