Hi, I'm new to b2evolution.
I've made a simple antispam plugin that works with the following technique described by modernbludesign:
http://www.modernbluedesign.com/web-design-blog/fighting-spam-with-css/
What i've done is to create the file _css_antispam.plugin.php inside the plugins/css_antispam_plugin folder.
Here is the code.
<?php
/**
* _css_antispam.plugin.php
*
* This file implements the CSS Antispam plugin.
*
*
* @copyright (c)2007 by Matias Lespiau - {@link http://www.fallenjehova.com.ar/}
*
* {@internal License choice
*
* }
*
* @package plugins
*
*
* @version $Id: _css_antispam.plugin.php,v 0.1 2007/07/09
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
/**
* CSS Antispam Plugin
*
* This plugin add's a hidden field to the comment's form
* and before accepting the comment, it checks if it was completed
* by the commenter.
*
* As it's css hidden to human beings by css display property,
* if the field is completed we are sure that the commenter is
* a bot.
*
*/
class css_antispam_plugin extends Plugin
{
/**
* Variables below MUST be overriden by plugin implementations,
* either in the subclass declaration or in the subclass constructor.
*/
var $name = 'CSS Antispam';
var $code = '';
var $priority = 60;
var $version = '2.0-dev';
var $author = 'Matias Lespiau';
var $group = 'antispam';
function PluginInit( & $params )
{
$this->short_desc = T_('CSS antispam methods');
$this->long_desc = T_('This plugin add\'s a hidden field to the comment\'s form and before accepting the comment, it checks if it was completed by the commenter. As it\'s css hidden to human beings by css display property, if the field is completed we are sure that the commenter is a bot.');
}
function BeforeTrackbackInsert( & $params )
{
$this->checkCSSProtection();
}
/**
* - Check for form field being empty.
*/
function checkCSSProtection() {
if( isset($_POST["mail"]) && !empty($_POST["mail"]) )
{
$this->msg( T_('You act like a spambot.'), 'error' );
}
}
function BeforeCommentFormInsert( & $params )
{
$this->checkCSSProtection();
}
function GetDefaultSettings()
{
return array();
}
}
?>
Then i added a new input field "mail" to the comments with the class aspam
if( is_logged_in() )
{ // User is logged in:
$Form->begin_fieldset();
$Form->info_field( T_('User'), '<strong>'.$current_User->get_preferred_name().'</strong>'
.' '.get_user_profile_link( ' [', ']', T_('Edit profile') ) );
$Form->end_fieldset();
}
else
{ // User is not logged in:
// Note: we use funky field names to defeat the most basic guestbook spam bots
$Form->text( 'u', $comment_author, 40, T_('Name'), '', 100, 'bComment' );
$Form->text( 'i', $comment_author_email, 40, T_('Email'), T_('Your email address will <strong>not</strong> be displayed on this site.'), 100, 'bComment' );
$Form->text( 'o', $comment_author_url, 40, T_('Site/Url'), T_('Your URL will be displayed.'), 100, 'bComment' );
$Form->text( 'mail', '', 40, '', '', 100, 'aspam' );
}
and the CSS code is:
.aspam {
visibility: hidden;
display: none;
}
This works great but I would like to improve it.
So my questions are:
1) Is there any unobtrusive way of introducing the form field and / or the css class when installing without having to do it by hand?
2) I know you can made some variables configurables, but i couldn't find the docs how to do it, can someone give me more information ? I would like to make the css class and the form field name configurable.
I hope you could excuse my bad english as it's not my natural language.
Thanks,
You could use BeforeCommentFormInsert and AfterCommentFormInsert events and use ob_start, ob_get_contents, ob_end_clean, to modify the html. Not sure if it will work though, but I don't see why not aye ;)