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/php/assets/server-icons.php

35 lines
1009 B
PHP

<?php
/**
* \file
* Implement the fetching of Community server icons.
*/
require_once 'servers/known-servers.php';
require_once 'assets/room-icons.php';
/**
* Fetch the icon of the given Community server and return its relative path.
* @param CommunityServer $server
* @param string $size Image dimensions.
* @return string Relative path or null if icon is absent.
*/
function server_icon(CommunityServer $server, string $size): ?string {
global $SERVER_ICON_MAPPING;
$hostname = $server->get_hostname();
$pubkey = $server->get_pubkey();
if (isset($SERVER_ICON_MAPPING[$hostname])) {
$room_token = $SERVER_ICON_MAPPING[$hostname];
} else if (isset($SERVER_ICON_MAPPING[$pubkey])) {
$room_token = $SERVER_ICON_MAPPING[$pubkey];
} else {
return "";
}
$room = $server->get_room_by_token($room_token);
if (!$room) {
log_warning("Room $room_token on $hostname does not exist, cannot be used as icon.");
return "";
}
return room_icon($room, $size);
}
?>