diff -uprN /home/files/coding/drupal/spam/CHANGELOG.txt sites/all/modules/spam/CHANGELOG.txt --- /home/files/coding/drupal/spam/CHANGELOG.txt 2009-08-11 04:43:36.000000000 +1000 +++ sites/all/modules/spam/CHANGELOG.txt 2009-09-01 07:09:29.000000000 +1000 @@ -1,3 +1,7 @@ +August 31st, 2009 + - spam.module + o bug #531214: fix feedback form, properly call drupal_process_form() + August 9th, 2009 (6.x-1.0) - spam.module o bug #531528: simplify debug logic, cleanup code diff -uprN /home/files/coding/drupal/spam/content/spam_content_comment.inc sites/all/modules/spam/content/spam_content_comment.inc --- /home/files/coding/drupal/spam/content/spam_content_comment.inc 2009-12-11 11:42:45.000000000 +1100 +++ sites/all/modules/spam/content/spam_content_comment.inc 2009-12-14 10:47:53.000000000 +1100 @@ -216,7 +216,7 @@ function comment_spamapi($op, $arg1 = NU // Add spam comments admin form to spam.module's hook_theme. return array( 'spam_content_comment_admin_overview' => array( - 'file' => 'modules/spam_content_comment.inc', + 'file' => 'content/spam_content_comment.inc', 'arguments' => array( 'form' => NULL, ), diff -uprN /home/files/coding/drupal/spam/filters/bayesian/bayesian.info sites/all/modules/spam/filters/bayesian/bayesian.info --- /home/files/coding/drupal/spam/filters/bayesian/bayesian.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/filters/bayesian/bayesian.info 1970-01-01 10:00:00.000000000 +1000 @@ -1,12 +0,0 @@ -; $Id: bayesian.info,v 1.1.2.1.2.1 2008/12/25 05:42:10 jeremy Exp $ -name = Bayesian filter -description = A bayesian filter. -package = Spam -dependencies[] = spam -core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" -core = "6.x" -project = "spam" -datestamp = "1249930375" - diff -uprN /home/files/coding/drupal/spam/filters/bayesian/bayesian.install sites/all/modules/spam/filters/bayesian/bayesian.install --- /home/files/coding/drupal/spam/filters/bayesian/bayesian.install 2008-12-25 16:42:10.000000000 +1100 +++ sites/all/modules/spam/filters/bayesian/bayesian.install 1970-01-01 10:00:00.000000000 +1000 @@ -1,105 +0,0 @@ -. All rights reserved. - * - * Provides a generic Bayesian filter for use with other modules. - * Defines hooks for use with the Spam API. - */ - -/** - * Implementation of hook_schema(). - */ -function bayesian_schema() { - $schema['bayesian_tokens'] = array( - 'description' => t('TODO'), - 'fields' => array( - 'tid' => array( - 'description' => t('TODO'), - 'type' => 'serial', - 'unsigned' => 1, - 'not null' => TRUE, - ), - 'class' => array( - 'description' => t('TODO'), - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '', - ), - 'token' => array( - 'description' => t('TODO'), - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'yes_count' => array( - 'description' => t('TODO'), - 'type' => 'int', - 'unsigned' => 1, - 'not null' => TRUE, - 'default' => 0, - ), - 'no_count' => array( - 'description' => t('TODO'), - 'type' => 'int', - 'unsigned' => 1, - 'not null' => TRUE, - 'default' => 0, - ), - 'probability' => array( - 'description' => t('TODO'), - 'type' => 'int', - 'unsigned' => 1, - 'not null' => TRUE, - 'default' => 0, - ), - 'last' => array( - 'description' => t('TODO'), - 'type' => 'int', - 'unsigned' => 1, - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'indexes' => array( - 'yes_count' => array('yes_count'), - 'no_count' => array('no_count'), - 'probability' => array('probability'), - 'last' => array('last'), - ), - 'unique keys' => array( - 'token' => array('class', 'token'), - ), - 'primary key' => array('tid'), - ); - - return $schema; -} - -/** - * Install bayesian module schema. - */ -function bayesian_install() { - // Create tables. - drupal_install_schema('bayesian'); -} - -/** - * Completely uninstall the spam module. - */ -function bayesian_uninstall() { - // Remove tables. - drupal_uninstall_schema('bayesian'); - - $tables = array('bayesian_tokens'); - foreach ($tables as $table) { - } - drupal_set_message(t('All bayesian module configuration data and tables have been deleted.')); -} - diff -uprN /home/files/coding/drupal/spam/filters/bayesian/bayesian.module sites/all/modules/spam/filters/bayesian/bayesian.module --- /home/files/coding/drupal/spam/filters/bayesian/bayesian.module 2008-12-25 16:42:10.000000000 +1100 +++ sites/all/modules/spam/filters/bayesian/bayesian.module 1970-01-01 10:00:00.000000000 +1000 @@ -1,189 +0,0 @@ -. All rights reserved. - * - * Provides a generic Bayesian filter for use with other modules. - * Defines hooks for use with the Spam API. - */ - -/** - * Spam API Hook - */ -function bayesian_spamapi($op, $type = NULL, $content = array(), $fields = array(), $extra = NULL) { - switch ($op) { - - case 'filter': - if (!module_invoke('spam', 'filter_enabled', 'bayesian', $type, $content, $fields, $extra)) return; - return bayesian_spam_filter($content, $type, $fields, $extra); - - case 'filter_module': - return 'bayesian'; - break; - - case 'filter_info': - return array( - 'name' => t('Bayesian filter'), - 'module' => t('bayesian'), - 'description' => t('A bayesian spam filter.'), - 'help' => t('The bayesian filter can learn to tell the difference between valid content spam content.'), - ); - break; - - case 'filter_install': - return array( - 'status' => SPAM_FILTER_ENABLED, - ); - - case 'mark_as_spam': - case 'mark_as_not_spam': - if (!module_invoke('spam', 'filter_enabled', 'bayesian', $type, $content, $fields, $extra)) return; - spam_log(SPAM_DEBUG, 'bayesian_spamapi', t('@op', array('@op' => $op)), $type, $extra['id']); - $fields = spam_invoke_module($type, 'filter_fields', $extra['content']); - $tokenizer = variable_get('bayesian_tokenizer', 'bayesian_tokenize'); - $tokens = $tokenizer($extra['content'], $type, $fields, $extra); - bayesian_tokens_update('spam', $tokens, ($op == 'mark_as_spam' ? TRUE : FALSE), $type, $extra['id']); - break; - } -} - -/** - * Determine whether or not the content is spam. - */ -function bayesian_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) { - $class = 'spam'; - $id = spam_invoke_module($type, 'content_id', $content, $extra); - $tokenizer = variable_get('bayesian_tokenizer', 'bayesian_tokenize'); - $tokens = $tokenizer($content, $type, $fields, $extra); - if (is_array($tokens)) { - foreach ($tokens as $token) { - $p = db_fetch_object(db_query("SELECT probability FROM {bayesian_tokens} WHERE class = '%s' AND token = '%s'", $class, $token)); - if (!$p->probability) { - $p->probability = variable_get('bayesian_default_probability', 40); - } - $t["$token,$p->probability"] = abs($p->probability - 50); - } - } - else { - // No tokens, return default score. - $action['total'] = variable_get('bayesian_default_probability', 40); - return $action; - } - - /* Sort token array so those tokens with the largest "drift" come first. - * Drift is this distance from a median of 50%. - */ - asort($t); - - /* Take the n most "interesting" tokens from the top of the token array. - * The larger a token's drift, the more interesting it is. - */ - $keys = array_keys($t); - $max = variable_get('bayesian_interesting_tokens', 15); - $total = 0; - for ($i = 0; $i < $max; $i++) { - if ($pair = array_pop($keys)) { - $p = explode(',', $pair); - $total = $total + $p[1]; - $action['bayesian'][$i] = array( - 'token' => $p[0], - 'probability' => $p[1], - ); - spam_log(SPAM_DEBUG, 'bayesian_spam_filter', t('interesting token [@count] (@token) probability(@probability)', array('@token' => $p[0], '@probability' => $p[1], '@count' => $i + 1)), $type, $id); - } - else { - // we've looked at all the tokens - break; - } - } - - $probability = round($total / $i, 1); - spam_log(SPAM_VERBOSE, 'bayesian_spam_filter', t('total(@total) count(@count) probability(@probability)', array('@probability' => $probability, '@total' => $total, '@count' => $i)), $type, $id); - - $action['total'] = $probability; - return $action; -} - -/** - * Update token probabilities in database. - */ -function bayesian_tokens_update($class, $tokens, $yes, $type = NULL, $id = 0) { - if (!is_array($tokens) || empty($tokens)) return; - foreach ($tokens as $token) { - $old = db_fetch_object(db_query("SELECT probability, yes_count, no_count FROM {bayesian_tokens} WHERE class = '%s' AND token = '%s'", $class, $token)); - if ($old->probability) { - $total = $old->yes_count + $old->no_count + 1; - $probability = spam_sanitize_score(($old->yes_count + ($yes ? 1 : 0)) / $total * 100); - spam_log(SPAM_DEBUG, 'bayesian_tokens_update', t('update token(@token) class(@class) yes(@yes) no(@no) prob(@prob): added @new', array('@token' => $token, '@class' => $class, '@yes' => $old->yes_count + ($yes ? 1 : 0), '@no' => $old->no_count + ($yes ? 0 : 1), '@prob' => $probability, '@new' => $yes ? 'yes' : 'no')), $type, $id); - if ($yes) { - db_query("UPDATE {bayesian_tokens} SET yes_count = yes_count + 1, probability = %d, last = %d WHERE class = '%s' AND token = '%s'", $probability, time(), $class, $token); - } - else { - db_query("UPDATE {bayesian_tokens} SET no_count = no_count + 1, probability = %d, last = %d WHERE class = '%s' AND token = '%s'", $probability, time(), $class, $token); - } - } - else { - $probability = ($yes ? 99 : 1); - spam_log(SPAM_DEBUG, 'bayesian_tokens_update', t('insert token(@token) class(@class) probability(@probability)', array('@token' => $token, '@class' => $class, '@probability' => $probability)), $type, $id); - db_query("INSERT INTO {bayesian_tokens} (class, token, yes_count, no_count, probability, last) VALUES('%s', '%s', %d, %d, %d, %d)", $class, $token, ($yes ? 1 : 0), ($yes ? 0 : 1), $probability, time()); - } - } -} - -/** - * Split content into an array of tokens. - */ -function bayesian_tokenize($content, $type, $fields, $extra = array(), $tag = NULL) { - static $tokens = array(); - - $id = spam_invoke_module($type, 'content_id', $content, $extra); - - if (is_object($content)) { - $content = (array)$content; - } - - if (!isset($tokens["$type-$id-$tag"])) { - $string = spam_get_text($content, $type, $fields, $extra); - - $URI = "(http://|https://|ftp://|mailto:)"; - // strip out unwanted html/url noise - $sanitized = preg_replace("'(www\.)|()|(href=)|(target=)|(src=)'i", '', $string); - $sanitized = preg_replace($URI, '', $sanitized); - - // Strip out values that should not be considered part of tokens, so - // things like '{viagra}' and 'vi.agra' are counted as hits towards - // 'viagra' - $sanitized = preg_replace("/[()\{\}\[\]#.,]/", '', $sanitized); - - // Force all tokens to lowercase, again to aggregate tokens. This both - // lowers the total token number of rows in the spam_tokens table and - // increases the strength of individual tokens by linking them to - // capitalized versions. - $sanitized = drupal_strtolower($sanitized); - - // divide sanitized string into tokens - $delimiters = " \t\n\r-_<>'\"`/|*%^&+=~:;?"; - $tok = strtok($sanitized, $delimiters); - while ($tok !== FALSE) { - // Only inspect the token if over minimum length. - if (drupal_strlen($tok) >= variable_get('bayesian_minimum_token_length', 3)) { - // If the token is longer than 255 characters, truncate it. - $toks[] = htmlspecialchars(drupal_substr("$tag$tok", 0, 254)); - } - $tok = strtok($delimiters); - } - - // allow external module ability to extract additional tokens - $hook = spam_invoke_api('tokenize', $string, $tag); - if ($hook['tokens']) { - $toks = array_merge($toks, $hook['tokens']); - } - $tokens["$type-$id-$tag"] = $toks; - } - - return $tokens["$type-$id-$tag"]; -} diff -uprN /home/files/coding/drupal/spam/filters/custom/custom.info sites/all/modules/spam/filters/custom/custom.info --- /home/files/coding/drupal/spam/filters/custom/custom.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/filters/custom/custom.info 1970-01-01 10:00:00.000000000 +1000 @@ -1,12 +0,0 @@ -; $Id: custom.info,v 1.1.2.2.2.1 2008/12/25 05:42:10 jeremy Exp $ -name = Custom filter -description = Allows the creation of custom spam filter rules. -package = Spam -dependencies[] = spam -core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" -core = "6.x" -project = "spam" -datestamp = "1249930375" - diff -uprN /home/files/coding/drupal/spam/filters/custom/custom.install sites/all/modules/spam/filters/custom/custom.install --- /home/files/coding/drupal/spam/filters/custom/custom.install 2008-12-25 16:42:10.000000000 +1100 +++ sites/all/modules/spam/filters/custom/custom.install 1970-01-01 10:00:00.000000000 +1000 @@ -1,43 +0,0 @@ - array( - 'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '11'), - 'filter' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), - 'style' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '3'), - 'status' => array('type' => 'int', 'not null' => FALSE, 'default' => 0, 'disp-width' => '2'), - 'scan' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '3'), - 'action' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '3'), - 'matches' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11'), - 'last' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11'), - 'weight' => array('type' => 'int', 'not null' => FALSE, 'default' => 0, 'disp-width' => '3'), - ), - 'primary key' => array('cid'), - 'indexes' => array( - 'filter' => array('filter'), - 'last' => array('last'), - 'matches' => array('matches'), - 'weight' => array('weight'), - ), - ); - - return $schema; -} - -function custom_install() { - // Create my tables. - drupal_install_schema('custom'); -} - -function custom_uninstall() { - // Remove tables. - drupal_uninstall_schema('custom'); - drupal_set_message('The spam_custom table has been dropped.'); -} diff -uprN /home/files/coding/drupal/spam/filters/custom/custom.module sites/all/modules/spam/filters/custom/custom.module --- /home/files/coding/drupal/spam/filters/custom/custom.module 2009-08-06 00:25:13.000000000 +1000 +++ sites/all/modules/spam/filters/custom/custom.module 1970-01-01 10:00:00.000000000 +1000 @@ -1,584 +0,0 @@ -. - * - * Allows manual definition of words and regular expressions to detect spam - * content. - */ - -define(SPAM_CUSTOM_STYLE_PLAIN, 0); -define(SPAM_CUSTOM_STYLE_REGEX, 1); - -define(SPAM_CUSTOM_STATUS_NOTSPAM, -2); -define(SPAM_CUSTOM_STATUS_PROBABLYNOT, -1); -define(SPAM_CUSTOM_STATUS_DISABLED, 0); -define(SPAM_CUSTOM_STATUS_PROBABLY, 1); -define(SPAM_CUSTOM_STATUS_SPAM, 2); - -define(SPAM_CUSTOM_SCAN_CONTENT, 0x1); -define(SPAM_CUSTOM_SCAN_REFERRER, 0x4); -define(SPAM_CUSTOM_SCAN_USERAGENT, 0x8); - -// TODO: support actions -//define(SPAM_CUSTOM_ACTION_DELETE, 0x1); -//define(SPAM_CUSTOM_ACTION_MAIL, 0x2); - -/** - * Spam API Hook - */ -function custom_spamapi($op, $type = NULL, $content = array(), $fields = array(), $extra = NULL) { - switch ($op) { - case 'filter': - if (!module_invoke('spam', 'filter_enabled', 'custom', $type, $content, $fields, $extra)) return; - return custom_spam_filter($content, $type, $fields, $extra); - - case 'filter_module': - return 'custom'; - - case 'filter_info': - return array( - 'name' => t('Custom filter'), - 'module' => t('custom'), - 'description' => t('Custom spam filters.'), - 'help' => t('The custom spam filter module allows you to manually define custom spam filter rules.'), - ); - - case 'filter_install': - return array( - 'status' => SPAM_FILTER_ENABLED, - 'gain' => 250, - 'weight' => -4, - ); - } -} - -/** - * Drupal _menu() hook. - */ -function custom_menu() { - $items = array(); - - $items['admin/settings/spam/filters/custom'] = array( - 'title' => 'Custom', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('custom_admin_settings'), - 'access arguments' => array('administer spam'), - 'description' => 'Configure the custom spam filter module.', - 'type' => MENU_LOCAL_TASK, - ); - - $items['admin/settings/spam/filters/custom/list'] = array( - 'title' => 'List', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('custom_admin_settings'), - 'access arguments' => array('administer spam'), - 'description' => 'Configure the custom spam filter module.', - 'type' => MENU_DEFAULT_LOCAL_TASK, - ); - $items['admin/settings/spam/filters/custom/create'] = array( - 'title' => 'Create', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('custom_admin_filter'), - 'access arguments' => array('administer spam'), - 'description' => 'Create a custom spam filter.', - 'type' => MENU_LOCAL_TASK, - ); - $items["admin/settings/spam/filters/custom/%/edit"] = array( - 'title' => 'Create', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('custom_admin_filter', 5), - 'access arguments' => array('administer spam'), - 'description' => 'Edit a custom spam filter.', - 'type' => MENU_LOCAL_TASK, - ); - - return $items; -} - -/** - * Adminsitrative interface for configuring custom spam filter rules. - */ -function custom_admin_settings() { - $form = array(); - - $form['options'] = array( - '#type' => 'fieldset', - '#title' => t('Options'), - '#prefix' => '
', - '#suffix' => '
' - ); - $options = array(); - foreach (module_invoke_all('spam_custom_operations') as $operation => $op) { - $options[$operation] = $op['label']; - } - $form['options']['operation'] = array( - '#type' => 'select', - '#options' => $options, - '#default_value' => 'scan' - ); - $form['options']['submit'] = array( - '#type' => 'submit', - '#value' => t('Execute') - ); - - $rows = array(); - $result = pager_query('SELECT * FROM {spam_custom} ORDER BY weight ASC'); - while ($custom = db_fetch_object($result)) { - $all[$custom->cid] = ''; - - // The filter text. - $form['filter'][$custom->cid] = array('#value' => $custom->filter); - - // What style of filter. - if ($custom->style == SPAM_CUSTOM_STYLE_PLAIN) { - $form['style'][$custom->cid] = array('#value' => t('Plain text')); - } - else if ($custom->style == SPAM_CUSTOM_STYLE_REGEX) { - $form['style'][$custom->cid] = array('#value' => t('Regular expression')); - } - - // What to scan. - $scan = array(); - if ($custom->scan & SPAM_CUSTOM_SCAN_CONTENT) { - $scan[] = t('Content'); - } - if ($custom->scan & SPAM_CUSTOM_SCAN_REFERRER) { - $scan[] = t('Referrer'); - } - if ($custom->scan & SPAM_CUSTOM_SCAN_USERAGENT) { - $scan[] = t('User agent'); - } - $form['scan'][$custom->cid] = array('#value' => implode(', ', $scan)); - - // What status to apply. - switch ($custom->status) { - case SPAM_CUSTOM_STATUS_NOTSPAM: - $status = t('Mark as not spam'); - break; - case SPAM_CUSTOM_STATUS_PROBABLYNOT: - $status = t('Mark as probably not spam'); - break; - case SPAM_CUSTOM_STATUS_DISABLED: - $status = t('Disabled'); - break; - case SPAM_CUSTOM_STATUS_PROBABLY: - $status = t('Mark as probably spam'); - break; - case SPAM_CUSTOM_STATUS_SPAM: - $status = t('Mark as spam'); - break; - default: - $status = t('Unknown'); - break; - } - $form['status'][$custom->cid] = array( - '#value' => $status - ); - - // How many times this filter has been matched. - $form['matches'][$custom->cid] = array('#value' => $custom->matches); - - // The last time this filter was matched. - $last = $custom->last ? t('@time ago', array('@time' => format_interval(time() - $custom->last))) : t('Never'); - $form['last'][$custom->cid] = array( - '#value' => $last - ); - - // Link to edit the filter. - $form['edit'][$custom->cid] = array( - '#value' => l(t('edit'), "admin/settings/spam/filters/custom/$custom->cid/edit"), - ); - - $rows[] = $row; - } - - $form['create2'] = array( - '#value' => '['. l(t('create custom filter'), 'admin/settings/spam/filters/custom/create') .']', - '#prefix' => '
', - '#suffix' => '
' - ); - - $form['custom'] = array( - '#type' => 'checkboxes', - '#options' => $all, - ); - $form['pager'] = array( - '#value' => theme('pager', NULL, 50, 0), - ); - - return $form; -} - -/** - * Drupal _theme() hook. - */ -function custom_theme() { - return array( - 'custom_admin_settings' => array( - 'file' => 'custom.module', - 'arguments' => array( - 'form' => NULL, - ), - ), - ); -} - -/** - * Format the custom filter admin page. - */ -function theme_custom_admin_settings($form) { - // TODO: use custom_upgrade() from custom_upgrade.inc in custom.install - //_custom_upgrade(); - $header = array(theme('table_select_header_cell'), t('Filter'), t('Style'), t('Scan'), t('Status'), t('Matches'), t('Last'), ''); - - $output = drupal_render($form['options']); - $rows = array(); - if (isset($form['filter']) && is_array($form['filter'])) { - foreach (element_children($form['filter']) as $key) { - $row = array(); - $row[] = drupal_render($form['custom'][$key]); - $row[] = drupal_render($form['filter'][$key]); - $row[] = drupal_render($form['style'][$key]); - $row[] = drupal_render($form['scan'][$key]); - $row[] = drupal_render($form['status'][$key]); - $row[] = drupal_render($form['matches'][$key]); - $row[] = drupal_render($form['last'][$key]); - $row[] = drupal_render($form['edit'][$key]); - $rows[] = $row; - } - - $output .= theme('table', $header, $rows); - if ($form['pager']['#value']) { - $output .= drupal_render($form['pager']); - } - } - else { - $output .= theme('table', $header, $rows); - $output .= ''. t('No custom filters created.') .''; - } - - $output .= drupal_render($form); - - return $output; -} - -/** - * Define callbacks for custom filter options. Unlike in main spam module, - * here a single ID is added to the end of the argument listing by the - * only function that calls this (custom_admin_settings_submit). - */ -function custom_spam_custom_operations() { - $operations = array( - 'disable' => array( - 'label' => t('Disable'), - 'callback' => 'custom_spam_filter_operations', - 'callback arguments' => array('disable'), - ), - 'delete' => array( - 'label' => t('Delete'), - 'callback' => 'custom_spam_filter_operations', - 'callback arguments' => array('delete'), - ), - ); - return $operations; -} - -/** - * Create or edit a custom spam filter. - */ -function custom_admin_filter($form_state, $cid = NULL) { - if ($cid) { - drupal_set_title('Edit'); - $custom = db_fetch_object(db_query('SELECT * FROM {spam_custom} WHERE cid = %d', $cid)); - if (!isset($custom->cid)) { - drupal_set_message(t('Failed to load custom filter.'), 'error'); - drupal_goto('admin/settings/spam/filters/custom'); - } - } - else { - drupal_set_title('Create'); - } - $form = array(); - $form['filter'] = array( - '#type' => 'textfield', - '#title' => t('Filter'), - '#description' => t('Enter a custom filter string. You can enter a word, a phrase, or a regular expression.'), - '#default_value' => $custom->cid ? $custom->filter : '', - '#required' => TRUE, - ); - $form['style'] = array( - '#type' => 'radios', - '#title' => t('Filter type'), - '#description' => t('For a custom filter to match exactly what you type, select plain text. If you would like to define a regular expression, your filter must be formatted as a Perl-compatible regular expression.'), - '#options' => array(SPAM_CUSTOM_STYLE_PLAIN => t('Plain text'), SPAM_CUSTOM_STYLE_REGEX => t('Regular expression')), - '#default_value' => $custom->cid ? $custom->style : SPAM_CUSTOM_STYLE_PLAIN, - '#required' => TRUE, - ); - $options = array(SPAM_CUSTOM_SCAN_CONTENT => ('Content'), SPAM_CUSTOM_SCAN_REFERRER => t('Referrer'), SPAM_CUSTOM_SCAN_USERAGENT => t('User agent')); - $scan = array(); - if ($custom->scan & SPAM_CUSTOM_SCAN_CONTENT) { - $scan[] = SPAM_CUSTOM_SCAN_CONTENT; - } - if ($custom->scan & SPAM_CUSTOM_SCAN_REFERRER) { - $scan[] = SPAM_CUSTOM_SCAN_REFERRER; - } - if ($custom->scan & SPAM_CUSTOM_SCAN_USERAGENT) { - $scan[] = SPAM_CUSTOM_SCAN_USERAGENT; - } - $form['scan'] = array( - '#type' => 'checkboxes', - '#title' => t('Scan'), - '#description' => t('Specify where you\'d like to apply your custom filter.'), - '#options' => $options, - '#required' => TRUE, - '#default_value' => !empty($scan) ? $scan : array(SPAM_CUSTOM_SCAN_CONTENT), - ); - $options = array(); - $form['status'] = array( - '#type' => 'radios', - '#title' => t('Status'), - '#description' => t('Select the status to apply when your custom filter matches site content. Filters are tested in the order they are displayed above, thus if content matches a filter that says to mark it as spam, and another to mark it as not spam, the first to match will be the actual status applied.'), - '#options' => array( - SPAM_CUSTOM_STATUS_DISABLED => t('Disabled'), - SPAM_CUSTOM_STATUS_SPAM => t('Mark as spam'), - SPAM_CUSTOM_STATUS_PROBABLY => t('Mark as probably spam'), - SPAM_CUSTOM_STATUS_PROBABLYNOT => t('Mark as probably not spam'), - SPAM_CUSTOM_STATUS_NOTSPAM => t('Mark as not spam')), - '#default_value' => $custom->cid ? $custom->status : SPAM_CUSTOM_STATUS_SPAM, - '#required' => TRUE, - ); - $form['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight'), - '#description' => t('Give your custom filter a weight. "Lighter" filters with smaller weights will run before "heavier" filters with larger weights.'), - '#default_value' => $custom->weight, - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => $custom->cid ? t('Update filter') : t('Create filter'), - ); - - if ($custom->cid) { - $form['cid'] = array( - '#type' => 'hidden', - '#value' => $custom->cid, - ); - } - - return $form; -} - -/** - * Be sure that the custom filter is valid. - */ -function custom_admin_filter_validate($form, &$form_state) { - if ($form_state['values']['style'] == SPAM_CUSTOM_STYLE_REGEX) { - if (preg_match($form_state['values']['filter'], 'test') === FALSE) { - form_set_error('filter', t('Failed to validate your filter\'s regular expression. It must be properly formatted as a Perl-compatible regular expression. Review the above error for details on the specific problem with your expression.')); - } - } - if (isset($form_state['values']['cid'])) { - // update - $cid = db_result(db_query("SELECT cid FROM {spam_custom} WHERE filter = '%s' AND cid <> %d", $form_state['values']['filter'], $form_state['values']['cid'])); - if ($cid) { - form_set_error($cid, t('Custom filter %filter already exists', array('%filter' => $form_state['values']['filter']))); - } - } - else { - // create - $cid = db_result(db_query("SELECT cid FROM {spam_custom} WHERE filter = '%s'", $form_state['values']['filter'])); - if ($cid) { - form_set_error($cid, t('Custom filter %filter already exists', array('%filter' => $form_state['values']['filter']))); - } - } -} - -/** - * Create/update custom filer. - */ -function custom_admin_filter_submit($form, &$form_state) { - $scan = 0; - if (is_array($form_state['values']['scan'])) { - foreach ($form_state['values']['scan'] as $s) { - $scan += $s; - } - } - if (isset($form_state['values']['cid'])) { - db_query("UPDATE {spam_custom} SET filter = '%s', style = %d, status = %d, scan = %d, weight = %d WHERE cid = %d", $form_state['values']['filter'], $form_state['values']['style'], $form_state['values']['status'], $scan, $form_state['values']['weight'], $form_state['values']['cid']); - drupal_set_message(t('Custom filter %filter updated.', array('%filter' => $form_state['values']['filter']))); - } - else { - db_query("INSERT INTO {spam_custom} (filter, style, status, scan, weight) VALUES ('%s', %d, %d, %d, %d)", $form_state['values']['filter'], $form_state['values']['style'], $form_state['values']['status'], $scan, $form_state['values']['weight']); - drupal_set_message(t('Custom filter %filter created.', array('%filter' => $form_state['values']['filter']))); - } - drupal_goto('admin/settings/spam/filters/custom'); -} - -/** - * Perform bulk operations on the filters. - */ -function custom_admin_settings_submit($form, &$form_state) { - if (is_array($form_state['values']['custom'])) { - foreach ($form_state['values']['custom'] as $cid => $selected) { - if ($selected) { - $process[] = $cid; - } - } - } - if (!empty($process)) { - foreach (module_invoke_all('spam_custom_operations') as $operation => $op) { - $options[$operation] = $op; - } - $operation = $form_state['values']['operation']; - if (isset($options[$operation])) { - $function = $options[$operation]['callback']; - $arguments = $options[$operation]['callback arguments']; - //TODO: Why is order different than spam.module, and why 1 at a time? - foreach ($process as $cid) { - call_user_func_array($function, array_merge($arguments, array($cid))); - } - } - } -} - -/** - * Perform custom operations. - * TODO: Confirmation would be nice. - */ -function custom_spam_filter_operations($op, $cid) { - $filter = db_fetch_object(db_query('SELECT cid, status, filter FROM {spam_custom} WHERE cid = %d', $cid)); - switch ($op) { - case 'delete': - if ($filter->cid) { - db_query('DELETE FROM {spam_custom} WHERE cid = %d', $cid); - drupal_set_message(t('Deleted custom filter %filter.', array('%filter' => $filter->filter))); - } - break; - case 'disable': - if ($filter->cid && $filter->status != SPAM_CUSTOM_STATUS_DISABLED) { - db_query('UPDATE {spam_custom} SET status = %d WHERE cid = %d', SPAM_CUSTOM_STATUS_DISABLED, $cid); - drupal_set_message(t('Disabled custom filter %filter.', array('%filter' => $filter->filter))); - } - break; - } -} - -/** - * Apply enabled custom filter rules against content. - */ -function custom_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) { - $probably = $probably_not = 0; - $id = spam_invoke_module($type, 'content_id', $content, $extra); - $result = db_query('SELECT cid, filter, style, status, scan, action FROM {spam_custom} WHERE status <> %d ORDER BY weight ASC', SPAM_CUSTOM_STATUS_DISABLED); - while ($custom = db_fetch_object($result)) { - $scan = ''; - if ($custom->scan & SPAM_CUSTOM_SCAN_CONTENT) { - // scan content - if (is_object($content)) { - $content = (array)$content; - } - $scan .= spam_get_text($content, $type, $fields, $extra); - spam_log(SPAM_DEBUG, 'custom_spam_filter', t('scanning content with %filter.', array('%filter' => $custom->filter)), $type, $id); - } - if ($custom->scan & SPAM_CUSTOM_SCAN_REFERRER) { - // scan referrer - // TODO: Determine if this is a live scan. If not, don't scan referrer. - $scan .= $_SERVER['HTTP_REFERER']; - spam_log(SPAM_DEBUG, 'custom_spam_filter', t('scanning referrer with %filter.', array('%filter' => $custom->filter)), $type, $id); - } - if ($custom->scan & SPAM_CUSTOM_SCAN_USERAGENT) { - // scan user agent - // TODO: Determine if this is a live scan. If not, don't scan user agent. - $scan .= $_SERVER['HTTP_USER_AGENT']; - spam_log(SPAM_DEBUG, 'custom_spam_filter', t('scanning user agent with %filter.', array('%filter' => $custom->filter)), $type, $id); - } - switch ($custom->style) { - case SPAM_CUSTOM_STYLE_PLAIN: - $match = preg_match_all("/$custom->filter/", $scan, $matches); - break; - case SPAM_CUSTOM_STYLE_REGEX: - $match = preg_match_all($custom->filter, $scan, $matches); - break; - } - if ($match) { - // Record that we've had one or more matches. - db_query('UPDATE {spam_custom} SET matches = matches + %d, last = %d WHERE cid = %d', $match, time(), $custom->cid); - spam_log(SPAM_VERBOSE, 'custom_spam_filter', t('matched with %filter.', array('%filter' => $custom->filter)), $type, $id); - - $action['custom'][] = array( - 'filter' => $custom->filter, - 'status' => $custom->status, - 'style' => $custom->style, - 'scan' => $custom->scan, - 'extra' => $custom->extra, - ); - - switch ($custom->status) { - - case SPAM_CUSTOM_STATUS_SPAM: - spam_log(SPAM_VERBOSE, 'custom_spam_filter', t('content is spam.'), $type, $id); - // no need to scan any more, we've found spam - $action['total'] = 99; - return $action; - - case SPAM_CUSTOM_STATUS_NOTSPAM: - spam_log(SPAM_VERBOSE, 'custom_spam_filter', t('content is not spam.'), $type, $id); - // no need to scan any more, we've found non-spam - $action['total'] = 1; - return $action; - - case SPAM_CUSTOM_STATUS_PROBABLYNOT: - spam_log(SPAM_DEBUG, 'custom_spam_filter', t('content is probably not spam.'), $type, $id); - // maintain internal counter that this is probably not spam - $probably_not += $match; - break; - - case SPAM_CUSTOM_STATUS_PROBABLY: - spam_log(SPAM_DEBUG, 'custom_spam_filter', t('content is probably spam.'), $type, $id); - // maintain internal counter that this is probably spam - $probably += $match; - break; - } - } - } - - if ($probably && $probably_not) { - if ($probably >= $probably_not) { - $probably -= $probably_not; - $probably_not = 0; - } - else { - $probably_not -= $probably; - $probably = 0; - } - } - if ($probably) { - spam_log(SPAM_VERBOSE, 'custom_spam_filter', t('matched adjusted total of !number probably spam rule(s).', array('!number' => $probably)), $type, $id); - if ($probably >= variable_get('spam_custom_probably', 3)) { - $action['total'] = 99; - } - else { - $action['total'] = variable_get('spam_custom_probably_value', variable_get('spam_threshold', SPAM_DEFAULT_THRESHOLD)); - } - } - else if ($probably_not) { - spam_log(SPAM_VERBOSE, 'custom_spam_filter', t('matched adjusted total of !number probably-not spam rule(s).', array('!number' => $probably_not)), $type, $id); - if ($probably_not >= variable_get('spam_custom_probablynot', 3)) { - $action['total'] = 1; - } - else { - $action['total'] = variable_get('spam_custom_probablynot_value', 40); - } - } - else { - // No matched filters, so don't change the overall spam score. - $action['total'] = 0; - } - return $action; -} diff -uprN /home/files/coding/drupal/spam/filters/custom/custom-upgrade.inc sites/all/modules/spam/filters/custom/custom-upgrade.inc --- /home/files/coding/drupal/spam/filters/custom/custom-upgrade.inc 2008-12-25 16:42:10.000000000 +1100 +++ sites/all/modules/spam/filters/custom/custom-upgrade.inc 1970-01-01 10:00:00.000000000 +1000 @@ -1,72 +0,0 @@ -style) { - case SPAM_CUSTOM_PLAIN: - case SPAM_CUSTOM_URL: - $style = SPAM_CUSTOM_STYLE_PLAIN; - break; - case SPAM_CUSTOM_REGEX: - $style = SPAM_CUSTOM_STYLE_REGEX; - break; - } - switch ($old->effect) { - case SPAM_CUSTOM_DISABLED: - default: - $status = SPAM_CUSTOM_STATUS_DISABLED; - break; - case SPAM_CUSTOM_MAYBE_SPAM: - case SPAM_CUSTOM_USUALLY_SPAM: - $status = SPAM_CUSTOM_STATUS_PROBABLY; - break; - case SPAM_CUSTOM_USUALLY_NOTSPAM: - case SPAM_CUSTOM_MAYBE_NOTSPAM: - $status = SPAM_CUSTOM_STATUS_PROBABLYNOT; - break; - case SPAM_CUSTOM_NEVER_SPAM: - $status = SPAM_CUSTOM_STATUS_NOTSPAM; - break; - case SPAM_CUSTOM_ALWAYS_SPAM: - $status = SPAM_CUSTOM_STATUS_SPAM; - break; - } - if ($old->action & SPAM_CUSTOM_ACTION_HEADER || $old->action & SPAM_CUSTOM_ACTION_BODY) { - $scan = SPAM_CUSTOM_SCAN_CONTENT; - } - else { - $scan = SPAM_CUSTOM_SCAN_CONTENT; - $status = SPAM_CUSTOM_STATUS_DISABLED; - } - db_query("INSERT INTO {spam_custom} (filter, style, status, scan, matches, last) VALUES('%s', %d, %d, %d, %d, %d)", $old->filter, $style, $status, $scan, $old->matches, $old->last); - } - // Done with upgrade, drop old table. - $ret = array(); - db_drop_table($ret, 'old_spam_custom'); - } -} - diff -uprN /home/files/coding/drupal/spam/filters/duplicate/duplicate.info sites/all/modules/spam/filters/duplicate/duplicate.info --- /home/files/coding/drupal/spam/filters/duplicate/duplicate.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/filters/duplicate/duplicate.info 1970-01-01 10:00:00.000000000 +1000 @@ -1,12 +0,0 @@ -; $Id: duplicate.info,v 1.1.2.1.2.1 2008/12/25 05:42:10 jeremy Exp $ -name = Duplicate filter -description = A duplication detecting spam filter. -package = Spam -dependencies[] = spam -core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" -core = "6.x" -project = "spam" -datestamp = "1249930375" - diff -uprN /home/files/coding/drupal/spam/filters/duplicate/duplicate.install sites/all/modules/spam/filters/duplicate/duplicate.install --- /home/files/coding/drupal/spam/filters/duplicate/duplicate.install 2008-12-25 16:42:10.000000000 +1100 +++ sites/all/modules/spam/filters/duplicate/duplicate.install 1970-01-01 10:00:00.000000000 +1000 @@ -1,45 +0,0 @@ - t('The base table for the Duplicate submodule'), - 'fields' => array( - 'iid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '11'), - 'sid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), - 'content_hash' => array('type' => 'char', 'length' => '32', 'not null' => TRUE, 'default' => ''), - 'hostname' => array('type' => 'varchar', 'length' => '15', 'not null' => TRUE, 'default' => ''), - 'duplicate_hash' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), - 'duplicate_ip' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), - 'spam' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '4'), - 'expired' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '4'), - 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11'), - ), - 'primary key' => array('iid'), - 'indexes' => array( - 'content_hash' => array('content_hash'), - 'hostname' => array('hostname'), - 'sid' => array('sid'), - 'spam' => array('spam'), - 'timestamp' => array('timestamp'), - ), - ); - - return $schema; -} - -function duplicate_install() { - // Create my tables. - drupal_install_schema('duplicate'); -} - -function duplicate_uninstall() { - // Remove tables. - drupal_uninstall_schema('duplicate'); - drupal_set_message('The spam_duplicate table has been dropped.'); -} diff -uprN /home/files/coding/drupal/spam/filters/duplicate/duplicate.module sites/all/modules/spam/filters/duplicate/duplicate.module --- /home/files/coding/drupal/spam/filters/duplicate/duplicate.module 2009-06-18 05:32:47.000000000 +1000 +++ sites/all/modules/spam/filters/duplicate/duplicate.module 1970-01-01 10:00:00.000000000 +1000 @@ -1,400 +0,0 @@ -. All rights reserved. - * - * Detects spam by looking for duplication of content, or posting IP. - */ - -define('DUPLICATE_BLACKLIST_SILENT', 0); -define('DUPLICATE_BLACKLIST_NOTIFY', 1); -define('DUPLICATE_BLACKLIST_BLOCK', 2); - -define('DUPLICATE_DEFAULT_THRESHOLD', 2); -define('DUPLICATE_DEFAULT_BLACKLIST', 3); - -define('DUPLICATE_NOT_SPAM', 0); -define('DUPLICATE_SPAM', 1); - -/** - * Drupal _menu() hook. - */ -function duplicate_menu() { - $items = array(); - - $items['admin/settings/spam/filters/duplicate'] = array( - 'title' => 'Duplicate', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('duplicate_admin_settings'), - 'access arguments' => array('administer spam'), - 'description' => 'Configure the spam duplicate filter.', - 'type' => MENU_LOCAL_TASK, - ); - $items['duplicate/denied/ip'] = array( - 'page callback' => 'duplicate_denied_ip', - 'type' => MENU_CALLBACK, - 'access callback' => TRUE, - ); - $items['duplicate/denied/post'] = array( - 'page callback' => 'duplicate_denied_post', - 'type' => MENU_CALLBACK, - 'access callback' => TRUE, - ); - - $items['admin/reports/spam/blocked_ip'] = array( - 'title' => 'Blocked IPs', - 'access arguments' => array('administer spam'), - 'page callback' => 'spam_logs_blocked_ip', - 'type' => MENU_LOCAL_TASK, - ); - - return $items; -} - -/** - * The arg() function may not be availble early in the bootstrap process, - * so we reimplement it here. - */ -function _duplicate_arg() { - static $arguments, $q; - - if (empty($arguments) || $q != $_GET['q']) { - $arguments = explode('/', $_GET['q']); - $q = $_GET['q']; - } - - if (isset($arguments[$index])) { - return $arguments[$index]; - } -} - - -/** - * If IP blacklisting and IP blocking are both enabled, perform a database - * query on each page load to see if the current visitor has been blacklisted. - */ -function duplicate_init() { - // Allow notification to blacklisted IP, if enabled. - if (_duplicate_arg(0) == 'duplicate' && _duplicate_arg(1) == 'denied' && _duplicate_arg(2) == 'ip') return; - - // Only perform database queries if functionality is enabled. - if ((variable_get('duplicate_blacklist_action', DUPLICATE_BLACKLIST_NOTIFY) == DUPLICATE_BLACKLIST_BLOCK) && (variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST) > -1)) { - // Blacklisting and IP blocking enabled. - $duplicate_ip = (int)db_query("SELECT COUNT(iid) FROM {spam_duplicate} WHERE hostname = '%s' AND spam = %d", ip_address(), DUPLICATE_SPAM); - if ($duplicate_ip >= variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST)) { - if (user_access('bypass filters')) { - spam_log(SPAM_DEBUG, 'duplicate_init', t('Found !count spam for IP !ip, ignoring because user !user (uid !uid) is configured to bypass filters', array('!count' => $duplicate_ip, '!ip' => ip_address(), '!user' => $user->name, 'uid' => $user->uid)), $type, $id); - return; - } - drupal_goto("duplicate/denied/ip"); - } - } -} - -/** - * Spam API Hook - */ -function duplicate_spamapi($op, $type = NULL, $content = array(), $fields = array(), $extra = NULL) { - - switch ($op) { - - case 'filter': - if (!module_invoke('spam', 'filter_enabled', 'duplicate', $type, $content, $fields, $extra)) return; - return duplicate_spam_filter($content, $type, $fields, $extra); - - case 'filter_module': - return 'duplicate'; - - case 'insert': - if (!module_invoke('spam', 'filter_enabled', 'duplicate', $type, $content, $fields, $extra)) return; - if (is_array($extra) && $extra['sid'] && $extra['host'] && - !empty($content) && !empty($fields)) { - $hash = _duplicate_content_hash($content, $fields); - db_query("INSERT INTO {spam_duplicate} (sid, content_hash, hostname, timestamp) VALUES(%d, '%s', '%s', %d)", $extra['sid'], $hash, $extra['host'], time()); - $action = _duplicate_action(); - if (is_array($action) && !empty($action)) { - if (isset($action['redirect'])) { - drupal_goto($action['redirect']); - } - } - } - break; - - case 'update': - if (!module_invoke('spam', 'filter_enabled', 'duplicate', $type, $content, $fields, $extra)) return; - if (is_array($extra) && $extra['sid'] && $extra['host'] && - !empty($content) && !empty($fields)) { - $hash = _duplicate_content_hash($content, $fields); - db_query("UPDATE {spam_duplicate} SET content_hash = '%s', hostname = '%s', timestamp = %d WHERE sid = %d", $hash, $extra['host'], time(), $extra['sid']); - if (!db_affected_rows()) { - db_query("INSERT INTO {spam_duplicate} (sid, content_hash, hostname, timestamp) VALUES(%d, '%s', '%s', %d)", $extra['sid'], $hash, $extra['host'], time()); - } - $action = _duplicate_action(); - if (is_array($action) && !empty($action)) { - if (isset($action['redirect'])) { - drupal_goto($action['redirect']); - } - } - } - break; - - case 'delete': - if (is_array($extra) && $extra['sid'] && !empty($content) && !empty($fields)) { - db_query("DELETE FROM {spam_duplicate} WHERE sid = %d", $extra['sid']); - } - break; - - case 'filter_info': - return array( - 'name' => t('Duplicate filter'), - 'module' => t('duplicate'), - 'description' => t('A duplication spam filter.'), - 'help' => t('The duplicate filter detects spam by detecting content duplication.'), - ); - break; - - case 'filter_install': - return array( - 'status' => SPAM_FILTER_ENABLED, - 'weight' => -8, - ); - - case 'mark_as_spam': - if (!module_invoke('spam', 'filter_enabled', 'duplicate', $type, $content, $fields, $extra)) return; - db_query('UPDATE {spam_duplicate} SET spam = %d WHERE sid = %d', DUPLICATE_SPAM, $extra['sid']); - if (!db_affected_rows() && $extra['id'] && $extra['sid']) { - $content = spam_invoke_module($type, 'load', $extra['id']); - $fields = spam_invoke_module($type, 'filter_fields', $content); - $hash = _duplicate_content_hash($content, $fields); - $hostname = spam_invoke_module($type, 'hostname', $extra['id']); - db_query("INSERT INTO {spam_duplicate} (sid, content_hash, hostname, timestamp) VALUES(%d, '%s', '%s', %d)", $extra['sid'], $hash, $hostname, time()); - } - $action = _duplicate_action(); - if (is_array($action) && isset($action['redirect'])) { - return $action['redirect']; - } - break; - - case 'mark_as_not_spam': - if (!module_invoke('spam', 'filter_enabled', 'duplicate', $type, $content, $fields, $extra)) return; - db_query('UPDATE {spam_duplicate} SET spam = %d WHERE sid = %d', DUPLICATE_NOT_SPAM, $extra['sid']); - if (!db_affected_rows() && $extra['id'] && $extra['sid']) { - // Updating content that we've not filtered before. Retrive all the - // data we need to add it to the spam_duplicate table. - $fields = spam_invoke_module($type, 'filter_fields', $extra['content']); - $hash = _duplicate_content_hash($extra['content'], $fields); - $hostname = spam_invoke_module($type, 'hostname', $extra['id']); - db_query("INSERT INTO {spam_duplicate} (sid, content_hash, hostname, timestamp) VALUES(%d, '%s', '%s', %d)", $extra['sid'], $hash, $hostname, time()); - } - break; - - } -} - -/** - * - */ -function duplicate_admin_settings() { - $form['content'] = array( - '#type' => 'fieldset', - '#title' => t('Content'), - '#collapsible' => TRUE, - ); - $limits = drupal_map_assoc(range(2, 15)); - $limits[-1] = t('unlimited'); - $form['content']['duplicate_threshold'] = array( - '#type' => 'select', - '#title' => t('Duplication threshold'), - '#default_value' => variable_get('duplicate_threshold', DUPLICATE_DEFAULT_THRESHOLD), - '#options' => $limits, - '#description' => t('Specify how many times the same identical content can be posted before it will be considered spam. When tuning this filter, note that users may accidentally submit the same content multiple times causing an otherwise acceptible posting to be duplicated.'), - ); - $form['content']['duplicate_post_message'] = array( - '#type' => 'textarea', - '#title' => t('Duplicate post message'), - '#default_value' => variable_get('duplicate_post_message', t('

