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.
$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),
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);
+}