An enhanced word filter for sNews, with whole words matching
filed under: sNews CMS / Hacks & Mods
I was doing a little troubleshooting today and noticed that the "bad words" filter in sNews was censoring out bits of words in the comments, i.e. charset became ch****t, obviously because the word arse is in my word filter file. Analysis becomes ****ysis, succumb becomes suc****b, etc etc.
Basically, this is annoying as hell, so I have re-written the sNews cleanWords function to use only whole word matching instead. This is one of the easier mods to implement.
Simply BACK-UP your snews.php file, then rename the existing cleanWords function to cleanWordsORIG, now copy the following cleanWords function into your snews.php file, just above the closing PHP tags;
// CLEAN - WORD FILTER
function cleanWords($text) {
$wordFilterFile = s('word_filter_file');
if ((strtolower(s('word_filter_enable')) == 'on') && (file_exists($wordFilterFile))) {
$bad_words_from_what = split("\n", file_get_contents($wordFilterFile));
$bad_words_to_what = s('word_filter_change');
for($x=0; $x< count($bad_words_from_what); $x++) {
$text = preg_replace("/\b$bad_words_from_what[$x]\b/", $bad_words_to_what, $text);
}
return $text;
} else {
return $text;
}
}
Tada, you're done. If you're wondering how to enable word filtering, first you need to upload a bad words list (each word on a new line, like this one) to the same base directory as your snews.php file, then in the admin menu, select settings then comments, select the Enable Badwords filter box, then add the file name of the filter you uploaded, then what text you want to display instead of the offending word.
Comments
No comments posted yet, why not be the first?
Categories
Recent Entries
Recent Comments
- Redbeard (I managed to get Vampire: The Masquerade - Bloodlines ...)
- Tina (Installed this today and working like a charm :) Thanks!)
- Tina (Thanks for this great mod :) Working on my site for quite a ...)
- konga (Hi Matt, if you plan to update it, please have a look into ...)
- David (Yo Matt, I have a problem, when I use this mod. ...)
- Dave (Have a Toshiba NB305. Win7 starter would not do screen ...)
- Daichisan (Howdy Matt, I dont really get it, whats ...)
- Matt (Mine is just customized further, that's all :) It just spits ...)
- Matt (David, Do you own or admin the server? Do you have exec ...)
Popular Entries
- Compact archives for sNews 1.7 (5/5)
- Light-weight related articles mod for sNews 1.7 (4.78/5)
- SEF / SEO search for your sNews website (4.75/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.67/5)
- Gravatar mod for sNews 1.7 (4.67/5)
- An improved tag cloud for sNews 1.7 (4.67/5)
- Image / math hybrid captcha version 2, vastly improved (4.64/5)
- Command & Conquer Generals, and the Zero Hour expansion on the Acer Aspire One netbook (4.6/5)
- Related Articles mod for sNews CMS, public beta release (4.6/5)