From f37cf7b358e9f13da01202c756a2333a2e8c2031 Mon Sep 17 00:00:00 2001 From: gravel Date: Sun, 21 May 2023 11:50:28 +0200 Subject: [PATCH] Add server icons from rooms --- output/index.css | 1 + php/servers/known-servers.php | 5 +++++ php/utils/server-icons.php | 25 +++++++++++++++++++++++++ php/utils/servers-rooms.php | 16 ++++++++++++++++ sites/+components/tbl_communities.php | 6 ++++++ 5 files changed, 53 insertions(+) create mode 100644 php/utils/server-icons.php diff --git a/output/index.css b/output/index.css index 20c8d9b..c326f81 100644 --- a/output/index.css +++ b/output/index.css @@ -349,6 +349,7 @@ a[href^="https:"] .protocol-indicator::after { color: white; text-shadow: 0 0 0.25em #000a; box-shadow: 0 0 0.05em #777; + background-size: cover; } .td_server_icon-circle span { diff --git a/php/servers/known-servers.php b/php/servers/known-servers.php index 6f3b74f..4bb7283 100644 --- a/php/servers/known-servers.php +++ b/php/servers/known-servers.php @@ -72,4 +72,9 @@ $ICON_BLOCKLIST = [ "gaohuangse.work" ]; + + $SERVER_ICON_MAPPING = [ + "open.getsession.org" => "session", + "sog.caliban.org" => "privacy" + ] ?> diff --git a/php/utils/server-icons.php b/php/utils/server-icons.php new file mode 100644 index 0000000..970bba6 --- /dev/null +++ b/php/utils/server-icons.php @@ -0,0 +1,25 @@ +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); + } +?> \ No newline at end of file diff --git a/php/utils/servers-rooms.php b/php/utils/servers-rooms.php index f3c4e30..d2c1ecf 100644 --- a/php/utils/servers-rooms.php +++ b/php/utils/servers-rooms.php @@ -776,6 +776,22 @@ return $this->pubkey != ""; } + /** + * Returns the room of the given token, or null if one does not exist. + */ + function get_room_by_token(string $token): \CommunityRoom | null { + $candidates = array_filter($this->rooms, function(\CommunityRoom $room) use ($token) { + return $room->token == $token; + }); + + /** Filter doesn't reindex */ + foreach ($candidates as $candidate) { + return $candidate; + } + + return null; + } + /** * Attempts to fetch the current server's room listing. * Downgrades the server's scheme to HTTP if necessary. diff --git a/sites/+components/tbl_communities.php b/sites/+components/tbl_communities.php index d9e54c4..c61d677 100644 --- a/sites/+components/tbl_communities.php +++ b/sites/+components/tbl_communities.php @@ -3,6 +3,7 @@ require_once "$PROJECT_ROOT/php/utils/servers-rooms.php"; require_once "$PROJECT_ROOT/php/utils/room-invites.php"; require_once "$PROJECT_ROOT/php/utils/room-icons.php"; + require_once "$PROJECT_ROOT/php/utils/server-icons.php"; /** * @var CommunityRoom[] $rooms @@ -52,6 +53,7 @@ $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(); @@ -145,9 +147,13 @@ title="Host: ()" item="image" > +
+ +
+