mirror of
https://github.com/silverstripe/silverstripe-spamprotection.git
synced 2024-09-27 20:06:22 +02:00
Created 0.3-rc1 release
This commit is contained in:
parent
c8038e931e
commit
3a24a39cfc
8
0.3-rc1/CHANGELOG
Normal file
8
0.3-rc1/CHANGELOG
Normal file
@ -0,0 +1,8 @@
|
||||
0.1:
|
||||
- initial release
|
||||
|
||||
0.2
|
||||
- Renamed 'SpamProtecterManager' to 'SpamProtectorManager'. Note the typo with the 'er'
|
||||
|
||||
0.3 (trunk)
|
||||
- Updated Error Reporting to be a bit more verbose
|
38
0.3-rc1/INSTALL
Normal file
38
0.3-rc1/INSTALL
Normal file
@ -0,0 +1,38 @@
|
||||
SilverStripe SpamProtection Module 0.1 beta
|
||||
=======================================
|
||||
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
1. Unzip this file (spamprotection-0.1.tar.gz) inside your SilverStripe installation directory.
|
||||
It should be at the same level as 'jsparty', 'cms' and 'sapphire' modules.
|
||||
|
||||
2. Ensure the directory name for the module is 'spamprotection'.
|
||||
|
||||
3. Visit your SilverStripe site in a webbrowser and run www.yoursite.com/dev/build
|
||||
|
||||
5. We now need to setup some basic features to get the module up and running. Open up _config.php
|
||||
inside project directory (typically 'mysite/_config.php') with your favourite text editor.
|
||||
Read the instructions below to setup the initial configuration of the module.
|
||||
|
||||
|
||||
SETTING UP THE MODULE (in 'mysite/_config.php')
|
||||
------------------------------------------------------
|
||||
|
||||
Before putting the following code in '_config.php', make sure you have a subclass of 'SpamProtectorField' installed or written. One
|
||||
example of 'SpamProtector' subclass is 'MollomField'.
|
||||
|
||||
SpamProtectorManager::set_spam_protector('MollomSpamProtector');
|
||||
|
||||
|
||||
UPDATING A FORM TO INCLUDE THE SPAM PROTECTOR FIELD
|
||||
---------------------------------------------------
|
||||
|
||||
This following code should appear after the form creation.
|
||||
|
||||
$protector = SpamProtectorManager::update_form($form, 'Message');
|
||||
|
||||
This code add an instance of a 'SpamProtectorField' class specified in SETTING UP THE MODULE section. The newly created field will have
|
||||
MollomField field. The first parameter is a Form object in which the field will be added into and the second parameter tells
|
||||
SpamProtectorManagor to place the new field before a field named 'Message'.
|
30
0.3-rc1/README
Normal file
30
0.3-rc1/README
Normal file
@ -0,0 +1,30 @@
|
||||
###############################################
|
||||
SpamProtection Module
|
||||
###############################################
|
||||
|
||||
Maintainer Contact
|
||||
-----------------------------------------------
|
||||
Saophalkun Ponlu
|
||||
<phalkunz (at) silverstripe (dot) com>
|
||||
|
||||
Will Rossiter
|
||||
<will (at) silverstripe (dot) com>
|
||||
|
||||
Requirements
|
||||
-----------------------------------------------
|
||||
SilverStripe 2.3
|
||||
|
||||
Documentation
|
||||
-----------------------------------------------
|
||||
http://doc.silverstripe.com/doku.php?id=modules:spamprotection
|
||||
|
||||
Installation Instructions
|
||||
-----------------------------------------------
|
||||
See INSTALL
|
||||
|
||||
Usage Overview
|
||||
-----------------------------------------------
|
||||
See INSTALL
|
||||
|
||||
Known issues
|
||||
-----------------------------------------------
|
3
0.3-rc1/_config.php
Normal file
3
0.3-rc1/_config.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
?>
|
33
0.3-rc1/code/EditableSpamProtectionField.php
Normal file
33
0.3-rc1/code/EditableSpamProtectionField.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Editable Spam Protecter Field. Used with the User Defined Forms module (if
|
||||
* installed) to allow the user to have captcha fields with their custom forms
|
||||
*
|
||||
* @package spamprotection
|
||||
*/
|
||||
|
||||
class EditableSpamProtectionField extends EditableFormField {
|
||||
|
||||
static $singular_name = 'Spam Protection Field';
|
||||
|
||||
static $plural_name = 'Spam Protection Fields';
|
||||
|
||||
function getFormField() {
|
||||
if($protector = SpamProtectorManager::get_spam_protector()) {
|
||||
if($protector) {
|
||||
$protector = new $protector();
|
||||
return $protector->getFormField($this->Name, $this->Title, null);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function Icon() {
|
||||
return 'spamprotection/images/' . strtolower($this->class) . '.png';
|
||||
}
|
||||
|
||||
function showInReports() {
|
||||
return false;
|
||||
}
|
||||
}
|
23
0.3-rc1/code/SpamProtector.php
Normal file
23
0.3-rc1/code/SpamProtector.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Spam Protector base interface. All Protectors should implement this interface
|
||||
* to ensure that they contain all the correct methods.
|
||||
*
|
||||
* @package spamprotection
|
||||
*/
|
||||
|
||||
interface SpamProtector {
|
||||
|
||||
/**
|
||||
* Return the Field Associated with this protector
|
||||
*/
|
||||
public function getFormField($name = null, $title = null, $value = null, $form = null, $rightTitle = null);
|
||||
|
||||
/**
|
||||
* Function required to handle dynamic feedback of the system.
|
||||
* if unneeded just return true
|
||||
*/
|
||||
public function sendFeedback($object = null, $feedback = "");
|
||||
|
||||
}
|
34
0.3-rc1/code/SpamProtectorField.php
Normal file
34
0.3-rc1/code/SpamProtectorField.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* This class acts as a template for spam protecting form field, for instance MollomField.
|
||||
*
|
||||
* @package spamprotection
|
||||
*/
|
||||
abstract class SpamProtectorField extends FormField {
|
||||
|
||||
/**
|
||||
* Fields to map spam protection too.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $spamFieldMapping = array();
|
||||
|
||||
|
||||
/**
|
||||
* Set the fields to map spam protection too
|
||||
*
|
||||
* @param Array array of Field Names, where the indexes of the array are the field names of the form and the values are the field names of the spam/captcha service
|
||||
*/
|
||||
public function setFieldMapping($array) {
|
||||
$this->spamFieldMapping = $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields that are mapped via spam protection
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getFieldMapping() {
|
||||
return $this->spamFieldMapping;
|
||||
}
|
||||
}
|
95
0.3-rc1/code/SpamProtectorManager.php
Normal file
95
0.3-rc1/code/SpamProtectorManager.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class is responsible for setting an system-wide spam protector field
|
||||
* and add the protecter field to a form.
|
||||
*
|
||||
* @package spamprotection
|
||||
*/
|
||||
|
||||
class SpamProtectorManager {
|
||||
|
||||
/**
|
||||
* Current Spam Protector used on the site
|
||||
*
|
||||
* @var SpamProtector
|
||||
*/
|
||||
private static $spam_protector = null;
|
||||
|
||||
/**
|
||||
* Set the name of the spam protecter class
|
||||
*
|
||||
* @param String the name of protecter field class
|
||||
*/
|
||||
public static function set_spam_protector($protector) {
|
||||
self::$spam_protector = $protector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the spam protector class
|
||||
*/
|
||||
public static function get_spam_protector() {
|
||||
return self::$spam_protector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the spam protector field to a form
|
||||
* @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 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
|
||||
* @param String Title for the captcha field
|
||||
* @param String RightTitle for the captcha field
|
||||
* @return SpamProtector object on success or null if the spamprotector class is not found
|
||||
* also null if spamprotectorfield creation fails.
|
||||
*/
|
||||
static function update_form($form, $before = null, $fieldsToSpamServiceMapping = array(), $title = null, $rightTitle = null) {
|
||||
$protectorClass = self::get_spam_protector();
|
||||
|
||||
// Don't update if no protector is set
|
||||
if(!$protectorClass) return false;
|
||||
|
||||
if(!class_exists($protectorClass)) {
|
||||
return user_error("Spam Protector class '$protectorClass' does not exist. Please define a valid Spam Protector", E_USER_WARNING);
|
||||
}
|
||||
|
||||
try {
|
||||
$protector = new $protectorClass();
|
||||
$field = $protector->getFormField("Captcha", $title, null, $form, $rightTitle);
|
||||
|
||||
if($field) {
|
||||
// update the mapping
|
||||
$field->setFieldMapping($fieldsToSpamServiceMapping);
|
||||
|
||||
// add the form field
|
||||
if($before && $form->Fields()->fieldByName($before)) {
|
||||
$form->Fields()->insertBefore($field, $before);
|
||||
}
|
||||
else {
|
||||
$form->Fields()->push($field);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
return user_error("SpamProtectorManager::update_form(): '$protectorClass' is not correctly set up. " . $e, E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Feedback to the Spam Protection. The level of feedback
|
||||
* will depend on the Protector class.
|
||||
*
|
||||
* @param DataObject The Object which you want to send feedback about. Must have a
|
||||
* SessionID field.
|
||||
* @param String Feedback on the $object usually 'spam' or 'ham' for non spam entries
|
||||
*/
|
||||
static function send_feedback($object, $feedback) {
|
||||
$protectorClass = self::get_spam_protector();
|
||||
|
||||
if(!$protectorClass) return false;
|
||||
|
||||
$protector = new $protectorClass();
|
||||
return $protector->sendFeedback($object, $feedback);
|
||||
}
|
||||
}
|
BIN
0.3-rc1/images/editablespamprotectionfield.png
Normal file
BIN
0.3-rc1/images/editablespamprotectionfield.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
0
0.3-rc1/lang/_manifest_exclude
Normal file
0
0.3-rc1/lang/_manifest_exclude
Normal file
16
0.3-rc1/lang/en_US.php
Normal file
16
0.3-rc1/lang/en_US.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
global $lang;
|
||||
|
||||
$lang['en_US']['EditableSpamProtectionField']['PLURALNAME'] = array(
|
||||
'Spam Protection Fields',
|
||||
50,
|
||||
'Pural name of the object, used in dropdowns and to generally identify a collection of this object in the interface'
|
||||
);
|
||||
$lang['en_US']['EditableSpamProtectionField']['SINGULARNAME'] = array(
|
||||
'Spam Protection Field',
|
||||
50,
|
||||
'Singular name of the object, used in dropdowns and to generally identify a single object in the interface'
|
||||
);
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user