Add server icons from rooms
parent
3345e9c9b3
commit
a058bf2de1
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require_once "$PROJECT_ROOT/php/servers/known-servers.php";
|
||||
require_once "$PROJECT_ROOT/php/utils/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();
|
||||
if (!isset($SERVER_ICON_MAPPING[$hostname])) {
|
||||
return "";
|
||||
}
|
||||
$room_token = $SERVER_ICON_MAPPING[$hostname];
|
||||
$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);
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue