2009-02-03 22:29:55 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This class is responsible for setting an system-wide spam protecter field
|
|
|
|
* and add the protecter field to a form
|
|
|
|
*/
|
2009-02-11 01:27:18 +01:00
|
|
|
class SpamProtecterManager {
|
2009-02-03 22:29:55 +01:00
|
|
|
|
|
|
|
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.
|
2009-02-17 10:03:59 +01:00
|
|
|
* @return SpamProtector object or return null if the spamprotecter class is not found
|
|
|
|
* or spamprotecterfield creation fails.
|
2009-02-03 22:29:55 +01:00
|
|
|
*/
|
2009-02-11 04:47:14 +01:00
|
|
|
static function update_form($form, $before=null, $callbackObject=null, $fieldsToSpamServiceMapping=null) {
|
2009-02-17 10:03:59 +01:00
|
|
|
if (!class_exists(self::$spam_protecter)) return null;
|
|
|
|
|
2009-02-11 04:47:14 +01:00
|
|
|
$protecter = new self::$spam_protecter();
|
2009-02-17 10:03:59 +01:00
|
|
|
$check = $protecter->updateForm($form, $before, $callbackObject, $fieldsToSpamServiceMapping);
|
|
|
|
|
|
|
|
if (!$check) return null;
|
|
|
|
|
2009-02-11 04:47:14 +01:00
|
|
|
return $protecter;
|
2009-02-03 22:29:55 +01:00
|
|
|
}
|
2009-02-16 01:28:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a DataObject as spam
|
|
|
|
*
|
|
|
|
* @param DataObject
|
|
|
|
*/
|
|
|
|
static function mark_spam($object) {
|
|
|
|
$protecter = new self::$spam_protecter();
|
|
|
|
return $protecter->markAsSpam($object);
|
|
|
|
}
|
2009-02-03 22:29:55 +01:00
|
|
|
}
|
|
|
|
?>
|