mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
commit
3079188625
@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"SilverStripe\\SpamProtection\\": "code/",
|
"SilverStripe\\SpamProtection\\": "src/",
|
||||||
"SilverStripe\\SpamProtection\\Tests\\": "tests/"
|
"SilverStripe\\SpamProtection\\Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<ruleset name="SilverStripe">
|
<ruleset name="SilverStripe">
|
||||||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
||||||
|
|
||||||
<file>code</file>
|
<file>src</file>
|
||||||
<file>tests</file>
|
<file>tests</file>
|
||||||
|
|
||||||
<rule ref="PSR2" >
|
<rule ref="PSR2" >
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||||
<directory suffix=".php">code/</directory>
|
<directory suffix=".php">src/</directory>
|
||||||
<exclude>
|
<exclude>
|
||||||
<directory suffix=".php">tests/</directory>
|
<directory suffix=".php">tests/</directory>
|
||||||
</exclude>
|
</exclude>
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace SilverStripe\SpamProtection;
|
namespace SilverStripe\SpamProtection;
|
||||||
|
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Core\Convert;
|
|
||||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\FieldGroup;
|
use SilverStripe\Forms\FieldGroup;
|
||||||
@ -41,15 +40,15 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
* @var array
|
* @var array
|
||||||
* @config
|
* @config
|
||||||
*/
|
*/
|
||||||
private static $check_fields = array(
|
private static $check_fields = [
|
||||||
EditableEmailField::class,
|
EditableEmailField::class,
|
||||||
EditableTextField::class,
|
EditableTextField::class,
|
||||||
EditableNumericField::class
|
EditableNumericField::class
|
||||||
);
|
];
|
||||||
|
|
||||||
private static $db = array(
|
private static $db = [
|
||||||
'SpamFieldSettings' => 'Text'
|
'SpamFieldSettings' => 'Text'
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var FormField
|
* @var FormField
|
||||||
@ -69,7 +68,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract saved field mappings and update this field.
|
// Extract saved field mappings and update this field.
|
||||||
$fieldMapping = array();
|
$fieldMapping = [];
|
||||||
foreach ($this->getCandidateFields() as $otherField) {
|
foreach ($this->getCandidateFields() as $otherField) {
|
||||||
$mapSetting = "Map-{$otherField->Name}";
|
$mapSetting = "Map-{$otherField->Name}";
|
||||||
$spamField = $this->spamMapValue($mapSetting);
|
$spamField = $this->spamMapValue($mapSetting);
|
||||||
@ -106,7 +105,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
|
|
||||||
// Get list of all configured classes available for spam detection
|
// Get list of all configured classes available for spam detection
|
||||||
$types = $this->config()->get('check_fields');
|
$types = $this->config()->get('check_fields');
|
||||||
$typesInherit = array();
|
$typesInherit = [];
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
$subTypes = ClassInfo::subclassesFor($type);
|
$subTypes = ClassInfo::subclassesFor($type);
|
||||||
$typesInherit = array_merge($typesInherit, $subTypes);
|
$typesInherit = array_merge($typesInherit, $subTypes);
|
||||||
@ -132,7 +131,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
{
|
{
|
||||||
$fieldMap = json_decode($this->SpamFieldSettings ?? '', true);
|
$fieldMap = json_decode($this->SpamFieldSettings ?? '', true);
|
||||||
if (empty($fieldMap)) {
|
if (empty($fieldMap)) {
|
||||||
$fieldMap = array();
|
$fieldMap = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->record as $key => $value) {
|
foreach ($this->record as $key => $value) {
|
||||||
@ -202,7 +201,7 @@ class EditableSpamProtectionField extends EditableFormField
|
|||||||
{
|
{
|
||||||
$map = json_decode($this->SpamFieldSettings ?? '', true);
|
$map = json_decode($this->SpamFieldSettings ?? '', true);
|
||||||
if (empty($map)) {
|
if (empty($map)) {
|
||||||
$map = array();
|
$map = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($mapSetting, $map ?? [])) {
|
if (array_key_exists($mapSetting, $map ?? [])) {
|
@ -14,19 +14,19 @@ class CommentSpamProtection extends Extension
|
|||||||
{
|
{
|
||||||
public function alterCommentForm(&$form)
|
public function alterCommentForm(&$form)
|
||||||
{
|
{
|
||||||
$form->enableSpamProtection(array(
|
$form->enableSpamProtection([
|
||||||
'name' => 'IsSpam',
|
'name' => 'IsSpam',
|
||||||
'mapping' => array(
|
'mapping' => [
|
||||||
'Name' => 'authorName',
|
'Name' => 'authorName',
|
||||||
'Email' => 'authorEmail',
|
'Email' => 'authorEmail',
|
||||||
'URL' => 'authorUrl',
|
'URL' => 'authorUrl',
|
||||||
'Comment' => 'body',
|
'Comment' => 'body',
|
||||||
'ReturnURL' => 'contextUrl'
|
'ReturnURL' => 'contextUrl'
|
||||||
),
|
],
|
||||||
'checks' => array(
|
'checks' => [
|
||||||
'spam',
|
'spam',
|
||||||
'profanity'
|
'profanity'
|
||||||
)
|
]
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
*
|
*
|
||||||
* @var array $mappable_fields
|
* @var array $mappable_fields
|
||||||
*/
|
*/
|
||||||
private static $mappable_fields = array(
|
private static $mappable_fields = [
|
||||||
'id',
|
'id',
|
||||||
'title',
|
'title',
|
||||||
'body',
|
'body',
|
||||||
@ -48,7 +48,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
'authorUrl',
|
'authorUrl',
|
||||||
'authorIp',
|
'authorIp',
|
||||||
'authorId'
|
'authorId'
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @config
|
* @config
|
||||||
@ -88,7 +88,7 @@ class FormSpamProtectionExtension extends Extension
|
|||||||
* @throws LogicException when get_protector method returns NULL.
|
* @throws LogicException when get_protector method returns NULL.
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
public function enableSpamProtection($options = array())
|
public function enableSpamProtection($options = [])
|
||||||
{
|
{
|
||||||
|
|
||||||
// captcha form field name (must be unique)
|
// captcha form field name (must be unique)
|
Loading…
Reference in New Issue
Block a user