APICHANGE: added SpamProtector interface for spam protectors;

MINOR: Fixed instructions
This commit is contained in:
Will Rossiter 2009-03-11 04:42:21 +00:00
parent c2be8dbee5
commit ca8c02b531
3 changed files with 29 additions and 8 deletions

View File

@ -41,7 +41,7 @@ This following code should appear after the form creation.
<<<< CODE STARTS >>>>
$protector = SpamProtecterManager::update_form($form, 'Message', $callbackObj);
$protector = SpamProtecterManager::update_form($form, 'Message');
<<<< CODE ENDS >>>>

View File

@ -19,7 +19,6 @@ class SpamProtecterManager {
* Add the spam protecter 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 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.
@ -28,12 +27,12 @@ class SpamProtecterManager {
* @return SpamProtector object on success or null if the spamprotecter class is not found
* also null if spamprotecterfield creation fails.
*/
static function update_form($form, $before=null, $callbackObject=null, $fieldsToSpamServiceMapping=null) {
static function update_form($form, $before=null, $fieldsToSpamServiceMapping=null) {
if (!class_exists(self::$spam_protecter)) return null;
$protecter = new self::$spam_protecter();
try {
$check = $protecter->updateForm($form, $before, $callbackObject, $fieldsToSpamServiceMapping);
$check = $protecter->updateForm($form, $before, $fieldsToSpamServiceMapping);
}
catch (Exception $e) {
$form->setMessage(
@ -49,13 +48,16 @@ class SpamProtecterManager {
}
/**
* Mark a DataObject as spam
* Send Feedback to the Spam Protection. The level of feedback
* will depend on the Protector class.
*
* @param DataObject
* @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 mark_spam($object) {
static function send_feedback($object, $feedback) {
$protecter = new self::$spam_protecter();
return $protecter->markAsSpam($object);
return $protecter->sendFeedback($object, $feedback);
}
}
?>

19
code/SpamProtector.php Normal file
View File

@ -0,0 +1,19 @@
<?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 {
public function sendFeedback($object = null, $feedback = "");
public function updateForm($form, $before = null, $fieldsToSpamServiceMapping = null);
public function setFieldMapping($fieldToPostTitle, $fieldsToPostBody = null, $fieldToAuthorName = null, $fieldToAuthorUrl = null, $fieldToAuthorEmail = null, $fieldToAuthorOpenId = null);
}
?>