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
|
/.gitignore export-ignore
|
||||||
/.travis.yml export-ignore
|
/.travis.yml export-ignore
|
||||||
/.scrutinizer.yml export-ignore
|
/.scrutinizer.yml export-ignore
|
||||||
|
/codecov.yml export-ignore
|
||||||
|
@ -25,7 +25,7 @@ before_script:
|
|||||||
script:
|
script:
|
||||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
|
- 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 [[ $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:
|
after_success:
|
||||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
||||||
|
87
README.md
87
README.md
@ -39,17 +39,21 @@ spam protection hooks with that protector.
|
|||||||
|
|
||||||
*mysite/_config/spamprotection.yml*
|
*mysite/_config/spamprotection.yml*
|
||||||
|
|
||||||
---
|
```yaml
|
||||||
name: spamprotection
|
---
|
||||||
---
|
name: spamprotection
|
||||||
FormSpamProtectionExtension:
|
---
|
||||||
default_spam_protector: MollomSpamProtector
|
SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension:
|
||||||
|
default_spam_protector: MollomSpamProtector
|
||||||
|
```
|
||||||
|
|
||||||
To add spam protection to your form instance call `enableSpamProtection`.
|
To add spam protection to your form instance call `enableSpamProtection`.
|
||||||
|
|
||||||
// your existing form code
|
```php
|
||||||
$form = new Form( .. );
|
// your existing form code
|
||||||
$form->enableSpamProtection();
|
$form = new Form(/* .. */);
|
||||||
|
$form->enableSpamProtection();
|
||||||
|
```
|
||||||
|
|
||||||
The logic to perform the actual spam validation is controlled by each of the
|
The logic to perform the actual spam validation is controlled by each of the
|
||||||
individual `SpamProtector` implementation since they each require a different
|
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.
|
`enableSpamProtection` takes a hash of optional configuration values.
|
||||||
|
|
||||||
$form->enableSpamProtection(array(
|
```php
|
||||||
'protector' => 'MathSpamProtector',
|
$form->enableSpamProtection(array(
|
||||||
'name' => 'Captcha'
|
'protector' => MathSpamProtector::class,
|
||||||
));
|
'name' => 'Captcha'
|
||||||
|
));
|
||||||
|
```
|
||||||
|
|
||||||
Options to configure are:
|
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
|
*`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:
|
field names. The list of standardized fields to pass to the spam protector are:
|
||||||
|
|
||||||
title
|
```
|
||||||
body
|
title
|
||||||
contextUrl
|
body
|
||||||
contextTitle
|
contextUrl
|
||||||
authorName
|
contextTitle
|
||||||
authorMail
|
authorName
|
||||||
authorUrl
|
authorMail
|
||||||
authorIp
|
authorUrl
|
||||||
authorId
|
authorIp
|
||||||
|
authorId
|
||||||
|
```
|
||||||
|
|
||||||
## Defining your own `SpamProtector`
|
## 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
|
`FormField` to be inserted into the `Form`. The `FormField` returned should be
|
||||||
in charge of the validation process.
|
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) {
|
class CustomSpamProtector implements SpamProtector
|
||||||
// CaptchaField is a imagined class which has some functionality.
|
{
|
||||||
// See silverstripe-mollom module for an example.
|
public function getFormField($name = null, $title = null, $value = null)
|
||||||
return new CaptchaField($name, $title, $value);
|
{
|
||||||
}
|
// 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
|
## Using Spam Protection with User Forms
|
||||||
|
|
||||||
This module provides an EditableSpamProtectionField wrapper which you can add
|
This module provides an `EditableSpamProtectionField` wrapper which you can add
|
||||||
to your UserForm instances. After installing this module and running /dev/build
|
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
|
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
|
`Spam Protection Field`. The type of spam protection used will be based on your
|
||||||
currently selected SpamProtector instance.
|
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
|
the developer to use spam protection. In that case, modules can provide the
|
||||||
following pattern
|
following pattern
|
||||||
|
|
||||||
$form = new Form(..);
|
```php
|
||||||
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
|
||||||
|
|
||||||
if($form->hasExtension('FormSpamProtectionExtension')) {
|
$form = new Form(/* .. */);
|
||||||
$form->enableSpamProtection();
|
|
||||||
}
|
if ($form->hasExtension(FormSpamProtectionExtension::class)) {
|
||||||
|
$form->enableSpamProtection();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||||
<directory suffix=".php">src/.</directory>
|
<directory suffix=".php">code/</directory>
|
||||||
<exclude>
|
<exclude>
|
||||||
<directory suffix=".php">tests/</directory>
|
<directory suffix=".php">tests/</directory>
|
||||||
</exclude>
|
</exclude>
|
||||||
|
Loading…
Reference in New Issue
Block a user