You have attempted to post the same identical content multiple times, causing your posts to be flagged as potential spam. If this has happened in error, please report this error along with your IP address (%IP) to a @site site administrator. We apologize for any inconvenience.

', array('@site' => variable_get('site_name', 'Drupal')))), - '#description' => t('Message to show visitors when their content has been blocked because it was posted multiple times. The text "%IP" will be replaced by the visitors actual IP address.'), - ); - - $form['ip'] = array( - '#type' => 'fieldset', - '#title' => t('IP'), - '#collapsible' => TRUE, - ); - $limits = drupal_map_assoc(range(1, 15)); - $limits[-1] = t('unlimited'); - $form['ip']['duplicate_blacklist'] = array( - '#type' => 'select', - '#title' => t('IP blacklist threshold'), - '#default_value' => variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST), - '#options' => $limits, - '#description' => t('Specify how many times a given IP address is allowed to post possible spam content before the IP address is blacklisted and prevented from posting any additional content.'), - ); - $form['ip']['duplicate_blacklist_action'] = array( - '#type' => 'radios', - '#title' => t('IP blacklist action'), - '#options' => array(t('Silently prevent visitor from posting'), t('Notify blacklisted visitor when posting, prevent from posting'), t('Notify blacklisted visitor, prevent from visiting site')), - '#default_value' => variable_get('duplicate_blacklist_action', DUPLICATE_BLACKLIST_NOTIFY), - '#description' => t('Select an action from the above options. If notification is enabled, the user will be redirected to a custom page displaying the "Blacklisted IP message" defined below. If you only prevent users from posting, they will be able to view all site content. If you prevent a user from visiting your site, they will only ever see the "Blacklisted IP message".'), - ); - $form['ip']['duplicate_blacklist_message'] = array( - '#type' => 'textarea', - '#title' => t('Blacklisted IP message'), - '#default_value' => variable_get('duplicate_blacklist_message', t('

