Merge pull request #200 from nonmakina/pph-and-uniques
Adds PPH and Unique IP for site and for each board.
This commit is contained in:
commit
048674e136
|
@ -24,12 +24,53 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% if stats %}
|
||||||
|
<div class="ban" style="border: none; background: none;">
|
||||||
|
<h1 id="post-statistics">
|
||||||
|
{% trans "Post Statistics" %}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<table class="modlog" style="width: 50%; text-align: left;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>{% trans "Board" %}</th>
|
||||||
|
<th>{% trans "PPH" %}</th>
|
||||||
|
<th>{% trans "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>
|
||||||
|
<td class="minimal">
|
||||||
|
<span>{{ boardStat.recent_ips }}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
<footer>
|
<footer>
|
||||||
<p class="unimportant" style="margin-top:20px;text-align:center;">- Tinyboard +
|
<p class="unimportant" style="margin-top:20px;text-align:center;">- Tinyboard +
|
||||||
<a href="https://engine.vichan.net/">vichan</a> {{ config.version }} -
|
<a href="https://engine.vichan.net/">vichan</a> {{ config.version }} -
|
||||||
<br>Tinyboard Copyright © 2010-2014 Tinyboard Development Group
|
<br>Tinyboard Copyright © 2010-2014 Tinyboard Development Group
|
||||||
<br><a href="https://engine.vichan.net/">vichan</a> Copyright © 2012-2016 vichan-devel
|
<br><a href="https://engine.vichan.net/">vichan</a> Copyright © 2012-2016 vichan-devel
|
||||||
<br><br>
|
<br><br>
|
||||||
<br><b>Leftypol.org is not currently under investigation by any Federal, State, or Local Authorities.</b></p>
|
<br><b>Leftypol.org is not currently under investigation by any Federal, State, or Local Authorities.</b></p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
|
@ -15,21 +15,28 @@
|
||||||
public static function build($action, $settings) {
|
public static function build($action, $settings) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if ($action == 'all')
|
if ($action == 'all' ||
|
||||||
|
$action == 'boards' ||
|
||||||
|
$action == 'news' ||
|
||||||
|
$action == 'post' ||
|
||||||
|
$action == 'post-thread' ||
|
||||||
|
$action == 'post-delete'){
|
||||||
file_write($config['dir']['home'] . $settings['file_main'], Categories::homepage($settings));
|
file_write($config['dir']['home'] . $settings['file_main'], Categories::homepage($settings));
|
||||||
|
|
||||||
if ($action == 'all' || $action == 'boards')
|
|
||||||
file_write($config['dir']['home'] . $settings['file_sidebar'], Categories::sidebar($settings));
|
|
||||||
|
|
||||||
if ($action == 'all' || $action == 'news')
|
|
||||||
file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings));
|
file_write($config['dir']['home'] . $settings['file_news'], Categories::news($settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action == 'all'){
|
||||||
|
file_write($config['dir']['home'] . $settings['file_sidebar'], Categories::sidebar($settings));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Build homepage
|
// Build homepage
|
||||||
public static function homepage($settings) {
|
public static function homepage($settings) {
|
||||||
global $config;
|
global $config;
|
||||||
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
||||||
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$stats = Categories::getPostStatistics($settings);
|
||||||
return Element(
|
return Element(
|
||||||
'themes/categories/frames.html',
|
'themes/categories/frames.html',
|
||||||
Array(
|
Array(
|
||||||
|
@ -37,6 +44,7 @@
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'categories' => Categories::getCategories($config),
|
'categories' => Categories::getCategories($config),
|
||||||
'news' => $news,
|
'news' => $news,
|
||||||
|
'stats' => $stats,
|
||||||
'boardlist' => createBoardlist(false)
|
'boardlist' => createBoardlist(false)
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -49,11 +57,12 @@
|
||||||
|
|
||||||
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
$query = query("SELECT * FROM ``news`` ORDER BY `time` DESC") or error(db_error());
|
||||||
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
$news = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
$stats = Categories::getPostStatistics($settings);
|
||||||
return Element('themes/categories/news.html', Array(
|
return Element('themes/categories/news.html', Array(
|
||||||
'settings' => $settings,
|
'settings' => $settings,
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
'news' => $news,
|
'news' => $news,
|
||||||
|
'stats' => $stats,
|
||||||
'boardlist' => createBoardlist(false)
|
'boardlist' => createBoardlist(false)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -83,6 +92,57 @@
|
||||||
|
|
||||||
return $categories;
|
return $categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function getPostStatistics($settings) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if (!isset($config['boards'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stats = [];
|
||||||
|
$unique = [];
|
||||||
|
|
||||||
|
foreach (array_merge(... $config['boards']) as $uri) {
|
||||||
|
$_board = getBoardInfo($uri);
|
||||||
|
if (!$_board) {
|
||||||
|
// board doesn't exist.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$boardStat['title'] = $_board['title'];
|
||||||
|
|
||||||
|
$pph_query = query(
|
||||||
|
sprintf("SELECT COUNT(*) AS count FROM ``posts_%s`` WHERE time > %d",
|
||||||
|
$_board['uri'],
|
||||||
|
time()-3600)
|
||||||
|
) or error(db_error());
|
||||||
|
|
||||||
|
$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['pph'] = array_sum(array_column($stats['boards'], 'pph'));
|
||||||
|
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue