Nur in spam: d6.patch. Gemeinsame Unterverzeichnisse: /home/milian/projects/drupal-5.7/modules/spam/modules und spam/modules. Gemeinsame Unterverzeichnisse: /home/milian/projects/drupal-5.7/modules/spam/po und spam/po. diff -up /home/milian/projects/drupal-5.7/modules/spam/spam.info spam/spam.info --- /home/milian/projects/drupal-5.7/modules/spam/spam.info 2008-02-23 01:44:35.000000000 +0100 +++ spam/spam.info 2008-02-22 22:45:44.000000000 +0100 @@ -2,10 +2,5 @@ name = Spam description = A collection of tools for detecting and managing spam. - - -; Information added by drupal.org packaging script on 2007-11-29 -version = "5.x-1.x-dev" -project = "spam" -datestamp = "1196294947" - +core = 6.x +package = Spam \ Kein Zeilenumbruch am Dateiende. diff -up /home/milian/projects/drupal-5.7/modules/spam/spam.install spam/spam.install --- /home/milian/projects/drupal-5.7/modules/spam/spam.install 2008-02-23 01:44:35.000000000 +0100 +++ spam/spam.install 2008-02-23 01:53:42.000000000 +0100 @@ -2,152 +2,109 @@ // $Id: spam.install,v 1.1.2.1.2.11 2007/11/24 01:58:58 jeremy Exp $ /** + * Implementation of hook_schema() + */ +function spam_schema() { + $schema = array(); + + $schema['spam_tracker'] = array( + 'fields' => array( + 'sid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '11'), + 'source' => array('type' => 'varchar', 'length' => '64', 'not null' => TRUE, 'default' => ''), + 'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), + 'probability' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '2'), + 'hostname' => array('type' => 'varchar', 'length' => '128', 'not null' => TRUE, 'default' => ''), + 'hash' => array('type' => 'char', 'length' => '32', 'not null' => TRUE, 'default' => ''), + 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11')), + 'primary key' => array('sid'), + 'indexes' => array( + 'hash' => array('hash'), + 'hostname' => array('hostname'), + 'id' => array('id'), + 'probability' => array('probability'), + 'source' => array('source')), + ); + + $schema['spam_tokens'] = array( + 'fields' => array( + 'tid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), + 'token' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), + 'spam' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '10'), + 'notspam' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '10'), + 'probability' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '10'), + 'last' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11')), + 'primary key' => array('tid'), + 'unique keys' => array( + 'token' => array('token')), + 'indexes' => array( + 'last' => array('last'), + 'notspam' => array('notspam'), + 'probability' => array('probability'), + 'spam' => array('spam')), + ); + + $schema['spam_reported'] = array( + 'fields' => array( + 'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '11'), + 'source' => array('type' => 'varchar', 'length' => '64', 'not null' => TRUE, 'default' => ''), + 'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), + 'hostname' => array('type' => 'varchar', 'length' => '128', 'not null' => TRUE, 'default' => ''), + 'feedback' => array('type' => 'text', 'not null' => FALSE), + 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11')), + 'primary key' => array('rid'), + 'indexes' => array( + 'id' => array('id'), + 'source' => array('source'), + 'uid' => array('uid')), + ); + + $schema['spam_custom'] = array( + 'fields' => array( + 'scid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), + 'filter' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), + 'style' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '2'), + 'effect' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '2'), + 'action' => array('type' => 'int', 'unsigned' => TRUE, 'size' => 'tiny', 'not null' => FALSE, 'default' => 0, 'disp-width' => '2'), + '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')), + 'primary key' => array('scid'), + 'indexes' => array( + 'filter' => array('filter'), + 'last' => array('last'), + 'matches' => array('matches')), + ); + + $schema['spam_log'] = array( + 'fields' => array( + 'sid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '11'), + 'source' => array('type' => 'varchar', 'length' => '64', 'not null' => TRUE, 'default' => ''), + 'id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), + 'hostname' => array('type' => 'varchar', 'length' => '128', 'not null' => TRUE, 'default' => ''), + 'entry' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''), + 'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0, 'disp-width' => '11')), + 'primary key' => array('sid'), + 'indexes' => array( + 'id' => array('id'), + 'source' => array('source'), + 'timestamp' => array('timestamp')), + ); + + return $schema; +} + +/** * Implementation of hook_install() */ function spam_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {spam_tracker} ( - sid int(11) unsigned NOT NULL auto_increment, - source varchar(64) NOT NULL default '', # node, comment, trackback, etc... - id int(11) unsigned NOT NULL default '0', - probability int(2) unsigned default '0', - hostname varchar(128) NOT NULL default '', # source IP - hash char(32) NOT NULL default '', - timestamp int(11) unsigned default '0', - PRIMARY KEY sid (sid), - KEY id (id), - KEY probability (probability), - KEY source (source), - KEY hostname (hostname), - KEY hash (hash) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE {spam_tokens} ( - tid int(10) unsigned NOT NULL auto_increment, - token varchar(255) NOT NULL default '', - spam int(10) unsigned default '0', - notspam int(10) unsigned default '0', - probability int(10) unsigned default '0', - last int(11) unsigned default '0', - PRIMARY KEY tid (tid), - UNIQUE KEY token (token), - KEY spam (spam), - KEY notspam (notspam), - KEY probability (probability), - KEY last (last) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE {spam_custom} ( - scid int(10) unsigned NOT NULL auto_increment, - filter varchar(255) NOT NULL default '', - style int(2) unsigned default '0', # text, regex, URL - effect int(2) unsigned default '0', - action tinyint(2) unsigned default '0', - matches int(11) unsigned default '0', - last int(11) unsigned default '0', - PRIMARY KEY scid (scid), - KEY filter (filter), - KEY matches (matches), - KEY last (last) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE {spam_reported} ( - rid int(11) unsigned NOT NULL auto_increment, - source varchar(64) NOT NULL default '', # node, comment, trackback, etc... - id int(11) unsigned NOT NULL default '0', - uid int(10) unsigned NOT NULL default '0', - hostname varchar(128) NOT NULL default '', # source IP - feedback text NULL default '', - timestamp int(11) unsigned default '0', - PRIMARY KEY rid (rid), - KEY source (source), - KEY id (id), - KEY uid (uid) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - db_query("CREATE TABLE {spam_log} ( - sid int(11) unsigned NOT NULL auto_increment, - source varchar(64) NOT NULL default '', # node, comment, trackback, etc... - id int(11) unsigned NOT NULL default '0', - uid int(10) unsigned NOT NULL default '0', - hostname varchar(128) NOT NULL default '', # source IP - entry varchar(255) NOT NULL default '', - timestamp int(11) unsigned default '0', - PRIMARY KEY sid (sid), - KEY source (source), - KEY id (id), - KEY timestamp (timestamp) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; - db_query("INSERT INTO {spam_custom} VALUES (1, '/(adipex|cialis|phentermine|viagra)/i', 1, 1, 2, 0, 0)"); - db_query("INSERT INTO {spam_custom} VALUES (2, '/casino games|poker online|texas hold\\''em|texas holdem/i', 1, 0, 2, 0, 0)"); - db_query("INSERT INTO {spam_custom} VALUES (3, '/(american|casino|free|grand|online|party)(|-)?(blackjack|casino|gambling|poker)/i', 1, 0, 2, 0, 0)"); - db_query("INSERT INTO {spam_custom} VALUES (4, 'diet pill', 0, 0, 2, 0, 0)"); - case 'pgsql': - db_query("CREATE TABLE {spam_tracker} ( - sid serial PRIMARY KEY, - source varchar(64) NOT NULL default '', - id integer NOT NULL default 0, - probability smallint default 0, - hostname varchar(128) NOT NULL default '', - hash char(32) NOT NULL default '', - timestamp integer default 0 - );"); - db_query("CREATE INDEX {spam_tracker}_id|_key ON {spam_tracker} (id);"); - db_query("CREATE INDEX {spam_tracker}_probability_key| ON {spam_tracker} (probability);"); - db_query("CREATE INDEX {spam_tracker}_source_key| ON {spam_tracker} (source);"); - db_query("CREATE INDEX {spam_tracker}_hostname_key} ON {spam_tracker} (hostname);"); - db_query("CREATE INDEX {spam_tracker}_hash_key} ON {spam_tracker} (hash);"); - db_query("CREATE TABLE {spam_tokens} ( - tid serial PRIMARY KEY, - token varchar(255) NOT NULL default '', - spam integer DEFAULT 0 CONSTRAINT {spam_tokens_spam_unsigned} CHECK (spam >= 0), - notspam integer DEFAULT 0 CONSTRAINT {spam_tokens_notspam_unsigned} CHECK (notspam >= 0), - probability integer DEFAULT 1 CONSTRAINT {spam_tokens_probability_positive} CHECK (probability > 0), - last integer DEFAULT 0 - );"); - db_query("CREATE UNIQUE INDEX (spam_tokens_token_key) ON {spam_tokens} (token);"); - db_query("CREATE INDEX (spam_tokens_spam_key) ON {spam_tokens} (spam);"); - db_query("CREATE INDEX (spam_tokens_notspam_key) ON {spam_tokens} (notspam);"); - db_query("CREATE INDEX (spam_tokens_probability_key} ON {spam_tokens} (probability);"); - db_query("CREATE INDEX spam_tokens_last_key ON {spam_tokens} (last);"); - db_query("CREATE TABLE {spam_custom} ( - scid serial PRIMARY KEY, - filter varchar(255) NOT NULL default '', - style smallint default 0, -- text, regex, URL - effect smallint default 0, - action smallint default 0, - matches integer default 0, - last integer default 0 - );"); - db_query("CREATE INDEX {spam_custom_filter_key} ON {spam_custom} (filter);"); - db_query("CREATE INDEX {spam_custom_matches_key} ON {spam_custom} (matches);"); - db_query("CREATE INDEX {spam_custom_last_key} ON {spam_custom} (last);"); - - db_query("INSERT INTO {spam_custom} VALUES (1, '/(adipex|cialis|phentermine|viagra)/i', 1, 1, 2, 0, 0);"); - db_query("INSERT INTO {spam_custom} VALUES (2, '/casino games|poker online|texas hold''em|texas holdem/i', 1, 0, 2, 0, 0);"); - db_query("INSERT INTO {spam_custom} VALUES (3, '/(american|casino|free|grand|online|party)( |-)?(blackjack|casino|gambling|poker)/i', 1, 0, 2, 0, 0);"); - db_query("INSERT INTO {spam_custom} VALUES (4, 'diet pill', 0, 0, 2, 0, 0);"); - db_query("CREATE TABLE {spam_reported} ( - rid serial PRIMARY KEY, - source varchar(64) NOT NULL default '', - id integer NOT NULL default 0, - uid integer NOT NULL default 0, - hostname varchar(128) NOT NULL default '', - feedback text NULL default '', - timestamp integer default 0 - );"); - db_query("CREATE TABLE {spam_log} ( - sid serial PRIMARY KEY, - source varchar(64) NOT NULL default '', - id integer NOT NULL default 0, - uid integer NOT NULL default 0, - hostname varchar(128) NOT NULL default '', - entry varchar(255) NOT NULL default '', - timestamp integer default 0 - );"); - db_query("CREATE INDEX {spam_log_source_key} ON {spam_log} (source);"); - db_query("CREATE INDEX {spam_log_id_key} ON {spam_log} (id);"); - db_query("CREATE INDEX {spam_log_timestamp_key} ON {spam_log} (timestamp);"); - } + drupal_install_schema('spam'); + + db_query("INSERT INTO {spam_custom} VALUES (1, '/(adipex|cialis|phentermine|viagra)/i', 1, 1, 2, 0, 0)"); + db_query("INSERT INTO {spam_custom} VALUES (2, '/casino games|poker online|texas hold\\''em|texas holdem/i', 1, 0, 2, 0, 0)"); + db_query("INSERT INTO {spam_custom} VALUES (3, '/(american|casino|free|grand|online|party)(|-)?(blackjack|casino|gambling|poker)/i', 1, 0, 2, 0, 0)"); + db_query("INSERT INTO {spam_custom} VALUES (4, 'diet pill', 0, 0, 2, 0, 0)"); + drupal_set_message(t('All tables required by the spam module have been created.')); } @@ -156,11 +113,7 @@ function spam_install() { * This code deletes all tables and variables created by this module. */ function spam_uninstall() { - db_query("DROP TABLE {spam_tracker}"); - db_query("DROP TABLE {spam_tokens}"); - db_query("DROP TABLE {spam_custom}"); - db_query("DROP TABLE {spam_reported}"); - db_query("DROP TABLE {spam_log}"); + drupal_uninstall_schema('spam'); // TODO: Build an array of all variables that need to be deleted, and // delete them individually. This query could accidentally remove variables @@ -172,206 +125,4 @@ function spam_uninstall() { //drupal_set_message(t('All tables and variables required by the Spam module have been removed.')); drupal_set_message(t('All tables required by the Spam module have been removed.')); -} - -/** - * Updates - */ -function spam_update_1() { - $ret = array(); - - if ($GLOBALS['db_type'] == 'mysql') { - $ret[] = update_sql("ALTER TABLE {spam_tokens} RENAME TO {spam_tokens_old}"); - $ret[] = update_sql("CREATE TABLE {spam_tokens} ( - tid int(10) unsigned NOT NULL auto_increment, - token varchar(255) NOT NULL default '', - spam int(10) unsigned default '0', - notspam int(10) unsigned default '0', - probability int(10) unsigned default '0', - last int(11) unsigned default '0', - PRIMARY KEY tid (tid), - UNIQUE KEY token (token), - KEY spam (spam), - KEY notspam (notspam), - KEY probability (probability), - KEY last (last) - ) TYPE=MyISAM;"); - } - else { - $ret[] = update_sql("ALTER TABLE {spam_tokens} RENAME TO {spam_tokens_old}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_tid_seq} RENAME TO {spam_tokens_old_tid_seq}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_pkey} RENAME TO {spam_tokens_old_pkey}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_token_key} RENAME TO {spam_tokens_old_token_key}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_spam_key} RENAME TO {spam_tokens_old_spam_key}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_notspam_key} RENAME TO {spam_tokens_old_notspam_key}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_probability_key} RENAME TO {spam_tokens_old_probability_key}"); - $ret[] = update_sql("ALTER TABLE {spam_tokens_last_key} RENAME TO {spam_tokens_old_last_key}"); - $ret[] = update_sql("CREATE TABLE {spam_tokens} ( - tid serial PRIMARY KEY, - token varchar(255) UNIQUE NOT NULL DEFAULT '', - spam integer default 0, - notspam integer default 0, - probability integer default 0, - last integer default 0 )"); - $ret[] = update_sql("CREATE INDEX {spam_tokens_spam_key} ON {spam_tokens} (spam)"); - $ret[] = update_sql("CREATE INDEX {spam_tokens_notspam_key} ON {spam_tokens} (notspam)"); - $ret[] = update_sql("CREATE INDEX {spam_tokens_probability_key} ON {spam_tokens} (probability)"); - $ret[] = update_sql("CREATE INDEX {spam_tokens_last_key} ON {spam_tokens} (last)"); - } - - $orig = $new = $url = 0; - - $result = db_query('SELECT * FROM {spam_tokens_old}'); - while ($old = db_fetch_object($result)) { - $orig++; - - // test if URI, if so, just save it - if (substr($old->token, 0, 4) == 'URL*') { - $url++; - $new += spam_save_token($old->token, $old); - } - else { - $token = preg_replace('/^header\*/', '', $old->token, 1); - if ($token != $old->token) { - $header = 'header*'; - } - else { - $header = ''; - } - - $tokens = array(); - $sanitized = preg_replace('(http://|https://|ftp://|mailto:)', '', $token); - $sanitized = preg_replace("'(www\.)|()|(href=)|(target=)|(src=)'i", '', $sanitized); - $sanitized = preg_replace("/[()\{\}\[\]#.,]/", '', $sanitized); - $sanitized = strtolower($sanitized); - $delimiters = " \t\n\r-_<>'\"`/|*%^&+=~:;?"; - $tok = strtok($sanitized, $delimiters); - while ($tok !== FALSE) { - // if longer than 255 characters, truncate the token - $tokens[] = htmlspecialchars(substr("$header$tok", 0, 254)); - $tok = strtok($delimiters); - } - foreach ($tokens as $t) { - if ($t != '') { - $new += spam_save_token($t, $old); - } - } - } - } - - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql('DROP TABLE {spam_tokens_old}'); - break; - case 'pgsql': - $ret[] = update_sql('DROP TABLE {spam_tokens_old}'); - break; - } - - print "

