- b2evolution CMS Support Forums
- b2evolution Support
- Plugins & Extensions
- Fighting spam!
- Comment list widget, do not make links unless they're old
1 gr8dude Jun 24, 2010 18:54
After spending some time removing spam comments from my site, I decided to tinker with the comments a little bit.
I edited _item_comment.inc.php such that the link is rendered as plain text (i.e. without the A tag); thinking that spammers will quit spamming, when they see that the there will be no link.
I thought I was done, but I wasn't. I am using a 'comments list' widget - the URLs were there too.
I know that it can be configured to NOT turn authors' addresses into links, but I believe this would be too harsh of a measure. After all, real people are more than welcome to post links to their sites.
In other words, we need a form of punishment that only harms the bad guys.
So I concluded that it would be great if I could use the age of the comment to determine whether the link should be a link or not. The rationale is that if the comment is spam, I will delete it within one or two days. If it is 3 days old, it means I didn't delete it, hence it is a good comment, hence it can be published.
This way spammers get nothing, while decent people get their credit where credit is due.
I found that the widget responsible for this is here: /inc/widgets/widgets/_coll_comment_list.widget.php and that the code I need to tinker with is this piece:
while( $Comment = & $CommentList->get_next() )
{ // Loop through comments:
// Load comment's Item object:
$Comment->get_Item();
echo $this->disp_params[ 'item_start' ];
$Comment->author( '', ' ', '', ' ', 'htmlbody', $this->disp_params[ 'author_links' ] );
echo T_( 'on ' );
$Comment->permanent_link( array(
'text' => $Comment->Item->title,
'title' => $this->disp_params[ 'hover_text' ],
) );
echo $this->disp_params[ 'item_end' ];
} // End of comment loop.}
echo $this->disp_params[ 'list_end' ];
echo $this->disp_params[ 'block_end' ];
It should be altered to something like this:
while( $Comment = & $CommentList->get_next() )
{ // Loop through comments:
// Load comment's Item object:
$Comment->get_Item();
echo $this->disp_params[ 'item_start' ];
if ($Comment->date > 3 days ago)
$Comment->author( '', ' ', '', ' ', 'htmlbody', $this->disp_params[ 'author_links' ] );
else
$Comment->author( '', ' ', '', ' ', 'htmlbody', false );
echo T_( 'on ' );
$Comment->permanent_link( array(
'text' => $Comment->Item->title,
'title' => $this->disp_params[ 'hover_text' ],
) );
echo $this->disp_params[ 'item_end' ];
} // End of comment loop.}
echo $this->disp_params[ 'list_end' ];
echo $this->disp_params[ 'block_end' ];
I need some assistance with this process, my questions are:
[list]
What is the standard PHP way of obtaining the delta between two timestamps? I did some digging and found that $Comment->date is of MySQL's DATETIME type. Is it a good idea to use a MySQL function to compare the days?
Does b2evo provide a set of date-related functions, or should I come up with my own?
Is it reasonable to move this logic to the Comment class? There is a function in it, called get_author, which seems to be a good place to add this logic too; this way - other pieces of b2evo that deal with links could recycle the code. This is the function I refer to: http://doc.b2evo.net/HEAD/evocore/Comment.html#methodget_author
It would be great if the setting would not be hard-coded, such that people could enable it only if they want it, and they could choose custom parameters. If it were a widget, I'd have to add another property (as in this case: $this->disp_params[ 'author_links' ]), but what is the right way to do it, if the change is made inside the Comment class?
[/list:u]
p.s. I know that there are CAPTCHA plugins, interfaces for Akismet, etc; I prefer this approach, because it adds no burden to normal people.