mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-10-22 14:05:59 +02:00
importing spam protection module
This commit is contained in:
commit
1a84fac482
3
_config.php
Normal file
3
_config.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
?>
|
80
code/MollomProtecter_Backup.php
Normal file
80
code/MollomProtecter_Backup.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This class acts as a template for spam protecting form field, for instance MollomField.
|
||||||
|
* It provides a number of properties for mapping fields of the form which this object belongs to
|
||||||
|
* to spam checking service fields.
|
||||||
|
*
|
||||||
|
* In order to further process the form values or take any action according the status of spam checking,
|
||||||
|
* markAsSpam() and markAsHam should be called in validate() after the status of the spam checking has
|
||||||
|
* been obtained.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SpamProtecterField_Backup extends FormField {
|
||||||
|
|
||||||
|
protected $spanControlCallbackObj = null;
|
||||||
|
|
||||||
|
function setCallbackObject($callbackObject) {
|
||||||
|
$this->spanControlCallbackObj = $callbackObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Map fields (by name) to Spam service's fields for spam checking */
|
||||||
|
protected $fieldToPostTitle = "";
|
||||||
|
|
||||||
|
// it can be more than one fields mapped to post content
|
||||||
|
protected $fieldsToPostBody = array();
|
||||||
|
|
||||||
|
protected $fieldToAuthorName = "";
|
||||||
|
|
||||||
|
protected $fieldToAuthorUrl = "";
|
||||||
|
|
||||||
|
protected $fieldToAuthorEmail = "";
|
||||||
|
|
||||||
|
protected $fieldToAuthorOpenId = "";
|
||||||
|
|
||||||
|
function setFieldToPostTitle($fieldName) {
|
||||||
|
$this->fieldToPostTitle = $fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map array of fields where their value will be used as a mollom post body
|
||||||
|
* @param array
|
||||||
|
*/
|
||||||
|
function setFieldsToPostBody($fieldNames) {
|
||||||
|
$this->fieldsToPostBody = $fieldNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setfieldToAuthorName($fieldName) {
|
||||||
|
$this->fieldToAuthorName = $fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFieldToAuthorUrl($fieldName) {
|
||||||
|
$this->fieldToAuthorUrl = $fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFieldToAuthorEmail($fieldName) {
|
||||||
|
$this->fieldToAuthorEmail = $fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFieldToAuthorOpenId($fieldName) {
|
||||||
|
$this->fieldToAuthorOpenId = $fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the callback object the spam checking response status
|
||||||
|
*/
|
||||||
|
protected function markAsSpam() {
|
||||||
|
if ($this->spanControlCallbackObj && $this->spanControlCallbackObj instanceof Spamable) {
|
||||||
|
$this->spanControlCallbackObj->markAsSpam($this->getForm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the callback object the spam checking response status
|
||||||
|
*/
|
||||||
|
protected function markAsHam() {
|
||||||
|
if ($this->spanControlCallbackObj && $this->spanControlCallbackObj instanceof Spamable) {
|
||||||
|
$this->spanControlCallbackObj->markAsHam($this->getForm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
47
code/SpamProctecterManager.php
Normal file
47
code/SpamProctecterManager.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This class is responsible for setting an system-wide spam protecter field
|
||||||
|
* and add the protecter field to a form
|
||||||
|
*/
|
||||||
|
class SpamProctecterManager {
|
||||||
|
|
||||||
|
static $spam_protecter = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the name of the spam protecter class
|
||||||
|
* @param string the name of protecter field class
|
||||||
|
*/
|
||||||
|
static function set_spam_protecter($protecter) {
|
||||||
|
self::$spam_protecter = $protecter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the spam protecter field to a form
|
||||||
|
* @param string the name of the protecter field
|
||||||
|
* @param string the title of the protecter field
|
||||||
|
* @param Form the form that the protecter field added into
|
||||||
|
* @param string the name of the field that the protecter field will be added in front of
|
||||||
|
* @param object an object that implements Spamable
|
||||||
|
* @param array an associative array
|
||||||
|
* with the name of the spam web service's field, for example post_title, post_body, author_name
|
||||||
|
* and a string of field names (seperated by comma) as a value.
|
||||||
|
* The naming of the fields is based on the implementation of the subclass of SpamProtecterField.
|
||||||
|
* *** Most of the web service doesn't require this.
|
||||||
|
* @return SpamProtecterField
|
||||||
|
*/
|
||||||
|
static function update_form($protecterFieldName, $protecterFieldTitle, $form, $before=null, $callbackObject=null, $fieldsToSpamServiceMapping=null) {
|
||||||
|
|
||||||
|
$protecterField = new self::$spam_protecter($protecterFieldName, $protecterFieldTitle);
|
||||||
|
$protecterField->setCallbackObject($callbackObject);
|
||||||
|
|
||||||
|
if ($before && $fields->fieldByName($before)) {
|
||||||
|
$form->Fields()->insertBefore($protecterField, $before);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$form->Fields()->push($protecterField);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $protecterField;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
40
code/SpamProtecterField.php
Normal file
40
code/SpamProtecterField.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This class acts as a template for spam protecting form field, for instance MollomField.
|
||||||
|
* It provides a number of properties for mapping fields of the form which this object belongs to
|
||||||
|
* to spam checking service fields.
|
||||||
|
*
|
||||||
|
* In order to further process the form values or take any action according the status of spam checking,
|
||||||
|
* markAsSpam() and markAsHam should be called in validate() after the status of the spam checking has
|
||||||
|
* been obtained.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SpamProtecterField extends FormField {
|
||||||
|
|
||||||
|
protected $spanControlCallbackObj = null;
|
||||||
|
|
||||||
|
function setCallbackObject($callbackObject) {
|
||||||
|
$this->spanControlCallbackObj = $callbackObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the callback object the submission is spam
|
||||||
|
*/
|
||||||
|
protected function markAsSpam() {
|
||||||
|
if ($this->spanControlCallbackObj && $this->spanControlCallbackObj instanceof Spamable) {
|
||||||
|
$this->spanControlCallbackObj->markAsSpam($this->getForm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the callback object the submission is ham
|
||||||
|
*/
|
||||||
|
protected function markAsHam() {
|
||||||
|
if ($this->spanControlCallbackObj && $this->spanControlCallbackObj instanceof Spamable) {
|
||||||
|
$this->spanControlCallbackObj->markAsHam($this->getForm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
12
code/Spamable.php
Normal file
12
code/Spamable.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This interface acts an template for setting up a spam callback class
|
||||||
|
*/
|
||||||
|
interface Spamable {
|
||||||
|
|
||||||
|
function markAsSpam($form);
|
||||||
|
|
||||||
|
function markAsHam($form):
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user