class Wordfilter extends Plugin { var $id = "Wordfilter"; var $name = "Word Filter"; var $version = "1.3"; var $description = "Filters out words and phrases from posts."; var $author = "Thirtysixway, grntbg"; var $defaultConfig = array( "Wordlist" => "shit\nfuck\ndamn\nass\nhell\nbitch", "Case" => false, "Replace" => "*", "MatchInWords" => false, // Match words within other words "MatchAccents" => false, // Match accented words ); var $wordlist = array(); // Initialize the plugin function init() { parent::init(); if ($this->eso->action == "conversation") { $this->eso->controller->addHook("formatForDisplay", array($this, "formatWordfilterForDisplay")); } } // Normalize the string by removing accents if needed function normalize($string) { return iconv('UTF-8', 'ASCII//TRANSLIT', $string); } // Format words and filter the display text function formatWordfilterForDisplay($controller, &$string) { global $config; // Get the word list and split by new lines $words = preg_split('/\r\n|\r|\n/', $config["Wordfilter"]["Wordlist"], -1, PREG_SPLIT_NO_EMPTY); // Save the original string for comparison $originalString = $string; // Normalize the string if MatchAccents is enabled if ($config["Wordfilter"]["MatchAccents"]) { $normalizedString = $this->normalize($string); } else { $normalizedString = $string; } // Normalize words in the wordlist if MatchAccents is enabled if ($config["Wordfilter"]["MatchAccents"]) { foreach ($words as &$word) { $word = $this->normalize($word); } } // Prepare replacement rules $replacements = []; // Loop through the words in the wordlist foreach ($words as $word) { // Escape any special characters in the word for regex $escaped_word = preg_quote($word, '#'); // Build the regex pattern based on MatchInWords and Case settings if ($config["Wordfilter"]["MatchInWords"]) { // Match the word anywhere, including in other words $regex = '#'.$escaped_word.'#i'; // Case-insensitive } else { // Match the word as a whole word only $regex = '#\b'.$escaped_word.'\b#i'; // Case-insensitive word boundaries } // Perform the matching on the normalized string preg_match_all($regex, $normalizedString, $matches, PREG_OFFSET_CAPTURE); // Handle matches and replacements foreach ($matches[0] as $match) { // Get the start position and length of the match $start = $match[1]; $length = strlen($match[0]); // Replace the match in the original string with asterisks $replacements[] = [ "start" => $start, "length" => $length, "replacement" => str_repeat($config["Wordfilter"]["Replace"], $length), ]; } } // Sort replacements in reverse order so we can safely modify the string usort($replacements, fn($a, $b) => $b['start'] - $a['start']); // Apply replacements to the original string foreach ($replacements as $replacement) { $string = mb_substr($string, 0, $replacement['start']) . $replacement['replacement'] . mb_substr($string, $replacement['start'] + $replacement['length']); } // Return the modified string if any change occurred return $string !== $originalString ? $string : $originalString; } // Settings for the plugin, can be used to configure the wordlist and options function settings() { global $config, $language; $this->eso->addLanguage("List of filtered words", "List of filtered words"); $this->eso->addLanguage("Enter each word on a new line", "Enter each word on a new line"); $this->eso->addLanguage("Make filter case sensitive", "Make filter case sensitive"); $this->eso->addLanguage("Match filter words within other words", "Match filter words within other words"); $this->eso->addLanguage("Match filter words containing accents", "Match filter words containing accents"); $this->eso->addLanguage("Replace each letter with this", "Replace each letter with"); // Update settings if changed if (isset($_POST["Wordfilter"])) { $config["Wordfilter"]["Wordlist"] = $_POST["Wordfilter"]["Wordlist"]; $config["Wordfilter"]["Case"] = ($_POST["Wordfilter"]["Case"] == "true") ? true : false; $config["Wordfilter"]["MatchInWords"] = ($_POST["Wordfilter"]["MatchInWords"] == "true") ? true : false; $config["Wordfilter"]["MatchAccents"] = ($_POST["Wordfilter"]["MatchAccents"] == "true") ? true : false; $config["Wordfilter"]["Replace"] = $_POST["Wordfilter"]["Replace"]; writeConfigFile("config/Wordfilter.php", '$config["Wordfilter"]', $config["Wordfilter"]); $this->eso->message("changesSaved"); } // Generate settings HTML form $CaseValue = ($config["Wordfilter"]["Case"]) ? " checked" : ""; $MatchInWordsValue = ($config["Wordfilter"]["MatchInWords"]) ? " checked" : ""; $MatchAccentsValue = ($config["Wordfilter"]["MatchAccents"]) ? " checked" : ""; $settingsHtml = "
"; return $settingsHtml; } } Esoteric Chat
Woah, slow down! Looks like you're trying to perform a few too many searches. Wait 37 seconds and try again.