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

183 lines
5.9 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" data-sort="true" data-sort-asc="true" data-sorted-by="6">
<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);
$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')?>'
data-icon-safe='<?=$room->icon_safety()?>'
>
<td class="td_language tbl_communities__td" title="Language flag for '<?=$name?>'"><?=$language?></td>
<td class="td_name tbl_communities__td">
<a
href="<?=$preview_link?>"
class="td_name-inner"
target="_blank"
title="Click here to preview '<?=$name?>'"
rel="noopener noreferrer external nofollow"
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 room-label-view-main <?=$tag->get_tag_classname()?> badge"
title="<?=$tag->get_description_sanitized()?>"
><?=
truncate($tag->get_text_sanitized(), 16)
?></span>
<?php endif; endforeach; ?>
</span>
</td>
<!--noindex--><td
class="td_description tbl_communities__td noindex robots-noindex robots-nocontent"
title="Description for '<?=$name?>'"
itemprop="description"
><?=$desc?></td><!--/noindex-->
<td
class="td_users tbl_communities__td"
title="'<?=$name?>' has had <?=$users?> active users in the last <?=$users_cutoff?>."
><?=$users?></td>
<td class="td_preview tbl_communities__td">
<a
href="<?=$preview_link?>"
class="protocol-indicator__parent"
title="Click here to preview '<?=$name?>'"
target="_blank"
rel="noopener noreferrer external nofollow"
>
<span class="protocol-indicator"></span>
</a>
</td>
<td class="td_qr_code tbl_communities__td">
<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="QR code pictogram linking to '<?=$name?>' Community QR code"
title="Click here to view the details for '<?=$name?>'"
>
</a>
</td>
<td class="td_server_icon tbl_communities__td"
title="Host: <?=$hostname?>"
item="image"
>
<?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 tbl_communities__td">
<div class="join_url_container" data-url="<?=$join_link?>">
<span class="join_url show-from-w5"
><?=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<span class="hidden">link to join '<?=$name?>'.</span></a>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>