@@ -164,7 +164,14 @@ function toprows($db, $col, $where, $limit = 8) {
164164$ top_refs = toprows ($ db , 'ref ' , "$ botw AND day>=' $ d30' AND ref<>'' " );
165165$ browsers = toprows ($ db , 'browser ' , "$ botw AND day>=' $ d30' " , 6 );
166166$ oses = toprows ($ db , 'os ' , "$ botw AND day>=' $ d30' " , 6 );
167- $ recent = $ db ->query ("SELECT ts,path,ref,browser,os,bot FROM hits ORDER BY id DESC LIMIT 15 " )->fetchAll (PDO ::FETCH_ASSOC );
167+ $ countries = $ db ->query ("SELECT country, MAX(cname) cname, COUNT(*) c FROM hits
168+ WHERE 1=1 $ botw AND day>=' $ d30' AND country<>''
169+ GROUP BY country ORDER BY c DESC LIMIT 15 " )->fetchAll (PDO ::FETCH_ASSOC );
170+ $ top_links = $ db ->query ("SELECT ref_full k, COUNT(*) c FROM hits
171+ WHERE 1=1 $ botw AND day>=' $ d30' AND ref_full<>''
172+ GROUP BY ref_full ORDER BY c DESC LIMIT 12 " )->fetchAll (PDO ::FETCH_ASSOC );
173+ $ recent = $ db ->query ("SELECT ts,path,ref,ref_full,browser,os,bot,country,cname
174+ FROM hits ORDER BY id DESC LIMIT 20 " )->fetchAll (PDO ::FETCH_ASSOC );
168175
169176page_head ('SkillFishOS · Statistiche ' );
170177echo '<div class="wrap"> ' ;
@@ -209,21 +216,52 @@ function tbl($title, $rows, $klabel, $linkpath = false) {
209216 }
210217 echo '</table></div> ' ;
211218}
219+ // countries
220+ echo '<div class="panel"><h3>Paesi di origine (30g)</h3><table><tr><th>Paese</th><th class="r">Visite</th></tr> ' ;
221+ if (!$ countries ) echo '<tr><td class="muted" colspan="2">Nessun dato ancora.</td></tr> ' ;
222+ $ cmax = 1 ; foreach ($ countries as $ r ) $ cmax = max ($ cmax , (int )$ r ['c ' ]);
223+ foreach ($ countries as $ r ) {
224+ $ label = sfstats_flag ($ r ['country ' ]) . ' ' . h ($ r ['cname ' ] ?: $ r ['country ' ]);
225+ $ pct = round (100 * $ r ['c ' ] / $ cmax );
226+ echo '<tr><td> ' . $ label . '<div class="bar" style="width: ' . $ pct . '%;margin-top:4px"></div></td><td class="r"> ' . (int )$ r ['c ' ] . '</td></tr> ' ;
227+ }
228+ echo '</table></div> ' ;
229+
212230echo '<div class="grid2"><div> ' ;
213231tbl ('Pagine più viste (30g) ' , $ top_pages , 'Pagina ' , true );
214- tbl ('Provenienza (referrer , 30g) ' , $ top_refs , 'Sito ' );
232+ tbl ('Provenienza (domini , 30g) ' , $ top_refs , 'Sito ' );
215233echo '</div><div> ' ;
216234tbl ('Browser (30g) ' , $ browsers , 'Browser ' );
217235tbl ('Sistema operativo (30g) ' , $ oses , 'OS ' );
218236echo '</div></div> ' ;
219237
238+ // full referrer links
239+ echo '<div class="panel"><h3>Link di provenienza completi (30g)</h3><table><tr><th>URL referrer</th><th class="r">Visite</th></tr> ' ;
240+ if (!$ top_links ) echo '<tr><td class="muted" colspan="2">Nessun link esterno registrato.</td></tr> ' ;
241+ $ lmax = 1 ; foreach ($ top_links as $ r ) $ lmax = max ($ lmax , (int )$ r ['c ' ]);
242+ foreach ($ top_links as $ r ) {
243+ $ u = $ r ['k ' ];
244+ $ pct = round (100 * $ r ['c ' ] / $ lmax );
245+ echo '<tr><td><a href=" ' . h ($ u ) . '" target="_blank" rel="noreferrer noopener nofollow"> ' . h ($ u ) . '</a> '
246+ . '<div class="bar" style="width: ' . $ pct . '%;margin-top:4px"></div></td><td class="r"> ' . (int )$ r ['c ' ] . '</td></tr> ' ;
247+ }
248+ echo '</table></div> ' ;
249+
220250// recent
221- echo '<div class="panel"><h3>Ultime visite</h3><table><tr><th>Quando (UTC)</th><th>Pagina</th><th>Da</th><th>Client</th></tr> ' ;
222- if (!$ recent ) echo '<tr><td class="muted" colspan="4 ">Nessuna visita registrata.</td></tr> ' ;
251+ echo '<div class="panel"><h3>Ultime visite</h3><table><tr><th>Quando (UTC)</th><th>Paese</th><th> Pagina</th><th>Da</th><th>Client</th></tr> ' ;
252+ if (!$ recent ) echo '<tr><td class="muted" colspan="5 ">Nessuna visita registrata.</td></tr> ' ;
223253foreach ($ recent as $ r ) {
254+ $ cc = $ r ['country ' ] ?? '' ;
255+ $ country = $ cc ? sfstats_flag ($ cc ) . ' ' . h ($ cc ) : '<span class="muted">—</span> ' ;
256+ if (!empty ($ r ['ref_full ' ])) {
257+ $ da = '<a href=" ' . h ($ r ['ref_full ' ]) . '" target="_blank" rel="noreferrer noopener nofollow"> ' . h ($ r ['ref ' ] ?: $ r ['ref_full ' ]) . '</a> ' ;
258+ } else {
259+ $ da = '<span class="muted"> ' . h ($ r ['ref ' ] ?: '— ' ) . '</span> ' ;
260+ }
224261 echo '<tr><td class="muted"> ' . h (gmdate ('d/m H:i ' , (int )$ r ['ts ' ])) . ($ r ['bot ' ] ? ' 🤖 ' : '' ) . '</td> '
262+ . '<td> ' . $ country . '</td> '
225263 . '<td> ' . h ($ r ['path ' ]) . '</td> '
226- . '<td class="muted" > ' . h ( $ r [ ' ref ' ] ?: ' — ' ) . '</td> '
264+ . '<td> ' . $ da . '</td> '
227265 . '<td class="muted"> ' . h ($ r ['browser ' ] . ' / ' . $ r ['os ' ]) . '</td></tr> ' ;
228266}
229267echo '</table></div> ' ;
0 commit comments