]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Channel list: Run StripControlCharacters() on the topic
authorBram Matthys <redacted>
Wed, 26 Apr 2023 17:52:25 +0000 (19:52 +0200)
committerBram Matthys <redacted>
Wed, 26 Apr 2023 17:52:58 +0000 (19:52 +0200)
The alternative would be irc2html() from
https://github.com/unrealircd/unrealircd-webpanel/pull/24
but not so sure about that... it makes colors and other markup
done by random users show quite prominently on an admin panel.

api/channels.php
misc/strings.php

index cebe6b959360e780158cdc62c7f798e79ea4e14a..13c932adcf40a8d07c68aa66cd69f0dc918f4c1b 100644 (file)
@@ -19,7 +19,7 @@ foreach($channels as $channel)
        $modes = (isset($channel->modes)) ? "+" . explode(" ",$channel->modes)[0] : "<none>";
        $topic = '';
        if (isset($channel->topic))
-               $topic = htmlentities($channel->topic, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 | ENT_DISALLOWED);
+               $topic = htmlentities(StripControlCharacters($channel->topic), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 | ENT_DISALLOWED);
        $date = explode("T", $channel->creation_time)[0];
        $out[] = [
                "Name" => htmlspecialchars($channel->name),
index 25cbdba5ae7f7a4b352ca2c91840ab7c73ee6334..f5d576753ee66e197be5aac0deb49d41afa7f679 100644 (file)
@@ -192,4 +192,19 @@ function rparv($string)
        if ($string)
                return $string;
        return false;
-}
\ No newline at end of file
+}
+
+/* Taken from https://www.aviran.org/stripremove-irc-client-control-characters/
+ * We may want to re-base it off our UnrealIRCd's one though.
+ */
+function StripControlCharacters($text)
+{
+    $controlCodes = array(
+        '/(\x03(?:\d{1,2}(?:,\d{1,2})?)?)/',    // Color code
+        '/\x02/',                               // Bold
+        '/\x0F/',                               // Escaped
+        '/\x16/',                               // Italic
+        '/\x1F/'                                // Underline
+    );
+    return preg_replace($controlCodes,'',$text);
+}