diff --git a/src/bans.php b/src/bans.php index 98195b0..990f8a1 100644 --- a/src/bans.php +++ b/src/bans.php @@ -18,32 +18,74 @@ if ($banlist !== null) { $data = []; foreach ($banlist as $ban) { + // Bans abbreviations: + // if we see a UID, IP or MyTSID ban, and we know + // the nickname of the banned user, we will show + // the user's name and then the type of ban + // that should be enough info for most users. + // it is possible to hover over the ban type to + // view the exact ban target + // + // for example, Wruczek got banned on his UID. we know that + // his last nickname was "Wruczek", so we simply show, that + // the ban is issued for: + // Wruczek (UID) + // after hovering over the "UID", you will see the exact UID + // + // if we dont know the last name of the banned user, we + // will just show the UID, IP or MyTSID - $name = "(cannot determine a name)"; + $target = "(unknown)"; + $lastNickname = Utils::escape($ban["lastnickname"]); + $filter = ""; + $abbreviation = null; - if ($ban["lastnickname"]) { - $name = (string)$ban["lastnickname"]; - } else if ($ban["uid"]) { - $name = new Html("" . $ban["uid"] . ""); - } else if ($ban["name"]) { - $name = (string)$ban["name"]; - } else if ($ban["ip"]) { - $ip = str_replace("\\", "", (string) $ban["ip"]); + if ($ban["ip"]) { + $ip = str_replace("\\", "", (string)$ban["ip"]); try { - $name = Utils::censorIpAddress($ip); + $ip = Utils::censorIpAddress($ip); } catch (\Exception $e) {} + if ($lastNickname) { + $abbreviation = [$ip, "IP"]; + } else { + $target = $ip; + } + if ($ip === Utils::getClientIp()) { $ipbanned = [ "invoker" => (string)$ban["invokername"], "reason" => (string)$ban["reason"] ]; } + } else if ($ban["uid"]) { + if ($lastNickname) { + $abbreviation = [$ban["uid"], "UID"]; + } else { + $target = new Html("" . $ban["uid"] . ""); + } + } else if ($ban["name"]) { + $target = $ban["name"]; + } else if (!empty($ban["mytsid"])) { // empty, older TS servers dont have MYTS bans, so the key might not exist + if ($lastNickname) { + $abbreviation = [$ban["mytsid"], "MyTSID"]; + } else { + $target = new Html("" . $ban["mytsid"] . ""); + } + } + + if ($abbreviation) { + $html = '%s (%s)'; + $target = new Html(sprintf($html, $lastNickname, $abbreviation[0], $abbreviation[1])); + + // make sure that the "full" data is also searchable in DataTables + $filter = "{$abbreviation[0]} $lastNickname"; } $data[] = [ - "name" => $name, + "filter" => $filter, + "target" => $target, "reason" => (string)$ban["reason"], "invoker" => (string)$ban["invokername"], "created" => $ban["created"], diff --git a/src/css/style.css b/src/css/style.css index bef501a..4648385 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -178,6 +178,11 @@ body { align-items: center; } +.bans-highlight { + color: #e83e8c; + font-family: var(--font-family-monospace); +} + /* Responsive datatables styles */ table.dataTable>tbody>tr.child ul.dtr-details>li:first-child { diff --git a/src/private/cache/.gitkeep b/src/private/cache/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/private/templates/bans.latte b/src/private/templates/bans.latte index 1b14c4a..a6bdd2a 100644 --- a/src/private/templates/bans.latte +++ b/src/private/templates/bans.latte @@ -38,7 +38,7 @@ - + @@ -49,7 +49,7 @@ {foreach $banlist as $ban} {var $expiretime = $ban["created"] + $ban["duration"]} - +
{_"BANS_HEADER_NAME"}{_"BANS_HEADER_TARGET"} {_"BANS_HEADER_REASON"} {_"BANS_HEADER_INVOKER"} {_"BANS_HEADER_BANDATE"}
{$ban["name"]}{$ban["target"]} {if $ban["reason"]} {$ban["reason"]}