|
|
|
<?php
|
|
|
|
require_once "$PROJECT_ROOT/php/utils/server-utils.php";
|
|
|
|
|
|
|
|
// Once handlers are attached in JS, this check ceases to be useful.
|
|
|
|
function column_sortable($id) {
|
|
|
|
// Join URL contents are not guaranteed to have visible text.
|
|
|
|
return $id != "qr" && $id != "preview" && $id != "join_url";
|
|
|
|
}
|
|
|
|
|
|
|
|
function sort_onclick($colno) {
|
|
|
|
global $TABLE_COLUMNS;
|
|
|
|
$column = $TABLE_COLUMNS[$colno];
|
|
|
|
if (!column_sortable($column['id'])) return "";
|
|
|
|
$name = $column['name'];
|
|
|
|
return " title='Click to sort by $name'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$TABLE_COLUMNS = [
|
|
|
|
['id' => "identifier", 'name' => "Identifier"],
|
|
|
|
['id' => "language", 'name' => "L"],
|
|
|
|
['id' => "name", 'name' => "Name"],
|
|
|
|
['id' => "description", 'name' => "Description"],
|
|
|
|
['id' => "users", 'name' => "Users"],
|
|
|
|
['id' => "preview", 'name' => "Preview"],
|
|
|
|
['id' => "qr_code", 'name' => "QR"],
|
|
|
|
['id' => "server_icon", 'name' => "Host"],
|
|
|
|
['id' => "join_url", 'name' => "URL"],
|
|
|
|
];
|
|
|
|
?>
|
|
|
|
|
|
|
|
<table id="tbl_communities">
|
|
|
|
<tr>
|
|
|
|
<?php foreach ($TABLE_COLUMNS as $colno => $column): ?>
|
|
|
|
<th<?=sort_onclick($colno)?> id="th_<?=$column['id']?>">
|
|
|
|
<?=$column['name']?>
|
|
|
|
|
|
|
|
</th>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</tr>
|
|
|
|
<?php foreach ($rooms as $id => $room): ?>
|
|
|
|
<?php
|
|
|
|
// Get the server public key.
|
|
|
|
|
|
|
|
// FIXME:
|
|
|
|
// ! This is bad practice.
|
|
|
|
// However, the fetching code hides component data
|
|
|
|
// and this is a low risk use case.
|
|
|
|
|
|
|
|
$pubkey = explode("=", $room->join_link)[1];
|
|
|
|
$icon_hue = hexdec($pubkey[2] . $pubkey[2]);
|
|
|
|
$icon_color = "hsl($icon_hue, 95%, 50%)";
|
|
|
|
|
|
|
|
$hostname = explode("//", $room->join_link)[1];
|
|
|
|
$hostname = explode("/", $hostname)[0];
|
|
|
|
|
|
|
|
// Escape external input.
|
|
|
|
// Ternaries prevent passing null-equal strings, which produce warnings.
|
|
|
|
$id = htmlspecialchars($id);
|
|
|
|
$language = $room->language ? htmlspecialchars($room->language) : "";
|
|
|
|
$name = htmlspecialchars($room->name);
|
|
|
|
$desc = $room->description ? htmlspecialchars($room->description) : "";
|
|
|
|
$users = htmlspecialchars($room->active_users);
|
|
|
|
$preview_link = htmlspecialchars($room->preview_link);
|
|
|
|
$join_link = htmlspecialchars($room->join_link);
|
|
|
|
// TODO: Do not forget to rename this escape when merging!
|
|
|
|
$token = htmlspecialchars($token);
|
|
|
|
$hostname = htmlspecialchars($hostname);
|
|
|
|
?>
|
|
|
|
|
|
|
|
<tr id="<?=$id?>" itemscope itemtype="https://schema.org/EntryPoint"
|
|
|
|
data-identifier="<?=$id?>"
|
|
|
|
data-pubkey="<?=$pubkey?>"
|
|
|
|
data-hostname="<?=$hostname?>"
|
|
|
|
>
|
|
|
|
<td class="td_identifier" itemprop="identifier"><?=$id?></td>
|
|
|
|
<td class="td_language"><?=$language?></td>
|
|
|
|
<td class="td_name" title="'<?=$room->name?>' preview" itemprop="name">
|
|
|
|
<a href="<?=$room->preview_link?>" target="_blank" rel="noopener noreferrer">
|
|
|
|
<?=$room->name?>
|
|
|
|
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
<td class="td_description" itemprop="description"><?=$desc?></td>
|
|
|
|
<td class="td_users"><?=$users?></td>
|
|
|
|
<td class="td_preview" itemprop="url">
|
|
|
|
<a href="<?=$preview_link?>" target="_blank" rel="noopener noreferrer nofollow">
|
|
|
|
<span class="protocol-indicator"></span>
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
<td class="td_qr_code">
|
|
|
|
<img
|
|
|
|
class="qr-code-icon"
|
|
|
|
src="qrcode-solid.svg"
|
|
|
|
alt="Pictogram of a QR code"
|
|
|
|
>
|
|
|
|
</td>
|
|
|
|
<td class="td_server_icon"
|
|
|
|
data-sort-by="<?=$pubkey?>"
|
|
|
|
title="<?=$hostname?> (<?=$token?>)"
|
|
|
|
item="image"
|
|
|
|
>
|
|
|
|
<div class="td_server_icon-circle" style="background-color: <?=$icon_color?>">
|
|
|
|
<span><?=strtoupper($pubkey[0] . $pubkey[1])?></span>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td class="td_join_url">
|
|
|
|
<div class="join_url_container" data-url="<?=$join_link?>">
|
|
|
|
<a class="join_url show-from-w5" title="<?=$join_link?>"
|
|
|
|
><?=truncate($join_link, 32)?></a>
|
|
|
|
<a class="noscript" href="<?=$join_link?>" rel="external nofollow"
|
|
|
|
>Copy link</a>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</table>
|