You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sessioncommunities.online/sites/+components/tbl-communities.php

174 lines
5.3 KiB
PHP

<?php
require_once 'php/utils/utils.php';
require_once 'php/servers/servers-rooms.php';
require_once 'php/assets/room-invites.php';
require_once 'php/assets/room-icons.php';
require_once 'php/assets/server-icons.php';
/**
* @var CommunityRoom[] $rooms
*/
// 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_code" && $id != "preview" && $id != "join_url";
}
function sort_onclick($colno) {
global $TABLE_COLUMNS;
$column = $TABLE_COLUMNS[$colno];
$name = isset($column['name_long']) ? $column['name_long'] : $column['name'];
if (!column_sortable($column['id'])) return " title='$name'";
return " title='Click to sort by $name.'";
}
// Note: Changing the names displayed requires updating
// the --expanded-static-column-width and --collapsed-static-column-width CSS variables.
$TABLE_COLUMNS = [
['id' => "language", 'name' => "L", 'name_long' => "Language"],
['id' => "name", 'name' => "Name"],
['id' => "description", 'name' => "About", 'name_long' => "Description"],
['id' => "users", 'name' => "#", 'name_long' => "Active Users"],
['id' => "preview", 'name' => "Preview"],
['id' => "qr_code", 'name' => "QR", 'name_long' => "QR Code (for use in-app)"],
['id' => "server_icon", 'name' => "Host", 'name_long' => "Server host"],
['id' => "join_url", 'name' => "URL", 'name_long' => "Join URL (for use in-app)"],
];
?>
<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
$pubkey = $room->server->get_pubkey();
$icon_hue = hexdec($pubkey[2] . $pubkey[2]);
$icon_color = "hsl($icon_hue, 80%, 50%)";
$server_icon = server_icon($room->server, '64x64');
$hostname = $room->server->get_base_url();
$id = html_sanitize($room->get_room_identifier());
$language = html_sanitize($room->language_flag);
$name = html_sanitize($room->name);
$desc = html_sanitize($room->description);
$users = html_sanitize($room->active_users);
$users_cutoff = html_sanitize($room->format_user_cutoff_period());
$preview_link = html_sanitize($room->get_preview_url());
$join_link = html_sanitize($room->get_join_url());
$pubkey = html_sanitize($pubkey);
$hostname = html_sanitize($hostname);
$staff_json = json_encode(array_map('html_sanitize', $room->get_staff()));
$tags_json = json_encode($room->get_room_tags());
?>
<tr class="room-row" itemscope itemtype="https://schema.org/EntryPoint"
data-identifier="<?=$id?>"
data-pubkey="<?=$pubkey?>"
data-hostname="<?=$hostname?>"
data-staff='<?=$staff_json?>'
data-tags='<?=$tags_json?>'
data-icon='<?=room_icon($room, '64x64')?>'
data-icon-safe='<?=room_icon_safety($room)?>'
data-created='<?=html_sanitize($room->created)?>'
>
<td class="td_language" title="Language flag for '<?=$name?>'"><?=$language?></td>
<td class="td_name"
data-sort-by="<?=strtolower($name)?>"
>
<a
href="<?=$preview_link?>"
class="td_name-inner"
target="_blank"
title="Click here to preview '<?=$name?>'"
rel="noopener noreferrer"
itemprop="name"
><?=
$name
?></a>
<span class="room-labels-container">
<?php foreach ($room->get_room_tags() as $tag): if (CommunityTag::is_showcased_tag($tag->text)): ?>
<span
class="room-label <?=$tag->get_tag_classname()?> badge"
title="<?=$tag->description?>"
><?=
truncate($tag->get_text(), 16)
?></span>
<?php endif; endforeach; ?>
</span>
</td>
<td
class="td_description"
title="Description for '<?=$name?>':
<?=$desc?>"
itemprop="description"
><?=$desc?></td>
<td
class="td_users"
title="'<?=$name?>' has had <?=$users?> active users in the last <?=$users_cutoff?>."
><?=$users?></td>
<td class="td_preview" itemprop="url">
<a
href="<?=$preview_link?>"
title="Click here to preview '<?=$name?>'"
target="_blank"
rel="noopener noreferrer nofollow"
>
<span class="protocol-indicator"></span>
</a>
</td>
<td class="td_qr_code">
<a
class="qr-code-button"
href="<?=room_qr_code($room)?>"
target="_blank"
>
<img
class="qr-code-icon"
width="36"
height="41"
src="qrcode-solid.svg"
alt="Pictogram of a QR code"
title="Click here to view the details for '<?=$name?>'"
>
</a>
</td>
<td class="td_server_icon"
data-sort-by="<?=$pubkey?>"
title="Host: <?=$hostname?> (<?=$pubkey?>)"
item="image"
>
<?php if (empty($server_icon)): ?>
<div class="td_server_icon-circle" style="background-color: <?=$icon_color?>">
<span><?=strtoupper($pubkey[0] . $pubkey[1])?></span>
</div>
<?php else: ?>
<div class="td_server_icon-circle" style="background-image: url('<?=$server_icon?>')"></div>
<?php endif; ?>
</td>
<td class="td_join_url">
<div class="join_url_container" data-url="<?=$join_link?>">
<span class="join_url show-from-w5" title="<?=$join_link?>"
><?=truncate($join_link, 32)?></span>
<a
class="noscript"
title="Right click and copy this link to join '<?=$name?>'."
href="<?=$join_link?>"
rel="external nofollow"
>Copy this</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>