Page 1 of 2

Anti Spam Mod

Posted: 07 Dec 2011, 19:43
by Mii
Don't you like it that people spam your board with posts containing !!!!!!!!!!! and other characters at the end?
This snippet will replace strings in a posts from !!!!! to ! and some other stuff.
./includes/functions.php wrote: Find

Code: Select all

function phpbb_user_session_handler()
{
    global $phpbb_hook;

    if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
    {
        if ($phpbb_hook->hook_return(__FUNCTION__))
        {
            return $phpbb_hook->hook_return_result(__FUNCTION__);
        }
    }

    return;
} 
Add After

Code: Select all

//Spelling corrector START
function message_validate_spam($message)
{
    if(isset($message) && $message != '')
    {
        $corr = array(
            'accidentally',    // 0
            'accordion',
            'acquaintance',
            'acquaintance',
            'aquire',
            'acquit',    // 5
            'a lot',
            'a lot',
            'argument',
            'a while',
            'axle',    // 10
            'barbeque',
            'believable',
            'broccoli',
            'cemetary',
            'chauvinism',    // 15
            'chocolaty',
            'colosseum',
            'collectible',
            'definite',    // 20
            'development',
            'drunkenness',
            'dumbbell',
            'exercise',
            'existence',    // 25
            'fiery',
            'flabbergast',
            'flotation',
            'frustum',
            'genius',    //30
            'grammar',
            'handkerchief',
            'harass',
            'inadvertent',
            'incidentally',    //35
            'indispensable',
            );
        $wrong = array(
            'accidently',    // 1
            'accordian',
            'acquaintence',
            'aquaintance',
            'acquire',
            'aquit',    // 5
            'alot',
            'allot',
            'arguement',
            'awhile',
            'axel',    // 10
            'barbeque',
            'believeable',
            'brocolli',
            'cemetery',
            'chauvanism',    // 15
            'chocolatey',
            'colliseum',
            'collectable',
            'definate',    // 20
            'developement',
            'drunkeness',
            'dumbell',
            'excercise',
            'existance',    // 25
            'firey',
            'flabberghast',
            'floatation',
            'frustrum',
            'genious',    // 30
            'grammer',
            'hankerchief',
            'harrass',
            'inadvertant',
            'incidently',    // 35
            'indispensible',
            );
        $l['corr'] = count($wrong) - 1;
        $l['wrong'] = count($corr) - 1;
        $typos = 0;
        if($l['corr'] == $l['wrong'])
        {
            while($l['corr'] >= 0&& $typos <= 20)
            {
                while(strstr($message,$wrong[$l['corr']]) !== false)
                {
                    $message = str_replace($wrong[$l['corr']], $corr[$l['corr']], $message);
                }
                while(strstr($message, ucwords($wrong[$l['corr']])) !== false)
                {
                    $message = str_replace(ucwords($wrong[$l['corr']]), ucwords($corr[$l['corr']]), $message);
                }
                $l['corr'] = $l['corr'] - 1;
                $typos = $typos + 1;
            }
            return $message;
        }
        else
        {
            return $message;
        }
    }
    else
    {
        return $message;
    }
}
//Spelling corrector END     
./includes/functions_posting.php wrote: Find

Code: Select all

    // Start the transaction here
    $db->sql_transaction('begin'); 
Add After

Code: Select all

    $data['message'] = message_validate_spam($data['message']);
$subject = message_validate_spam($subject);  
---------------------------- THE NEXT PART IS OPTIONAL FOR MCHAT INTEGRATION ----------------------------
./mchat.php wrote:Find

Code: Select all

        // Reguest...
        $message = utf8_normalize_nfc(request_var('message', '', true)); 
Add After

Code: Select all

        $message = message_validate_spam($message); 
You can add strings to replace in the message_validate_spam function in ./includes/functions.php. I'm sure you'll know how.

Anti Spam Mod

Posted: 07 Dec 2011, 21:41
by Vox Populi
I can't say this is a true Anti Spam snippet however, it does assist in keeping your board consistent and clean. The code is appreciated and I saved it for a later date.

I know where you are coming from as it does get old, the !!!! and ???? and ......... etc;. Heck, with your code, complete words can be rewritten .... It'd be pretty darn big, but it's almost like a spell checker... :)

The most commonly mis-spelled words could be invoked with this code. It's a great start!

Thanks again.

Anti Spam Mod

Posted: 07 Dec 2011, 23:58
by doktornotor
Hmm, indeed, this would be quite interesting with some level of abstraction and ACP settings. :thumb:

Anti Spam Mod

Posted: 08 Dec 2011, 21:59
by Mii
Vox Populi wrote:I can't say this is a true Anti Spam snippet however, it does assist in keeping your board consistent and clean. The code is appreciated and I saved it for a later date.

