Skip to content

Commit

Permalink
Merge pull request #10 from heyday/master
Browse files Browse the repository at this point in the history
SilverStripe 4 Upgrade
  • Loading branch information
camspiers authored Aug 14, 2019
2 parents 297dee3 + d8f1a56 commit 2ba40f8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 19 deletions.
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
# SilverStripe honeypot
# SilverStripe Honey Pot

For a SilverStripe `2.4` compatible version use the branch `1.0`
A SilverStripe 4.x compatible version of camspiers/honeypot

## Installation (with composer)

$ composer require camspiers/honeypot
$ composer require heyday/silverstripe-honeypot

Set the default spam protector in *mysite/_config/spamprotection.yml*
Set the default spam protector in *app/_config/spamprotection.yml*

---
name: spamprotection
---
FormSpamProtectionExtension:
default_spam_protector: HoneyPotSpamProtector
SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension:
default_spam_protector: Heyday\SilverStripe\HoneyPot\HoneyPotSpamProtector

Or, on a form by form basis

use Heyday\SilverStripe\HoneyPot\HoneyPotField;
use SilverStripe\Forms\Form;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\FieldList;

/**
* Class SomeForm
*/
class SomeForm extends Form
{
/**
* @param Controller $controller
*/
public function __construct(Controller $controller)
{
$fields = new FieldList();
$fields->push(new HoneyPotField('Website')); // 'Website' here can be any old string
...
}
}
16 changes: 16 additions & 0 deletions code/HoneyPotField.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?php

namespace Heyday\SilverStripe\HoneyPot;

use SilverStripe\Forms\TextField;

/**
* Class HoneyPotField
* @package Heyday\SilverStripe\HoneyPot
*/
class HoneyPotField extends TextField
{

/**
* @param \SilverStripe\Forms\Validator $validator
* @return bool
*/
public function validate($validator)
{
if (!(is_null($this->value) || $this->value === '')) {
Expand All @@ -18,6 +30,10 @@ public function validate($validator)
return true;
}

/**
* @param array $properties
* @return \SilverStripe\ORM\FieldType\DBHTMLText
*/
public function FieldHolder($properties = array())
{
return $this->renderWith('HoneyPotField_holder');
Expand Down
26 changes: 15 additions & 11 deletions code/HoneyPotSpamProtector.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<?php

/**
* @package honeypot
*/
namespace Heyday\SilverStripe\HoneyPot;

use SilverStripe\SpamProtection\SpamProtector;

class HoneyPotSpamProtector implements SpamProtector {

/**
* Returns the {@link HoneyPotField} associated with this protector
*
* @return HoneyPotField
*/
/**
* Returns the {@link HoneyPotField} associated with this protector
*
* @param null $name
* @param null $title
* @param null $value
* @return HoneyPotField
*/
public function getFormField($name = null, $title = null, $value = null) {
return new HoneyPotField($name, $title, $value);
}

/**
* Not used by HoneyPotSpamProtector
*/
/**
* Not used by HoneyPotSpamProtector
* @param $fieldMapping
*/
public function setFieldMapping($fieldMapping) {}

}
File renamed without changes.
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"name": "camspiers/honeypot",
"name": "heyday/silverstripe-honeypot",
"type": "silverstripe-module",
"require": {
"silverstripe/spamprotection": "~2.0.0",
"silverstripe/spamprotection": "~3.0.0",
"composer/installers": "~1.0"
},
"autoload": {
"psr-4": {
"Heyday\\SilverStripe\\HoneyPot\\": "code/"
}
}
}

0 comments on commit 2ba40f8

Please sign in to comment.