2009-02-03 22:29:55 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This class is responsible for setting an system-wide spam protecter field
|
2009-08-11 04:51:03 +02:00
|
|
|
* and add the protecter field to a form.
|
|
|
|
*
|
|
|
|
* @package spamprotection
|
2009-02-03 22:29:55 +01:00
|
|
|
*/
|
2009-08-11 04:51:03 +02:00
|
|
|
|
2009-06-05 00:57:33 +02:00
|
|
|
class SpamProtectorManager {
|
2009-02-03 22:29:55 +01:00
|
|
|
|
2009-06-05 00:57:33 +02:00
|
|
|
static $spam_protector = null;
|
2009-02-03 22:29:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the name of the spam protecter class
|
2009-08-11 04:51:03 +02:00
|
|
|
*
|
|
|
|
* @param String the name of protecter field class
|
2009-02-03 22:29:55 +01:00
|
|
|
*/
|
2009-06-05 00:57:33 +02:00
|
|
|
static function set_spam_protector($protector) {
|
|
|
|
self::$spam_protector = $protector;
|
2009-02-03 22:29:55 +01:00
|
|
|
}
|
|
|
|
|
2009-03-25 03:14:26 +01:00
|
|
|
/**
|
|
|
|
* Get the name of the spam protector class
|
|
|
|
*/
|
2009-06-05 00:57:33 +02:00
|
|
|
static function get_spam_protector() {
|
|
|
|
return self::$spam_protector;
|
2009-03-25 03:14:26 +01:00
|
|
|
}
|
|
|
|
|
2009-02-03 22:29:55 +01:00
|
|
|
/**
|
2009-06-05 00:57:33 +02:00
|
|
|
* Add the spam protector field to a form
|
2009-02-03 22:29:55 +01:00
|
|
|
* @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.
|
2009-06-05 01:44:08 +02:00
|
|
|
* The naming of the fields is based on the implementation of the subclass of SpamProtectorField.
|
2009-02-03 22:29:55 +01:00
|
|
|
* *** Most of the web service doesn't require this.
|
2009-06-05 01:44:08 +02:00
|
|
|
* @return SpamProtector object on success or null if the spamprotector class is not found
|
|
|
|
* also null if spamprotectorfield creation fails.
|
2009-02-03 22:29:55 +01:00
|
|
|
*/
|
2009-03-11 05:42:21 +01:00
|
|
|
static function update_form($form, $before=null, $fieldsToSpamServiceMapping=null) {
|
2009-05-26 01:26:23 +02:00
|
|
|
$check = null;
|
2009-06-05 00:57:33 +02:00
|
|
|
$protectorClass = self::$spam_protector;
|
2009-08-11 04:51:03 +02:00
|
|
|
|
|
|
|
if(!class_exists($protectorClass)) {
|
|
|
|
user_error("Spam Protector class '$protectorClass' does not exist. Please define a valid Spam Protector", E_USER_WARNING);
|
|
|
|
}
|
2009-02-17 10:03:59 +01:00
|
|
|
|
2009-08-17 00:42:26 +02:00
|
|
|
if(!$protectorClass) return null;
|
|
|
|
|
2009-02-24 01:35:59 +01:00
|
|
|
try {
|
2009-06-05 01:44:08 +02:00
|
|
|
$check = $protector->updateForm($form, $before, $fieldsToSpamServiceMapping);
|
2009-05-26 01:26:23 +02:00
|
|
|
} catch (Exception $e) {
|
2009-08-11 04:51:03 +02:00
|
|
|
user_error("SpamProtectorManager::update_form(): '$protectorClass' is not correctly set up. " . $e, E_USER_WARNING);
|
2009-02-24 01:35:59 +01:00
|
|
|
}
|
2009-02-17 10:03:59 +01:00
|
|
|
|
2009-05-26 01:26:23 +02:00
|
|
|
if(!$check) return null;
|
2009-02-17 10:03:59 +01:00
|
|
|
|
2009-06-05 00:57:33 +02:00
|
|
|
return $protector;
|
2009-02-03 22:29:55 +01:00
|
|
|
}
|
2009-02-16 01:28:53 +01:00
|
|
|
|
|
|
|
/**
|
2009-03-11 05:42:21 +01:00
|
|
|
* Send Feedback to the Spam Protection. The level of feedback
|
|
|
|
* will depend on the Protector class.
|
2009-02-16 01:28:53 +01:00
|
|
|
*
|
2009-03-11 05:42:21 +01:00
|
|
|
* @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
|
2009-02-16 01:28:53 +01:00
|
|
|
*/
|
2009-03-11 05:42:21 +01:00
|
|
|
static function send_feedback($object, $feedback) {
|
2009-06-05 00:57:33 +02:00
|
|
|
$protector = new self::$spam_protector();
|
|
|
|
return $protector->sendFeedback($object, $feedback);
|
2009-02-16 01:28:53 +01:00
|
|
|
}
|
2009-02-03 22:29:55 +01:00
|
|
|
}
|
2009-06-05 00:57:33 +02:00
|
|
|
?>
|