Improved Spam list plugin

Share your CuteNews.RU skins and code snippets.

Improved Spam list plugin

Postby kirby145 » Sat Sep 15, 2007 4:57 am

This is a very small improvement but definately a time saver. Now on the spam word blocker plugin when you add or remove a word, you don't have to go through another page to continue. This just keeps it all on one page and makes a little message telling you if it worked.

Simply paste this in /plugins/spam.php

Code: Select all
<?php
/*
Plugin Name: Spam filter
Plugin URI: http://cutenews.ru
Description: Create a list with words and don't allow comments which contain these words.
Version: 0.1
Application: CuteNews
Author: Лёха zloy и красивый
Author URI: http://lexa.cutenews.ru
*/


add_filter('news-allow-addcomment', 'spam_filter');

add_filter('cutenews-options', 'spam_AddToOptions');
add_action('plugin-options', 'spam_CheckAdminOptions');

function spam_filter($allow){
global $name, $mail, $comments;

$barword = new PluginSettings('BarWord');

if ($comments){
foreach($barword->settings as $bad){
if (preg_match("/$bad/i", strtolower($comments))){$allow = false;}
}
}

return ($allow ? true : false);
}

function spam_AddToOptions($options){
global $PHP_SELF;

$options[] = array(
'name' => 'Spam filter',
'url' => $PHP_SELF.'?mod=options&amp;action=spam',
'access' => '1',
);

return $options;
}

function spam_CheckAdminOptions(){
if ($_GET['action'] == 'spam'){spam_AdminOptions();}
}

function spam_AdminOptions(){
global $PHP_SELF;

echoheader('options', 'Spam');

$barword = new PluginSettings('BarWord');

$buffer = '<table border=0 cellpading=0 cellspacing=0 width="645">
<table border=0 cellpading=0 cellspacing=0 width="645" >
<form method=post action="'.$PHP_SELF.'?mod=options&amp;action=spam">
<td width=321 height="33"><b>Add a word</b>
<table border=0 cellpading=0 cellspacing=0 width=379 class="panel" cellpadding="7" >
<tr>
<td width=79 height="25">&nbsp;Word:
<td width=300 height="25">
<input type="text" name="add_badword">&nbsp;&nbsp;<input type="submit" value="Add to list">
</tr>
</form>
</table>

<tr>
<td width=654 height="11">
<img height=20 border=0 src="skins/images/blank.gif" width=1>
</tr><tr>
<td width=654 height=14>
<b>Spam list</b>
</tr>
<tr>
<td width=654 height=1>
<table width=641 height=100% cellspacing=2 cellpadding=2>
<tr>
<td width=260 class="panel"><b>Word</b></td>
<td width=140 class="panel">&nbsp;<b>Action</b></td>
</tr>';

if ($words = $barword->settings){
foreach($words as $key => $bad){
$i++;
if ($i%2 == 0){$bg = ' class="enabled"';}
else {$bg = ' class="disabled"';}

if ($bad){$buffer .= '<tr'.$bg.'><td>'.$bad.'<td><a href="'.$PHP_SELF.'?mod=options&amp;action=spam&amp;subaction=remove&amp;id='.$key.'">[Remove]</a>';}
}
}

$buffer .= '</table></table>';

if ($_POST['add_badword']){
$barword -> settings[] = strtolower($_POST['add_badword']);
$barword -> save();

$buffer = '<p>Word successfully added!</p><table border=0 cellpading=0 cellspacing=0 width="645">
<table border=0 cellpading=0 cellspacing=0 width="645" >
<form method=post action="'.$PHP_SELF.'?mod=options&amp;action=spam">
<td width=321 height="33"><b>Add a word</b>
<table border=0 cellpading=0 cellspacing=0 width=379 class="panel" cellpadding="7" >
<tr>
<td width=79 height="25">&nbsp;Word:
<td width=300 height="25">
<input type="text" name="add_badword">&nbsp;&nbsp;<input type="submit" value="Add to list">
</tr>
</form>
</table>

<tr>
<td width=654 height="11">
<img height=20 border=0 src="skins/images/blank.gif" width=1>
</tr><tr>
<td width=654 height=14>
<b>Spam list</b>
</tr>
<tr>
<td width=654 height=1>
<table width=641 height=100% cellspacing=2 cellpadding=2>
<tr>
<td width=260 class="panel"><b>Word</b></td>
<td width=140 class="panel">&nbsp;<b>Action</b></td>
</tr>';

if ($words = $barword->settings){
foreach($words as $key => $bad){
$i++;
if ($i%2 == 0){$bg = ' class="enabled"';}
else {$bg = ' class="disabled"';}

if ($bad){$buffer .= '<tr'.$bg.'><td>'.$bad.'<td><a href="'.$PHP_SELF.'?mod=options&amp;action=spam&amp;subaction=remove&amp;id='.$key.'">[Remove]</a>';}
}
}
}

if ($_GET['subaction'] == 'remove'){
unset($barword -> settings[$_GET['id']]);
$barword -> save();

$buffer = '<p>The word was removed from the list!</p><table border=0 cellpading=0 cellspacing=0 width="645">
<table border=0 cellpading=0 cellspacing=0 width="645" >
<form method=post action="'.$PHP_SELF.'?mod=options&amp;action=spam">
<td width=321 height="33"><b>Add a word</b>
<table border=0 cellpading=0 cellspacing=0 width=379 class="panel" cellpadding="7" >
<tr>
<td width=79 height="25">&nbsp;Word:
<td width=300 height="25">
<input type="text" name="add_badword">&nbsp;&nbsp;<input type="submit" value="Add to list">
</tr>
</form>
</table>

<tr>
<td width=654 height="11">
<img height=20 border=0 src="skins/images/blank.gif" width=1>
</tr><tr>
<td width=654 height=14>
<b>Spam list</b>
</tr>
<tr>
<td width=654 height=1>
<table width=641 height=100% cellspacing=2 cellpadding=2>
<tr>
<td width=260 class="panel"><b>Word</b></td>
<td width=140 class="panel">&nbsp;<b>Action</b></td>
</tr>';

if ($words = $barword->settings){
foreach($words as $key => $bad){
$i++;
if ($i%2 == 0){$bg = ' class="enabled"';}
else {$bg = ' class="disabled"';}

if ($bad){$buffer .= '<tr'.$bg.'><td>'.$bad.'<td><a href="'.$PHP_SELF.'?mod=options&amp;action=spam&amp;subaction=remove&amp;id='.$key.'">[Remove]</a>';}
}
}
}

echo $buffer;

echofooter();
}
?>


