Skip to content

Commit 80e985b

Browse files
committed
Update spamprotection module from 0.3 to 2.0.5
1 parent 4e53e75 commit 80e985b

File tree

12 files changed

+364
-298
lines changed

12 files changed

+364
-298
lines changed

spamprotection/CHANGELOG

Lines changed: 0 additions & 8 deletions
This file was deleted.

spamprotection/LICENSE

Lines changed: 0 additions & 17 deletions
This file was deleted.

spamprotection/README.md

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# SpamProtection Module
22

3+
[![Build Status](https://secure.travis-ci.org/silverstripe/silverstripe-spamprotection.png?branch=master)](http://travis-ci.org/silverstripe/silverstripe-spamprotection)
4+
![helpfulrobot](https://helpfulrobot.io/silverstripe/spamprotection/badge)
5+
6+
37
## Maintainer Contact
48

59
* Saophalkun Ponlu
@@ -14,12 +18,110 @@ SilverStripe 3.0.0 or greater
1418

1519
## Documentation
1620

17-
See docs/
21+
This module provides a generic, consistent API for adding spam protection to
22+
your SilverStripe Forms. This does not provide any spam protection out of the
23+
box, for that, you must also download one of the spam protection
24+
implementations. Currently available options are:
25+
26+
* [Mollom](https://github.com/silverstripe/silverstripe-mollom)
27+
* [Recaptcha](https://github.com/chillu/silverstripe-recaptcha)
28+
* [MathSpamProtection](https://github.com/silverstripe/silverstripe-mathspamprotection)
29+
* [Akismet](https://github.com/tractorcow/silverstripe-akismet)
30+
31+
As a developer you can also provide your own protector by creating a class which
32+
implements the `SpamProtector` interface. More on that below.
33+
34+
## Configuring
35+
36+
After installing this module and a protector of your choice (i.e mollom) you'll
37+
need to rebuild your database through `dev/build` and set the default protector
38+
via SilverStripe's config system. This will update any Form instances that have
39+
spam protection hooks with that protector.
40+
41+
*mysite/_config/spamprotection.yml*
42+
43+
---
44+
name: spamprotection
45+
---
46+
FormSpamProtectionExtension:
47+
default_spam_protector: MollomSpamProtector
48+
49+
To add spam protection to your form instance call `enableSpamProtection`.
50+
51+
// your existing form code
52+
$form = new Form( .. );
53+
$form->enableSpamProtection();
54+
55+
The logic to perform the actual spam validation is controlled by each of the
56+
individual `SpamProtector` implementation since they each require a different
57+
implementation client side or server side.
58+
59+
### Options
60+
61+
`enableSpamProtection` takes a hash of optional configuration values.
62+
63+
$form->enableSpamProtection(array(
64+
'protector' => 'MathSpamProtector',
65+
'name' => 'Captcha'
66+
));
67+
68+
Options to configure are:
69+
70+
*`protector`* a class name string or class instance which implements
71+
`SpamProtector`. Defaults to your
72+
`FormSpamProtectionExtension.default_spam_protector` value.
73+
74+
*`name`* the form field name argument for the Captcha. Defaults to `Catcha`.
75+
*`title`* title of the Captcha form field. Defaults to `''`
76+
*`insertBefore`* name of existing field to insert the spam protection field prior to
77+
*`mapping`* an array mapping of the Form fields to the standardized list of
78+
field names. The list of standardized fields to pass to the spam protector are:
79+
80+
title
81+
body
82+
contextUrl
83+
contextTitle
84+
authorName
85+
authorMail
86+
authorUrl
87+
authorIp
88+
authorId
89+
90+
## Defining your own `SpamProtector`
91+
92+
Any class that implements `SpamProtector` and the `getFormField()` method can
93+
be set as the spam protector. The `getFormField()` method returns the
94+
`FormField` to be inserted into the `Form`. The `FormField` returned should be
95+
in charge of the validation process.
96+
97+
<?php
98+
99+
class CustomSpamProtector implements SpamProtector {
100+
101+
public function getFormField($name = null, $title = null, $value = null) {
102+
// CaptchaField is a imagined class which has some functionality.
103+
// See silverstripe-mollom module for an example.
104+
return new CaptchaField($name, $title, $value);
105+
}
106+
}
107+
108+
109+
## Using Spam Protection with User Forms
110+
111+
This module provides an EditableSpamProtectionField wrapper which you can add
112+
to your UserForm instances. After installing this module and running /dev/build
113+
to rebuild the database, your Form Builder interface will have an option for
114+
`Spam Protection Field`. The type of spam protection used will be based on your
115+
currently selected SpamProtector instance.
18116

19-
## Installation Instructions
117+
## Releasing code with Spam Protection support
20118

21-
See docs/Install
119+
Spam protection is useful to provide but in some cases we do not want to require
120+
the developer to use spam protection. In that case, modules can provide the
121+
following pattern
22122

23-
## Usage Overview
123+
$form = new Form(..);
24124

25-
See docs/Install
125+
if($form->hasExtension('FormSpamProtectionExtension')) {
126+
$form->enableSpamProtection();
127+
}

spamprotection/_config.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,4 @@
88
*
99
* @package spamprotection
1010
*/
11-
12-
/**
13-
* If the comments module is installed then add the spam protection module
14-
* to the comments form via this extension.
15-
*
16-
* Place this line in your mysite/_config.php
17-
*/
18-
19-
// CommentingController::add_extension('CommentSpamProtection');
11+
Deprecation::notification_version('1.1', 'spamprotection');

0 commit comments

Comments
 (0)