You are currently not allowed to post content to @site, as previous content posted by your IP address (%IP) has been flagged as potential spam.

If you have not posted spam to @site, please report this error along with your IP address to a site administrator. We apologize for any inconvenience.

', array('@site' => variable_get('site_name', 'Drupal')))), - '#description' => t('Message to show visitors when their IP has been blacklisted. The text "%IP" will be replaced by the visitors actual IP address.') - ); - - return system_settings_form($form); -} - -/** - * Save the configuration. - */ -function duplicate_admin_settings_submit($form, &$form_state) { -/* TODO The 'op' element in the form values is deprecated. - Each button can have #validate and #submit functions associated with it. - Thus, there should be one button that submits the form and which invokes - the normal form_id_validate and form_id_submit handlers. Any additional - buttons which need to invoke different validate or submit functionality - should have button-specific functions. */ - if ($form_state['values']['op'] == t('Reset to defaults')) { - variable_del('duplicate_threshold'); - variable_del('duplicate_post_message'); - variable_del('duplicate_blacklist'); - variable_del('duplicate_blacklist_action'); - variable_del('duplicate_blacklist_message'); - drupal_set_message('Configuration reset to defaults.'); - } - else { - variable_set('duplicate_threshold', $form_state['values']['duplicate_threshold']); - variable_set('duplicate_post_message', $form_state['values']['duplicate_post_message']); - variable_set('duplicate_blacklist', $form_state['values']['duplicate_blacklist']); - variable_set('duplicate_blacklist_action', $form_state['values']['duplicate_blacklist_action']); - variable_set('duplicate_blacklist_message', $form_state['values']['duplicate_blacklist_message']); - drupal_set_message('Configuration saved.'); - } -} - -/** - * Get and md5 hash of all content truncated together. - */ -function _duplicate_content_hash($content, $fields) { - if (is_object($content)) { - $content = (array)$content; - } - $hash = ''; - foreach ($fields['main'] as $field) { - $hash .= $content[$field]; - } - return md5($hash); -} - -/** - * Determine whether or not the content is spam. - */ -function duplicate_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) { - $score = 0; - $action = array(); - $hash = _duplicate_content_hash($content, $fields); - $id = spam_invoke_module($type, 'content_id', $content, $extra); - $duplicate_hash = db_result(db_query("SELECT COUNT(d.iid) FROM {spam_duplicate} d LEFT JOIN {spam_tracker} t ON d.sid = t.sid WHERE content_hash = '%s' AND content_id <> %d", $hash, $id)) + 1; - if ($duplicate_hash >= variable_get('duplicate_threshold', DUPLICATE_DEFAULT_THRESHOLD)) { - $sids = db_query("SELECT sid FROM {spam_duplicate} WHERE content_hash = '%s'", $hash); - if (!$filter_test) { - while ($sid = db_result($sids)) { - $unpublish = db_fetch_object(db_query('SELECT content_type, content_id, score FROM {spam_tracker} WHERE sid = %d', $sid)); - spam_mark_as_spam($unpublish->content_type, $unpublish->content_id, array('score' => 99)); - } - // Update counter tracking that we've blocked a duplicate posting of this - // content. (It will actually increment the counter on - // "duplicate_threshold" rows.) - db_query("UPDATE {spam_duplicate} SET duplicate_hash = duplicate_hash + 1 WHERE content_hash = '%s'", $hash); - } - $action['hash'] = array( - 'score' => 99, - 'description' => t('Content is identical to %count other existing posts.', array('%count' => variable_get('duplicate_threshold', DUPLICATE_DEFAULT_THRESHOLD))), - ); - $action['total'] = 99; - $action['redirect'] = 'duplicate/denied/post'; - _duplicate_action($action); - return $action; - } - - $duplicate_ip = db_result(db_query("SELECT COUNT(iid) FROM {spam_duplicate} WHERE hostname = '%s' AND spam = %d", ip_address(), DUPLICATE_SPAM)); - if ($duplicate_ip >= variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST) && (variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST) > -1)) { - $action['ip'] = array( - 'score' => 99, - 'description' => t('Content was posted by the same IP address used to post %count other spam posts.', array('%count' => variable_get('duplicate_blacklist', DUPLICATE_DEFAULT_BLACKLIST))), - ); - $action['total'] = 99; - $action['redirect'] = 'duplicate/denied/ip'; - } - - return $action; -} - -function _duplicate_action($register = array()) { - static $action = array(); - - if (!empty($register)) { - $action = $register; - } - - return $action; -} - -/** - * - */ -function duplicate_denied_ip() { - $message = strtr(variable_get('duplicate_blacklist_message', t('

