1 <?php
2
3 4 5 6 7 8
9
10 class SpamProtectorManager {
11
12 13 14 15 16
17 private static $spam_protector = null;
18
19 20 21 22 23
24 public static function set_spam_protector($protector) {
25 self::$spam_protector = $protector;
26 }
27
28 29 30
31 public static function get_spam_protector() {
32 return self::$spam_protector;
33 }
34
35 36 37 38 39 40 41 42 43 44 45 46
47 static function update_form($form, $before = null, $fieldsToSpamServiceMapping = array(), $title = null, $rightTitle = null) {
48 $protectorClass = self::get_spam_protector();
49
50
51 if(!$protectorClass) return false;
52
53 if(!class_exists($protectorClass)) {
54 return user_error("Spam Protector class '$protectorClass' does not exist. Please define a valid Spam Protector", E_USER_WARNING);
55 }
56
57 try {
58 if ($title === null)
59 $title = _t('EditableSpamProtectionField.FORM_TITLE', 'Enter a code');
60
61 $protector = new $protectorClass();
62 $field = $protector->getFormField("Captcha", $title, null, $form, $rightTitle);
63
64 if($field) {
65
66 $field->setFieldMapping($fieldsToSpamServiceMapping);
67
68
69 if($before && $form->Fields()->fieldByName($before)) {
70 $form->Fields()->insertBefore($field, $before);
71 }
72 else {
73 $form->Fields()->push($field);
74 }
75 }
76
77 } catch (Exception $e) {
78 return user_error("SpamProtectorManager::update_form(): '$protectorClass' is not correctly set up. " . $e, E_USER_WARNING);
79 }
80 }
81
82 83 84 85 86 87 88 89
90 static function send_feedback($object, $feedback) {
91 $protectorClass = self::get_spam_protector();
92
93 if(!$protectorClass) return false;
94
95 $protector = new $protectorClass();
96 return $protector->sendFeedback($object, $feedback);
97 }
98 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-