I know where you are coming from as it does get old, the !!!! and ???? and ......... etc;. Heck, with your code, complete words can be rewritten .... It'd be pretty darn big, but it's almost like a spell checker... :)

The most commonly mis-spelled words could be invoked with this code. It's a great start!

Thanks again.
Yeah, I already thought about using it as a spell checker, but that would seriously increase server-load. This snippet was written because members were spamming posts with incredibly many "!!!"'s, just to gain points. (Ultimate Points System)
If you want you can use it as a spelling correcter though.

Anti Spam Mod

Posted: 08 Dec 2011, 22:06
by Vox Populi
I was thinking not so much a spell checker but an automated correction type of mod. I know there is a list of most commonly mis-spelled words. Server load, yup. You are correct for sure on that.

I have a feeling, somebody is going to snatch this and run with it.

You have come up with a brilliant idea and simple too.

Again, thanks for sharing.

Anti Spam Mod

Posted: 08 Dec 2011, 22:09
by Mii
Vox Populi wrote:I was thinking not so much a spell checker but an automated correction type of mod. I know there is a list of most commonly mis-spelled words. Server load, yup. You are correct for sure on that.

I have a feeling, somebody is going to snatch this and run with it.

You have come up with a brilliant idea and simple too.

Again, thanks for sharing.
Hmm, I just tested, and it doesn't take that much server load. Especially since it isn't loaded on every page, but only when submitting a post. (Other then wordcensor) I'm going to create a modification for this, but I first need to have a decent list of common misspelled words.

I only need to find out how to notice capitol letters in the words and how to not change them. I think I just create 2 versions of each word. (1 with a starting capital letter, and one without).

Anti Spam Mod

Posted: 08 Dec 2011, 22:31
by martin123456
Going bk to anti spam idea i just use this in the word censor
place the censored characters in it and replace word is in the code box bellow this way it never shows

Code: Select all

 
But saying that i agree with the dok and sir vox :)

Anti Spam Mod

Posted: 08 Dec 2011, 22:35
by Vox Populi
Yeah, that's an idea that should be used too. Good thought.

By the way, Google has a plethora of commonly misspelled words in the English language.. http://www.infoplease.com/ipa/A0862708.html and many more.

Also, you'll need to know how the word was misspelled to change it. So, now you need to search for most commonly misspelled words in the English language AND HOW they are misspelled most of the time. You can only correct those really. You can't add every misspelling eg; Knowledge. Misspelled : Knowlege, noledge???? too? Hmmm, pretty complex.

Anti Spam Mod

Posted: 08 Dec 2011, 22:37
by Mii
Bl4d3 x wrote:Going bk to anti spam idea i just use this in the word censor
place the censored characters in it and replace word is in the code box bellow this way it never shows

Code: Select all

 
But saying that i agree with the dok and sir vox :)
Using the word censor would take way more server load. Here is my first version. (Easy to use, all strings are placed in an array.

Code: Select all

//Anti spam start
function message_validate_spam($message)
{
    if(isset($message) && $message != '')
    {
        $corr = array(
            1    =>    'accidentally',
            2    =>    'accordion',
            3    =>    'acquaintance',
            4    =>    'acquaintance',
            5    =>    'aquire',
            6    =>    'acquit',
            7    =>    'a lot',
            8    =>    'a lot',
            9    =>    'argument',
            10    =>    'a while',
            11    =>    'axle',
            12    => 'barbeque',
            13    => 'believable',
            14    => 'broccoli',
            15    => 'cemetary',
            );
        $wrong = array(
            1    => 'accidently',
            2    => 'accordian',
            3    => 'acquaintence',
            4    => 'aquaintance',
            5    => 'acquire',
            6    => 'aquit',
            7    => 'alot',
            8    => 'allot',
            9    => 'arguement',
            10    => 'awhile',
            11    => 'axel',
            12    => 'barbeque',
            13    => 'believeable',
            14    => 'brocolli',
            15    => 'cemetery',
            );
        $l['corr'] = count($wrong);
        $l['wrong'] = count($corr);
        if($l['corr'] == $l['wrong'])
        {
            while($l['corr'] > 0)
            {
                while(strstr($message,$wrong[$l['corr']]) !== false)
                {
                    $message = str_replace($wrong[$l['corr']], $corr[$l['corr']], $message);
                }
                $l['corr'] = $l['corr'] - 1;
            }
            return $message;
        }
        else
        {
            return $message;
        }
    }
    else
    {
        return $message;
    }
}
//Ant spam end 

Anti Spam Mod

Posted: 08 Dec 2011, 22:41
by Vox Populi
Ahhh, I see. Looks great. So a person can add to this easily. The array takes away the load... Good thought again.

I think it's best to keep it away from the ACP too but then, somebody will mess the file up and be hammering you!! :D

http://www.alphadictionary.com/articles ... words.html