Krop Spam – permanently stop spam in your blog comments

I’ve been tired of comment spam at my blogs (I also use WordPress as a CMS engine so comment spam is even more pain in the ass) so I have created a method to stop it. My method proved to be very efficient and doesn’t need any human interaction (while plugins such as Akismet require blog owner to periodically look through spam folder to check if there aren’t any false positives). I have decided to wrap it up in a plugin.

How does it work?

Well, I’ve noticed that spambots usually directly attack the wp-comments-post.php script that is a WordPress comment processing script. Some (but this is really rare) spammers also try to parse the WWW page and when they find a <form> there, they just blindly fill it in and submit.

If you look into any WordPress template source code, you’ll find that there is a <textarea name=”comment”> somewhere inside. This is a text field for comment content that user enters. Spammers just fill it in with garbage.

What my plugin does is change this <textarea> name to something meaningless for spammers (by default its „komentarzyk” which means „a little comment” in Polish 😉 ). This way, whenever a spammer attacks your wp-comments-post.php directly, he doesn’t fill now required „komentarzyk” field and the comment is not added. Moreover, my plugin leaves the <textarea name=”comment” in the source code, but makes it small (1 row and 1 column only) and tries to hide it through CSS (display: none) so human user will probably not fill that field in. Spammers don’t bother to check textarea’s size nor do they understand CSS, so even when they parse your webpage, they not only fill in required „komentarzyk” field, but also fill in the „comment” field (because they fill in just everything they find). This way they let your blog now they are bad people – if „comment” field is filled in, probably machine filled in your comment form instead of human. So we refuse the comment to be added.

So, how to install the plugin?

1. Download the Krop Spam plugin and unzip it into your WordPress wp-content/plugins directory.
2. Enable the plugin in WordPress admin.
3. Open up wp-comments-post.php in your favorite text editor and find a line that says:

$comment_content = trim($_POST['comment']);  

4. Replace this line with following fragment:

if(trim($_POST['comment']) != '') wp_die( __('Sorry, small comments field should be left empty - it\'s a spam trap.'));
$comment_content = trim($_POST['komentarzyk']);

5. You’re done 🙂

I have tested the plugin with few WordPress themes found on the internet and it works correctly. The only plugin’s requirement is that it needs to have access to any temporary directory (usually /tmp) on the server. It’s almost always possible. If not – talk to you provider.

How efficient is it?

I have been using this method at my Karkonosze page since a few months ago and it decreased the number of spam I receive from 20-30 a week to 1 in 3 months. There’s no guarantee it will work for you though 😉

Fending questions off

In her blue eyes she’s so blue
And her tears tear skies apart
All her colours’ve lost their hue
She’s alone and she knows that

Now she fends just for herself
Fends incoming questions off
All her life is filled with death
Peace of heart she’s looking for

Eye to I and sight to side
Every day she’s passing through
Eager like eagle for flight
Out again she seeks for truth

Tuning Freevo: display feedback when manually seeking

There is a nice feature in Freevo that allows one to seek the currently playing movie to any given position. One just needs to press 0 on the remote control, then enter to which minute of the movie they wish to jump and press enter. For instance, pressing 0,6,0,ENTER would fast forward the movie to the first hour. Unfortunatelly, there is no visual feedback while pressing these keys. I thought it would be nice to see „Seek to:” in mplayer’s OSD when first pressed 0 and then see „Seek to: 6”, „Seek to: 60” while pressing next buttons.

I managed to do it in this way (source code editing necessary):

1. Went to the /usr/lib/python2.4/site-packages/freevo/video/plugins directory.

2. Opened up the mplayer.py file in text editor.

3. Found a line saying: def eventhandler(self, event, menuw=None):

4. Ten lines below def eventhandler there is a line saying:

if event == VIDEO_MANUAL_SEEK:

5. After that line there is

rc.set_context('input')

just add that line:

self.app.write('osd_show_text "seek to: "\n')

below the rc.set_context line (self.app.write should be left aligned with tabs the same way rc.set_context is).

6. Further in the file there is a line saying:

self.seek = self.seek * 10 + int(event)

just add the line:

self.app.write('osd_show_text "seek to: ' + str(self.seek) + '"\n')

below the self.seek line (self.app.write should be left aligned with tabs the same way self.seek is).

7. Saved the file, restarted Freevo and voila!, it’s almost working (I don’t know how to make it not disappear after a second, but it does give visual feedback).

Tuning Freevo: subtitle and audio language switch

I decided that posts in the Freevo category will be published in English so the target audience can be wider.

Freevo is a HTPC (Home Theatre Personal Computer) overlay for some of the most common Linux multimedia applications (mplayer, xine, etc). It is visually and functionally similar to the Microsoft’s Windows XP Media Centre. I have made a PC box of some old components that where scattered arround in my cellar, installed Ubuntu Linux there, tweaked A LOT to make it work with things like TV-OUT and remote control and finally installed and configured Freevo. It allows me to watch virtually any kind of movies (DVD, DIVX, XVID, MKV, WMA, MPEG, etc.), play a collection of my MP3 files, browse my photographs and much more. Thanks to a huge hard drive (250GB) I could put practically whole multimedia content on the box.

In my first post I would like to give You some tips and tricks to enable features that aren’t normally available in Freevo (as of version 1.5.4).

O.K., let’s get going 🙂 The very first thing that I didn’t like about Freevo was it’s unability to select different subtitles using my remote. It was especially annoying when watching MVK movies that have some subtitles (eg. English and French) encoded inside the video file. Mplayer or Freevo automatically selects embedded subtitles and ignores the fact that there also exists a specially prepared Movie_title.txt file with Polish (my native tongue 😉 ) subtitles.

So what needs to be done to fix that problem is this:

1. Make sure You have some remote control button configured and not used for anything in video context. Open up /etc/freevo/lircrc file and one of the sections could be something like this:

begin  
prog=freevo  
button=subtitle  
config=SUBTITLE  
end

2. Open up /etc/freevo/local_conf.py file and seek for a line

# EVENTS['video']['1'] = Event(VIDEO_SEND_MPLAYER_CMD, arg='contrast -100')

I’ve added two lines below:

EVENTS['video']['SUBTITLE'] = Event(VIDEO_SEND_MPLAYER_CMD, arg='sub_select')  
EVENTS['video']['LANG'] = Event(VIDEO_SEND_MPLAYER_CMD, arg='switch_audio')

The first one makes the SUBTITLE button cycle through all available subtitles during the movie. The second line makes the LANG button cycle through different available versions of audio. I find it useful when watching DVDs where default language often is different than my native.

Yes, that is SOOO easy 🙂