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

176 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 or columns 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)"],
];
$SERVER_ICON_COLUMN = array_keys(array_filter($TABLE_COLUMNS, function($column){return $column['id'] == "server_icon";}))[0];
?>
<table id="tbl_communities" data-sort="true" data-sort-asc="true" data-sorted-by="<?=$SERVER_ICON_COLUMN?>">
<tr>
<?php foreach ($TABLE_COLUMNS as $colno => $column): ?>
<th<?=sort_onclick($colno)?> id="th_<?=$column['id']?>" class="tbl_communities__th">
<?=$column['name']?>
</th>
<?php endforeach; ?>
</tr>
<?php foreach ($rooms as $id => $room): ?>
<?php
if ($room->is_off_record()) {
// This can later allow SOGS
// to pass server-wide info using hidden dummy rooms.
continue;
}
$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');
$pubkey_shorthand = strtoupper($pubkey[0] . $pubkey[1]);
$id = html_sanitize($room->get_room_identifier());
$language = html_sanitize($room->get_language_flag());
$name = html_sanitize($room->name);
// $name_trunc = truncate($name, 16);
$name_trunc = "Community";
$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($room->server->get_hostname());
$class_list = ["room-row"];
if ($room->is_stickied_room()) {
$class_list[] = "room-row-stickied";
}
$classname = implode(" ", $class_list);
/**
* Note on refactoring:
* Icon is hard to move to JSON because it'd have to be generated by fetching code
* Icon safety is depended on by CSS styles
*/
?>
<tr class="<?=$classname?>"
itemscope
itemtype="https://schema.org/EntryPoint"
data-id="<?=$id?>"
data-icon='<?=room_icon($room, '64x64')?>:<?=$room->icon_safety()?>'
>
<td class="td_language" title="Language flag for '<?=$name_trunc?>'"><?=$language?></td>
<td class="td_name">
<a
href="<?=$preview_link?>"
target="_blank"
title="Click here to preview <?=$name_trunc?>"
rel="noopener noreferrer external nofollow"
itemprop="name"
><?=
$name
?></a>
<span><?php /* class="tags-container" */ ?>
<?php foreach ($room->get_showcased_room_tags() as $tag): ?>
<span
class="tag <?=$tag->get_tag_classname()?> badge"
title="<?=$tag->get_description_sanitized()?>"
><?=
truncate($tag->get_text_sanitized(), 16)
?></span>
<?php endforeach; ?>
</span>
</td>
<td
class="td_description"
title="Description"
itemprop="description"
><?=$desc?></td>
<td
class="td_users"
title="<?=$users?> active users in the last <?=$users_cutoff?>."
><?=$users?></td>
<td class="td_preview">
<a
href="<?=$preview_link?>"
title="Preview <?=$name_trunc?>"
target="_blank"
rel="noopener noreferrer external nofollow"
>
<span></span>
</a>
</td>
<td class="td_qr_code">
<a
href="<?=room_qr_code($room)?>"
target="_blank"
>
<div
title="Click here to view details for <?=$name_trunc?>"
></div>
</a>
</td>
<td class="td_server_icon"
title="Host: <?=$hostname?>"
>
<?php if (empty($server_icon)): ?>
<div class="td_server_icon-circle" style="background-color: <?=$icon_color?>">
<span class="td_server_icon-text"><?=$pubkey_shorthand?></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>
<span></span><?php /* Join URL preview */ ?>
<a
class="noscript"
href="<?=$join_link?>"
title="Right click -> Copy link"
rel="external nofollow"
>Copy this</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>