mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
Update usage examples in readme, minor fixes in travis configuration and gitattributes
This commit is contained in:
parent
c5f0827c2e
commit
37dde110c9
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -4,3 +4,4 @@
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/codecov.yml export-ignore
|
||||
|
@ -25,7 +25,7 @@ before_script:
|
||||
script:
|
||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist src/ tests/ ; fi
|
||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist code/ tests/ ; fi
|
||||
|
||||
after_success:
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
||||
|
77
README.md
77
README.md
@ -39,17 +39,21 @@ spam protection hooks with that protector.
|
||||
|
||||
*mysite/_config/spamprotection.yml*
|
||||
|
||||
---
|
||||
name: spamprotection
|
||||
---
|
||||
FormSpamProtectionExtension:
|
||||
```yaml
|
||||
---
|
||||
name: spamprotection
|
||||
---
|
||||
SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension:
|
||||
default_spam_protector: MollomSpamProtector
|
||||
```
|
||||
|
||||
To add spam protection to your form instance call `enableSpamProtection`.
|
||||
|
||||
// your existing form code
|
||||
$form = new Form( .. );
|
||||
$form->enableSpamProtection();
|
||||
```php
|
||||
// your existing form code
|
||||
$form = new Form(/* .. */);
|
||||
$form->enableSpamProtection();
|
||||
```
|
||||
|
||||
The logic to perform the actual spam validation is controlled by each of the
|
||||
individual `SpamProtector` implementation since they each require a different
|
||||
@ -59,10 +63,12 @@ implementation client side or server side.
|
||||
|
||||
`enableSpamProtection` takes a hash of optional configuration values.
|
||||
|
||||
$form->enableSpamProtection(array(
|
||||
'protector' => 'MathSpamProtector',
|
||||
```php
|
||||
$form->enableSpamProtection(array(
|
||||
'protector' => MathSpamProtector::class,
|
||||
'name' => 'Captcha'
|
||||
));
|
||||
));
|
||||
```
|
||||
|
||||
Options to configure are:
|
||||
|
||||
@ -76,15 +82,17 @@ Options to configure are:
|
||||
*`mapping`* an array mapping of the Form fields to the standardized list of
|
||||
field names. The list of standardized fields to pass to the spam protector are:
|
||||
|
||||
title
|
||||
body
|
||||
contextUrl
|
||||
contextTitle
|
||||
authorName
|
||||
authorMail
|
||||
authorUrl
|
||||
authorIp
|
||||
authorId
|
||||
```
|
||||
title
|
||||
body
|
||||
contextUrl
|
||||
contextTitle
|
||||
authorName
|
||||
authorMail
|
||||
authorUrl
|
||||
authorIp
|
||||
authorId
|
||||
```
|
||||
|
||||
## Defining your own `SpamProtector`
|
||||
|
||||
@ -93,22 +101,26 @@ be set as the spam protector. The `getFormField()` method returns the
|
||||
`FormField` to be inserted into the `Form`. The `FormField` returned should be
|
||||
in charge of the validation process.
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
class CustomSpamProtector implements SpamProtector {
|
||||
use CaptchaField;
|
||||
use SilverStripe\SpamProtection\SpamProtector;
|
||||
|
||||
public function getFormField($name = null, $title = null, $value = null) {
|
||||
// CaptchaField is a imagined class which has some functionality.
|
||||
class CustomSpamProtector implements SpamProtector
|
||||
{
|
||||
public function getFormField($name = null, $title = null, $value = null)
|
||||
{
|
||||
// CaptchaField is an imagined class which has some functionality.
|
||||
// See silverstripe-mollom module for an example.
|
||||
return new CaptchaField($name, $title, $value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
## Using Spam Protection with User Forms
|
||||
|
||||
This module provides an EditableSpamProtectionField wrapper which you can add
|
||||
to your UserForm instances. After installing this module and running /dev/build
|
||||
This module provides an `EditableSpamProtectionField` wrapper which you can add
|
||||
to your UserForm instances. After installing this module and running `/dev/build`
|
||||
to rebuild the database, your Form Builder interface will have an option for
|
||||
`Spam Protection Field`. The type of spam protection used will be based on your
|
||||
currently selected SpamProtector instance.
|
||||
@ -119,8 +131,13 @@ Spam protection is useful to provide but in some cases we do not want to require
|
||||
the developer to use spam protection. In that case, modules can provide the
|
||||
following pattern
|
||||
|
||||
$form = new Form(..);
|
||||
```php
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
|
||||
|
||||
if($form->hasExtension('FormSpamProtectionExtension')) {
|
||||
$form = new Form(/* .. */);
|
||||
|
||||
if ($form->hasExtension(FormSpamProtectionExtension::class)) {
|
||||
$form->enableSpamProtection();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src/.</directory>
|
||||
<directory suffix=".php">code/</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">tests/</directory>
|
||||
</exclude>
|
||||
|
Loading…
Reference in New Issue
Block a user