You are currently not allowed to post content to @site, as previous content posted by your IP address (%IP) has been flagged as potential spam.

If you have not posted spam to @site, please report this error along with your IP address to a site administrator. We apologize for any inconvenience.

')), array('@site' => variable_get('site_name', 'Drupal'), '%IP' => ip_address())); - spam_denied_page($message, t('Your IP address has been blocked by our spam filter.')); -} - -/** - * - */ -function duplicate_denied_post() { - $message = strtr(variable_get('duplicate_post_message', t('

You have attempted to post the same identical content multiple times, causing your posts to be flagged as potential spam. If this has happened in error, please report this error along with your IP address (%IP) to a @site site administrator. We apologize for any inconvenience.

')), array('@site' => variable_get('site_name', 'Drupal'), '%IP' => ip_address())); - spam_denied_page($message, t('You have attempted to post the same content multiple times.')); -} - -function spam_logs_blocked_ip() { - drupal_set_title(t('Spam Module Blocked IPs')); - - $header = array( - array('data' => t('IP Address'), 'field' => 'hostname'), - array('data' => t('Last Seen'), 'field' => 'timestamp', 'sort' => 'desc'), - array('data' => t('Counter'), 'field' => 'count'), - ); - - // This SQL is *nasty*, so if you think you can do better, please be my guest! - // This unfortunately has to be SQL because the pager module can't be told - // how many rows we've got (so we can't do our own processing in PHP and - // still get paging to work properly). - $sql = "SELECT * FROM (SELECT DISTINCT x.hostname, x.timestamp, COUNT(x.hostname) AS count FROM (SELECT timestamp, hostname FROM {spam_tracker} WHERE score > %d ORDER BY timestamp DESC) AS x GROUP BY x.hostname) AS y WHERE y.count >= %d"; - $arguments = array(variable_get('spam_threshold', SPAM_DEFAULT_THRESHOLD), variable_get('spam_blacklist_ip', DUPLICATE_DEFAULT_BLACKLIST)); - - $count_sql = preg_replace('/^SELECT \* /', 'SELECT count(hostname) ', $sql); - - $result = pager_query($sql . tablesort_sql($header), 50, 0, $count_sql, $arguments); - - while ($log = db_fetch_object($result)) { - $rows[] = array('data' => array( - $log->hostname, - format_date($log->timestamp, 'small'), - $log->count - ) - ); - } - - if (!$rows) { - $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 6)); - } - - return theme('table', $header, $rows) . theme('pager', NULL, 50, 0); -} diff -uprN /home/files/coding/drupal/spam/filters/node_age/node_age.info sites/all/modules/spam/filters/node_age/node_age.info --- /home/files/coding/drupal/spam/filters/node_age/node_age.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/filters/node_age/node_age.info 1970-01-01 10:00:00.000000000 +1000 @@ -1,13 +0,0 @@ -; $Id: node_age.info,v 1.1.2.1.2.1 2008/12/25 05:42:10 jeremy Exp $ -name = Spam node age filter -description = A node-age comment filter plug-in for the spam module. -package = Spam -dependencies[] = spam -dependencies[] = comment -core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" -core = "6.x" -project = "spam" -datestamp = "1249930375" - diff -uprN /home/files/coding/drupal/spam/filters/node_age/node_age.module sites/all/modules/spam/filters/node_age/node_age.module --- /home/files/coding/drupal/spam/filters/node_age/node_age.module 2009-08-07 03:55:31.000000000 +1000 +++ sites/all/modules/spam/filters/node_age/node_age.module 1970-01-01 10:00:00.000000000 +1000 @@ -1,196 +0,0 @@ -. All rights reserved. - * - */ - -/** - * Drupal _menu() hook. - */ -function node_age_menu() { - $items = array(); - - $items['admin/settings/spam/filters/node-age'] = array( - 'title' => 'Node age', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('node_age_admin_settings'), - 'access arguments' => array('administer spam'), - 'description' => 'Configure the node age filter.', - 'type' => MENU_LOCAL_TASK, - ); - - return $items; -} - -function node_age_spamapi($op, $type = NULL, $content = array(), $fields = array(), $extra = NULL) { - - switch ($op) { - case 'filter': - if (!module_invoke('spam', 'filter_enabled', 'node_age', $type, $content, $fields, $extra)) return; - return node_age_spam_filter($content, $type, $fields, $extra); - - case 'filter_module': - return 'node_age'; - - case 'filter_info': - return array( - 'name' => t('Node age'), - 'module' => t('node_age'), - 'description' => t('A node-age comment spam filter.'), - 'help' => t('The node-age filter assigns a higher spam probability to comments made against older nodes.'), - ); - break; - - case 'filter_install': - return array( - 'status' => SPAM_FILTER_ENABLED, - 'gain' => 150, - 'weight' => -2, - ); - - } -} - -/** - * Determine if a comment is being posted against too old of a node. - */ -function node_age_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) { - if ($type == 'comment') { - $action = array(); - $id = spam_invoke_module($type, 'content_id', $content, $extra); - if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) { - $nid = arg(2); - spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('retrieved nid (@nid) from url', array('@nid' => $nid)), $type, $id); - } - else { - $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', $id)); - spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('retrieved nid (@nid) from database', array('@nid' => $nid)), $type, $id); - } - - if (!$nid) { - spam_log(SPAM_LOG, 'node_age_spam_filter', t('warning: nid not found for comment (@cid), skipping', array('@cid' => $id)), $type, $id); - $action['total'] = 0; - return $action; - } - - $node = spam_invoke_module('node', 'load', $nid); - if (is_object($node)) { - $timestamp_field = variable_get('node_age_filter_on', 'created'); - if ($node->$timestamp_field < (time() - variable_get('node_age_limit_long', 4838400))) { - $action['total'] = variable_get('node_age_weight_long', 99); - spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('node (@nid) older than long limit, spam probability(@weight)', array('@nid' => $nid, '@weight' => $action['total'])), $type, $id); - } - else if ($node->$timestamp_field < (time() - variable_get('node_age_limit_short', 2419200))) { - $action['total'] = variable_get('node_age_weight_short', 85); - spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('node (@nid) older than short limit, spam probability(@weight)', array('@nid' => $nid, '@weight' => $action['total'])), $type, $id); - } - else { - $action['total'] = 0; - spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('node (@nid) is recent.', array('@nid' => $nid)), $type, $id); - } - } else { - spam_log(SPAM_LOG, 'node_age_spam_filter', t('warning: nid (@nid) does not map to node, skipping', array('@nid' => $nid)), $type, $id); - $action['total'] = 0; - } - } - else { - spam_log(SPAM_DEBUG, 'node_age_spam_filter', t('content type is not comment, skipping'), $type, $id); - $action['total'] = 0; - } - return $action; -} - -/** - * Module administrative configuration options. - */ -function node_age_admin_settings() { - $form = array(); - $form['short'] = array( - '#type' => 'fieldset', - '#title' => 'Old content', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $limits = drupal_map_assoc(spam_range(604800, 14515200, 604800), 'format_interval'); - $weights = drupal_map_assoc(array(60, 65, 70, 75, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99)); - $form['short']['node_age_limit_short'] = array( - '#type' => 'select', - '#title' => t('Old content is content not published within the past'), - '#options' => $limits, - '#required' => TRUE, - '#default_value' => variable_get('node_age_limit_short', 2419200), - ); - $form['short']['node_age_weight_short'] = array( - '#type' => 'select', - '#title' => t('Probability that comments posted to old content is spam'), - '#options' => $weights, - '#required' => TRUE, - '#description' => t('Probability that comments posted to old content are spam, as a percentage.'), - '#default_value' => variable_get('node_age_weight_short', 85), - ); - - $form['long'] = array( - '#type' => 'fieldset', - '#title' => 'Really old content', - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ); - $form['long']['node_age_limit_long'] = array( - '#type' => 'select', - '#title' => t('Really old content is content not published within the past'), - '#options' => $limits, - '#required' => TRUE, - '#default_value' => variable_get('node_age_limit_long', 4838400), - ); - $form['long']['node_age_weight_long'] = array( - '#type' => 'select', - '#title' => t('Probability that comments posted to really old content is spam'), - '#options' => $weights, - '#required' => TRUE, - '#description' => t('Probability that comments posted to really old content are spam, as a percentage.'), - '#default_value' => variable_get('node_age_weight_long', 99), - ); - return system_settings_form($form); -} - -/** - * Validate the configuration. - */ -function node_age_admin_settings_validate($form, &$form_state) { - $limit_short = $form_state['values']['node_age_limit_short']; - $limit_long = $form_state['values']['node_age_limit_long']; - if ($limit_short >= $limit_long) { - form_set_error('node_age_limit_long', t('Really old content has to be older than old content.')); - } -} - -/** - * Save the configuration. - */ -function node_age_admin_settings_submit($form, &$form_state) { -/* TODO The 'op' element in the form values is deprecated. - Each button can have #validate and #submit functions associated with it. - Thus, there should be one button that submits the form and which invokes - the normal form_id_validate and form_id_submit handlers. Any additional - buttons which need to invoke different validate or submit functionality - should have button-specific functions. */ - if ($form_state['values']['op'] == t('Reset to defaults')) { - variable_del('node_age_limit_short'); - variable_del('node_age_weight_short'); - variable_del('node_age_limit_long'); - variable_del('node_age_weight_long'); - drupal_set_message('Configuration reset to defaults.'); - } - else { - variable_set('node_age_limit_short', $form_state['values']['node_age_limit_short']); - variable_set('node_age_weight_short', $form_state['values']['node_age_weight_short']); - variable_set('node_age_limit_long', $form_state['values']['node_age_limit_long']); - variable_set('node_age_weight_long', $form_state['values']['node_age_weight_long']); - drupal_set_message('Configuration saved.'); - } -} diff -uprN /home/files/coding/drupal/spam/filters/surbl/surbl.info sites/all/modules/spam/filters/surbl/surbl.info --- /home/files/coding/drupal/spam/filters/surbl/surbl.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/filters/surbl/surbl.info 1970-01-01 10:00:00.000000000 +1000 @@ -1,12 +0,0 @@ -; $Id: surbl.info,v 1.1.2.1.2.1 2008/12/25 05:42:10 jeremy Exp $ -name = Spam Surbl filter -description = A Surbl filter plug-in for the spam module. -package = Spam -dependencies[] = spam -core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" -core = "6.x" -project = "spam" -datestamp = "1249930375" - diff -uprN /home/files/coding/drupal/spam/filters/surbl/surbl.module sites/all/modules/spam/filters/surbl/surbl.module --- /home/files/coding/drupal/spam/filters/surbl/surbl.module 2008-12-25 16:42:10.000000000 +1100 +++ sites/all/modules/spam/filters/surbl/surbl.module 1970-01-01 10:00:00.000000000 +1000 @@ -1,151 +0,0 @@ -. - * - */ - -/** - * http://www.surbl.org/lists.html#multi bitmap - */ -define('SURBL_SC', 2); -define('SURBL_WS', 4); -define('SURBL_PH', 8); -define('SURBL_OB', 16); -define('SURBL_AB', 32); -define('SURBL_JP', 64); - -/** - * Spam hook_spamapi implementation. - */ -function surbl_spamapi($op, $type = NULL, $content = array(), $fields = array(), $extra = NULL) { - switch ($op) { - case 'filter': - if (!module_invoke('spam', 'filter_enabled', 'surbl', $type, $content, $fields, $extra)) return; - return surbl_spam_filter($content, $type, $fields, $extra); - - case 'filter_module': - return 'surbl'; - - case 'filter_info': - return array( - 'name' => t('Surbl filter'), - 'module' => t('surbl'), - 'description' => t('A spam url filter.'), - 'help' => t('Look up URLs in SURBL to determine if is spam.'), - ); - break; - - case 'filter_install': - return array( - 'status' => SPAM_FILTER_ENABLED, - 'gain' => 250, - 'weight' => -7, - ); - - } -} - -/** - * Extract URLs from content. - */ -function _surbl_url_extract($content, $type, $fields, $extra = array()) { - static $urls = array(); - $id = spam_invoke_module($type, 'content_id', $content, $extra); - - if (is_object($content)) { - $content = (array)$content; - } - - if (!isset($urls["$type-$id"])) { - $string = ''; - foreach ($fields['main'] as $field) { - $string .= $content["$field"] .' '; - } - if (is_array($fields['other'])) { - foreach ($fields['other'] as $field) { - $string .= $content["$field"] .' '; - } - } - - // TODO: Improve this matching. We don't actually extract mailto: urls. - $URI = "(http://|https://|ftp://|mailto:)"; - // Find all urls in content. - preg_match_all("!(

