Akismet Spam Service
Posted by Brian Moon
|
December 29, 2006 03:12PM |
Admin Registered: 24 years ago Posts: 4,495 |
here is a new version with the functions renamed.
Brian - Cowboy Ninja Coder - Personal Blog - Twitter
|
Re: Akismet Spam Service December 29, 2006 08:48PM |
Registered: 19 years ago Posts: 9 |
|
Re: Akismet Spam Service March 17, 2007 04:03PM |
Registered: 18 years ago Posts: 35 |
Quote
brianlmoon
(...)
Someone in IRC pointed me to Akismet. It looked neato. So, I hacked up this module. Akismet is a real time spam checking service. You have to have a key from them to use it. Its free for personal use. If you are a commercial site, you can pay to get a commercial key.
(...)
This code has been tested for sanity. That is all. There are likely bugs.
So... I just set up my new Travel Forum and wanted antispam for it. Having heard good things about Akismet, this looked like the module to use (it still does ;)). So thanks, Brian!
But, as you said: "There are likely bugs." - and did encounter a number of problems (yes, I got the latest version - and I'm running 5.1.20).
First of all: the readme.txt isn't particularly clear, especially where it says" "For read_threads.tpl, look for the same URLs." - I got that sorted eventually: they're not the same, but similar in that read.tpl uses MESSAGES->something whereas read_threads.tpl uses MESSAGE->something. Logical, but kind of hard to spot when you're not familiar with the code yet.
My second problem was that template modifications (as suggested in the readme.txt) would insert two different links, with different results, but both with the link description "Spam" - not very helpful. Even worse, I found that in the original read.tpl and read_threads.tpl templates the same confirmation message is used for deleting a single message and for deleting a message and all its reactions (subthread) - that's pretty misleading by itself, but when the "Spam" links use those same confirmation messages again, the moderator no longer gets a clue what is actually going to happen.
I solved these user-interface problems with 1) a small addition to the main language file (extra confirmation message for deleting a subthread) and 2) extending the provided language file with a number of different link descriptions as well as a number of different confirmation messages.
So far user interface.
The next thing I ran into was that in akismet.php the variable $buf was not initialized, which generated a warning. (Or NOTICE - I always run PHP to give me notices as well - they're what I call "lurking bugs" - and some nasty bugs can indeed be lurking in something as innocent-lokoing as an uninitialized variable.) So I added an initialization for it.
Then I found that when I used a "delete message" link (or delete thread), the module was actually trying to report it as spam; surely that's inappropriate: there's a reason there are separate for "report and delete" and just "delete" - and there are plenty of reasons a moderator or admin might want to delete a message, subthread or whole thread without intending to report it as spam. That led to another modification in akismet.php,so that it uses its own $mod_step constants for handling spam, which are then changed to the standard values for deleting a message or thread. Which in turn required a change to the "moderation" hook in moderation.php to pick up any modified $mod_step values while allowing any other existing hook functions not to return a value.
Finally, I noticed that the way the request for akismet.com is constructed contains two errors: 1) the HTTP RFCs require CRLF between headers (both RFC 1945 for HTTP 1.0 and RFC 2616 for HTTP 1.1) - the akismet.com server may be tolerant of this now, but that's no guarantee this will continue to be the case and their current API docs show an example using \r\n instead of just \n as akistmet.php is doing); and 2) while Phorum allows the admin to set any charset, the HTTP RFCs require any charset other than ISO-8859-1 to be specified explicitly.
All that adds up to a bunch of changes, and not just in the module... so here goes - (approximate) line numbers as for version 5.1.20:
1. moderation.php around line 58:
change:
phorum_hook("moderation",$mod_step);
to:
# modified MK 2007-03-17
$tmp_mod_step = $mod_step; # save value in case hook function doesn't return a value
$mod_step = phorum_hook("moderation",$mod_step); # akismet hooks in here (and returns value now)
if (!isset($mod_step)) {
$mod_step = $tmp_mod_step;
}
2. Language files: english.php, added:
"ConfirmDeleteSubthread"=> "Are you sure you want to delete this message and all reactions?",
While I was at it, I added the corresponding items to dutch.php and dutch_informal.php which I'm also using:
"ConfirmDeleteSubthread"=> "Weet u zeker dat u dit bericht met alle reacties wilt verwijderen?",
"ConfirmDeleteSubthread"=> "Weet je zeker dat je dit bericht met alle reacties wilt verwijderen?",
3. Template changes to read.tpl and read_threads.tpl:
My moderation section for read.tpl now looks like this:
{IF MODERATOR true}
<div class="PhorumReadNavBlock">
<span class="PhorumNavHeading PhorumHeadingLeft">{LANG->Moderate}:</span>
{IF MESSAGES->threadstart true}
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSpamThread}')) window.location='{MESSAGES->spam_url2}';">{LANG->SpamThread}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteThread}')) window.location='{MESSAGES->delete_url2}';">{LANG->DeleteThread}</a>•
{IF MESSAGES->move_url}<a class="PhorumNavLink" href="{MESSAGES->move_url}">{LANG->MoveThread}</a>•{/IF}
<a class="PhorumNavLink" href="{MESSAGES->merge_url}">{LANG->MergeThread}</a>•
{IF MESSAGES->closed false}<a class="PhorumNavLink" href="{MESSAGES->close_url}">{LANG->CloseThread}</a>{ELSE}<a class="PhorumNavLink" href="{MESSAGES->reopen_url}">{LANG->ReopenThread}</a>{/IF}
{ELSE}
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSpamMessage}')) window.location='{MESSAGES->spam_url1}';">{LANG->SpamMessage}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteMessage}')) window.location='{MESSAGES->delete_url1}';">{LANG->DeleteMessage}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSpamSubthread}')) window.location='{MESSAGES->spam_url2}';">{LANG->SpamSubThread}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSubthread}')) window.location='{MESSAGES->delete_url2}';">{LANG->DelMessRepliesShort}</a>•
<a class="PhorumNavLink" href="{MESSAGES->split_url}">{LANG->SplitThread}</a>
{/IF}
{IF MESSAGES->is_unapproved}•<a class="PhorumNavLink" href="{MESSAGES->approve_url}">{LANG->ApproveMessage}</a>
{ELSE}•<a class="PhorumNavLink" href="{MESSAGES->hide_url}">{LANG->HideMessage}</a>{/IF}
•<a class="PhorumNavLink" href="{MESSAGES->edit_url}">{LANG->EditPost}</a>
</div>
{/IF}
The corresponding section for my read_threads.tpl looks like this:
{IF MODERATOR true}
<div class="PhorumReadNavBlock">
<span class="PhorumNavHeading">{LANG->Moderate}:</span>
{IF MESSAGE->threadstart true}
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSpamThread}')) window.location='{MESSAGES->spam_url2}';">{LANG->SpamThread}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteThread}')) window.location='{MESSAGE->delete_url2}';">{LANG->DeleteThread}</a>•
{IF MESSAGE->move_url}<a class="PhorumNavLink" href="{MESSAGE->move_url}">{LANG->MoveThread}</a>•{/IF}
<a class="PhorumNavLink" href="{MESSAGE->merge_url}">{LANG->MergeThread}</a>•
{IF MESSAGE->closed false}<a class="PhorumNavLink" href="{MESSAGE->close_url}">{LANG->CloseThread}</a>{ELSE}<a class="PhorumNavLink" href="{MESSAGE->reopen_url}">{LANG->ReopenThread}</a>{/IF}
{ELSE}
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSpamMessage}')) window.location='{MESSAGE->spam_url1}';">{LANG->SpamMessage}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteMessage}')) window.location='{MESSAGE->delete_url1}';">{LANG->DeleteMessage}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSpamSubthread}')) window.location='{MESSAGE->spam_url2}';">{LANG->SpamThread}</a>•
<a class="PhorumNavLink" href="javascript:if(window.confirm('{LANG->ConfirmDeleteSubthread}')) window.location='{MESSAGE->delete_url2}';">{LANG->DelMessRepliesShort}</a>•
<a class="PhorumNavLink" href="{MESSAGE->split_url}">{LANG->SplitThread}</a>
{/IF}
{IF MESSAGE->is_unapproved}•<a class="PhorumNavLink" href="{MESSAGE->approve_url}">{LANG->ApproveMessage}</a>
{ELSE}•<a class="PhorumNavLink" href="{MESSAGE->hide_url}">{LANG->HideMessage}</a>
{/IF}
•<a class="PhorumNavLink" href="{MESSAGE->edit_url}">{LANG->EditPost}</a>
</div>
{/IF}
4. Finally, an updated akismet module, which I'm attaching in ZIP format.
All changes are documented with #end-of-line comments (I left those in deliberately so it's clear not only what I changed, but also why). It includes the extended English language file as well as corresponding Dutch and Dutch informal versions.
NOTE I did not update the readme.txt - this message has all the instructions for changing the templates.
Hope this helps some people ... :)
-- Marjolein Katsma * Marjolein's Travel blog * Marjolein's Travel Forum
The first condition of understanding a foreign country is to smell it.
-- Rudyard Kipling
Edited 2 time(s). Last edit at 03/18/2007 03:41AM by iamback.
|
Re: Akismet Spam Service June 06, 2007 06:02AM |
Registered: 24 years ago Posts: 1,076 |
|
Re: Akismet Spam Service November 06, 2007 11:18AM |
Registered: 19 years ago Posts: 28 |
|
Re: Akismet Spam Service November 06, 2007 11:36AM |
Registered: 19 years ago Posts: 28 |
|
Re: Akismet Spam Service November 06, 2007 03:18PM |
Registered: 24 years ago Posts: 1,076 |
Quote
m.twoQuote
Panu
I had to change $PHORUM["user"]["post_count"] to $PHORUM["user"]["posts"] to skip checking registered users with enough posts.
Where I have to change that?
Ööh, one and a half year later... :)
It should be in the first if block in the phorum_akismet_check_spam function. (akismet.php)
---
-=[ Panu ]=-
|
Re: Akismet Spam Service November 07, 2007 06:28AM |
Registered: 19 years ago Posts: 28 |
Sorry, only registered users may post in this forum.
