Browse Source

Per board pph

pull/40/head
nonmakina 3 years ago
parent
commit
c438ff9ab0
  1. 43
      templates/themes/categories/news.html
  2. 34
      templates/themes/categories/theme.php

43
templates/themes/categories/news.html

@ -24,17 +24,46 @@
{% endfor %}
{% endif %}
</div>
<div class="ban">
{% if stats %}
<div class="ban post">
<h2 id="post-statistics">
{% trans "Post Statistics" %}
</h2>
<p>
{{ stats.pph }} {% trans "posts in the last hour." %}
{{ stats.unique_ip_count }} {% trans "unique posters in the last hour." %}
</p>
<table class="modlog" style="width: 50%; text-align: left;">
<thead>
<tr>
<th>Board</th>
<th>PPH</th>
<th>Recent IPs</th>
</tr>
</thead>
<tbody>
<tr>
<td class="minimal">
<span>{% trans Total %}</span>
</td>
<td class="minimal">
<span>{{ stats.pph }}</span>
</td>
<td class="minimal">
<span>{{ stats.recent_ips }}</span>
</td>
</tr>
{% for boardStat in stats.boards %}
<tr>
<td class="minimal">
<span>{{ boardStat.title }}</span>
</td>
<td class="minimal">
<span>{{ boardStat.pph }}</span>
</td class="minimal">
<span>{{ boardStat.recent_ips }}</span>
</td>
</tr>
</tbody>
</table>
</div>
{% endif %}
<footer>
<p class="unimportant" style="margin-top:20px;text-align:center;">- Tinyboard +
<a href="https://engine.vichan.net/">vichan</a> {{ config.version }} -

34
templates/themes/categories/theme.php

@ -94,33 +94,49 @@
}
private static function getPostStatistics($settings) {
$boards = query("SELECT uri FROM ``boards``");
$unique = Array();
$pph = 0;
if (!isset($config['boards'])) {
return null;
}
$stats = [];
foreach (array_merge(... $config['boards']) as $_board) {
$title = boardTitle($board);
if (!$title) {
// board doesn't exist.
continue;
}
$boardStat['title'] = $title;
foreach ($boards->fetchAll() as $_board) {
$pph_query = query(
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
$_board['uri'],
time()-3600)
) or error(db_error());
$pph += $pph_query->fetch()['count'];
$boardStat['pph'] = $pph_query->fetch()['count'];
$unique_query = query(
sprintf("SELECT ip FROM ``posts_%s`` WHERE time > %d",
sprintf("SELECT DISTINCT ip FROM ``posts_%s`` WHERE time > %d",
$_board['uri'],
time()-3600)
) or error(db_error());
foreach ($unique_query->fetchAll() as $_k => $row) {
$unique_ips = $unique_query->fetchAll();
$boardStat['recent_ips'] = count($unique_ips);
foreach ( as $_k => $row) {
$unique[$row['ip']] = true;
}
$stats['boards'][] = $boardStat;
}
$unique_ip_count = count($unique);
$stats['recent_ips'] = count($unique);
$stats['pph'] = count(array_column($stats['board'], 'pph'));
return Array('pph' => $pph, 'unique_ip_count' => $unique_ip_count);
return $stats;
}

Loading…
Cancel
Save