-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsodom.module
executable file
·105 lines (96 loc) · 4.78 KB
/
sodom.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Protects against comment form spam.
* @author benjamin birkenhake <[email protected]>
*
*/
function sodom_menu() {
$items = array();
// Modules Settings
$items['admin/settings/sodom'] = array(
'title' => 'Sodom Spam Protection',
'description' => 'Several Settings for your Sodom Spam Protection',
'page callback' => 'drupal_get_form',
'page arguments' => array('sodom_admin_settings'),
'access arguments' => array('administer sodom'),
'menu_name' => 'Sodom',
);
return $items;
}
function sodom_admin_settings(){
$form["sodom"] = array();
$options = array("checkbox" => t("Checkbox"), "textfield" => t("Textfield"));
$form["sodom"]["sodom_protection_type"] = array ('#type' => 'select',
'#title' => t('Protection Type'),
'#default_value' => variable_get('sodom_protection_type', "checkbox"),
'#size' => 1,
'#description' => t('Which type of Protection do you need?'),
'#options' => $options,
);
// Checkbox
$form["sodom"]["checkbox"] = array('#type' => 'fieldset', '#title' => t('Checkbox Settings'),);
$form["sodom"]["checkbox"]["sodom_checkbox_title"] = array ('#type' => 'textfield',
'#title' => t('Title of the Checkbox'),
'#default_value' => variable_get('sodom_checkbox_title', t("I am neither a Dog nor a Spambot.")),
'#size' => 50,
'#description' => t('The Title of your Sodom-Spam-Protection-Checkbox'),
);
$form["sodom"]["checkbox"]["sodom_checkbox_error"] = array ('#type' => 'textfield',
'#title' => t('Error-Message of the Checkbox'),
'#default_value' => variable_get('sodom_checkbox_error', t("Your Comment hasn't been saved, because you have to make a check, or are you a Dog or Spambot?!")),
'#size' => 50,
'#description' => t('The Error-Message of your Sodom-Spam-Protection-Checkbox'),
);
// Textfield
$form["sodom"]["textfield"] = array('#type' => 'fieldset', '#title' => t('Textfield Settings'),);
$form["sodom"]["textfield"]["sodom_textfield_question"] = array ('#type' => 'textfield',
'#title' => t('The Question, you want to ask'),
'#default_value' => variable_get('sodom_textfield_question', t("Are you a Dog or a Spambot? Answer with 'Yes' or 'No'")),
'#size' => 50,
'#description' => t('The Question of your Sodom-Spam-Protection-Textfield'),
);
$form["sodom"]["textfield"]["sodom_textfield_answer"] = array ('#type' => 'textfield',
'#title' => t('The Correct Answer to your Question.'),
'#default_value' => variable_get('sodom_textfield_answer', t("No")),
'#size' => 50,
'#description' => t('The Answer of your Sodom-Spam-Protection-Textfield'),
);
$form["sodom"]["textfield"]["sodom_textfield_error"] = array ('#type' => 'textfield',
'#title' => t('Error-Message of the Textfield'),
'#default_value' => variable_get('sodom_textfield_error', t("Your Comment has NOT been saved, because you have to answer the question correctly, or are you a Dog or Spambot?!")),
'#size' => 50,
'#description' => t('The Error-Message of your Sodom-Spam-Protection-Textfield'),
);
return system_settings_form($form);
}
function sodom_form_alter(&$form, &$form_state, $form_id){
//dprint_r($form_state);
global $user;
if($form_id == "comment_form" and $user->uid==0){
if(variable_get('sodom_protection_type', "checkbox")=="checkbox"){
$form['sodom'] = array(
"#type" => "checkbox",
"#title" => variable_get('sodom_checkbox_title', t("I am neither a Dog nor a Spambot.")),
);
}elseif(variable_get('sodom_protection_type', "checkbox")=="textfield"){
$form['sodom'] = array(
"#type" => "textfield",
"#title" => variable_get('sodom_textfield_question', t("Are you a Dog or a Spambot? Answer with 'Yes' or 'No'")),
);
}
}
}
function sodom_comment(&$a1, $op){
global $user;
if(variable_get('sodom_protection_type', "checkbox")=="checkbox"){
if($op== "validate" and $a1['sodom'] == 0 and $user->uid == 0 ){
watchdog("sodom", t("Dog or Spambot Attack")."! <br/> ".t("Name").":".$a1["name"]." <br/> ".t("Comment").": ".$a1["comment"], array(), WATCHDOG_INFO);
form_set_error("sodom", variable_get('sodom_checkbox_error', "Your Comment has NOT been saved, because you have to make a check, or are you a Dog or Spambot?!"));
}
}elseif(variable_get('sodom_protection_type', "checkbox")=="textfield"){
if($op== "validate" and $a1['sodom'] != variable_get('sodom_textfield_answer', t("No")) and $user->uid == 0 ){
watchdog("sodom", t("Dog or Spambot Attack")."! <br/> ".t("Name").":".$a1["name"]." <br/> ".t("Comment").": ".$a1["comment"], array(), WATCHDOG_INFO);
form_set_error("sodom", variable_get('sodom_textfield_error', t("Your Comment has NOT been saved, because you have to answer the question correctly, or are you a Dog or Spambot?!")));
}
}
}