Right below this section:
$comment->setCommenterId($gallery->getActiveUserId());
$comment->setHost(GalleryUtilities::getRemoteHostAddress());
$comment->setSubject($form['subject']);
$comment->setComment($form['comment']);
$comment->setAuthor($form['author']);
$comment->setDate(time());
Add the following code:
##BEGIN Gallery Spam Prevention Mod by TechBlogByDave (http://www.techblogbydave.blogspot.com)
$disallowed = array('http', 'url=');
$checks = array($form['author'], $form['subject'], $form['comment']);
foreach ($checks as $check){
foreach ($disallowed as $dis){
if (stristr($check, $dis)){
die("In order to combat spam, $check has been tagged as a disallowed keyword. Your comment has not been saved.");
}
}
}
##END Gallery Spam Prevention Mod
Save the file and voila- any comment with the text "http" or "url=" will be met with an error message and not even be saved to the datbase. You can even add additional keywords into the "disallowed" array that you don't want in comments such as cuss words. Keep in mind that when you upgrade your Gallery 2 to a newer version you will have to re-apply the mod. Hope this helps!
8 comments:
Thank You very much for this.
Thanks a lot :-).
Hey Dave - thanks a lot for this little mod... its been such a pain for a long time, and this is exactly what I was looking for.
Cheers,
Steve Jones
Thank you so much for this!
Great work there Dave. I've been searching for a solution to this problem for a while now.
I'm going to give your script a whirl!
Thank you! Works like a charm! Hard to advertise something with out a link to it so this catches most spam!
Same change needed in EditComment.inc as well. Sneaky comment spammers will create a seemingly innocent comment that doesn't have any links in it, then change the comment later to have links and the proper spam content.
Thank you VERY much ... this was indeed a nightmare ... I didn't go for refusing hhtp links ... I used the 4000 spam comment I had to find the worst keywords and it seems to be working ...
Post a Comment