PHP


Spamlists and WordPress

Tags: , , , ,

I’ve been getting dozens of e-mails with spam posts to this blog and it’s become far to annoying to ignore any further!  I’ve been using WordPress’s integrated blacklist tool, but it’s time consuming to maintain and only protects against past threats.  I took a look at the database and I’ve managed to collect over 3,000 spam comments that take up more than 20 mbs of database space…which is quite a lot IMO.

In the past the best prevention I’ve found against spammers is to use spam lists.  One I like in particular is FSpamlist.com.  You have to sign-up to get an API key, but after that using it is very straight forward.   Stop Forum Spam is a big one too, you don’t need an API key to check for spammers so it was even easier to add.  I put a simple WordPress plugin together to integrate the lists with my blog.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
/*
Plugin Name: Spamlist
Plugin URI: http://wannabe.contropa.com/fspamlist-and-wordpress/351/
Description: Uses spamlists to stop spammers
Version: 1.0
Author: Foxumon
Author URI: http://www.contropa.com
License: GPL2
*/
 
add_action('wp_blacklist_check', 'spamlist', 10 , 6);
 
function spamlist($author, $email, $url, $comment, $user_ip, $user_agent) {
    $username = $author;
    $email = $email;
    //$ip = $user_ip;
    
    $fspamcheck = file_get_contents('http://www.fspamlist.com/xml.php?key=######&spammer='.$email.','.$username.','.$ip);
    if (strpos($fspamcheck, '<isspammer>true</isspammer>') !== FALSE) {
        wp_die('Your e-mail address has been marked as spam.  You may request that it be removed here: http://www.temerc.com/forums/viewforum.php?f=72','spam');
    }
    
    $fspamcheck = file_get_contents('http://www.stopforumspam.com/api?email='.$email.'&username='.$username);
    if (strpos($fspamcheck, '<appears>yes</appears>') !== FALSE) {
        wp_die('Your e-mail address has been marked as spam.  You may request that it be removed here: http://stopforumspam.com/removal','spam');
    }
}
?>

I’m currently not planning on submitting it to the WordPress plugins directory or anything like that, but you want to try it out too you just save the code as “spamlist.php” add it to a “spamlist” folder in your plug-ins directory and then it ought to show up in your admin where you can active it.

It’s currently not set to report the spam that it blocks in any way…I’m not sure if I want it to or not.  I’m currently looking at over 3k of spam comments that are just sitting around taking up room in my database, but at the same time I don’t want to get any legitimate posters blocked without anyway of knowing.  Anyways, I’m going to test it out for now and see how it goes 🙂

Permalink » No comments

Spam Words

Tags: , ,

This is a very simple spam prevention mod for phpBB2.  The idea is that you define specific words that come up often in spam and it will block messages containing those words.

There is already a “spam words” mod out there, but with this mod you don’t need to make any database changes and you can set how many times the words need to be matched before blocking the message as spam.  Although, there isn’t an admin panel to go with this mod so settings need to be changed in the code.

Features:

  • Checks if a post includes any designated spam words
  • Set how many times those words need to be found to mark as spam
  • Set how many posts a user needs to have their post checked
  • PM a designated account with details about the post

Click here to download the mod

Permalink » No comments

Facebook Connect for phpBB2

Tags: , , , ,

Another mod for phpBB2 that I have just completed is the well sought after “Facebook Connect” mod.  It’s a very straightforward version and should be very simply to install, though I give no guarantee that it will work for you.

I used to JavaScript Api to get the job done.  In a nutshell what it does is it first adds in a column to your User’s table to store someone’s Facebook ID.  Then the first time a user clicks on the “facebook connect” button it will ask the user if they want to link to an existing account or create a new one.  It will then add in the facebook ID to th row for the selected account.  Then the next time a user clicks on the “Facebook Connect” button it will check the User’s table for the user’s facebook ID and automatically log them in.

So, like I said, pretty straight forward.  The forum account will still work independently from Facebook, but will give the user instant activation and a faster way to login.

Features:

  • Instant account activation.
  • Single click log in when user is already logged into Facebook.
  • Allows for linking/unlinking for logged in users.
  • Will add the user’s Facebook avatar if they don’t already have one.

Click here to download the mod

8/02/10 Minor edit needed: It reads “Please submit both an email and password” which should be changed to “Please submit both a username and password”

Permalink » 13 Comments

Edit Join Date mod for PHPBB2

Tags: , , ,

I have written some mods for PHPBB2 (don’t ask why I’m not on 3 :P)  and I havn’t gotten into the habit of documenting them properly so they can shared, but this time I went through the whole nine yards 🙂  I don’t know how well this file would work with any auto installers, though.

I will give credit where credit it due – this mod is adapted from tomlevens’ “Edit User’s Postcount” mod.

What this mod does is add a field to the user management section of the admin panel which enables you to change a user’s join date.

click here to download join_date.mod

Permalink » No comments

Regular Expressions

Tags: , , , ,

I can never seem to locate a guide that has an easy explanation of the common regular expressions that I use on a regular basis.  I usually just find bits and pieces, or find the right info, but not displayed in a way that’s easy to reference.  So here’s my own notes on RegEx 🙂

CharacterUsage
.wildcard character - will match anything
|or operator - (this|that) will match either
-range selector - will match a range of character or numbers i.e. 1-9
[]match any character inside the brackets [aeiou] would match anything with a vowel.
^match the start of a string - ^a will match 'atlas' but not 'mad'
[^]don't match - it will negate what you put inside like [^cheese]
$match the end of a string - at$ will match 'mat' but not 'saturn'
?match preceding character 0-1 times - tree? will match 'tre', 'tree', but not 'treee'
*match preceding character 0+ time - same as * except it would match 'treee'+
+match preceding character 1+ times - this version will not match 'tre'
{#}match preceding character # times - tree{3} will match 'treeee'
{#,#2}match preceding character at least #, but not more than #2 - tree{3,4} will match 'treeee' or 'treeeee'
icase insensitive flag - add at end i.e. '#(regex)#i'
sdotall flag - make the "." character match anything
xverbose flag - ignore all whitespace and allows "#" commenting
Regular expression syntax

One piece I use often as kind of a ‘match-all’ is “(.*?)” so preg_match_all(‘#<a>(.*?)</a>#is’, $content, $matches); would match everything in the string that is within anchor tags.

The delimiter can also be changed, in the previous example it is the “#” pound character, but could easily be changed to “/” as in ‘/<a>(.*?)</a>/is’ or changed into whatever is most convenient for the enclosed string.

Permalink » No comments