From: Wim Livens Date: Sun, 2 Oct 2022 22:40:02 +0000 (+0200) Subject: keep and show basic download stats X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/commitdiff_plain/d476bcd5e359b590b36e7372833e0e6ebd419587?hp=a4111660b05af9df96bbe567aa43acff34b6339d keep and show basic download stats --- diff --git a/f.php b/f.php index 5555523..0368d97 100644 --- a/f.php +++ b/f.php @@ -285,6 +285,9 @@ else { if ($link['onetime'] == 'O') { jirafeau_delete_link($link_name); } + +jirafeau_write_download_stats($link_name, get_ip_address($cfg)); + exit; ?> diff --git a/lib/functions.php b/lib/functions.php index f2a26e0..cf89593 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -161,6 +161,9 @@ function jirafeau_clean_rm_link($link) if (file_exists(VAR_LINKS . $p . $link)) { unlink(VAR_LINKS . $p . $link); } + if (file_exists(VAR_LINKS . $p . $link . '_download')) { + unlink(VAR_LINKS . $p . $link . '_download'); + } $parse = VAR_LINKS . $p; $scan = array(); while (file_exists($parse) @@ -706,6 +709,7 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) if (!count($l)) { continue; } + $ld = jirafeau_get_download_stats($node); /* Filter. */ if (!empty($name) && !@preg_match("/$name/i", jirafeau_escape($l['file_name']))) { @@ -730,6 +734,11 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) if (strlen($l['ip']) > 0) { echo t('ORIGIN') . ': ' . $l['ip'] . '
'; } + echo t('DOWNLOAD_COUNT') . ': ' . $ld['count'] . '
'; + if ($ld['count'] > 0) { + echo t('DOWNLOAD_DATE') . ': ' . jirafeau_get_datetimefield($ld['date']) . '
'; + echo t('DOWNLOAD_IP') . ': ' . $ld['ip'] . '
'; + } echo ''; echo '
' . '' . @@ -1603,3 +1612,32 @@ function jirafeau_default_web_root() { return $_SERVER['HTTP_HOST'] . str_replace('install.php', '', $_SERVER['REQUEST_URI']); } + +function jirafeau_get_download_stats($hash) +{ + $filename = VAR_LINKS . s2p("$hash") . $hash . '_download'; + + if (!file_exists($filename)) { + return array('count'=>0); + } + + $c = file($filename); + $data['count'] = trim($c[0]); + $data['date'] = trim($c[1]); + $data['ip'] = trim($c[2]); + + return $data; +} + +function jirafeau_write_download_stats($hash, $ip) +{ + $data = jirafeau_get_download_stats($hash); + $count = $data['count']; + $count++; + + $filename = VAR_LINKS . s2p("$hash") . $hash . '_download'; + + $handle = fopen($filename, 'w'); + fwrite($handle, $count . NL . time() . NL . $ip); + fclose($handle); +} diff --git a/lib/locales/en.json b/lib/locales/en.json index b3de22c..44a192b 100644 --- a/lib/locales/en.json +++ b/lib/locales/en.json @@ -109,6 +109,9 @@ "ONETIME": "One-time", "UPLOAD_DATE": "Upload date", "ORIGIN": "Origin", + "DOWNLOAD_COUNT": "Downloads", + "DOWNLOAD_DATE": "Last download", + "DOWNLOAD_IP": "Downloaded from", "ACTION": "Action", "DEL_LINK": "Del link", "DEL_FILE_LINKS": "Del file and links",