/[drupal]/contributions/modules/blogspam/blogspam.module
ViewVC logotype

Contents of /contributions/modules/blogspam/blogspam.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Tue Jan 6 13:01:35 2009 UTC (10 months, 2 weeks ago) by chrissearle
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +41 -1 lines
File MIME type: text/x-php
Merge in stats change from 6.x
1 <?php
2 // $Id: blogspam.module,v 1.2 2009/01/06 08:27:24 chrissearle Exp $
3
4 /**
5 * @file
6 *
7 * Use blogspam (http://blogspam.net) for testing comments
8 */
9
10 /**
11 * Implementation of hook_menu().
12 */
13 function blogspam_menu() {
14 $items = array();
15
16 $items['admin/settings/blogspam'] = array(
17 'title' => 'Blogspam',
18 'description' => 'Configure server to use for blogspam.',
19 'page callback' => 'drupal_get_form',
20 'page arguments' => array('blogspam_admin_settings'),
21 'access arguments' => array('administer site configuration'),
22 'type' => MENU_NORMAL_ITEM,
23 );
24
25 return $items;
26 }
27
28 function blogspam_admin_settings() {
29 $form['blogspam_server'] = array(
30 '#type' => 'textfield',
31 '#title' => t('Blogspam server to use'),
32 '#default_value' => variable_get('blogspam_server', 'http://test.blogspam.net:8888/'),
33 '#description' => t('Which blogspam server do you wish to use?'),
34 );
35
36 $form['blogspam_xmlrpc_error'] = array(
37 '#type' => 'radios',
38 '#title' => t('Allow comment post if blogspam server is down?'),
39 '#options' => array(
40 t('Allow all comments'),
41 t('Block all comments')),
42 '#default_value' => variable_get('blogspam_xmlrpc_error', 0),
43 '#description' => t('If the server is down - how should we handle comments?'),
44 );
45
46 $form['blogspam_option_maxlinks'] = array(
47 '#type' => 'textfield',
48 '#title' => t('Link count'),
49 '#default_value' => variable_get('blogspam_option_maxlinks', 10),
50 '#description' => t('If a comment contains this many links or more then it will be rejected.'),
51 );
52
53 $form['blogspam_stats'] = array(
54 '#type' => 'fieldset',
55 '#title' => t('Statistics to date'),
56 );
57
58 $stats = _blogspam_stats();
59
60 $form['blogspam_stats']['ok'] = array(
61 '#type' => 'item',
62 '#title' => t('Accepted'),
63 '#value' => $stats['ok'],
64 );
65
66 $form['blogspam_stats']['spam'] = array(
67 '#type' => 'item',
68 '#title' => t('Rejected as spam'),
69 '#value' => $stats['spam'],
70 );
71
72 return system_settings_form($form);
73 }
74
75 /**
76 * Implementation of hook_comment().
77 */
78 function blogspam_comment($comment, $op) {
79 switch ($op) {
80 case 'validate':
81 global $base_url;
82
83 if (!$comment['author']) {
84 $struct = array(
85 'ip' => ip_address(),
86 'comment' => $comment['comment'],
87 'agent' => $_SERVER['HTTP_USER_AGENT'],
88 'site' => $base_url,
89 'options' => implode(',', array('max-links='. variable_get('blogspam_option_maxlinks', 10))),
90 );
91
92 if ($comment['name']) {
93 $struct['name'] = $comment['name'];
94 }
95
96 if ($comment['mail']) {
97 $struct['email'] = $comment['mail'];
98 }
99
100 if ($comment['subject']) {
101 $struct['subject'] = $comment['subject'];
102 }
103
104 $check = xmlrpc(variable_get('blogspam_server', 'http://test.blogspam.net:8888/'), 'testComment', $struct);
105
106 $xmlrpc_error_flag = variable_get('blogspam_xmlrpc_error', 0);
107
108 if ($check == FALSE) {
109 watchdog('blogspam',
110 "Call to Blogspam checker failed with code %code and message %msg",
111 array('%code' => xmlrpc_errno(), '%msg' => xmlrpc_error_msg()));
112
113 if ($xmlrpc_error_flag == 1) {
114 form_set_error('comment', t("Unable to check comment with blogspam - please try again later"));
115 }
116 }
117 elseif ($check != "OK") {
118 form_set_error('comment', t("Blogspam checker has blocked this post due to: ") . $check);
119 }
120 }
121 break;
122 }
123 }
124
125
126 /**
127 * Get stats.
128 */
129 function _blogspam_stats() {
130 global $base_url;
131
132 $stats = xmlrpc(variable_get('blogspam_server', 'http://test.blogspam.net:8888/'), 'getStats', $base_url);
133
134 if ($stats == FALSE) {
135 watchdog('blogspam',
136 "Call to Blogspam stats failed with code %code and message %msg",
137 array('%code' => xmlrpc_errno(), '%msg' => xmlrpc_error_msg()));
138
139 return array('ok' => t('Unknown'),
140 'spam' => t('Unknown'));
141 }
142
143 return $stats;
144 }

  ViewVC Help
Powered by ViewVC 1.1.2