What this plugin does

Installation

Always backup your database as a precaution

  1. Decide which spam service you wish to use. Register at the service you choose to use and obtain an API key.
  2. Download, unpack and upload the spam_protection plugin folder to your plugin directory.
  3. Install the plugin in the administration panel.
  4. Go into the plugin's configurations in the admin panel and select your spam service and enter your API key.
  5. Check to see that everything is configured to your preference.
  6. The rest is up to your spam service and you can find all spam items caught in Administration -> Other -> Spam Protection

Adding spam filtering to your extensions

An example of what it would look like to add spam filtering to your extension:

if(cot_plugin_active('spam_protection'))
{
    require_once cot_incfile('spam_protection', 'plug');
    $spam_data = array(
        'content' => $msg['text'],
        'authorname' => $usr['name'],
        'authoremail' => $usr['profile']['user_email'],
        'authorid' => $usr['id'],
        'authorip' => $usr['ip'],
        'date' => $sys['now'],
        'section' => 'guestbook',
        'data' => array(
            'guestbook' => $msg
        ), 
    );
    $spam_check_result = spam_protection_check($spam_data);
    if($spam_check_result['is_spam'])
    {
        // Item was returned as spam
        spam_protection_queue_add($spam_data); // Add to the moderation queue if you want. Not required.
    }
}

See spam_protection_check below for more options to pass.

Available Tags

forums.posts.tpl

Block: FORUMS_POSTS_ROW

comments.tpl

Block: COMMENTS_ROW

Section adapters

Section adapters allow you to add your own spam filtered items to the moderation queue.

To enable queue moderation on your custom filtered items, simply:

You can refer to the comments.php adapter as it is a simple example.

Available callback functions in section adapters

A list of functions that will get used at the time you mark an item for spam or ham in the moderation queue if defined.

spam_protection_queue_ham(array $item, $service, array $data)

Used on each item one at a time when you use the action 'Mark as Ham' in the moderation queue.

spam_protection_queue_spam(array $item, $service, array $data)

Used on each item one at a time when you use the action 'Mark as Spam' in the moderation queue.

spam_protection_queue_after($type)

Ran after the whole queue is marked.

spam_protection_queue_before($type)

Ran before the queue is marked.

spam_protection_check_data($type, $data)

Ran before the item is marked and can be used to validat
e/change the data before being marked.

Available service adapter functions

Functions that are available from any spam service that you use and can be used anywhere you include this plugin.

spam_protection_service_connection()

Used to create a new service object for use with the spam service

spam_protection_service_setup($service, array $data)

Used to load the service object with spam data.

spam_protection_service_validate_key([$service])

Validate the spam service API key entered for the service.

if(spam_protection_service_validate_key())
{
    // API key is valid
}
else 
{
    // API key is invalid
}

spam_protection_service_submit_ham($service)

Submit false positives to the spam service in order to make it more knowledgeable in the future.

$service = spam_protection_service_connection();
$service = spam_protection_service_setup($service, array(
    'content' => $row['text'],
    'authorname' => $row['author'],
    'authorid' => $row['authorid'],
    'authorip' => $row['authorip'],
    'date' => $row['date'],
));
spam_protection_service_submit_ham($service);

spam_protection_service_submit_spam($service)

Submit false negatives to the spam service in order to make it more knowledgeable in the future.

$service = spam_protection_service_connection();
$service = spam_protection_service_setup($service, array(
    'content' => $row['text'],
    'authorname' => $row['author'],
    'authorid' => $row['authorid'],
    'authorip' => $row['authorip'],
    'date' => $row['date'],
));
spam_protection_service_submit_spam($service);

spam_protection_queue_add($data)

Send spam data to moderation queue for further review. Items marked as spam can still be false positive.

spam_protection_queue_remove($id)

Remove item from moderation queue. Just deletes the record from the spam_protection database table.

spam_protection_check($data)

Send data to the spam service for validation.

$spam_data = array(
    'content' => 'blahblah viagra blahblah',
    'authorname' => 'viagra-user',
    'authoremail' => 'viagra@drugs.com'
);
$result = spam_protection_check($spam_data);
if($result['is_spam'])
{
    // is spam
}
else
{
    // not spam
}

Complete removal

The following is to completely remove this plugin.

  1. Uninstall the plugin in the Cotonti plugin administration
  2. Delete the plugin folder "spam_protection" in your plugins folder
  3. Delete the database table ( usually cot_spam_protection ) in phpMyAdmin or the likes

Notes