diff --git a/templates/themes/categories/news.html b/templates/themes/categories/news.html
index eea44a15..4aadc633 100644
--- a/templates/themes/categories/news.html
+++ b/templates/themes/categories/news.html
@@ -36,7 +36,9 @@
{% trans "Board" %} |
{% trans "PPH" %} |
- {% trans "Recent IPs" %} |
+ {% trans "IPs last hour" %} |
+ {% trans "IPs last day" %} |
+ {% trans "IPs last week" %} |
@@ -48,7 +50,13 @@
{{ stats.pph }}
- {{ stats.recent_ips }}
+ {{ stats.hourly_ips }}
+ |
+
+ {{ stats.daily_ips }}
+ |
+
+ {{ stats.weekly_ips }}
|
{% for boardStat in stats.boards %}
@@ -60,7 +68,13 @@
{{ boardStat.pph }}
- {{ boardStat.recent_ips }}
+ {{ boardStat.hourly_ips }}
+ |
+
+ {{ boardStat.daily_ips }}
+ |
+
+ {{ boardStat.weekly_ips }}
|
{% endfor %}
diff --git a/templates/themes/categories/theme.php b/templates/themes/categories/theme.php
index e83359b3..a9b90e72 100644
--- a/templates/themes/categories/theme.php
+++ b/templates/themes/categories/theme.php
@@ -100,8 +100,14 @@
return null;
}
+ $HOUR = 3600;
+ $DAY = $HOUR * 24;
+ $WEEK = $DAY * 7;
+
$stats = [];
- $unique = [];
+ $hourly = [];
+ $daily = [];
+ $weekly = [];
foreach (array_merge(... $config['boards']) as $uri) {
$_board = getBoardInfo($uri);
@@ -112,6 +118,10 @@
$boardStat['title'] = $_board['title'];
+ $boardStat['hourly_ips'] = Categories::countUniqueIps($hourly, $HOUR, $_board);
+ $boardStat['daily_ips'] = Categories::countUniqueIps($daily, $DAY, $_board);
+ $boardStat['weekly_ips'] = Categories::countUniqueIps($weekly, $WEEK, $_board);
+
$pph_query = query(
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
$_board['uri'],
@@ -120,29 +130,30 @@
$boardStat['pph'] = $pph_query->fetch()['count'];
- $unique_query = query(
- sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
- $_board['uri'],
- time()-3600)
- ) or error(db_error());
-
- $unique_ips = $unique_query->fetchAll();
- $boardStat['recent_ips'] = count($unique_ips);
-
- foreach ($unique_ips as $_k => $row) {
- $unique[$row['ip']] = true;
- }
-
$stats['boards'][] = $boardStat;
}
- $stats['recent_ips'] = count($unique);
+ $stats['hourly_ips'] = count($hourly);
+ $stats['daily_ips'] = count($daily);
+ $stats['weekly_ips'] = count($weekly);
$stats['pph'] = array_sum(array_column($stats['boards'], 'pph'));
return $stats;
}
+ private static function countUniqueIps($markAsCounted, $timespan, $_board) {
+ $unique_query = query(
+ sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
+ $_board['uri'],
+ time()-$timespan)
+ ) or error(db_error());
+ $uniqueIps = $unique_query->fetchAll();
+ foreach ($uniqueIps as $_k => $row) {
+ $markAsCounted[$row['ip']] = true;
+ }
+ return count($uniqueIps);
+ }
};
?>