Topic: Modifying the Censor

The censor system is alright, but it only censors the word, and not the word with a prefix or suffix on it. I do know MySQL, so I'm wondering if anyone can direct me to where the censors are applied to a post. Thank you.

Re: Modifying the Censor

Doesn't the wildcard (*) cover prefixes/suffixes?

Looking for a certain modification for your forum? Please take a look here before posting.

3 (edited by GameSource 2006-06-08 00:34)

Re: Modifying the Censor

If it does, perhaps I've accidentally changed how posts are censored when I installed a mod or something.

Can someone still tell me where the censor is applied in the code? Just what file, general direction, etc.

Re: Modifying the Censor

Either include/functions.php or include/parser.php, I think the latter.

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Modifying the Censor

Ok, here we go, include/functions.php:

//
// Replace censored words in $text
//
function censor_words($text)
{
    global $db;
    static $search_for, $replace_with;

    // If not already built in a previous call, build an array of censor words and their replacement text
    if (!isset($search_for))
    {
        $result = $db->query('SELECT search_for, replace_with FROM '.$db->prefix.'censoring') or error('Unable to fetch censor word list', __FILE__, __LINE__, $db->error());
        $num_words = $db->num_rows($result);

        $search_for = array();
        for ($i = 0; $i < $num_words; ++$i)
        {
            list($search_for[$i], $replace_with[$i]) = $db->fetch_row($result);
            $search_for[$i] = '/\b('.str_replace('\*', '\w*?', preg_quote($search_for[$i], '/')).')\b/i';
        }
    }

    if (!empty($search_for))
        $text = substr(preg_replace($search_for, $replace_with, ' '.$text.' '), 1, -1);

    return $text;
}
Looking for a certain modification for your forum? Please take a look here before posting.

Re: Modifying the Censor

Thank you, I'll compare it to what is in my file.