" . t("Converting %original tokens into %new tokens.", array('%original' => $orig, '%new' => $new)) . "

"; - return $ret; -} - -function spam_save_token($token, $old) { - $existing = db_fetch_object(db_query("SELECT * from {spam_tokens} WHERE token = '%s'", $token)); - if (isset($existing->token)) { - $total = $existing->spam + $existing->notspam + $old->spam + $old->notspam; - $probability = (($existing->spam + $old->spam) / $total * 100); - if ($probability > 99) { - $probability = 99; - } - else if ($probability < 1) { - $probability = 1; - } - db_query("UPDATE {spam_tokens} SET spam = %d, notspam = %d, probability = %d, last = %d WHERE token = '%s'", - $existing->spam + $old->spam, $existing->notspam + $old->notspam, $probability, - ($existing->last >= $old->last ? $existing->last : $old->last), $existing->token); - return 0; - } - else { - // we shouldn't have to make changes here, but let's be sure things are sane $spam = $old->spam < 1 ? 1 : $old->spam; - $notspam = $old->notspam < 1 ? 1 : $old->notspam; - $total = $spam + $notspam; - $probability = ($spam / $total * 100); - if ($probability > 99) { - $probability = 99; - } - else if ($probability < 1) { - $probability = 1; - } - db_query("INSERT INTO {spam_tokens} (token, spam, notspam, probability, last) VALUES('%s', %d, %d, %d, %d)", $token, $spam, $notspam, $probability, $old->last); - return 1; - } -} - -function spam_update_2() { - $ret = array(); - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("CREATE TABLE {spam_reported} ( - rid int(11) unsigned NOT NULL auto_increment, - source varchar(64) NOT NULL default '', - id int(11) unsigned NOT NULL default '0', - uid int(10) unsigned NOT NULL default '0', - hostname varchar(128) NOT NULL default '', - feedback text NULL default '', - timestamp int(11) unsigned default '0', - PRIMARY KEY rid (rid), - KEY source (source), - KEY id (id), - KEY uid (uid) - ) TYPE=MyISAM;"); - break; - - case 'pgsql': - $ret[] = update_sql("CREATE TABLE {spam_reported} ( - rid serial PRIMARY KEY, - source varchar(64) NOT NULL default '', - id integer NOT NULL default 0, - uid integer NOT NULL default 0, - hostname varchar(128) NOT NULL default '', - feedback text NULL default '', - timestamp integer default 0);"); - - break; - } - - return $ret; -} - -function spam_update_3() { - return _system_update_utf8(array('spam_tracker', 'spam_tokens', 'spam_custom', 'spam_reported', 'spam_log', 'spam_tracker')); -} - -/** - * Changes to administrative menus require that the menu cache be flushed. - * This should have been included with release 1.1. - */ -function spam_update_4() { - // Kludge so we only execute this update once. - static $already = FALSE; - if ($already) { - return; - } - $already = TRUE; - $ret = array(); - $ret[] = update_sql("DELETE FROM {cache_menu}"); - return $ret; -} - -/** - * Original version of spam_update_4 resulted in an error. _update_5 is added - * for anyone who may have already updated to version 1.1-1. - */ -function spam_update_5() { - $rc = spam_update_4(); - // Kludge so we only execute update once, and don't return errors either way. - if ($rc) { - return $rc; - } - return array(); -} +} \ Kein Zeilenumbruch am Dateiende. diff -up /home/milian/projects/drupal-5.7/modules/spam/spam.module spam/spam.module --- /home/milian/projects/drupal-5.7/modules/spam/spam.module 2008-02-23 01:44:35.000000000 +0100 +++ spam/spam.module 2008-02-23 03:03:22.000000000 +0100 @@ -89,11 +89,11 @@ function spam_content_filter($source, $i $old = db_fetch_object(db_query("SELECT * FROM {spam_tracker} WHERE source = '%s' AND id = %d", $source, $id)); if ($old->id) { // content has been updated - db_query("UPDATE {spam_tracker} SET probability = %d, hostname = '%s', hash = '%s', timestamp = %d WHERE source = '%s' AND id = '%d'", $probability, $_SERVER['REMOTE_ADDR'], $hash, time(), $source, $id); + db_query("UPDATE {spam_tracker} SET probability = %d, hostname = '%s', hash = '%s', timestamp = %d WHERE source = '%s' AND id = '%d'", $probability, ip_address(), $hash, time(), $source, $id); } else { // this is the first time we've filtered this content - db_query("INSERT INTO {spam_tracker} (id, source, probability, hostname, hash, timestamp) VALUES(%d, '%s', %d, '%s', '%s', %d)", $id, $source, $probability, $_SERVER['REMOTE_ADDR'], $hash, time()); + db_query("INSERT INTO {spam_tracker} (id, source, probability, hostname, hash, timestamp) VALUES(%d, '%s', %d, '%s', '%s', %d)", $id, $source, $probability, ip_address(), $hash, time()); } spam_log(SPAM_LOG, t('spam_content_filter: @prob% probability of being spam for @source "%header"', array('@prob' => $probability, '@source' => $source, '%header' => $header)), $source, $id); @@ -105,7 +105,7 @@ function spam_content_filter($source, $i else { $return = spam_default_actions($source, $id, $header, $body, $probability, $old, $action); } - + if ($probability >= variable_get('spam_threshold', 80)) { /* This ip should have already been blocked when the content was previewed, * but if the website is not configured to require previews this is our @@ -134,9 +134,9 @@ function spam_ip_filter($source, $id, $f $blacklist = variable_get('spam_blacklist_ip', 2); if ($blacklist > -1) { $filtered ? $blacklist++ : ''; - $ip = db_fetch_object(db_query("SELECT count(sid) AS count FROM {spam_tracker} WHERE probability >= %d AND hostname = '%s'", variable_get('spam_threshold', 80), $_SERVER['REMOTE_ADDR'])); + $ip = db_fetch_object(db_query("SELECT count(sid) AS count FROM {spam_tracker} WHERE probability >= %d AND hostname = '%s'", variable_get('spam_threshold', 80), ip_address())); if ($ip->count >= $blacklist) { - spam_log(SPAM_VERBOSE, t('spam_ip_filter: blocked @hostname from posting content due to @num earlier spam postings.', array('@hostname' => $_SERVER['REMOTE_ADDR'], '@num' => "$ip->count")), $source, $id); + spam_log(SPAM_VERBOSE, t('spam_ip_filter: blocked @hostname from posting content due to @num earlier spam postings.', array('@hostname' => ip_address(), '@num' => "$ip->count")), $source, $id); // This IP address has been blacklisted but is continuing to attempt to // post content. Some spammer scripts can pound your site so heavily as // to cause a DoS, so we will attempt to slow them down by sleeping for @@ -148,7 +148,7 @@ function spam_ip_filter($source, $id, $f if (!module_invoke('throttle', 'status')) { sleep(variable_get('spam_ip_filter_sleep', 25)); } - drupal_set_message(t('Your IP address (@ip) was recently used to post spam to this website. For this reason, you are currently not allowed to post new content. If you believe this is in error, please contact the site administrator.', array('@ip' => $_SERVER['REMOTE_ADDR']))); + drupal_set_message(t('Your IP address (@ip) was recently used to post spam to this website. For this reason, you are currently not allowed to post new content. If you believe this is in error, please contact the site administrator.', array('@ip' => ip_address()))); drupal_access_denied(); exit(); } @@ -157,7 +157,7 @@ function spam_ip_filter($source, $id, $f /* Compares log request to current logging level, and if appropriate writes * the log entry into the spam_log database table. - * + * * @param $level The level of the current log message. * @param $message The text of the message to be logged. * @param $source Optional text specifying source (type) of content. @@ -176,7 +176,7 @@ function spam_log($level, $message, $sou $source = $SOURCE; if (variable_get('spam_log_level', SPAM_LOG) >= $level) { - db_query("INSERT INTO {spam_log} (hostname, source, id, uid, entry, timestamp) VALUES('%s', '%s', %d, %d, '%s', %d)", $_SERVER['REMOTE_ADDR'], $source, $id, $user->uid, $message, time()); + db_query("INSERT INTO {spam_log} (hostname, source, id, uid, entry, timestamp) VALUES('%s', '%s', %d, %d, '%s', %d)", ip_address(), $source, $id, $user->uid, $message, time()); } } @@ -195,7 +195,7 @@ define('WEIGHT_NEVER_SPAM', -200); * @path Current display path * @return Text appropriate for current $path */ -function spam_help($path) { +function spam_help($path, $arg) { switch ($path) { case 'admin/help#spam': $output .= '

