From 05208f0aba322ba2e1c99e522edd8298b0ec5192 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 25 Mar 2009 02:14:26 +0000 Subject: [PATCH] FEATURE: added ability to create a spam protector field in user defined forms --- INSTALL | 6 +- code/EditableSpamProtectionField.php | 84 +++++++++++++++++++++++ code/SpamProtecterManager.php | 7 ++ code/SpamProtector.php | 15 ++++ images/editablespamprotectionfield.png | Bin 0 -> 2526 bytes templates/EditableSpamProtectionField.ss | 20 ++++++ 6 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 code/EditableSpamProtectionField.php create mode 100644 images/editablespamprotectionfield.png create mode 100644 templates/EditableSpamProtectionField.ss diff --git a/INSTALL b/INSTALL index 85e2b12..da8ab6e 100644 --- a/INSTALL +++ b/INSTALL @@ -48,6 +48,6 @@ $protector = SpamProtecterManager::update_form($form, 'Message'); What does this do? ------------------ -This code add an instance of a 'SpamProtecterField' 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 SpamProtecterManager to place the new field before a field named 'Message'. The last parameter is an object that get notified when the spam verification is done and given the form object. - -The purpose of having callback object is we can process the submission differently according to the spam status of the submission. For example, put any submission with 'spam' status into spam queue. +This code add an instance of a 'SpamProtecterField' 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 +SpamProtecterManager to place the new field before a field named 'Message'. diff --git a/code/EditableSpamProtectionField.php b/code/EditableSpamProtectionField.php new file mode 100644 index 0000000..f663b64 --- /dev/null +++ b/code/EditableSpamProtectionField.php @@ -0,0 +1,84 @@ +ID]"; + + $extraFields = new FieldSet(); + + foreach( parent::ExtraOptions() as $extraField ) + $extraFields->push( $extraField ); + + if( $this->readonly ) + $extraFields = $extraFields->makeReadonly(); + + return $extraFields; + } + + function populateFromPostData($data) { + parent::populateFromPostData($data); + } + + function getFormField() { + return $this->createField(); + } + + function getFilterField() { + return $this->createField(true); + } + + function createField() { + if($protector = SpamProtecterManager::get_spam_protecter()) { + if($protector) { + $protector = new $protector(); + if($class = $protector->getFieldName()) { + $spamProtection = new $class($class, $this->Title); + if($spamProtection) { + // set field mapping for all the fields in this form. + // fields should have the same ParentID as this + $fields = DataObject::get("EditableTextField", "ParentID = '$this->ParentID'"); + $fields = ($fields) ? $fields->toArray('Name') : null; + + // @TODO get FieldMapping Working. + $spamProtection->setFieldMapping(null, $fields); + return $spamProtection; + } + } + } + } + return false; + } + /** + * Populates the default fields. + */ + function DefaultField() { + return ""; + } + + function EditSegment() { + return $this->renderWith( $this->class ); + } +} +?> \ No newline at end of file diff --git a/code/SpamProtecterManager.php b/code/SpamProtecterManager.php index b7aabf7..a4cfb39 100644 --- a/code/SpamProtecterManager.php +++ b/code/SpamProtecterManager.php @@ -15,6 +15,13 @@ class SpamProtecterManager { self::$spam_protecter = $protecter; } + /** + * Get the name of the spam protector class + */ + static function get_spam_protecter() { + return self::$spam_protecter; + } + /** * Add the spam protecter field to a form * @param Form the form that the protecter field added into diff --git a/code/SpamProtector.php b/code/SpamProtector.php index 0e08c62..52d8836 100644 --- a/code/SpamProtector.php +++ b/code/SpamProtector.php @@ -10,10 +10,25 @@ 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); } ?> \ No newline at end of file diff --git a/images/editablespamprotectionfield.png b/images/editablespamprotectionfield.png new file mode 100644 index 0000000000000000000000000000000000000000..746b7ca5032e79898cdfdd90b7d6c0766bc7c18b GIT binary patch literal 2526 zcmV<42_g20P)L>#00*)> z;>xhl5jZRM3|*39%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MORE', 'More options') %> + <% _t('DELETE', 'Delete this field') %> +
+
+
+ $DefaultField +
+ <% control ExtraOptions %> + $FieldHolder + <% end_control %> +
+ + + + \ No newline at end of file