Coder Social home page Coder Social logo

silverstripe-akismet's Introduction

Akismet Silverstripe Module

NOTE: This module is no longer commercially supported in Silverstripe CMS 5 and it does not provide a CMS5-compatible version. The parent library is outdated and there are better alternatives like UndefinedOffset/silverstripe-nocaptcha.

CI

Simple spam filter for Silverstripe using Akismet

Also, please report any issues you may encounter, as it helps us all out!

Please see the changelog for module history.

Credits and Authors

Requirements

Note: For a Silverstripe 3.x compatible version, please use the 1.x release line.

Installation Instructions

This module can be easily installed on any already-developed website

  • You can install using Composer, as below:
composer require silverstripe/akismet ^4.0

AkismetSpamProtector is automatically assigned as the default spam protector class.

  • Get an API key from akismet.com and set in the site against one of the following ways.

config.yml:

---
Name: myspamprotection
---
SilverStripe\Akismet\AkismetSpamProtector:
  api_key: 5555dddd55d5d

_config.php:

use SilverStripe\Akismet\AkismetSpamProtector;

AkismetSpamProtector::singleton()->setApiKey('5555dddd55d5d');

.env:

SS_AKISMET_API_KEY="5555dddd55d5d"

If instead you want to configure your akismet key via the siteconfig (as a password field) you can add the included extension to SiteConfig

mysite/_config/settings.yml:

SilverStripe\SiteConfig\SiteConfig:
  extensions:
    - SilverStripe\Akismet\Config\AkismetConfig

Priority of defined API keys

Please note that the API key values defined in the various ways above will be prioritised as:

  1. Values assigned to the singleton via AkismetSpamProtector::singleton()->setApiKey()
  2. Values defined in configuration, whether YAML or in _config.php files with Config::modify()->set(...)
  3. Values defined in the environment via .env

Testing

By default, spam protection is disabled for users with ADMIN priviliges. There is also an option to disable spam protection for all logged in users. In order to disable this for testing purposes, you can temporarily modify these options in your development environment as below:

use SilverStripe\Akismet\AkismetSpamProtector;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;

if (!Director::isLive()) {
	Config::modify()->remove(AkismetSpamProtector::class, 'bypass_permission');
	Config::modify()->remove(AkismetSpamProtector::class, 'bypass_members');
}

In order to check that your form is blocking spam correctly, you can always set 'viagra-test-123' as the author and Akismet will always mark this as spam.

Comments

If you're using Comments module you can quickly set akismet to filter these out by adding the CommentSpamProtection extension to the CommentingController

config.yml

SilverStripe\Comments\Controllers\CommentingController:
  extensions:
    - CommentSpamProtection

If necessary, you can also mark spam comments to be saved to the database. This will still display the spam rejection notice, but spam comments will now be available for moderation in the backend. In order to enable this feature add the following to your configuration.

config.yml

# Allows spam posts to be saved for review if necessary
SilverStripe\Akismet\AkismetSpamProtector:
  save_spam: true

Custom Form Usage

To enable spam protection in your custom forms, call the enableSpamProtection method with your field names mapped to the akismet fields:

$form  = new Form($this, 'Form', $fields, $actions, $validator);
$form->enableSpamProtection(array(
  'mapping' => array(
    'Name' => 'authorName',
    'Email' => 'authorMail',
    'Comments' => 'body'
    )
  )
);

Important notes for those in the EU

Because of the way Akismet works (message, author, and other information sent to a third party) in some countries it's legally necessary to notify and gain the user's permission prior to verification.

To create a checkbox style authorisation prompt for this field set the following configuration option:

config.yml

SilverStripe\Akismet\AkismetSpamProtector:
  require_confirmation: true

_config.php

Config::modify()->set(AkismetSpamProtector::class, 'require_confirmation', true);

silverstripe-akismet's People

Contributors

emteknetnz avatar guysartorelli avatar dhensby avatar robbieaverill avatar assertchris avatar raissanorth avatar tractorcow avatar jon-shape avatar maxime-rainville avatar dnsl48 avatar scott1702 avatar makreig avatar scopeynz avatar nightjar avatar bergice avatar brettt89 avatar chillu avatar sabina-talipova avatar elliot-sawyer avatar asecondwill avatar

Stargazers

Ramon Lapenta avatar Ed Chipman avatar

Watchers

Hamish Friedlander avatar Michal Kleiner avatar Saophalkun Ponlu avatar Paul avatar James Cloos avatar  avatar

silverstripe-akismet's Issues

tijsverkoyen/akismet constraint is too strict and might not work on PHP8

Someone has reported that tijsverkoyen/akismet 1.1.0 doesn't work with PHP8. There's apparently a commit in tijsverkoyen/akismet dev-master that allows it to work with PHP8.

There's also a v1.1.1 tag that in theory could be installed which our very strict constraint won't allow.

"tijsverkoyen/akismet": "1.1.0",

Acceptance criteria

  • We've validated that silverstripe/silverstripe-akismet works on PHP8 and PHP8.1.

Holder: SS4 compatibility

Requirements:

  • Add namespacing
  • Change "code" to "src"
  • Update code as required to match new core APIs
  • Update tests
  • Freeze translations in SS3 branch
  • Update translations
  • Beta tag released

Pull requests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.