From 30b012dcc983beffa67526341d291cfcad2b1d9f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 29 Sep 2025 17:09:39 +0500 Subject: feat: statistics --- .gitignore | 2 + lib/partials.php | 9 +- public/static/img/icons/stats.png | Bin 0 -> 541 bytes public/stats.php | 219 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 1 deletion(-) create mode 100755 public/static/img/icons/stats.png create mode 100644 public/stats.php diff --git a/.gitignore b/.gitignore index a54a906..fed4050 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,9 @@ config.php *.ini *.db userdata/ + ruffle/ +chart.js TOS.txt PRIVACY.txt diff --git a/lib/partials.php b/lib/partials.php index 288f660..5e187a5 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -159,7 +159,14 @@ function html_footer()

-

Serving files and of active content

+

+ Serving files and of active content + + + [Stats] + + +

query("SELECT YEAR(uploaded_at) AS year, QUARTER(uploaded_at) AS quarter, COUNT(*) AS file_count + FROM files + WHERE uploaded_at >= DATE_SUB(CURDATE(), INTERVAL 5 YEAR) + GROUP BY YEAR(uploaded_at), QUARTER(uploaded_at) + ORDER BY year, quarter +"); +$uploaded_files = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// recent images & videos +if (STATS_LAST_FILES) { + $stmt = $db->query("SELECT id, extension FROM files WHERE mime LIKE 'image/%' ORDER BY uploaded_at DESC LIMIT 5"); + $recent_images = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $stmt = $db->query("SELECT id, extension FROM files WHERE mime LIKE 'video/%' ORDER BY uploaded_at DESC LIMIT 5"); + $recent_videos = $stmt->fetchAll(PDO::FETCH_ASSOC); +} + +// the most viewed files +if (STATS_MOST_VIEWED) { + $stmt = $db->query("SELECT id, extension, mime FROM files ORDER BY views DESC LIMIT 5"); + $most_viewed_files = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($most_viewed_files as &$f) { + if (str_starts_with($f['mime'], 'video/')) { + $f['color'] = 'blue'; + } else if ($f['mime'] == 'application/x-shockwave-flash') { + $f['color'] = 'red'; + } + } + unset($f); +} + +// --- file stats +function format_filesize($file_size) +{ + $suffix = 'MB'; + $file_size /= 1024 * 1024; // MB + + if ($file_size >= 1024) { + $file_size /= 1024; + $suffix = 'GB'; + } + + return sprintf('%.2f%s', $file_size, $suffix); +} +$stmt = $db->query("SELECT COUNT(*) AS file_count, SUM(size) AS active_content, AVG(size) AS approx_filesize, + COUNT(*) / TIMESTAMPDIFF(MINUTE, MIN(uploaded_at), MAX(uploaded_at)) AS avg_upload_rate + FROM files + WHERE id NOT IN (SELECT id FROM file_bans) +"); +$file_stats = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]; + +if (STATS_DISKSIZE > 0) { + $file_stats['future_file_count'] = floor(STATS_DISKSIZE / $file_stats['approx_filesize']); + if ($file_stats['avg_upload_rate'] > 0.01) { + $file_stats['estimated_time'] = floor((STATS_DISKSIZE - $file_stats['active_content']) / $file_stats['avg_upload_rate']); + $dt = new DateTime(); + $dt->modify("+{$file_stats['estimated_time']} minutes"); + $file_stats['estimated_time'] = $dt->format("F j, Y"); + } +} + +$file_stats['active_content'] = format_filesize($file_stats['active_content']); +$file_stats['approx_filesize'] = format_filesize($file_stats['approx_filesize']); + +?> + + + + + Statistics - <?= INSTANCE_NAME ?> + + + + + + + + +
+ + +

Statistics

+

Files uploaded (per quarter)

+ + +

Recent images

+
+ +
+ + No thumbnail. + +
+ +
+ + +

Recent videos

+
+ +
+ + No thumbnail. + +
+ +
+ + +

The most viewed files

+ + +

About files

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Serving files
Active content
Average filesize
Average upload rate (per minute)
How many files can be uploaded~
Estimated date of hard disk space running out
+
+
+ + + + + + + + \ No newline at end of file -- cgit v1.2.3