'. t("The spam module is a powerful collection of tools designed to help website administrators to automatically deal with spam. Spam is any content that is posted to a website that is unrelated to the subject at hand, usually in the form of advertising and links back to the spammer's own website. This module can automatically detect spam, instantly unpublish it, and send notification to the site administrator.") .'

'; @@ -217,10 +217,10 @@ function spam_help($path) { case 'admin/content/node/list/reported': $output .= '

'. t('The following content has been reported as spam.') .'

'; break; - case 'admin/logs/spam': + case 'admin/reports/spam': $output .= t('If enabled, the spam module will log the various filter actions that lead up to site content being marked as spam or not spam. These logs can be helpful in understanding why certain content was or was not marked as spam.'); break; - case 'admin/logs/spam/blockedips': + case 'admin/reports/spam/blockedips': $output .= t('The following IPs have been marked as blocked.'); break; case 'admin/settings/spam/filter': @@ -280,7 +280,7 @@ function spam_admin_settings_filter() { '#type' => 'fieldset', '#title' => 'Filter', ); - + $form['filter']['spam_filter_comments'] = array( '#type' => 'checkbox', '#title' => t('Filter comments'), @@ -288,7 +288,7 @@ function spam_admin_settings_filter() { '#default_value' => variable_get('spam_filter_comments', 1), '#description' => t('Enable this option to filter new comments as they are posted, determining whether or not they are spam.'), ); - + $form['filter']['content_types'] = array( '#type' => 'fieldset', '#title' => t('Filter content types'), @@ -296,7 +296,7 @@ function spam_admin_settings_filter() { '#collapsed' => FALSE, '#description' => t('Examine these content types as they are posted, determining whether or not they are spam. This could be useful if you allow anonymous users to post content or public registrations.'), ); - + $node_types = node_get_types(); foreach ($node_types as $type => $properties) { $form['filter']['content_types']["spam_filter_$type"] = array( @@ -307,7 +307,7 @@ function spam_admin_settings_filter() { // '#description' => t("Enable this option to filter new $name content as it is posted, determining whether or not it is spam."), ); } - + $form['filter']['spam_filter_urls'] = array( '#type' => 'checkbox', '#title' => t('Filter spam URLs'), @@ -315,7 +315,7 @@ function spam_admin_settings_filter() { '#default_value' => variable_get('spam_filter_urls', 1), '#description' => t('Enabling this option will tell the spam filter to treat URLs embedded within comments and other contents as a special case. When URLs that were found within known spam are found in new content, the new content is automatically considered to be spam. When this option is enabled, a single spam URL found within an otherwise spam-free posting will cause the filter to mark the new content as spam.'), ); - + // provide hook for external modules to define custom filter types $hook = spam_invoke_hook('filter_settings'); if ($hook['group']) { @@ -331,7 +331,7 @@ function spam_admin_settings_limits() { '#type' => 'fieldset', '#title' => 'Limits', ); - + $limits = array(-1 => t('unlimited'), 0 => t('none'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 50 => 50, 100 => 100); $form['limits']['spam_urls_total'] = array( '#type' => 'select', @@ -340,7 +340,7 @@ function spam_admin_settings_limits() { '#options' => $limits, '#description' => t('Specificy the maximum number of URLs that are allowed in a single posting before it is considered to be spam. For example, if you select 5 from the pop down menu, and then a posting to your site has 6 weblinks, the posting will be marked as spam. Some form of filtering must be enabled above for this to have any affect.'), ); - + unset($limits[0]); $form['limits']['spam_urls_repeat'] = array( '#type' => 'select', @@ -349,7 +349,7 @@ function spam_admin_settings_limits() { '#options' => $limits, '#description' => t('Specificy the maximum number of times that the same URL is allowed to appear in a single posting before it is considered to be spam. For example, if you select 5 from the pop down menu, and then a posting has 6 weblinks to the same exact location, the posting will be marked as spam. Some form of filtering must be enabled above for this to have any affect.'), ); - + $form['limits']['spam_duplicate_content'] = array( '#type' => 'select', '#title' => t('Maximum duplicate content'), @@ -357,7 +357,7 @@ function spam_admin_settings_limits() { '#options' => $limits, '#description' => t('Specify the maximum number of times the same identical posting will be allowed to your site before all of the duplicate postings are considered spam. Some times a user may accidently hit "submit" multiple times, causing an otherwise acceptible posting to be duplicated. However, other times a spammer may repeatedly post the same spam content to your site.'), ); - + $form['limits']['spam_blacklist_ip'] = array( '#type' => 'select', '#title' => t('Detected spam postings before blacklisting IP'), @@ -374,7 +374,7 @@ function spam_admin_settings_actions() { '#type' => 'fieldset', '#title' => 'Actions', ); - + $form['actions']['spam_unpublish'] = array( '#type' => 'checkbox', '#title' => t('Unpublish spam'), @@ -382,7 +382,7 @@ function spam_admin_settings_actions() { '#default_value' => variable_get('spam_unpublish', 1), '#description' => t('When checked, any new content that is detected as spam will be automatically unpublished. This will prevent the content from being displayed, allowing a site administrator a chance to first review it.'), ); - + $form['actions']['spam_notify_user'] = array( '#type' => 'checkbox', '#title' => t('Notify user'), @@ -390,7 +390,7 @@ function spam_admin_settings_actions() { '#default_value' => variable_get('spam_notify_user', 1), '#description' => t('If both the above "Unpublish spam" box and this box are checked, users will be notified with a message when the content they post is blocked by the spam filter. This is intended to minimize confusion when the spam filter mistakes a valid posting as spam and the posting doesn\'t immediately apear to the user.'), ); - + $form['actions']['spam_notify_admin'] = array( '#type' => 'checkbox', '#title' => t('Email notification'), @@ -398,10 +398,10 @@ function spam_admin_settings_actions() { '#default_value' => variable_get('spam_notify_admin', 1), '#description' => t('Enabling this option will cause an email to be sent to the site administrator whenever the filters detect spam content.'), ); - + $period = drupal_map_assoc(array(0, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), 'format_interval'); $period[0] = t('never'); - + $form['actions']['spam_expire_time'] = array( '#type' => 'select', '#title' => t('Expire spam after'), @@ -409,7 +409,7 @@ function spam_admin_settings_actions() { '#options' => $period, '#description' => t('Content that is marked as spam for more than the selected amount of time will be automatically and permanently deleted. Requires crontab.'), ); - + // provide hook for external modules to define actions $updated = spam_invoke_hook('action_settings'); if ($updated['group']) { @@ -424,7 +424,7 @@ function spam_admin_settings_advanced() '#type' => 'fieldset', '#title' => 'Advanced', ); - + $form['advanced']['spam_log_level'] = array( '#type' => 'radios', '#title' => t('Log'), @@ -432,10 +432,10 @@ function spam_admin_settings_advanced() '#options' => array(0 => t('nothing'), SPAM_LOG => t('major events'), SPAM_VERBOSE => t('major and minor events'), SPAM_DEBUG => t('everything')), '#description' => t('By default, the spam module will only log major events. If you are trying to figure out why the spam filter is marking content as spam or not spam, you may want to try logging everything. If you\'re concerned about performance, you may want to disable logging completely.'), ); - + $period = drupal_map_assoc(array(0, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), 'format_interval'); $period[0] = t('never'); - + $form['advanced']['spam_flush_log_timer'] = array( '#type' => 'select', '#title' => t('Discard spam logs older than'), @@ -443,7 +443,7 @@ function spam_admin_settings_advanced() '#options' => $period, '#description' => t('Older spam log entries will be automatically discarded. Requires crontab.'), ); - + $form['advanced']['spam_display_probability'] = array( '#type' => 'checkbox', '#title' => t('Display probability'), @@ -451,7 +451,7 @@ function spam_admin_settings_advanced() '#default_value' => variable_get('spam_display_probability', 0), '#description' => t('If enabled, the probability that a given piece of content is spam will be displayed by the content. This is useful while you are tuning your spam filter, and will provide a link to the relevant logs showing how that content was determined to be or not to be spam.'), ); - + $form['advanced']['spam_report_feedback'] = array( '#type' => 'checkbox', '#title' => t('Require feedback when reporting spam'), @@ -459,7 +459,7 @@ function spam_admin_settings_advanced() '#default_value' => variable_get('spam_report_feedback', TRUE), '#description' => t('If checked, users that are able to report content as spam will be required to leave feedback when reporting spam. If unchecked, users will not be prompted to leave feedback.'), ); - + /* If you feel you need to display more than 50 spam comments or spam nodes * at a time, uncomment the following two lines of code. For most people * this will be unnecessary, and potentially confusing, so by default I am @@ -481,7 +481,7 @@ function spam_admin_settings_advanced() $form['advanced'] = array_merge($form['advanced'], $hook['group']); } return system_settings_form($form); -} +} /** * Drupal _cron hook. Provides ability to automatically expired spam content. @@ -494,7 +494,8 @@ function spam_cron() { if ($email_timer < (time() - 86400)) { variable_set('spam_email_timer', time()); $result = db_query('SELECT source, COUNT(source) AS count FROM {spam_reported} GROUP BY source'); - if (db_num_rows($result)) { + if (db_result($result)) { + // NOTE: this should be refactored, using the spam_report_notify_admin() function $admin = user_load(array('uid' => 1)); $message = t("Hello @adminname,\n\n Users have reported finding spam on your website. The following content has been reported:\n", array('@adminname' => $admin->name)); $urls = array(); @@ -506,8 +507,8 @@ function spam_cron() { foreach ($urls as $url) { $message .= " $url\n"; } - spam_mail(t('[@sitename] Spam reported', array('@sitename' => variable_get('site_name', 'drupal'))), "$message"); - } + spam_report_notify_admin(t('[@sitename] Spam reported'), "$message"); + } } // expire spam content that is older than we're configured to keep. @@ -581,7 +582,7 @@ function spam_comment($comment, $action) /** * Drupal _nodeapi hook. Passes new node content through the spam filter. - * + * * @param $node The text of the node. * @param $op Specifies the current operation. * @param $arg Optional argument. @@ -644,189 +645,185 @@ function spam_link($type, $node = 0, $ma * @return array of permissions used by this module. */ function spam_perm() { - return(array('report spam', 'access spam', 'administer spam', 'bypass filter')); + return array('report spam', 'access spam', 'administer spam', 'bypass filter'); } /** * Implementation of hook_menu(). */ -function spam_menu($may_cache) { +function spam_menu() { $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/logs/spam', - 'title' => t('Spam logs'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_logs_overview', - 'description' => t('Detect and manage spam posts.'), - ); - - $items[] = array( - 'path' => 'admin/logs/spam/logs', - 'title' => t('Logs'), - 'access' => user_access('access spam'), - 'callback' => 'spam_logs_overview', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, - ); - - $items[] = array( - 'path' => 'admin/logs/spam/blockedips', - 'title' => t('Blocked IPs'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_blocked_ips_overview', - 'type' => MENU_LOCAL_TASK, - ); - - $items[] = array( - 'path' => 'admin/content/spam/logs/entry', - 'access' => user_access('access spam'), - 'callback' => 'spam_logs_entry', - 'type' => MENU_LOCAL_CALLBACK, - ); - - $items[] = array( - 'path' => 'admin/content/comment/list/spam', - 'title' => t('Spam'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_comment_overview'), - 'type' => MENU_LOCAL_TASK, - ); - - // Main module administration page - $items[] = array( - 'path' => 'admin/settings/spam', - 'title' => t('Spam'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_admin_settings', - 'description' => t('Control settings for the spam module.'), - ); - - $items[] = array( - 'path' => 'admin/settings/spam/filter', - 'title' => t('Filters'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_admin_settings_filter'), - 'description' => t('Select content type filters for the spam module.'), - 'weight' => -5, - 'type' => MENU_LOCAL_TASK, - ); - - $items[] = array( - 'path' => 'admin/settings/spam/limits', - 'title' => t('Limits'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_admin_settings_limits'), - 'description' => t('Set filtering limits for the spam module.'), - 'weight' => -5, - 'type' => MENU_LOCAL_TASK, - ); - - $items[] = array( - 'path' => 'admin/settings/spam/actions', - 'title' => t('Actions'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_admin_settings_actions'), - 'description' => t('Select actions for the spam module.'), - 'weight' => -4, - 'type' => MENU_LOCAL_TASK, - ); - - $items[] = array( - 'path' => 'admin/settings/spam/advanced', - 'title' => t('Advanced'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_admin_settings_advanced'), - 'description' => t('Set advanced option for the spam module.'), - 'weight' => -4, - 'type' => MENU_LOCAL_TASK, - ); - - $items[] = array( - 'path' => 'admin/settings/spam/custom', - 'title' => t('Custom filters'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_custom_filter_overview', - 'type' => MENU_LOCAL_TASK, - 'weight' => -3, - ); - - $items[] = array( - 'path' => 'admin/settings/spam/url', - 'title' => t('URL filters'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_url_filter_overview', - 'type' => MENU_LOCAL_TASK, - 'weight' => -3, - ); - - // node admin submenu - $items[] = array( - 'path' => 'admin/content/node/list/spam', - 'title' => t('Spam'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_node_overview'), - 'type' => MENU_LOCAL_TASK); - - // spam page - $items[] = array( - 'path' => 'spam', - 'title' => t('Spam'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_page', - 'type' => MENU_CALLBACK); - - // report spam page - $items[] = array( - 'path' => 'spam/report', - 'title' => t('Spam'), - 'access' => user_access('report spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_user_report'), - 'type' => MENU_CALLBACK, - ); + $items['admin/reports/spam'] = array( + 'title' => 'Spam logs', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'spam_logs_overview', + 'description' => 'Detect and manage spam posts.', + ); + + $items['admin/reports/spam/logs'] = array( + 'title' => 'Logs', + 'access callback' => 'user_access', + 'access arguments' => array('access spam'), + 'page callback' => 'spam_logs_overview', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + + $items['admin/reports/spam/blockedips'] = array( + 'title' => 'Blocked IPs', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'spam_blocked_ips_overview', + 'type' => MENU_LOCAL_TASK, + ); + + $items['admin/content/spam/logs/entry'] = array( + 'access callback' => 'user_access', + 'access arguments' => array('access spam'), + 'page callback' => 'spam_logs_entry', + 'type' => MENU_LOCAL_CALLBACK, + ); + + $items['admin/content/comment/list/spam'] = array( + 'title' => 'Spam', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_comment_overview'), + 'type' => MENU_LOCAL_TASK, + ); + + // Main module administration page + $items['admin/settings/spam'] = array( + 'title' => 'Spam', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'spam_admin_settings', + 'description' => 'Control settings for the spam module.', + ); + // NOTE: do we want to change the order? since spam_admin_settings() has a different one + $items['admin/settings/spam/filter'] = array( + 'title' => 'Filters', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_admin_settings_filter'), + 'description' => 'Select content type filters for the spam module.', + 'weight' => -5, + 'type' => MENU_LOCAL_TASK, + ); + + $items['admin/settings/spam/limits'] = array( + 'title' => 'Limits', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_admin_settings_limits'), + 'description' => 'Set filtering limits for the spam module.', + 'weight' => -5, + 'type' => MENU_LOCAL_TASK, + ); + + $items['admin/settings/spam/actions'] = array( + 'title' => 'Actions', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_admin_settings_actions'), + 'description' => 'Select actions for the spam module.', + 'weight' => -4, + 'type' => MENU_LOCAL_TASK, + ); + + $items['admin/settings/spam/advanced'] = array( + 'title' => 'Advanced', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_admin_settings_advanced'), + 'description' => 'Set advanced option for the spam module.', + 'weight' => -4, + 'type' => MENU_LOCAL_TASK, + ); + + $items['admin/settings/spam/custom'] = array( + 'title' => 'Custom filters', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'spam_custom_filter_overview', + 'type' => MENU_LOCAL_TASK, + 'weight' => -3, + ); + + $items['admin/settings/spam/url'] = array( + 'title' => 'URL filters', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'spam_url_filter_overview', + 'type' => MENU_LOCAL_TASK, + 'weight' => -3, + ); + + // node admin submenu + $items['admin/content/node/list/spam'] = array( + 'title' => 'Spam', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_node_overview'), + 'type' => MENU_LOCAL_TASK + ); + + // spam page + $items['spam'] = array( + 'title' => 'Spam', + 'access callback' => 'user_access', 'access arguments' => array('administer spam'), + 'page callback' => 'spam_page', + 'type' => MENU_CALLBACK + ); + + // report spam page + $items['spam/report'] = array( + 'title' => 'Spam', + 'access callback' => 'user_access', + 'access arguments' => array('report spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_user_report'), + 'type' => MENU_CALLBACK, + ); + + // reported comment spam admin submenu + $items['admin/content/comment/list/reported'] = array( + 'title' => 'Reported spam', + 'access callback' => 'user_access', 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_reported_comments_overview'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 5, + ); + + // reported node spam admin submenu + $items['admin/content/node/list/reported'] = array( + 'title' => t('Reported spam'), + 'access callback' => 'user_access', 'access arguments' => array('administer spam'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('spam_reported_nodes_overview'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 5, + ); + + // reported spam details page + // TODO: _load functions for %source/%id ? + $items['admin/content/spam/reported/%/%/details'] = array( + 'title' => 'Reported spam details', + 'access callback' => 'user_access', + 'access arguments' => array('administer spam'), + 'page callback' => 'spam_reported_details', + 'type' => MENU_CALLBACK + ); - // reported comment spam admin submenu - $items[] = array( - 'path' => 'admin/content/comment/list/reported', - 'title' => t('Reported spam'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_reported_comments_overview'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 5, - ); - - // reported node spam admin submenu - $items[] = array( - 'path' => 'admin/content/node/list/reported', - 'title' => t('Reported spam'), - 'access' => user_access('administer spam'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('spam_reported_nodes_overview'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 5, - ); - } - else if (arg(6) == 'details') { - $source = arg(4); - $id = arg(5); - // reported spam details page - $items[] = array( - 'path' => "admin/content/spam/reported/$source/$id/details", - 'title' => t('Reported spam details'), - 'access' => user_access('administer spam'), - 'callback' => 'spam_reported_details', - 'type' => MENU_CALLBACK - ); - } return $items; } @@ -864,7 +861,7 @@ function spam_page() { $goto_fragment = "comment-$comment->cid"; $header = $comment->subject; $body = "$comment->comment $comment->name $comment->mail $comment->homepage"; - watchdog('spam', t('Spam: marked comment "%subject" as @spam', array('%subject' => $comment->subject, '@spam' => ($is_spam ? 'spam' : 'not spam')))); + watchdog('spam', 'Spam: marked comment "%subject" as @spam', array('%subject' => $comment->subject, '@spam' => ($is_spam ? 'spam' : 'not spam'))); break; case 'node': $node = node_load(array('nid' => $id)); @@ -873,7 +870,7 @@ function spam_page() { $goto_fragment = ""; $header = $node->title; $body = $node->body; - watchdog('spam', t('Spam: marked node "%title" as @spam', array('%title' => $node->title, '@spam' => ($is_spam ? 'spam' : 'not spam')))); + watchdog('spam', 'Spam: marked node "%title" as @spam', array('%title' => $node->title, '@spam' => ($is_spam ? 'spam' : 'not spam'))); break; default: /* Allow external modules the ability to handle custom content types. @@ -911,7 +908,7 @@ function spam_page() { else { // this is the first time we've filtered this content spam_tokens_save($tokens, $is_spam); - db_query("INSERT INTO {spam_tracker} (source,id,probability,hostname,hash,timestamp) VALUES('%s',%d,%d,'%s','%s',%d)", $source, $id, ($is_spam ? 99 : 1), $_SERVER['REMOTE_ADDR'], $hash, time()); + db_query("INSERT INTO {spam_tracker} (source,id,probability,hostname,hash,timestamp) VALUES('%s',%d,%d,'%s','%s',%d)", $source, $id, ($is_spam ? 99 : 1), ip_address(), $hash, time()); } spam_default_actions($source, $id, $header, $body, ($is_spam ? 99: 1), $old, FALSE); @@ -925,7 +922,7 @@ function spam_page() { /** * Validation code for the spam_user_report form/function */ -function spam_user_report_validate($form_id, $form_values) { +function spam_user_report_validate($form, &$form_state) { /* spam/report// * 0 1 2 3 */ @@ -943,7 +940,7 @@ function spam_user_report_validate($form /** * Submit code for the spam_user_report form/function */ -function spam_user_report_submit($form_id, $form_values) { +function spam_user_report_submit($form, &$form_state) { /* spam/report// * 0 1 2 3 */ @@ -951,12 +948,12 @@ function spam_user_report_submit($form_i $source = arg(2); $id = arg(3); - db_query("INSERT INTO {spam_reported} (source, id, uid, hostname, feedback, timestamp) VALUES('%s', %d, %d, '%s', '%s', %d)", $source, $id, $user->uid, $_SERVER['REMOTE_ADDR'], $form_values['spam_feedback'], time()); + db_query("INSERT INTO {spam_reported} (source, id, uid, hostname, feedback, timestamp) VALUES('%s', %d, %d, '%s', '%s', %d)", $source, $id, $user->uid, ip_address(), $form_state['values']['spam_feedback'], time()); drupal_set_message(t('Thank you for your assistance. The site administrator has been notified and will review the content shortly.')); - $feedback = (strlen($form_values['spam_feedback']) < 128 ? $form_values['spam_feedback'] : substr($form_values['spam_feedback'], 0, 128) . '...'); + $feedback = (strlen($form_state['values']['spam_feedback']) < 128 ? $form_state['values']['spam_feedback'] : substr($form_state['values']['spam_feedback'], 0, 128) .'...'); spam_log(SPAM_LOG, t('spam_report: reported as possible spam. User feedback begins, "@feedback"', array('@feedback' => $feedback)), $source, $id); - switch($source) { + switch ($source) { case 'node': $url = "node/$id"; break; @@ -1002,7 +999,7 @@ function spam_user_report() { break; } - menu_set_location(array(array('path' => '/', 'title' => t('Report Spam')))); + menu_set_breadcrumb(array(array('path' => '/', 'title' => t('Report Spam')))); $form['feedback'] = array('#type' => 'fieldset', '#title' => t('Spam Feedback') ); $form['feedback']['message'] = array( @@ -1011,8 +1008,8 @@ function spam_user_report() { '#weight' => -1, ); $form['feedback']['spam_feedback'] = array( - '#type' => 'textarea', - '#title' => t('Please help us by entering a brief explanation as to why this content is spam'), + '#type' => 'textarea', + '#title' => t('Please help us by entering a brief explanation as to why this content is spam'), '#rows' => 10, '#default_value' => '', '#weight' => 0, @@ -1061,7 +1058,7 @@ function spam_invoke_hook($name, $arg1 = function spam_spam($name, $arg1, $arg2, $arg3) { // Do stuff based on the hook type (name). switch ($name) { - case 'tab_description': + case 'tab_description': $tabs = array(); $tabs['Filters'] = t('Select content type filters for the spam module.'); $tabs['Limits'] = t('Set filtering limits for the spam module.'); @@ -1096,7 +1093,7 @@ function spam_tokenize($string, $tag = N // 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); + $sanitized = preg_replace("/[()\{\}\[\]#.,]/", '', $sanitized); // Force all non URL* tokens to lowercase, again to aggregate // tokens. This both lowers the total token number of rows in the @@ -1151,7 +1148,7 @@ function spam_tokenize($string, $tag = N function spam_duplicate_filter($hash, $source, $id, $header, $body) { $limit = variable_get('spam_duplicate_content', 2); if ($limit > -1) { - $duplicate = db_fetch_object(db_query("SELECT COUNT(sid) AS count FROM {spam_tracker} WHERE hash = '%s' AND (source != '%s' OR id != %d)", $hash, $source, $id)); + $duplicate = db_fetch_object(db_query("SELECT COUNT(sid) AS count FROM {spam_tracker} WHERE hash = '%s' AND (source <> '%s' OR id <> %d)", $hash, $source, $id)); if ($duplicate->count >= variable_get('spam_duplicate_content', 2)) { $total = 0; spam_log(SPAM_DEBUG, t('spam_duplicate_filter: hash "@hash" found @count times.', array('@hash' => $hash, '@count' => $duplicate->count)), $source, $id); @@ -1175,7 +1172,7 @@ function spam_duplicate_filter($hash, $s * of tokens is spam. * * @param $tokens An array of tokens. - * + * * @return An integer from 1 to 99 which is the probability that the * array of tokens passed to this function are spam. */ @@ -1207,7 +1204,7 @@ function spam_bayesian_filter($tokens = $total = 0; for ($i = 0; $i < $max; $i++) { if ($pair = array_pop($keys)) { - $p = explode(',',$pair); + $p = explode(',', $pair); $total = $total + $p[1]; spam_log(SPAM_DEBUG, t("bayesian filter: token '@token' spam probability @percent%", array('@token' => $p[0], '@percent' => $p[1]))); } @@ -1225,7 +1222,7 @@ function spam_bayesian_filter($tokens = /** * Search for text string, URL or pattern within the passed in string of text. * If found, adjusts the weight variable appropriately. Matching some filters - * can cause the delete parameter to be incremented, telling the calling + * can cause the delete parameter to be incremented, telling the calling * function to delete the passed in content. * * @param $text String of text to pass through custom filter. @@ -1254,7 +1251,7 @@ function spam_custom_filter($header, $bo $matches = 0; $text = $header .' '. $body; - $result = db_query('SELECT scid, filter, style, effect, action FROM {spam_custom} WHERE effect != %d', SPAM_CUSTOM_DISABLED); + $result = db_query('SELECT scid, filter, style, effect, action FROM {spam_custom} WHERE effect <> %d', SPAM_CUSTOM_DISABLED); while ($filter = db_fetch_object($result)) { // determine which portion of the content we are scanning @@ -1269,7 +1266,7 @@ function spam_custom_filter($header, $bo } // scan the content - switch($filter->style) { + switch ($filter->style) { case SPAM_CUSTOM_PLAIN: case SPAM_CUSTOM_URL: $match = preg_match_all("/$filter->filter/", $text, $temporary); @@ -1313,12 +1310,12 @@ function spam_custom_filter($header, $bo case SPAM_CUSTOM_USUALLY_NOTSPAM: $weight += ($match * WEIGHT_RARELY_SPAM); spam_log(SPAM_DEBUG, t("custom filters: matched 'rarely spam' filter @num times, added @weight weight, matched filter '%filter'", array('@num' => $match, '@weight' => ($match * WEIGHT_RARELY_SPAM), '%filter' => $filter->filter))); - break; - case SPAM_CUSTOM_NEVER_SPAM: - $weight += ($match * WEIGHT_NEVER_SPAM); - spam_log(SPAM_DEBUG, t("custom filters: matched 'never spam' filter @num times, added @weight weight, matched filter '%filter'", array('@num' => $match, '@weight' => ($match * WEIGHT_NEVER_SPAM), '%filter' => $filter->filter))); - break; - } + break; + case SPAM_CUSTOM_NEVER_SPAM: + $weight += ($match * WEIGHT_NEVER_SPAM); + spam_log(SPAM_DEBUG, t("custom filters: matched 'never spam' filter @num times, added @weight weight, matched filter '%filter'", array('@num' => $match, '@weight' => ($match * WEIGHT_NEVER_SPAM), '%filter' => $filter->filter))); + break; + } } } @@ -1372,7 +1369,7 @@ function spam_urls_count($url = NULL) { * Check if content has two many total urls, or if the same base url is * repeated too many times. * - * @param $url An array indicating how many time each url is found in the + * @param $url An array indicating how many time each url is found in the * content, as generated by spam_urls_count(). * @return Weighted added to spam probability, if any. * @@ -1466,6 +1463,32 @@ function spam_tokens_unsave($tokens, $is } /** + * Register theme functions + */ +function spam_theme() { + return array( + 'spam_link' => array( + 'arguments' => array('content', 'type'), + ), + 'spam_custom_filter_scan' => array( + 'arguments' => array('form'), + ), + 'spam_reported_comments_overview' => array( + 'arguments' => array('form'), + ), + 'spam_reported_nodes_overview' => array( + 'arguments' => array('form'), + ), + 'spam_comment_overview' => array( + 'arguments' => array('form'), + ), + 'spam_node_overview' => array( + 'arguments' => array('form'), + ), + ); +} + +/** * Display spam status (if enabled), and provide adminsitrators with links to * mark content as spam or not spam. * @@ -1529,7 +1552,7 @@ function theme_spam_link($content, $type * Compare the passed in probability to the configured spam threshold. * * @param $probability 1-99% chance of being spam. - * + * * @return 0 = not spam, 1 = spam */ function _is_spam($probability) { @@ -1600,13 +1623,15 @@ function spam_logs_overview($source = NU * The log entry to get details of. */ function spam_logs_entry($id = NULL) { - if (!$id) { return NULL; } + if (!$id) { + return NULL; + } $entry = db_fetch_object(db_query('SELECT s.*, u.name, u.uid FROM {spam_log} s INNER JOIN {users} u ON s.uid = u.uid WHERE s.sid = %d', $id)); return theme('table', NULL, array( - array( array('data' => t('Type'), 'header' => TRUE), array('data' => l(t($entry->source), "admin/logs/spam/logs/$entry->source")) ), - array( array('data' => t('!type ID', array('!type' => ucfirst($entry->source))), 'header' => TRUE), array('data' => l(t($entry->id), "admin/logs/spam/logs/$entry->source/$entry->id")) ), + array( array('data' => t('Type'), 'header' => TRUE), array('data' => l(t($entry->source), "admin/reports/spam/logs/$entry->source")) ), + array( array('data' => t('!type ID', array('!type' => ucfirst($entry->source))), 'header' => TRUE), array('data' => l(t($entry->id), "admin/reports/spam/logs/$entry->source/$entry->id")) ), array( array('data' => t('Date'), 'header' => TRUE), array('data' => format_date($entry->timestamp, 'large')) ), array( array('data' => t('User'), 'header' => TRUE), array('data' => theme('username', $entry)) ), array( array('data' => t('Message'), 'header' => TRUE), array('data' => $entry->entry) ), @@ -1623,7 +1648,6 @@ function spam_logs_entry($id = NULL) { * One of "scan", "delete", or "edit". */ function spam_custom_filter_overview($id = NULL, $action = NULL) { - // hand off action processing to other functions. if (isset($action) && isset($id) && is_numeric($id)) { $filter = spam_custom_filter_load($id); @@ -1689,9 +1713,9 @@ function spam_custom_filter_overview($id htmlspecialchars($custom->filter), $custom->style == 0 ? t('text') : t('regex'), $scan, $spam_effects["$custom->effect"], $action, $custom->matches == 0 ? "none" : $custom->matches, $custom->last ? format_date($custom->last, 'small') : t('none'), - l(t('scan'), "admin/settings/spam/custom/$custom->scid/scan") . " " + l(t('scan'), "admin/settings/spam/custom/$custom->scid/scan") ." " . l(t('edit'), "admin/settings/spam/custom/$custom->scid/edit") - . " " . l(t('delete'), "admin/settings/spam/custom/$custom->scid/delete") + ." " . l(t('delete'), "admin/settings/spam/custom/$custom->scid/delete") )); } @@ -1707,7 +1731,7 @@ function spam_custom_filter_overview($id * @param $filter * A loaded filter for editing. */ -function spam_custom_filter_edit($filter = NULL) { +function spam_custom_filter_edit($form_state, $filter = NULL) { $action = 0; if ($filter->action & SPAM_CUSTOM_ACTION_HEADER) { $action = SPAM_CUSTOM_ACTION_HEADER; @@ -1715,7 +1739,6 @@ function spam_custom_filter_edit($filter else if ($filter->action & SPAM_CUSTOM_ACTION_BODY) { $action = SPAM_CUSTOM_ACTION_BODY; } - $form['scid'] = array( '#type' => 'hidden', '#value' => (isset($filter) ? $filter->scid : ''), @@ -1778,19 +1801,19 @@ function spam_custom_filter_edit($filter /** * Form API hook; validate the custom filter. */ -function spam_custom_filter_edit_validate($form_id, $form_values) { - if (!empty($form_values['filter'])) { - if (($form_values['style'] == 1) && preg_match($form_values['filter'], 'test') === FALSE) { +function spam_custom_filter_edit_validate($form, &$form_state) { + if (!empty($form_state['values']['filter'])) { + if (($form_state['values']['style'] == 1) && preg_match($form_state['values']['filter'], 'test') === FALSE) { // failed regex validation is a critical error and things break, so we // just echo an error and exit. (If we don't exit, additional errors // appear about modifying headers making it confusing). - form_set_error('filter', t('Your regular expression @regex does not validate.', array('@regex' => $form_values['filter']))); + form_set_error('filter', t('Your regular expression @regex does not validate.', array('@regex' => $form_state['values']['filter']))); } - if (!isset($form_values['scid'])) { // there's no reason to allow duplicate filters - $duplicate = db_fetch_object(db_query("SELECT scid FROM {spam_custom} WHERE filter = '%s'", $form_values['filter'])); + if (!isset($form_state['values']['scid'])) { // there's no reason to allow duplicate filters + $duplicate = db_fetch_object(db_query("SELECT scid FROM {spam_custom} WHERE filter = '%s'", $form_state['values']['filter'])); if ($duplicate->scid) { - form_set_error('filter', t('Custom filter %filter already exists.', array('%filter' => $form_values['filter']))); + form_set_error('filter', t('Custom filter %filter already exists.', array('%filter' => $form_state['values']['filter']))); } } } @@ -1799,28 +1822,28 @@ function spam_custom_filter_edit_validat /** * Form API hook; submit the custom filter. */ -function spam_custom_filter_edit_submit($form_id, $form_values) { +function spam_custom_filter_edit_submit($form, &$form_state) { $action = 0; - if ($form_values['scan'] & SPAM_CUSTOM_ACTION_HEADER) { + if ($form_state['values']['scan'] & SPAM_CUSTOM_ACTION_HEADER) { $action += SPAM_CUSTOM_ACTION_HEADER; } - else if ($form_values['scan'] & SPAM_CUSTOM_ACTION_BODY) { + else if ($form_state['values']['scan'] & SPAM_CUSTOM_ACTION_BODY) { $action += SPAM_CUSTOM_ACTION_BODY; } - if ($form_values['autodelete']) { + if ($form_state['values']['autodelete']) { $action += SPAM_CUSTOM_ACTION_DELETE; } - if ($form_values['nomail']) { + if ($form_state['values']['nomail']) { $action += SPAM_CUSTOM_ACTION_NOMAIL; } - if ($form_values['scid']) { - db_query("UPDATE {spam_custom} SET filter = '%s', style = %d, effect = %d, action = %d WHERE scid = %d", $form_values['filter'], $form_values['style'], $form_values['effect'], $action, $form_values['scid']); - drupal_set_message(t('Custom filter %filter updated.', array('%filter' => $form_values['filter']))); + if ($form_state['values']['scid']) { + db_query("UPDATE {spam_custom} SET filter = '%s', style = %d, effect = %d, action = %d WHERE scid = %d", $form_state['values']['filter'], $form_state['values']['style'], $form_state['values']['effect'], $action, $form_state['values']['scid']); + drupal_set_message(t('Custom filter %filter updated.', array('%filter' => $form_state['values']['filter']))); } else { - db_query("INSERT INTO {spam_custom} (filter, style, effect, action) VALUES('%s', %d, %d, %d)", $form_values['filter'], $form_values['style'], $form_values['effect'], $action); - drupal_set_message(t('Custom filter %filter added.', array('%filter' => $form_values['filter']))); + db_query("INSERT INTO {spam_custom} (filter, style, effect, action) VALUES('%s', %d, %d, %d)", $form_state['values']['filter'], $form_state['values']['style'], $form_state['values']['effect'], $action); + drupal_set_message(t('Custom filter %filter added.', array('%filter' => $form_state['values']['filter']))); } return 'admin/settings/spam/custom'; @@ -1832,7 +1855,7 @@ function spam_custom_filter_edit_submit( * @param $filter * A loaded filter for deleting. */ -function spam_custom_filter_delete($filter = NULL) { +function spam_custom_filter_delete($form_state, $filter = NULL) { $form['scid'] = array( '#type' => 'hidden', '#value' => $filter->scid, ); return confirm_form($form, t('Are you sure you want to delete the %filter filter?', array('%filter' => $filter->filter)), 'admin/settings/spam/custom', t('This action can not be undone.'), t('Delete'), t('Cancel')); @@ -1841,9 +1864,9 @@ function spam_custom_filter_delete($filt /** * Removes custom filter from database. */ -function spam_custom_filter_delete_submit($form_id, $form_values) { - $filter = spam_custom_filter_load($form_values['scid']); - db_query('DELETE FROM {spam_custom} WHERE scid = %d', $form_values['scid']); +function spam_custom_filter_delete_submit($form, &$form_state) { + $filter = spam_custom_filter_load($form_state['values']['scid']); + db_query('DELETE FROM {spam_custom} WHERE scid = %d', $form_state['values']['scid']); drupal_set_message(t('Filter %filter deleted.', array('%filter' => $filter->filter))); return 'admin/settings/spam/custom'; } @@ -1865,7 +1888,7 @@ function spam_custom_filter_load($scid) * @param $filter * The filter object we are scanning with. */ -function spam_custom_filter_scan($filter) { +function spam_custom_filter_scan($form_state, $filter) { $form['scid'] = array( '#type' => 'hidden', '#value' => $filter->scid, @@ -1905,6 +1928,7 @@ function spam_custom_filter_scan($filter array('data' => t('operations'), 'colspan' => 2) )); + // NOTE: is the code below database independent and safe enough? if ($filter->style == 1) { // Try and convert perl regex to MySQL regex by stripping off regular // expression boundaries. For example "/spam/i" becomes "spam". @@ -1943,9 +1967,9 @@ function spam_custom_filter_scan($filter $comments[$comment->cid] = ''; $form['rating'][$comment->cid] = array('#value' => $is_spam ? t('spam') : t('not spam')); $form['status'][$comment->cid] = array('#value' => ($comment->status == 0 ? t('published') : t('not published'))); - $form['subject'][$comment->cid] = array('#value' => (strlen($comment->subject) > 128 ? htmlspecialchars(substr($comment->subject, 0, 128)). t('...') : htmlspecialchars($comment->subject))); - $form['comment'][$comment->cid] = array('#value' => (strlen($comment->comment) > 256 ? htmlspecialchars(substr($comment->comment, 0, 256)). t('...') : htmlspecialchars($comment->comment))); - $form['operations'][$comment->cid] = array('#value' => l(t('view'), "node/$comment->nid#comment-$comment->cid") . ' ' . $is_spam ? l(t('mark as not spam'), "spam/comment/$comment->cid/notspam") : l(t('mark as spam'), "spam/comment/$comment->cid/spam")); + $form['subject'][$comment->cid] = array('#value' => (strlen($comment->subject) > 128 ? htmlspecialchars(substr($comment->subject, 0, 128)) . t('...') : htmlspecialchars($comment->subject))); + $form['comment'][$comment->cid] = array('#value' => (strlen($comment->comment) > 256 ? htmlspecialchars(substr($comment->comment, 0, 256)) . t('...') : htmlspecialchars($comment->comment))); + $form['operations'][$comment->cid] = array('#value' => l(t('view'), "node/$comment->nid#comment-$comment->cid") .' '. $is_spam ? l(t('mark as not spam'), "spam/comment/$comment->cid/notspam") : l(t('mark as spam'), "spam/comment/$comment->cid/spam")); } $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments); @@ -1956,23 +1980,23 @@ function spam_custom_filter_scan($filter /** * Form API hook; validate the custom filter scanner. */ -function spam_custom_filter_scan_validate($form_id, $form_values) { - $form_values['comments'] = array_diff($form_values['comments'], array(0)); - if (count($form_values['comments']) == 0) { +function spam_custom_filter_scan_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(NULL, t('Please select one or more comments to perform the update on.')); - return 'admin/settings/spam/custom/$form_values[scid]/scan'; + return 'admin/settings/spam/custom/'. $form_state['values']['scid'] .'/scan'; } } /** * Form API hook; submit the custom filter scanner. */ -function spam_custom_filter_scan_submit ($form_id, $form_values) { - $operation = spam_comment_operations($form_values['operation']); - $scid = $form_values['scid']; +function spam_custom_filter_scan_submit($form, &$form_state) { + $operation = spam_comment_operations($form_state['values']['operation']); + $scid = $form_state['values']['scid']; if ($operation) { - foreach($form_values['comments'] as $cid => $value) { + foreach ($form_state['values']['comments'] as $cid => $value) { if ($value) { $operation($cid); } @@ -2058,7 +2082,7 @@ function spam_url_filter_overview($id = htmlspecialchars(preg_replace('/^URL\*/', '', $url->token)), $url->spam, $url->notspam, $url->probability .'%', $url->last ? format_date($url->last, 'small') : t('none'), - l(t('edit'), "admin/settings/spam/url/$url->tid/edit") . ' ' + l(t('edit'), "admin/settings/spam/url/$url->tid/edit") .' ' . l(t('delete'), "admin/settings/spam/url/$url->tid/delete") )); } @@ -2075,7 +2099,7 @@ function spam_url_filter_overview($id = * @param $filter * A loaded filter for editing. */ -function spam_url_filter_edit($filter = NULL) { +function spam_url_filter_edit($form_state, $filter = NULL) { $form['tid'] = array( '#type' => 'hidden', '#value' => (isset($filter) ? $filter->tid : ''), @@ -2103,11 +2127,11 @@ function spam_url_filter_edit($filter = /** * Form API hook; validate the URL filter. */ -function spam_url_filter_edit_validate($form_id, $form_values) { - if (!isset($form_values['tid'])) { // there's no reason to allow duplicate filters - $duplicate = db_fetch_object(db_query("SELECT token FROM {spam_tokens} WHERE token = 'URL*%s'", $form_values['url'])); +function spam_url_filter_edit_validate($form, &$form_state) { + if (!isset($form_state['values']['tid'])) { // there's no reason to allow duplicate filters + $duplicate = db_fetch_object(db_query("SELECT token FROM {spam_tokens} WHERE token = 'URL*%s'", $form_state['values']['url'])); if ($duplicate->token) { - form_set_error('domain', t('URL filter %filter already exists.', array('%filter' => $form_values['url']))); + form_set_error('domain', t('URL filter %filter already exists.', array('%filter' => $form_state['values']['url']))); } } } @@ -2115,14 +2139,14 @@ function spam_url_filter_edit_validate($ /** * Form API hook; submit the URL filter. */ -function spam_url_filter_edit_submit($form_id, $form_values) { - if ($form_values['tid']) { - db_query("UPDATE {spam_tokens} SET token = 'URL*%s' WHERE tid = %d", $form_values['url'], $form_values['tid']); - drupal_set_message(t('URL filter %filter updated.', array('%filter' => $form_values['url']))); +function spam_url_filter_edit_submit($form, &$form_state) { + if ($form_state['values']['tid']) { + db_query("UPDATE {spam_tokens} SET token = 'URL*%s' WHERE tid = %d", $form_state['values']['url'], $form_state['values']['tid']); + drupal_set_message(t('URL filter %filter updated.', array('%filter' => $form_state['values']['url']))); } else { - db_query("INSERT INTO {spam_tokens} (token, probability) VALUES('URL*%s', %d)", $form_values['url'], 99); - drupal_set_message(t('URL filter %filter added.', array('%filter' => $form_values['url']))); + db_query("INSERT INTO {spam_tokens} (token, probability) VALUES('URL*%s', %d)", $form_state['values']['url'], 99); + drupal_set_message(t('URL filter %filter added.', array('%filter' => $form_state['values']['url']))); } return 'admin/settings/spam/url'; @@ -2131,7 +2155,7 @@ function spam_url_filter_edit_submit($fo /** * Delete URL filter delete confirmation box. */ -function spam_url_filter_delete($filter = NULL) { +function spam_url_filter_delete($form_state, $filter = NULL) { $form['tid'] = array( '#type' => 'hidden', '#value' => $filter->tid, ); return confirm_form($form, t('Are you sure you want to delete the %filter filter?', array('%filter' => str_replace('URL*', '', $filter->token))), 'admin/settings/spam/url', t('This action can not be undone.'), t('Delete'), t('Cancel')); @@ -2140,8 +2164,8 @@ function spam_url_filter_delete($filter /** * Removes custom URL from database. */ -function spam_url_filter_delete_submit($form_id, $form_values) { - $filter = spam_url_filter_load($form_values['tid']); +function spam_url_filter_delete_submit($form, &$form_state) { + $filter = spam_url_filter_load($form_state['values']['tid']); db_query('DELETE FROM {spam_tokens} WHERE tid = %d', $filter->tid); drupal_set_message(t('URL filter %filter deleted.', array('%filter' => str_replace('URL*', '', $filter->token)))); return 'admin/settings/spam/url'; @@ -2210,42 +2234,120 @@ function spam_default_actions($type, $id // generate a mail message if (!($quiet || $action[SPAM_CUSTOM_ACTION_NOMAIL])) { if ($is_spam && variable_get('spam_notify_admin', 1)) { - $subject = t('[@sitename] Detected spam @type', array('@sitename' => variable_get('site_name', 'drupal'), '@type' => $type)); if ($old->id) { // update - spam_mail($subject .' on update', spam_mail_body($type, $header, $body, $id)); + spam_notify_admin($type, t('[@sitename] Detected spam @type on update'), $header, $body, $id); } else { // add - spam_mail($subject, spam_mail_body($type, $header, $body, $id)); + spam_notify_admin($type, t('[@sitename] Detected spam @type'), $header, $body, $id); } } } } /** - * Wrapper to user_mail() - * + * implementation of hook_mail */ -function spam_mail($subject, $message) { - $admin = user_load(array('uid' => 1)); - drupal_mail('spam_mail', $admin->mail, $subject, wordwrap($message, 72), variable_get('site_mail', ini_get('sendmail_from'))); -} +function spam_notify_admin_mail($key, &$message, $params) { + $lang = $params['language']->language; -/** - * Generate an appropriate notification mail message - */ -function spam_mail_body($type, $header, $body, $id) { - global $base_url; - switch ($type) { + // NOTE: maybe an if-else-statement is prettier? + switch ($params['type']) { case 'comment': - return t("Hello @adminname.\n\n A @type recently posted to your '@sitename' website has been automatically marked as spam. The text of the spam @type is as follows:\n\n\nSubject: @title\n\n@body\n\n Edit the @type here: @editurl\n View all spam @types here: @allurl", array('@adminname' => $admin->name, '@types' => $type .'s', '@type' => $type, '@sitename' => variable_get('site_name', 'drupal'), '@title' => $header, '@body' => $body, '@editurl' => $base_url .url("$type/edit/$id"), '@allurl' => $base_url .url("admin/content/$type/list/spam"))); + $message['variables']['@editurl'] = $params['baseurl'] . url('comment/'. $params['id'] .'/edit'); + $message['variables']['@allurl'] = $params['baseurl'] . url('admin/content/comment/list/spam'); + // fallthrough because of same message body case 'node': - return t("Hello @adminname.\n\n A @type recently posted to your '@sitename' website has been automatically marked as spam. The text of the spam @type is as follows:\n\n\nSubject: @title\n\n@body\n\n Edit the @type here: @editurl\n View all spam @types here: @allurl", array('@adminname' => $admin->name, '@types' => $type .'s', '@type' => $type, '@sitename' => variable_get('site_name', 'drupal'), '@title' => $header, '@body' => $body, '@editurl' => $base_url .url("$type/$id/edit"), '@allurl' => $base_url .url("admin/content/$type/list/spam"))); + if ($params['type'] == 'node') { // take fallthrough into account + $message['variables']['@editurl'] = $params['baseurl'] . url('node/'. $params['id'] .'/edit'); + $message['variables']['@allurl'] = $params['baseurl'] . url('admin/content/node/list/spam'); + } + + $message['body'] = t("Hello @adminname.\n\n A @type recently posted to your '@sitename' website has been automatically marked as spam. The text of the spam @type is as follows:\n\n\nSubject: @title\n\n@body\n\n Edit the @type here: @editurl\n View all spam @types here: @allurl", $params['variables'], $lang); + break; default: - return t("Hello @adminname.\n\n @type content recently posted to your '@sitename' website has been automatically marked as spam. The text of the spam content is as follows:\n\n\nSubject: @title\n\n@body\n", array('@adminname' => $admin->name, '@type' => $type, '@sitename' => variable_get('site_name', 'drupal'), '@title' => $header, '@body' => $body)); + $message['body'] = t("Hello @adminname.\n\n @type content recently posted to your '@sitename' website has been automatically marked as spam. The text of the spam content is as follows:\n\n\nSubject: @title\n\n@body\n", $params['variables'], $lang); } + + $message['subject'] = strtr($params['subject'], $params['variables']); +} + +/** + * notify admin via email of new spam + * + * @param $type node type, i.e. comment, node etc. + * @param $subject email title + * @param $header spam title + * @param $body spam content + * @param $id spam id + */ +function spam_notify_admin($type, $subject, $header, $body, $id, $message = '') { + $params = spam_get_mail_vars(); + $params['variables'] += array( + // NOTE: shouldn't we use ! instead of @ + // see http://api.drupal.org/api/function/t/6 + '@title' => $header, + '@body' => $body, + '@type' => $type, + '@types' => $types, + ); + $params += array( + 'subject' => $subject, + 'id' => $id, + ); + drupal_mail('spam_notify_admin', 'notice', $params['admin']->mail, $params['language'], $params); +} + +/** + * implementation of hook_mail + * + * @NOTE: is this function really needed?! + */ +function spam_report_notify_admin_mail($key, &$message, $params) { + $message['body'] = $params['message']; + $message['subject'] = strtr($params['subject'], $params['variables'], $params['language']); +} +/** + * notify admin via email of reported spam (cron based) + * + * @param $type node type, i.e. comment, node etc. + * @param $subject email title + * @param $header spam title + * @param $body spam content + * @param $id spam id + */ +function spam_report_notify_admin($subject, $message) { + $params = spam_get_mail_vars(); + $params += array( + 'subject' => $subject, + 'message' => $message, + ); + drupal_mail('spam_report_notify_admin', 'notice', $admin->mail, $language, $params); } /** + * get common mail vars + * + * @return array([variables], [base_url], [admin], [language]) + */ +function spam_get_mail_vars() { + // NOTE: what about making some things static? + // do we ever send more than one notify? + $admin = user_load(array('uid' => 1)); + $language = user_preferred_language($admin); + global $base_url; + return array( + 'variables' => array( + // NOTE: shouldn't we use ! instead of @ + // see http://api.drupal.org/api/function/t/6 + '@sitename' => variable_get('site_name', 'Drupal'), + '@adminname' => $admin->name, + ), + 'base_url' => $base_url, + 'admin' => $admin, + 'language' => $language, + ); +} +/** * Load's all fields from the matching spam entry in the spam_tracker table. * * @param $source Module type such as 'comment', 'node', ... @@ -2268,9 +2370,9 @@ function spam_get_probability($probabili /** * Validation code for the spam_reported_comments_overview form/function */ -function spam_reported_comments_overview_validate($form_id, $form_values) { - $form_values['comments'] = array_diff($form_values['comments'], array(0)); - if (count($form_values['comments']) == 0) { +function spam_reported_comments_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'); } @@ -2279,11 +2381,11 @@ function spam_reported_comments_overview /** * Submit code for the spam_reported_comments_overview form/function */ -function spam_reported_comments_overview_submit ($form_id, $form_values) { - $operation = spam_reported_comment_operations($form_values['operation']); +function spam_reported_comments_overview_submit($form, &$form_state) { + $operation = spam_reported_comment_operations($form_state['values']['operation']); if ($operation) { - foreach($form_values['comments'] as $cid => $value) { + foreach ($form_state['values']['comments'] as $cid => $value) { if ($value) { $operation('comment', $cid); } @@ -2296,7 +2398,7 @@ function spam_reported_comments_overview * Return the function to call dependant on the $action requested. */ function spam_reported_comment_operations($action = 'NOTHING') { - switch($action) { + switch ($action) { case 'IGNORE': $operation = 'spam_reported_ignore'; break; @@ -2310,7 +2412,7 @@ function spam_reported_comment_operation $operation = 'spam_donothing_comment'; // do nothing if we don't know what to do break; } - + return $operation; } @@ -2336,7 +2438,7 @@ function spam_reported_comments_overview '#options' => $operations, '#description' => t('') ); - + $form['options']['submit'] = array( '#type' => 'submit', '#value' => t('Update') @@ -2345,7 +2447,7 @@ function spam_reported_comments_overview // create the select all button w/ select as a label //$selectButton = spam_select_all('spam_reported_comments_overview'); $form['header'] = array('#type' => 'value', '#value' => array( - $selectButton, + // $selectButton, // was commented out above! array('data' => t('times reported'), 'field' => 'count', 'sort' => 'desc'), array('data' => t('last reported'), 'field' => 's.timestamp'), array('data' => t('reported by'), 'field' => 'r.name'), @@ -2367,11 +2469,11 @@ function spam_reported_comments_overview $form['times_reported'][$comment->cid] = array('#value' => $comment->count); $form['last_reported'][$comment->cid] = array('#value' => format_date($comment->timestamp, 'small')); $form['reported_by'][$comment->cid] = array('#value' => theme('username', user_load(array('uid' => $comment->ruid)))); - $form['subject'][$comment->cid] = array('#value' => l($comment->subject, "node/$comment->nid", array('title' => htmlspecialchars(substr($comment->comment, 0, 128))), NULL, "comment-$comment->cid") .' '. (node_last_viewed($comment->nid) < $comment->timestamp ? theme('mark') : '')); + $form['subject'][$comment->cid] = array('#value' => l($comment->subject, "node/$comment->nid", array('title' => htmlspecialchars(substr($comment->comment, 0, 128))), NULL, "comment-$comment->cid") .' '. (node_last_viewed($comment->nid) < $comment->timestamp ? theme('mark') : '')); $form['author'][$comment->cid] = array('#value' => theme('username', user_load(array('uid' => $comment->uid)))); $form['hostname'][$comment->cid] = array('#value' => $comment->hostname); $form['status'][$comment->cid] = array('#value' => ($comment->status == 0 ? t('published') : t('not published'))); - $form['operations'][$comment->cid] = array('#value' => l(t('View log'), "admin/logs/spam/logs/comment/$comment->cid") . ' ' . l(t('Details'), "admin/content/spam/reported/comment/$comment->cid/details", array('title' => htmlspecialchars(substr($comment->feedback, 0, 128)))) . ' ' . l(t('Edit'), "comment/edit/$comment->cid")); + $form['operations'][$comment->cid] = array('#value' => l(t('View log'), "admin/reports/spam/logs/comment/$comment->cid") .' '. l(t('Details'), "admin/content/spam/reported/comment/$comment->cid/details", array('title' => htmlspecialchars(substr($comment->feedback, 0, 128)))) .' '. l(t('Edit'), "comment/edit/$comment->cid")); } $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments); @@ -2416,9 +2518,9 @@ function theme_spam_reported_comments_ov /** * Validation code for the spam_reported_nodes_overview form/function */ -function spam_reported_nodes_overview_validate($form_id, $form_values) { - $form_values['nodes'] = array_diff($form_values['nodes'], array(0)); - if (count($form_values['nodes']) == 0) { +function spam_reported_nodes_overview_validate($form, &$form_state) { + $form_state['values']['nodes'] = array_diff($form_state['values']['nodes'], array(0)); + if (count($form_state['values']['nodes']) == 0) { form_set_error('', t('Please select one or more nodes to perform the update on.')); drupal_goto('admin/content/node/list/reported'); } @@ -2427,11 +2529,11 @@ function spam_reported_nodes_overview_va /** * Submit code for the spam_reported_nodes_overview form/function */ -function spam_reported_nodes_overview_submit ($form_id, $form_values) { - $operation = spam_reported_nodes_operations($form_values['operation']); +function spam_reported_nodes_overview_submit($form, &$form_state) { + $operation = spam_reported_nodes_operations($form_state['values']['operation']); if ($operation) { - foreach($form_values['nodes'] as $cid => $value) { + foreach ($form_state['values']['nodes'] as $cid => $value) { if ($value) { $operation('node', $cid); } @@ -2444,7 +2546,7 @@ function spam_reported_nodes_overview_su * Return the function to call dependant on the $action requested. */ function spam_reported_nodes_operations($action = 'NOTHING') { - switch($action) { + switch ($action) { case 'IGNORE': $operation = 'spam_reported_ignore'; break; @@ -2458,7 +2560,7 @@ function spam_reported_nodes_operations( $operation = 'spam_donothing_node'; // do nothing if we don't know what to do break; } - + return $operation; } @@ -2482,7 +2584,7 @@ function spam_reported_nodes_overview() '#options' => $operations, '#description' => t('') ); - + $form['options']['submit'] = array( '#type' => 'submit', '#value' => t('Update') @@ -2491,7 +2593,7 @@ function spam_reported_nodes_overview() // create the select all button w/ select as a label //$selectButton = spam_select_all('spam_reported_nodes_overview'); $form['header'] = array('#type' => 'value', '#value' => array( - $selectButton, + // $selectButton, // was commented out above! array('data' => t('times reported'), 'field' => 'count', 'sort' => 'desc'), array('data' => t('last reported'), 'field' => 's.timestamp'), array('data' => t('reported by'), 'field' => 'r.name'), @@ -2520,7 +2622,7 @@ function spam_reported_nodes_overview() $form['hostname'][$node->nid] = array('#value' => $node->hostname); $form['status'][$node->nid] = array('#value' => ($node->status ? t('published') : t('not published'))); $form['timestamp'][$node->nid] = array('#value' => format_date($node->changed, 'small')); - $form['operations'][$node->nid] = array('#value' => l(t('View log'), "admin/logs/spam/logs/node/$node->nid") . ' ' . l(t('Details'), "admin/content/spam/reported/node/$node->nid/details", array('title' => htmlspecialchars(substr($node->feedback, 0, 128)))) . ' ' . l(t('Edit'), "node/$node->nid/edit")); + $form['operations'][$node->nid] = array('#value' => l(t('View log'), "admin/reports/spam/logs/node/$node->nid") .' '. l(t('Details'), "admin/content/spam/reported/node/$node->nid/details", array('title' => htmlspecialchars(substr($node->feedback, 0, 128)))) .' '. l(t('Edit'), "node/$node->nid/edit")); } $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes); @@ -2580,8 +2682,8 @@ function spam_reported_details() { else { $output .= ''; } - $output .= ' '; - $output .= ' '; + $output .= ' '; + $output .= ' '; $output .= ' '; $reported_user = user_load(array('uid' => $entry->uid)); $output .= ' '; @@ -2597,7 +2699,7 @@ function spam_reported_details() { * Return the function to call dependant on the $action requested. */ function spam_comment_operations($action = 'NOTHING') { - switch($action) { + switch ($action) { case 'SPAM': $operation = 'spam_spam_comment'; break; @@ -2617,7 +2719,7 @@ function spam_comment_operations($action $operation = 'spam_donothing_comment'; // do nothing if we don't know what to do break; } - + return $operation; } @@ -2649,7 +2751,7 @@ function spam_comment_overview() { array('data' => t('subject'), 'field' => 'subject'), array('data' => t('author'), 'field' => 'u.name'), array('data' => t('hostname'), 'field' => 'c.hostname'), - array('data' => t('status'), 'field' => 'status'), + array('data' => t('status'), 'field' => 'status'), array('data' => t('timestamp'), 'field' => 'c.timestamp', 'sort' => 'desc'), array('data' => t('operations')) )); @@ -2667,7 +2769,7 @@ function spam_comment_overview() { $form['hostname'][$comment->cid] = array('#value' => $comment->hostname); $form['status'][$comment->cid] = array('#value' => ($comment->status == 0 ? t('published') : t('not published'))); $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(), 'destination=admin/content/comment/') . ' ' . l(t('details'), "admin/logs/spam/logs/comment/$comment->cid")); + $form['operations'][$comment->cid] = array('#value' => l(t('edit'), "comment/edit/$comment->cid", array('query' => 'destination=admin/content/comment/')) .' '. l(t('details'), "admin/reports/spam/logs/comment/$comment->cid")); } $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments); @@ -2692,10 +2794,10 @@ function spam_blocked_ips_overview() { // 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 probability>%d ORDER BY timestamp DESC) AS x GROUP BY x.hostname) AS y WHERE y.count>=%d"; - $arguments=array(variable_get('spam_threshold', 80),variable_get('spam_blacklist_ip', 2)); + $sql = "SELECT * FROM (SELECT DISTINCT x.hostname, x.timestamp, COUNT(x.hostname) AS count FROM (SELECT timestamp,hostname FROM {spam_tracker} WHERE probability>%d ORDER BY timestamp DESC) AS x GROUP BY x.hostname) AS y WHERE y.count>=%d"; + $arguments = array(variable_get('spam_threshold', 80), variable_get('spam_blacklist_ip', 2)); - $count_sql=preg_replace('/^SELECT \* /','SELECT count(hostname) ',$sql); + $count_sql = preg_replace('/^SELECT \* /', 'SELECT count(hostname) ', $sql); $result = pager_query($sql . tablesort_sql($header), 50, 0, $count_sql, $arguments); @@ -2719,9 +2821,9 @@ function spam_blocked_ips_overview() { /** * Form API hook; validate spam_comment_overview() form. */ -function spam_comment_overview_validate($form_id, $form_values) { - $form_values['comments'] = array_diff($form_values['comments'], array(0)); - if (count($form_values['comments']) == 0) { +function spam_comment_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(NULL, t('Please select one or more comments to perform the update on.')); return 'admin/content/comment/list/spam'; } @@ -2730,11 +2832,11 @@ function spam_comment_overview_validate( /** * Form API hook; submit spam_comment_overview() form. */ -function spam_comment_overview_submit($form_id, $form_values) { - $operation = spam_comment_operations($form_values['operation']); +function spam_comment_overview_submit($form, &$form_state) { + $operation = spam_comment_operations($form_state['values']['operation']); if ($operation) { - foreach($form_values['comments'] as $cid => $value) { + foreach ($form_state['values']['comments'] as $cid => $value) { if ($value) { $operation($cid); } @@ -2780,9 +2882,9 @@ function theme_spam_comment_overview($fo /** * Validation code for the spam_node_overview form/function */ -function spam_node_overview_validate($form_id, $form_values) { - $form_values['nodes'] = array_diff($form_values['nodes'], array(0)); - if (count($form_values['nodes']) == 0) { +function spam_node_overview_validate($form, &$form_state) { + $form_state['values']['nodes'] = array_diff($form_state['values']['nodes'], array(0)); + if (count($form_state['values']['nodes']) == 0) { form_set_error('', t('Please select one or more nodes to perform the update on.')); drupal_goto('admin/content/node/list/spam'); } @@ -2791,11 +2893,11 @@ function spam_node_overview_validate($fo /** * Submit code for the spam_node_overview form/function */ -function spam_node_overview_submit ($form_id, $form_values) { - $operation = spam_node_operations_list($form_values['operation']); +function spam_node_overview_submit($form, &$form_state) { + $operation = spam_node_operations_list($form_state['values']['operation']); if ($operation) { - foreach($form_values['nodes'] as $nid => $value) { + foreach ($form_state['values']['nodes'] as $nid => $value) { if ($value) { $operation($nid); } @@ -2808,7 +2910,7 @@ function spam_node_overview_submit ($for * Return the function to call dependant on the $action requested. */ function spam_node_operations_list($action = 'NOTHING') { - switch($action) { + switch ($action) { case 'NOT_SPAM': $operation = 'spam_notspam_node'; break; @@ -2884,7 +2986,7 @@ function spam_node_overview() { '#options' => $operations, '#description' => t('') ); - + $form['options']['submit'] = array( '#type' => 'submit', '#value' => t('Update') @@ -2893,7 +2995,7 @@ function spam_node_overview() { // create the select all button w/ select as a label //$selectButton = spam_select_all('spam_node_overview'); $form['header'] = array('#type' => 'value', '#value' => array( - $selectButton, + // $selectButton, // was commented out above! array('data' => t('title'), 'field' => 'n.title'), array('data' => t('type'), 'field' => 'n.type'), array('data' => t('author'), 'field' => 'u.name'), @@ -2914,9 +3016,9 @@ function spam_node_overview() { $form['type'][$node->nid] = array('#value' => node_get_types('name', $node)); $form['author'][$node->nid] = array('#value' => theme('username', $node)); $form['hostname'][$node->nid] = array('#value' => $node->hostname); - $form['status'][$node->nid] = array('#value' => ($node->status ? t('published') : t('not published'))); + $form['status'][$node->nid] = array('#value' => ($node->status ? t('published') : t('not published'))); $form['timestamp'][$node->nid] = array('#value' => format_date($node->changed, 'small')); - $form['operations'][$node->nid] = array('#value' => l(t('View log'), "admin/logs/spam/logs/node/$node->nid") . ' ' . l(t('Edit'), "node/$node->nid/edit") . ' ' . l(t('Delete'), "admin/content/node/delete/$node->nid")); + $form['operations'][$node->nid] = array('#value' => l(t('View log'), "admin/reports/spam/logs/node/$node->nid") .' '. l(t('Edit'), "node/$node->nid/edit") .' '. l(t('Delete'), "admin/content/node/delete/$node->nid")); } $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes); @@ -2990,7 +3092,7 @@ function spam_publish_comment($cid) { db_query('UPDATE {comments} SET status = 0 WHERE cid = %d', $comment->cid); _comment_update_node_statistics($comment->nid); cache_clear_all(); - watchdog('spam', t('Spam: published comment "%subject".', array('%subject' => $comment->subject))); + watchdog('spam', 'Spam: published comment "%subject".', array('%subject' => $comment->subject)); spam_log(SPAM_LOG, t('spam_publish_comment: published comment "%subject".', array('%subject' => $comment->subject)), 'comment', $comment->cid); } } @@ -3000,7 +3102,7 @@ function spam_unpublish_comment($cid) { db_query('UPDATE {comments} SET status = 1 WHERE cid = %d', $comment->cid); _comment_update_node_statistics($comment->nid); cache_clear_all(); - watchdog('spam', t('Spam: unpublished comment "%subject".', array('%subject' => $comment->subject))); + watchdog('spam', 'Spam: unpublished comment "%subject".', array('%subject' => $comment->subject)); spam_log(SPAM_LOG, t('spam_unpublish_comment: unpublished comment "%subject".', array('%subject' => $comment->subject)), 'comment', $comment->cid); } } @@ -3015,12 +3117,13 @@ function spam_delete_comment($cid) { if ($cid == 0) return; if ($comment = spam_load_comment($cid)) { + module_load_include('inc', 'comment', 'comment.admin'); $user = user_load(array('uid' => 1)); _comment_delete_thread($comment); _comment_update_node_statistics($comment->nid); $user = $save_user; cache_clear_all(); - watchdog('spam', t('Spam: deleted comment "%subject" and all replies.', array('%subject' => $comment->subject))); + watchdog('spam', 'Spam: deleted comment "%subject" and all replies.', array('%subject' => $comment->subject)); spam_log(SPAM_LOG, t('spam_delete_comment: deleted comment "%subject" and all replies.', array('%subject' => $comment->subject)), 'comment', $comment->cid); } } @@ -3036,7 +3139,7 @@ function spam_spam_comment($cid) { spam_tokens_save($tokens, 1); db_query("UPDATE {spam_tracker} SET probability = %d, timestamp = %d WHERE source = 'comment' AND id = %d", 99, time(), $cid); if (!db_affected_rows()) { - db_query("INSERT INTO {spam_tracker} (id, source, probability, hostname, hash, timestamp) VALUES(%d, '%s', %d, '%s', '%s', %d)", $cid, 'comment', 99, $_SERVER['REMOTE_ADDR'], md5($comment->subject . $comment->comment), time()); + db_query("INSERT INTO {spam_tracker} (id, source, probability, hostname, hash, timestamp) VALUES(%d, '%s', %d, '%s', '%s', %d)", $cid, 'comment', 99, ip_address(), md5($comment->subject . $comment->comment), time()); } spam_default_actions('comment', $cid, $comment->subject, $comment->comment, 99, NULL, FALSE, 1); spam_log(SPAM_LOG, t('spam_page: comment manually marked as spam'), 'comment', $comment->cid); @@ -3074,7 +3177,7 @@ function spam_publish_node($nid) { if ($node = node_load(array('nid' => $nid))) { db_query('UPDATE {node} SET status = 1 WHERE nid = %d', $node->nid); cache_clear_all(); - watchdog('spam', t('Spam: published @type "%subject".', array('@type' => node_get_types('name', $node), '%subject' => $node->title))); + watchdog('spam', 'Spam: published @type "%subject".', array('@type' => node_get_types('name', $node), '%subject' => $node->title)); spam_log(SPAM_LOG, t('spam_publish_node: published node "%title".', array('%title' => $node->title)), 'node', $node->nid); } } @@ -3086,7 +3189,7 @@ function spam_unpublish_node($nid) { if ($node = node_load(array('nid' => $nid))) { db_query('UPDATE {node} SET status = 0 WHERE nid = %d', $node->nid); cache_clear_all(); - watchdog('spam', t('Spam: unpublished @type "%subject".', array('@type' => node_get_types('name', $node), '%subject' => $node->title))); + watchdog('spam', 'Spam: unpublished @type "%subject".', array('@type' => node_get_types('name', $node), '%subject' => $node->title)); spam_log(SPAM_LOG, t('spam_unpublish_node: unpublished node "%title".', array('%title' => $node->title)), 'node', $node->nid); } } @@ -3106,7 +3209,7 @@ function spam_delete_node($nid) { $user = user_load(array('uid' => 1)); node_delete($nid); $user = $save_user; - watchdog('spam', t('Spam: deleted @type "%subject".', array('@type' => node_get_types('name', $node), '%subject' => $node->title))); + watchdog('spam', 'Spam: deleted @type "%subject".', array('@type' => node_get_types('name', $node), '%subject' => $node->title)); spam_log(SPAM_LOG, t('spam_delete_node: deleted node "%title".', array('%title' => $node->title)), 'node', $node->nid); } } @@ -3122,7 +3225,7 @@ function spam_spam_node($nid) { spam_tokens_unsave($tokens, 1); db_query("UPDATE {spam_tracker} SET probability = %d, timestamp = %d WHERE source = 'node' AND id = %d", 99, time(), $nid); if (!db_affected_rows()) { - db_query("INSERT INTO {spam_tracker} (id, source, probability, hostname, hash, timestamp) VALUES(%d, '%s', %d, '%s', '%s', %d)", $nid, 'node', 99, $_SERVER['REMOTE_ADDR'], md5($node->title . $node->body), time()); + db_query("INSERT INTO {spam_tracker} (id, source, probability, hostname, hash, timestamp) VALUES(%d, '%s', %d, '%s', '%s', %d)", $nid, 'node', 99, ip_address(), md5($node->title . $node->body), time()); } spam_default_actions('node', $nid, $node->title, $node->body, 99, NULL, FALSE, 1); spam_log(SPAM_LOG, t('spam_page: node manually marked as spam'), 'node', $node->nid); Gemeinsame Unterverzeichnisse: /home/milian/projects/drupal-5.7/modules/spam/trackback_blackhole und spam/trackback_blackhole.
'. t('Type') .'' . l(t($entry->source), "admin/logs/spam/logs/$entry->source") . '
'. t('@type ID', array('@type' => ucfirst($entry->source))) .'' . l(t($entry->id), "admin/logs/spam/logs/$entry->source/$entry->id") . '
'. t('Type') .''. l(t($entry->source), "admin/reports/spam/logs/$entry->source") .'
'. t('@type ID', array('@type' => ucfirst($entry->source))) .''. l(t($entry->id), "admin/reports/spam/logs/$entry->source/$entry->id") .'
'. t('Date') .''. format_date($entry->timestamp, 'large') .'
'. t('User') .''. theme('username', $reported_user) .'