Created 0.2-rc1 release

This commit is contained in:
Will Rossiter 2009-07-06 08:14:27 +00:00
parent 141fda6491
commit c8038e931e
8 changed files with 271 additions and 0 deletions

53
0.2-rc1/INSTALL Normal file
View File

@ -0,0 +1,53 @@
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.
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'.
<<<< CODE STARTS >>>>
SpamProtectorManager::set_spam_protector('MollomSpamProtector');
<<<< CODE ENDS >>>>
What does this do?
------------------
This tell 'SpamProtection' module that you want to use 'MollomField' as a spam protection module across your site.
UPDATING A FORM TO INCLUDE THE SPAM PROTECTOR FIELD
---------------------------------------------------
This following code should appear after the form creation.
<<<< CODE STARTS >>>>
$protector = SpamProtectorManager::update_form($form, 'Message');
<<<< CODE ENDS >>>>
What does this do?
------------------
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'.

24
0.2-rc1/README Normal file
View File

@ -0,0 +1,24 @@
###############################################
SpamProtection Module
###############################################
Maintainer Contact
-----------------------------------------------
Saophalkun Ponlu
<phalkunz (at) silverstripe (dot) com>
Requirements
-----------------------------------------------
Documentation
-----------------------------------------------
Installation Instructions
-----------------------------------------------
See INSTALL
Usage Overview
-----------------------------------------------
Known issues
-----------------------------------------------

3
0.2-rc1/_config.php Normal file
View File

@ -0,0 +1,3 @@
<?php
?>

View File

@ -0,0 +1,50 @@
<?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 __construct( $record = null, $isSingleton = false ) {
parent::__construct( $record, $isSingleton );
}
function getFormField() {
return $this->createField();
}
function getFilterField() {
return $this->createField(true);
}
function createField() {
if($protector = SpamProtectorManager::get_spam_protector()) {
if($protector) {
$protector = new $protector();
if($class = $protector->getFieldName()) {
return new $class($class, $this->Title);
}
}
}
return false;
}
/**
* @return string
*/
public function Icon() {
return 'spamprotection/images/' . strtolower($this->class) . '.png';
}
function showInReports() {
return false;
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Spam Protector base interface. All Protectors should implement this interface
* to ensure that they contain all the correct methods and we do not get too many
* odd missing function errors
*
* @package SpamProtection
*/
interface SpamProtector {
/**
* Return the name of the Field Associated with this protector
*/
public function getFieldName();
/**
* Function required to handle dynamic feedback of the system.
* if unneeded just return true
*/
public function sendFeedback($object = null, $feedback = "");
/**
* Updates the form with the given protection
*/
public function updateForm($form, $before = null, $fieldsToSpamServiceMapping = null);
/**
* Set which fields need to be mapped for protection
*/
public function setFieldMapping($fieldToPostTitle, $fieldsToPostBody = null, $fieldToAuthorName = null, $fieldToAuthorUrl = null, $fieldToAuthorEmail = null, $fieldToAuthorOpenId = null);
}
?>

View 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 SpamProtectorField 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());
}
}
}
?>

View File

@ -0,0 +1,67 @@
<?php
/**
* This class is responsible for setting an system-wide spam protecter field
* and add the protecter field to a form
*/
class SpamProtectorManager {
static $spam_protector = null;
/**
* Set the name of the spam protecter class
* @param string the name of protecter field class
*/
static function set_spam_protector($protector) {
self::$spam_protector = $protector;
}
/**
* Get the name of the spam protector class
*/
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 (seperated by comma) as a value.
* The naming of the fields is based on the implementation of the subclass of SpamProtectorField.
* *** Most of the web service doesn't require this.
* @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=null) {
$check = null;
$protectorClass = self::$spam_protector;
if(!class_exists($protectorClass)) return null;
$protector = new $protectorClass();
try {
$check = $protector->updateForm($form, $before, $fieldsToSpamServiceMapping);
} catch (Exception $e) {
user_error("SpamProtectorManager::update_form(): '$protectorClass' is not correctly set up.", E_USER_WARNING);
}
if(!$check) return null;
return $protector;
}
/**
* 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) {
$protector = new self::$spam_protector();
return $protector->sendFeedback($object, $feedback);
}
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB