forked from tildeverse/tilde.chat
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
$title="stats page";
|
|
$desc="stats about tilde.chat and its channels";
|
|
$stats = json_decode(file_get_contents("../stats.json"));
|
|
include __DIR__."/../header.php";
|
|
?>
|
|
|
|
<h1>stats</h1>
|
|
<hr>
|
|
<p>there are <?=$stats->usercount?> users across <?=$stats->channelcount?> channels.</p>
|
|
<p>if the channel is set with <a href="https://wiki.inspircd.org/Channel_Modes">chanmode +s</a> it will be omitted from this list.</p>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-bordered table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Users</th>
|
|
<th>Topic</th>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody data-link="row" class="rowlink">
|
|
<?php foreach($stats->channels as $channel): ?>
|
|
<tr>
|
|
<td><a href="<?=$channel->webchatlink?>"><?=$channel->name?></a></td>
|
|
<td><?=$channel->usercount?></td>
|
|
<td style="word-wrap: break-word; white-space: pre-wrap; max-width:700px"><?=$channel->topic?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<hr>
|
|
<p>also available as <a href="/stats.json">json</a>.</p>
|
|
|
|
<script>
|
|
// sort stats page
|
|
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
|
|
|
|
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
|
|
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
|
|
)(getCellValue(asc ? b : a, idx), getCellValue(asc ? a : b, idx));
|
|
|
|
// do the work...
|
|
document.querySelectorAll('th').forEach(function(th) {
|
|
th.addEventListener('click', (() => {
|
|
const table = th.closest('table').querySelector("tbody");
|
|
Array.from(table.querySelectorAll('tr'))
|
|
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
|
|
.forEach(tr => table.appendChild(tr) );
|
|
}));
|
|
th.style.cursor = 'pointer';
|
|
});
|
|
</script>
|
|
|
|
<?php include __DIR__."/../footer.php"; ?>
|
|
|