|[ \n\r\t\(]*)($URI([a-zA-Z0-9@:%_~#?&=.,/;-]*[a-zA-Z0-9@:%_~#&=/;-]))([.,?]?)(?=(

|[ \n\r\t\)]*))!i", $string, $matches); - $u = array(); - foreach ($matches[2] as $url) { - $url = preg_replace("'$URI'", '', $url); - // get full domain (ie www.sample.com) - preg_match("/^()?([^\/\"\']+)/i", $url, $domain); - // get root domain (ie sample.com) - preg_match("/[^\.\/]+\.[^\.\/]+$/", $domain[2], $root); - $u[md5($root[0])] = htmlspecialchars(drupal_strtolower($root[0])); - } - $urls["$type-$id"] = $u; - } - - return $urls["$type-$id"]; -} - -/** - * Search for known spam urls in content. - */ -function surbl_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) { - $action = array(); - - $id = spam_invoke_module($type, 'content_id', $content, $extra); - $spam = FALSE; - - $urls = _surbl_url_extract($content, $type, $fields, $extra); - - if (is_array($urls) && !empty($urls)) { - foreach ($urls as $url) { - $lookup = "$url.multi.surbl.org"; - $ip = gethostbyname($lookup); - if ($ip != $lookup) { - // this domain was in a SURBL, process accordingly - preg_match("/[^\.\/]+$/", $ip, $code); - if ($code[0] & SURBL_SC) { - spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array('@url' => $url, '@surbl' => t('SpamCop message-body URI domains'))), $type, $id); - } - if ($code[0] & SURBL_WS) { - spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array('@url' => $url, '@surbl' => t('sa-blacklist domains'))), $type, $id); - } - if ($code[0] & SURBL_PH) { - spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array('@url' => $url, '@surbl' => t('Phishing data source'))), $type, $id); - } - if ($code[0] & SURBL_OB) { - spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array('@url' => $url, '@surbl' => t('Outblaze URI blacklist'))), $type, $id); - } - if ($code[0] & SURBL_AB) { - spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array('@url' => $url, '@surbl' => t('AbuseButler spamvertised sites'))), $type, $id); - } - if ($code[0] & SURBL_JP) { - spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array('@url' => $url, '@surbl' => t('jwSpamSpy + Prolocation data source'))), $type, $id); - } - $action['surbl'][] = array( - 'url' => $url, - 'probability' => 99, - ); - $spam = TRUE; - } - else { - spam_log(SPAM_DEBUG, 'surbl_spam_filter', t('not spam url(@url)', array('@url' => $url)), $type, $id); - } - } - } - - if ($spam) { - $action['total'] = 99; - } - else { - $action['total'] = 0; - } - - return $action; -} - diff -uprN /home/files/coding/drupal/spam/filters/url/url.info sites/all/modules/spam/filters/url/url.info --- /home/files/coding/drupal/spam/filters/url/url.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/filters/url/url.info 1970-01-01 10:00:00.000000000 +1000 @@ -1,13 +0,0 @@ -; $Id: url.info,v 1.1.2.1.2.1 2008/12/25 05:42:11 jeremy Exp $ -name = Spam URL filter -description = A URL filter plug-in for the spam module. -package = Spam -dependencies[] = spam -dependencies[] = bayesian -core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" -core = "6.x" -project = "spam" -datestamp = "1249930375" - diff -uprN /home/files/coding/drupal/spam/filters/url/url.module sites/all/modules/spam/filters/url/url.module --- /home/files/coding/drupal/spam/filters/url/url.module 2008-12-25 16:42:11.000000000 +1100 +++ sites/all/modules/spam/filters/url/url.module 1970-01-01 10:00:00.000000000 +1000 @@ -1,182 +0,0 @@ -. All rights reserved. - * - */ - -function url_spamapi($op, $type = NULL, $content = array(), $fields = array(), $extra = NULL) { - // Don't both with this hook unless the filter is actually enabled. - - switch ($op) { - case 'filter': - if (!module_invoke('spam', 'filter_enabled', 'url', $type, $content, $fields, $extra)) return; - return url_spam_filter($content, $type, $fields, $extra); - - case 'filter_module': - return 'url'; - - case 'filter_info': - return array( - 'name' => t('URL filter'), - 'module' => t('url'), - 'description' => t('A spam url filter.'), - 'help' => t('The url filter blocks posts containing spam-URLs, automatically learned with the bayesian filter module.'), - ); - break; - - case 'filter_install': - return array( - 'status' => SPAM_FILTER_ENABLED, - 'gain' => 250, - 'weight' => -6, - ); - - case 'mark_as_spam': - case 'mark_as_not_spam': - if (!module_invoke('spam', 'filter_enabled', 'url', $type, $content, $fields, $extra)) return; - spam_log(SPAM_DEBUG, 'url_spamapi', t('@op', array('@op' => $op)), $type, $extra['id']); - $fields = spam_invoke_module($type, 'filter_fields', $extra['content']); - $urls = _url_extract($extra['content'], $type, $fields, $extra); - url_update($urls, ($op == 'mark_as_spam' ? TRUE : FALSE), $type, $extra['id']); - break; - } -} - -function _url_extract($content, $type, $fields, $extra = array()) { - static $urls = array(); - $id = spam_invoke_module($type, 'content_id', $content, $extra); - - if (is_object($content)) { - $content = (array)$content; - } - - if (!isset($urls["$type-$id"])) { - $string = ''; - foreach ($fields['main'] as $field) { - $string .= $content["$field"] .' '; - } - if (is_array($fields['other'])) { - foreach ($fields['other'] as $field) { - $string .= $content["$field"] .' '; - } - } - - // TODO: Improve this matching. We don't actually extract mailto: urls. - $URI = "(http://|https://|ftp://|mailto:)"; - // Find all urls in content. - preg_match_all("!(

|[ \n\r\t\(]*)($URI([a-zA-Z0-9@:%_~#?&=.,/;-]*[a-zA-Z0-9@:%_~#&=/;-]))([.,?]?)(?=(

|[ \n\r\t\)]*))!i", $string, $matches); - foreach ($matches[2] as $url) { - $url = preg_replace("'$URI'", '', $url); - // get full domain (ie www.sample.com) - preg_match("/^()?([^\/\"\']+)/i", $url, $domain); - // get root domain (ie sample.com) - preg_match("/[^\.\/]+\.[^\.\/]+$/", $domain[2], $root); - $url = htmlspecialchars(drupal_strtolower($root[0])); - _url_count($url); - $u[] = $url; - } - $urls["$type-$id"] = $u; - } - - return $urls["$type-$id"]; -} - -/** - * Search for known spam urls in content. - */ -function url_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) { - $action = array(); - - $id = spam_invoke_module($type, 'content_id', $content, $extra); - $spam = FALSE; - - $urls = _url_extract($content, $type, $fields, $extra); - - if (is_array($urls) && !empty($urls)) { - $count = _url_count(); - - $limit = variable_get('url_limit_total', 10); - if ($limit > -1 && $count['total'] > $limit) { - spam_log(SPAM_VERBOSE, 'url_spam_filter', t('total urls(@total) > url_limit_total(@limit)', array('@total' => $count['total'], '@limit' => variable_get('url_limit_total', 10))), $type, $id); - $action['url'][] = array( - 'limit' => 'total', - 'total' => $count['total'], - ); - $action['total'] = 99; - return $action; - } - $limit = variable_get('url_limit_repeat', 5); - if ($limit > -1) { - // Sort urls from most repeated to least repeated. - asort($count); - - // skip count['total'] - array_pop($count); - - $max = array_pop($count); - if ($max > $limit) { - spam_log(SPAM_VERBOSE, 'url_spam_filter', t('repeated urls(@total) > url_limit_repeat(@limit)', array('@total' => $max, '@limit' => variable_get('url_limit_repeat', 5))), $type, $id); - $action['url'][] = array( - 'limit' => 'repeat', - 'total' => $max, - ); - $action['total'] = 99; - } - } - - foreach ($urls as $url) { - $p = db_fetch_object(db_query("SELECT probability FROM {bayesian_tokens} WHERE class = 'url' AND token = '%s'", $url)); - $action['url'][] = array( - 'url' => $url, - 'probability' => $p->probability, - ); - if ($p->probability >= variable_get('spam_threshold', SPAM_DEFAULT_THRESHOLD)) { - spam_log(SPAM_VERBOSE, 'url_spam_filter', t('found spam url(@url) probability(@probability)', array('@url' => $url, '@probability' => $p->probability)), $type, $id); - $spam = TRUE; - break; - } - spam_log(SPAM_DEBUG, 'url_spam_filter', t('not spam url(@url) probability(@probability)', array('@url' => $url, '@probability' => $p->probability)), $type, $id); - } - } - - if ($spam) { - $action['total'] = 99; - } - else { - $action['total'] = 0; - } - - return $action; -} - -/** - * Update url probabilities in database. - */ -function url_update($urls, $yes, $type, $id) { - module_invoke('bayesian', 'tokens_update', 'url', $urls, $yes, $type, $id); -} - -/** - * Keep track of the total number of URLs found in the current content. - * - * @param $url A URL to be added to a static array. - * @return Array of URLs showing how many times each URL is present, and - * the total number of arrays. - */ -function _url_count($url = NULL) { - // build up an array of all URLs seen in current content - static $urls = array(); - - if ($url != NULL) { - $urls["$url"]++; - $urls['total']++; - } - - return $urls; -} - diff -uprN /home/files/coding/drupal/spam/INSTALL.txt sites/all/modules/spam/INSTALL.txt --- /home/files/coding/drupal/spam/INSTALL.txt 2009-08-11 04:33:54.000000000 +1000 +++ sites/all/modules/spam/INSTALL.txt 2009-08-11 05:47:41.000000000 +1000 @@ -22,11 +22,11 @@ to always visit update.php to perform an ------------- Installation: ------------- -1) Extra the spam tarball. Move the resulting 'spam/' subdirectory within the +1) Extract the spam tarball. Move the resulting 'spam/' subdirectory within the appropriate 'sites/*/modules' directory. Be sure the web server has read permissions to this directory and the files within it. -2) Log into your website and enabled the spam module. +2) Log into your website and enable the spam module. Visit "Administer >> Site building >> Modules" and scroll down to the spam section. Put a check mark next to "Spam API" and any spam filters you'd diff -uprN /home/files/coding/drupal/spam/modules/spam_comment.inc sites/all/modules/spam/modules/spam_comment.inc --- /home/files/coding/drupal/spam/modules/spam_comment.inc 2009-08-07 06:37:19.000000000 +1000 +++ sites/all/modules/spam/modules/spam_comment.inc 1970-01-01 10:00:00.000000000 +1000 @@ -1,387 +0,0 @@ -cid))) { - $comment->status = COMMENT_NOT_PUBLISHED; - } - break; - } -} - -/** - * Cache the comment id to be sure it's available when we need it. - */ -function _spam_comment_cid($id = NULL) { - static $cid = 0; - - if (isset($id) && is_numeric($id)) { - $cid = $id; - } - - return $cid; -} - -/** - * Spam module _spamapi() hook. - */ -function comment_spamapi($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL) { - switch ($op) { - case 'content_module': - // Register with the spam api as a content type module. - return 'comment'; - - case 'content_id': - // Tell the spam module the id of a given comment. - if (is_object($arg1)) { - // The delete hook uses an object instead of an array. - $arg1 = (array)$arg1; - } - return _spam_comment_cid($arg1['cid']); - - case 'content_types': - // Register the "comment" content type with the spam module. - return array(array( - 'name' => t('comments'), - 'module' => t('comment'), - 'title' => t('Comments'), - 'description' => t('Check this box to filter comments for spam.'), - 'default_value' => 1, - )); - - case 'filter_content_type': - return (variable_get('spam_filter_comments', 1)); - - case 'filter_fields': - // Tell spam module which fields it should scan for spam. - $fields['main'] = array('subject', 'comment'); - if (is_object($arg1)) { - // The delete hook uses an object instead of an array. - $arg1 = (array)$arg1; - } - if (isset($arg1['author'])) { - $fields['other'][] = 'author'; - } - if (isset($arg1['name'])) { - $fields['other'][] = 'name'; - } - if (isset($arg1['mail'])) { - $fields['other'][] = 'mail'; - } - if (isset($arg1['homepage'])) { - $fields['other'][] = 'homepage'; - } - return $fields; - - case 'feedback_form': - $form = array(); - if (is_numeric($form['cid'])) { - $form['cid'] = array( - '#type' => 'textfield', - '#title' => t('Comment ID'), - '#value' => $arg1['cid'], - '#disabled' => TRUE, - ); - } - // fall through... - case 'error_form': - if (!is_array($form)) { - $form = array(); - } - $form['comment'] = array( - '#type' => 'fieldset', - '#title' => 'Comment', - ); - $form['comment']['title'] = array( - '#type' => 'textfield', - '#title' => t('Subject'), - '#value' => $arg1['subject'], - '#disabled' => TRUE, - ); - $form['comment']['body'] = array( - '#type' => 'textarea', - '#title' => t('Comment'), - '#value' => $arg1['comment'], - '#disabled' => TRUE, - ); - $form['comment']['author'] = array( - '#type' => 'markup', - '#prefix' => '
' . t('Author') . ':
', - '#value' => theme('username', user_load(array('uid' => $arg1['uid']))), - ); - return $form; - - case 'load': - return db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $arg1)); - - case 'title': - return db_result(db_query('SELECT subject FROM {comments} WHERE cid = %d', $arg1)); - - case 'edit_link': - return "comment/edit/$arg1"; - - case 'status': - $status = db_result(db_query('SELECT status FROM {comments} WHERE cid = %d', $arg1)); - if ($status == COMMENT_PUBLISHED) { - return SPAM_PUBLISHED; - } - else { - return SPAM_NOT_PUBLISHED; - } - - case 'hostname': - return db_result(db_query('SELECT hostname FROM {comments} WHERE cid = %d', $arg1)); - - case 'link': - if (is_object($arg1) && isset($arg1->cid)) { - return spam_links('comment', $arg1->cid, $arg1); - } - break; - - case 'redirect': - $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', $arg1)); - return drupal_goto("/node/$nid", NULL, "comment-$arg1"); - - case 'overview_filter_join': - return 'INNER JOIN {comments} c ON t.content_id = c.cid'; - - case 'overview_filter_where': - switch ($arg1) { - case 'title': - return "c.subject LIKE '%%%s%%'"; - case 'status': - return 'c.status = %d'; - } - - case 'menu': - // Create page for listing all spam comments in comment admin section. - $items = array(); - $items['admin/content/comment/list/spam'] = array( - 'title' => t('Spam'), - 'page callback' => 'spam_comment_admin', - 'access arguments' => array('administer spam'), - //TODO: remove dependencies on comment.admin.inc? - 'file' => 'comment.admin.inc', - 'file path' => drupal_get_path('module', 'comment'), - 'type' => MENU_LOCAL_TASK, - ); - return $items; - - case 'publish': - // Only update comments that exist and need to be published. - $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d AND status = %d OR status = %d', $arg1, COMMENT_NOT_PUBLISHED, SPAM_COMMENT)); - if ($nid) { - db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_PUBLISHED, $arg1); - _comment_update_node_statistics($nid); - } - break; - - case 'unpublish': - // Only update comments that exist and need to be unpublished. - // When 'unpublishing' comments, we actually mark them as spam. - $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d AND status = %d', $arg1, COMMENT_PUBLISHED)); - if ($nid) { - db_query('UPDATE {comments} SET status = %d WHERE cid = %d', SPAM_COMMENT, $arg1); - _comment_update_node_statistics($nid); - } - break; - - case 'theme_forms': - // Add spam comments admin form to spam.module's hook_theme. - return array( - 'spam_comment_admin_overview' => array( - 'file' => 'modules/spam_comment.inc', - 'arguments' => array( - 'form' => NULL, - ), - ), - ); - } -} - -/** - * Form alter gets its own function so we can reference &$form without causing - * errors in PHP4 installations. (If we use spamapi, we have to set a default, - * which PHP4 doesn't support.) - */ -function comment_spamapi_form_alter(&$form, &$form_state, $form_id) { - // Scan comments before they are inserted into the database - if ($form_id == 'comment_form' && is_array($form)) { - $form['#validate'][] = 'comment_spam_scan'; - } - // Add spam options to comment form - else if ($form_id == 'comment_admin_overview' || $form_id == 'spam_comment_admin_overview') { - $form['#spam_submit_valuetype'] = 'comments'; - $form['#spam_submit_itemtype'] = 'comment'; - $form['#submit'] = array_merge(array('spam_admin_overview_submit'), $form['#submit']); - $parameters = $form['#parameters']; - if (is_array($parameters)) { - if (!in_array('new', $parameters)) { - $form['options']['operation']['#options']['markasnotspam'] = 'Mark the selected comments as not spam'; - } - if (!in_array('spam', $parameters)) { - $form['options']['operation']['#options']['markasspam'] = 'Mark the selected comments as spam'; - } - if (in_array('new', $parameters)) { - $form['options']['operation']['#options']['teachnotspam'] = 'Teach filters selected comments are not spam'; - } - } - if (is_array($form['#post']) && is_array($form['#post']['comments'])) { - foreach ($form['#post']['comments'] as $cid) { - $score = _spam_comment_score($cid); - if ($form['#post']['operation'] == 'markasspam') { - if (!spam_score_is_spam($score)) { - spam_mark_as_spam('comment', $cid); - } - } - else if ($form['#post']['operation'] == 'markasnotspam') { - if (spam_score_is_spam($score)) { - spam_mark_as_not_spam('comment', $cid); - } - } - else if ($form['#post']['operation'] == 'teachnotspam') { - spam_mark_as_not_spam('comment', $cid); - } - } - } - } -} - -/** - * Retreive spam score, caching in memory for repeated use. - */ -function _spam_comment_score($cid) { - static $scores = array(); - - if (!isset($scores[$cid])) { - $scores[$cid] = db_result(db_query("SELECT score FROM {spam_tracker} WHERE content_type = 'comment' AND content_id = %d", $cid)); - } - - return $scores[$cid]; -} - -/** - * Menu callback; present an administrative spam comment listing. - */ -function spam_comment_admin() { - $edit = $_POST; - - if ($edit['operation'] == 'delete' && $edit['comments']) { - return drupal_get_form('comment_multiple_delete_confirm'); - } - else { - return drupal_get_form('spam_comment_admin_overview', arg(4)); - } -} - -/** - * The 5.x version of comment_admin_overview doesn't provide hooks to easily - * create a spam overview page. This is nearly an exact copy of that function, - * with minor changes for loading spam and processing it. - */ -function spam_comment_admin_overview(&$form_state, $arg) { - // build an 'Update options' form - $form['options'] = array( - '#type' => 'fieldset', '#title' => t('Update options'), - '#prefix' => '
', '#suffix' => '
' - ); - $options = array( - 'markasnotspam' => t('Mark the selected comments as not spam'), - 'delete' => t('Delete the selected comments'), - ); - - $form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'markasnotspam'); - $form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update')); - - // load the comments that we want to display - $form['header'] = array('#type' => 'value', '#value' => array( - theme('table_select_header_cell'), - array('data' => t('Subject'), 'field' => 'subject'), - array('data' => t('Author'), 'field' => 'name'), - array('data' => t('Posted in'), 'field' => 'node_title'), - array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'), - array('data' => t('Operations')) - )); - $result = pager_query('SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, n.title AS node_title FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid INNER JOIN {node} n ON n.nid = c.nid WHERE c.status = %d'. tablesort_sql($form['header']['#value']), 50, 0, NULL, SPAM_COMMENT); - - // build a table listing the appropriate comments - $destination = drupal_get_destination(); - while ($comment = db_fetch_object($result)) { - $comments[$comment->cid] = ''; - $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - $form['subject'][$comment->cid] = array('#value' => l($comment->subject, 'node/'. $comment->nid, array('attributes' => array('title' => truncate_utf8($comment->comment, 128)), 'fragment' => 'comment-'. $comment->cid))); - $form['username'][$comment->cid] = array('#value' => theme('username', $comment)); - $form['node_title'][$comment->cid] = array('#value' => l($comment->node_title, 'node/'. $comment->nid)); - $form['timestamp'][$comment->cid] = array('#value' => format_date($comment->timestamp, 'small')); - $form['operations'][$comment->cid] = array('#value' => l(t('edit'), 'comment/edit/'. $comment->cid, array('query' => $destination))); - } - $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments); - $form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); - - return $form; -} - -/** - * Duplicate function from comment module so we can set correct goto url. - */ -function spam_comment_admin_overview_validate($form, &$form_state) { - $form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0)); - if (count($form_state['values']['comments']) == 0) { - form_set_error('', t('Please select one or more comments to perform the update on.')); - drupal_goto('admin/content/comment/list/spam'); - } -} - -/** - * Re-use function from comment module. - */ -function spam_comment_admin_overview_submit($form, &$form_state) { - comment_admin_overview_submit($form, $form_state); -} - -/** - * Re-use function from comment module. - */ -function theme_spam_comment_admin_overview($form) { - return theme('comment_admin_overview', $form); -} - -/** - * Scan comment content before it is posted into the database. - */ -function comment_spam_scan($form, &$form_state) { - if ($form_state['clicked_button']['#value'] == t('Save')) { - $comment = $form['#post']; - $_SESSION['spam_form'] = $form; - spam_scan($comment, 'comment'); - } - else if (isset($_SESSION['spam_form'])) { - unset($_SESSION['spam_form']); - } -} diff -uprN /home/files/coding/drupal/spam/modules/spam_node.inc sites/all/modules/spam/modules/spam_node.inc --- /home/files/coding/drupal/spam/modules/spam_node.inc 2009-08-07 07:06:50.000000000 +1000 +++ sites/all/modules/spam/modules/spam_node.inc 1970-01-01 10:00:00.000000000 +1000 @@ -1,200 +0,0 @@ - $type->type, - 'module' => $type->module, - 'title' => $type->name, - 'description' => $type->description, - 'default_value' => 0, - ); - } - return $types; - - case 'filter_content_type': - if (is_array($arg1)) { - $arg1 = (object)$arg1; - } - return (variable_get("spam_filter_$arg1->type", 0)); - - case 'filter_fields': - // Tell spam filter which fields should be scanned for spam. - $fields['main'] = array('title', 'body'); - // TODO: other fields (CCK) - return $fields; - - case 'feedback_form': - $form = array(); - if (is_numeric($form['nid'])) { - $form['nid'] = array( - '#type' => 'textfield', - '#title' => t('Node ID'), - '#value' => $arg1['nid'], - '#disabled' => TRUE, - ); - } - // fall through... - case 'error_form': - if (!is_array($form)) { - $form = array(); - } - $form['node'] = array( - '#type' => 'fieldset', - '#title' => $type, - ); - $form['node']['title'] = array( - '#type' => 'textfield', - '#title' => t('Title'), - '#value' => $arg1['title'], - '#disabled' => TRUE, - ); - $form['node']['body'] = array( - '#type' => 'textarea', - '#title' => t('Body'), - '#value' => $arg1['body'], - '#disabled' => TRUE, - ); - $form['node']['author'] = array( - '#type' => 'markup', - '#prefix' => '
' . t('Author') . ':
', - '#value' => theme('username', user_load(array('uid' => $arg1['uid']))), - ); - // TODO: CCK fields - return $form; - - case 'load': - return node_load($arg1); - - case 'title': - return db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $arg1)); - - case 'status': - $status = db_result(db_query('SELECT status FROM {node} WHERE nid = %d', $arg1)); - if ($status == 1) { - return SPAM_PUBLISHED; - } - else { - return SPAM_NOT_PUBLISHED; - } - - case 'edit_link': - return "node/$arg1/edit"; - - case 'link': - if (is_object($arg1) && isset($arg1->nid)) { - return spam_links('node', $arg1->nid, $arg1); - } - break; - - case 'redirect': - return drupal_goto("/node/$arg1"); - - case 'overview_filter_join': - return 'INNER JOIN {node} n ON t.content_id = n.nid'; - - case 'overview_filter_where': - switch ($arg1) { - case 'title': - return "n.title LIKE '%%%s%%'"; - case 'status': - return "n.status != %d"; - } - - case 'publish': - if (is_numeric($arg1)) { - $arg1 = node_load($arg1); - node_publish_action($arg1); - node_save($arg1); - } - break; - - case 'unpublish': - if (is_numeric($arg1)) { - $arg1 = node_load($arg1); - node_unpublish_action($arg1); - node_save($arg1); - } - break; - - } -} - -/** - * Form alter gets its own function so we can reference &$form without causing - * errors in PHP4 installations. (If we use spamapi, we have to set a default, - * which PHP4 doesn't support.) - */ -function node_spamapi_form_alter(&$form, &$form_state, $form_id) { - if (strpos($form_id, '_node_form')) { - $form['#validate'][] = 'node_spam_scan'; - } -} - -/** - * Scan node content before it is posted into the database. - */ -function node_spam_scan($form, &$form_state) { - if ($form_state['clicked_button']['#value'] == t('Save')) { - $node = $form['#post']; - $node['type'] = $form['type']['#value']; - $_SESSION['spam_form'] = $form; - spam_scan($node, 'node'); - } - else if (isset($_SESSION['spam_form'])) { - unset($_SESSION['spam_form']); - } -} diff -uprN /home/files/coding/drupal/spam/modules/spam_user.inc sites/all/modules/spam/modules/spam_user.inc --- /home/files/coding/drupal/spam/modules/spam_user.inc 2009-08-07 06:44:26.000000000 +1000 +++ sites/all/modules/spam/modules/spam_user.inc 1970-01-01 10:00:00.000000000 +1000 @@ -1,258 +0,0 @@ -uid, $user) as $link) { - if ($link['href']) { - $links .= l($link['title'], $link['href']) .' '; - } - else { - $links .= $link['title'] .' '; - } - } - $items['spam_links'] = array( - 'value' => $links, - 'class' => 'spam', - ); - $status = db_result(db_query('SELECT status FROM {users} WHERE uid = %d', $user->uid)); - $status_text = t('User status: %status', array('%status' => $status ? t('not blocked') : t('blocked'))); - $items['spam_status'] = array( - 'value' => $status_text, - 'class' => 'spam', - ); - return array(t('Spam status') => $items); - } - break; - } -} - -/** - * Cache the user id to be sure it's available when we need it. - */ -function _spam_user_uid($id) { - static $uid = 0; - - if (isset($id) && is_numeric($id)) { - $uid = $id; - } - - return $uid; -} - -/** - * User module _spamapi() hook. - */ -function user_spamapi($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL) { - switch ($op) { - case 'content_module': - // Register with the spam api as a content type module. - return 'user'; - - case 'content_id': - if (is_object($arg1)) { - $arg1 = (array)$arg1; - } - return _spam_user_uid($arg1['uid']); - - case 'content_types': - // Register the "user" content type with the spam module. - return array(array( - 'name' => t('users'), - 'module' => t('user'), - 'title' => t('Users'), - 'description' => t('Check this box to filter users for spam.'), - 'default_value' => 0, - )); - - case 'process_form': - // Hook to scan user before it is inserted into the database. - if ($arg1 == 'user_register' && is_array($arg2)) { - $user = $arg2['#post']; - if (is_array($user) && $user['op'] == t('Create new account')) { - $_SESSION['spam_form'] = $arg2; - spam_scan($user, 'user'); - } - else { - if (isset($_SESSION['spam_form'])) { - unset($_SESSION['spam_form']); - } - } - } - break; - - case 'filter_content_type': - return (variable_get('spam_filter_users', 0)); - - case 'filter_fields': - // Be sure we're always working with an array. - if (is_object($arg1)) { - $arg1 = (array)$arg1; - } - // Determine uid so we can cache fields in static. - if (isset($arg1['uid'])) { - $uid = $arg1['uid']; - } - else { - $uid = 0; - } - // Only figure out filter_fields once per user per page load. - static $fields = array(); - if (!isset($fields[$uid])) { - $fields[$uid]['main'] = array('name', 'mail'); - $fields[$uid]['other'] = array(); - if (isset($arg1['signature'])) { - $fields[$uid]['other'][] = 'signature'; - } - if (db_table_exists('profile_fields')) { - $result = db_query('SELECT name FROM {profile_fields}'); - while ($profile = db_fetch_object($result)) { - if (isset($arg1[$profile->name])) { - $fields[$uid]['other'][] = $profile->name; - } - } - } - } - return $fields[$uid]; - - case 'redirect': - if (is_numeric($arg1)) { - return drupal_goto("/user/$arg1"); - } - break; - - case 'load': - if (is_numeric($arg1)) { - return user_load(array('uid' => $arg1)); - } - break; - - case 'title': - return db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $arg1)); - - case 'edit_link': - return "user/$arg1/edit"; - - case 'status': - $status = db_result(db_query('SELECT status FROM {users} WHERE uid = %d', $arg1)); - if ($status == 1) { - return SPAM_PUBLISHED; - } - else { - return SPAM_NOT_PUBLISHED; - } - - case 'overview_filter_join': - return 'INNER JOIN {users} u ON t.content_id = u.uid'; - - case 'overview_filter_where': - switch ($arg1) { - case 'title': - return "u.name LIKE '%%%s%%'"; - case 'status': - return "u.status != %d"; - } - - case 'feedback_filter_join_field': - return 'u.uid'; - - case 'publish': - // TODO: When un/publish user, should probably also un/publish content - if (is_numeric($arg1)) { - module_invoke('user', 'user_operations_unblock', array($arg1)); - } - break; - - case 'unpublish': - // TODO: When un/publish user, should probably also un/publish content - if (is_numeric($arg1)) { - module_invoke('user', 'user_operations_block', array($arg1)); - } - break; - - case 'feedback_form': - $form = array(); - if (is_numeric($form['uid'])) { - $form['uid'] = array( - '#type' => 'textfield', - '#title' => t('User ID'), - '#value' => $arg1['uid'], - '#disabled' => TRUE, - ); - } - // fall through... - case 'error_form': - if (!is_array($form)) { - $form = array(); - } - $form['name'] = array( - '#type' => 'textfield', - '#title' => t('Username'), - '#value' => $arg1['name'], - '#disabled' => TRUE, - ); - $form['mail'] = array( - '#type' => 'textfield', - '#title' => t('Email address'), - '#value' => $arg1['mail'], - '#disabled' => TRUE, - ); - // TODO: Show profile fields. - return $form; - } -} - -/** - * Be sure we're scanning the latest profile data. - */ -function spam_user_profile_update($user) { - if (module_exists('profile')) { - profile_load_profile($user); - } - return $user; -} - -/** - * Form alter gets its own function so we can reference &$form without causing - * errors in PHP4 installations. (If we use spamapi, we have to set a default, - * which PHP4 doesn't support.) - */ -function user_spamapi_form_alter(&$form, &$form_state, $form_id) { - // Scan users before they are inserted into the database - if ($form_id == 'user_register' && is_array($form)) { - $form['#validate'][] = 'user_spam_scan'; - } -} - -/** - * Scan user before it is created in the database. - */ -function user_spam_scan($form, &$form_state) { - if ($form_state['clicked_button']['#value'] == t('Create new account')) { - $account = $form['#post']; - $_SESSION['spam_form'] = $form; - spam_scan($account, 'user'); - } - else if (isset($_SESSION['spam_form'])) { - unset($_SESSION['spam_form']); - } -} diff -uprN /home/files/coding/drupal/spam/spam.info sites/all/modules/spam/spam.info --- /home/files/coding/drupal/spam/spam.info 2009-08-11 04:52:55.000000000 +1000 +++ sites/all/modules/spam/spam.info 2009-09-01 10:28:00.000000000 +1000 @@ -3,9 +3,9 @@ name = Spam API description = The core Spam API for autodetecting and managing spam. package = Spam core = 6.x -; Information added by drupal.org packaging script on 2009-08-10 -version = "6.x-1.0" +; Information added by drupal.org packaging script on 2009-09-01 +version = "6.x-1.x-dev" core = "6.x" project = "spam" -datestamp = "1249930375" +datestamp = "1251764880" diff -uprN /home/files/coding/drupal/spam/spam.module sites/all/modules/spam/spam.module --- /home/files/coding/drupal/spam/spam.module 2009-08-10 13:03:11.000000000 +1000 +++ sites/all/modules/spam/spam.module 2009-12-11 11:33:28.000000000 +1100 @@ -1,5 +1,5 @@ name, '', 0, 5); + $module = substr_replace($file->name, '', 0, 13); if (module_exists($module)) { require_once './' . $file->filename; } @@ -971,7 +971,8 @@ function spam_init_api() { function spam_invoke_api() { $args = func_get_args(); array_unshift($args, 'spamapi'); - return call_user_func_array('module_invoke_all', $args); + $contentblah = call_user_func_array('module_invoke_all', $args); + return $contentblah; } /** @@ -1066,6 +1067,7 @@ function spam_admin_feedback_form($form_ $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete feedback'), + '#submit' => array('spam_admin_feedback_delete_submit'), ); $form['cancel'] = array( '#value' => l(t('Cancel'), 'admin/content/spam/feedback'), @@ -1099,39 +1101,27 @@ function spam_admin_feedback_form($form_ * Process spam feedback. */ function spam_admin_feedback_form_submit($form, &$form_state) { -/* TODO The 'op' element in the form values is deprecated. - Each button can have #validate and #submit functions associated with it. - Thus, there should be one button that submits the form and which invokes - the normal form_id_validate and form_id_submit handlers. Any additional - buttons which need to invoke different validate or submit functionality - should have button-specific functions. */ - if ($form_state['values']['op'] == t('Publish content')) { - $content = unserialize($form_state['values']['content']); - // mark the content as not spam - $extra['content'] = $content; - spam_mark_as_not_spam($form_state['values']['type'], $form_state['values']['id'], $extra); - // publish the content - // TODO: don't execute form if content is already published - // return will contain a url to the new content - $form = unserialize($form_state['values']['spam_form']); - $_SESSION['bypass_spam_filter'] = _spam_sign($form['#post']['form_token']); - $return = drupal_process_form($content['form_id'], unserialize($form_state['values']['spam_form'])); - db_query('DELETE FROM {spam_filters_errors} WHERE bid = %d', $form_state['values']['bid']); - drupal_set_message(t('Content published.')); - drupal_goto('admin/content/spam/feedback'); - } -/* TODO The 'op' element in the form values is deprecated. - Each button can have #validate and #submit functions associated with it. - Thus, there should be one button that submits the form and which invokes - the normal form_id_validate and form_id_submit handlers. Any additional - buttons which need to invoke different validate or submit functionality - should have button-specific functions. */ - if ($form_state['values']['op'] == t('Delete feedback')) { - // TODO: Confirm the delete. - db_query('DELETE FROM {spam_filters_errors} WHERE bid = %d', $form_state['values']['bid']); - drupal_set_message(t('Feedback deleted.')); - drupal_goto('admin/content/spam/feedback'); - } + $content = unserialize($form_state['values']['content']); + // mark the content as not spam + $extra['content'] = $content; + spam_mark_as_not_spam($form_state['values']['type'], $form_state['values']['id'], $extra); + // publish the content + // TODO: don't execute form if content is already published + // return will contain a url to the new content + $form = unserialize($form_state['values']['spam_form']); + $_SESSION['bypass_spam_filter'] = _spam_sign($form['#post']['form_token']); + $form_state = array(); + $return = drupal_process_form($content['form_id'], $form, $form_state); + db_query('DELETE FROM {spam_filters_errors} WHERE bid = %d', $form_state['values']['bid']); + drupal_set_message(t('Content published.')); + drupal_goto('admin/content/spam/feedback'); +} + +function spam_admin_feedback_delete_submit($form, &$form_state) { + // TODO: Confirm the delete. + db_query('DELETE FROM {spam_filters_errors} WHERE bid = %d', $form_state['values']['bid']); + drupal_set_message(t('Feedback deleted.')); + drupal_goto('admin/content/spam/feedback'); } function _spam_truncate($text, $length = 64) { @@ -1227,12 +1217,6 @@ function theme_spam_filter_form($form) { */ function spam_filter_form_submit($form, &$form_state) { $filters = spam_overview_filters(); -/* TODO The 'op' element in the form values is deprecated. - Each button can have #validate and #submit functions associated with it. - Thus, there should be one button that submits the form and which invokes - the normal form_id_validate and form_id_submit handlers. Any additional - buttons which need to invoke different validate or submit functionality - should have button-specific functions. */ switch ($form_state['values']['op']) { case t('Filter'): case t('Refine'): @@ -1594,8 +1578,6 @@ function _spam_sign($text) { * Helper function, generate a link for reporting mis-filtered content. */ function _spam_error_link($text) { -// TODO: Finish implementing error reporting functionality. -//return t('Unable to generate error link. Please email the site admins.'); if (($text) && is_array(unserialize($text))) { return l(t('Report spam filter error.'), "spam/denied/error/" . md5($text) .'/'. _spam_sign($text)); }