I'm not a php expert but I was able to figure this little trick out ;)
User avatar
kirby145
 
Posts: 36
Joined: Sat Sep 08, 2007 8:27 pm
Location: look behind you

Postby kirby145 » Sat Sep 15, 2007 4:57 am

And, in case you want to add in a few spam words from the start, here's a list of common comment spam words:

http://codex.wordpress.org/Spam_Words
User avatar
kirby145
 
Posts: 36
Joined: Sat Sep 08, 2007 8:27 pm
Location: look behind you

Postby D72 » Mon Oct 01, 2007 12:45 pm

But does it actually improve the current spam plugin? Or is this just a timesaver to add and remove spam words?
I think the current spam plugin is not "Spam Proof" at all. I use at several websites, a guestbook by a comment page and after a couple of weeks, the spam bots find their way to my guestbook and ahve to setup a standalone guestbook.
So if this is really an improved spam plugin...
Please tell us.
User avatar
D72
 
Posts: 336
Joined: Thu Feb 22, 2007 12:05 am
Location: NL

Postby kirby145 » Wed Oct 03, 2007 4:04 am

Nope just a timesaver sorry. I'm sure next version will improve some of its spam blocking though.
User avatar
kirby145
 
Posts: 36
Joined: Sat Sep 08, 2007 8:27 pm
Location: look behind you

Postby D72 » Sat Oct 06, 2007 1:13 am

that's a shame. I used your code anyway and waiting patiently for a improved spam blocker :)
i hate spam!
User avatar
D72
 
Posts: 336
Joined: Thu Feb 22, 2007 12:05 am
Location: NL

Postby MiNi.SpIdEr » Sat Jun 06, 2009 10:57 am

wow its work g8 :lol:

how can i add an error message ? like "Sorry we dont accept this word :p"

heheheh
MiNi.SpIdEr
 
Posts: 78
Joined: Tue Jan 22, 2008 6:30 pm


Return to Skins and snippets



Who is online

Users browsing this forum: No registered users and 0 guests