function spam_cron in Spam 5
Same name and namespace in other branches
- 5.3 spam.module \spam_cron()
- 6 spam.module \spam_cron()
Drupal _cron hook. Provides ability to automatically expired spam content.
File
- ./
spam.module, line 488
Code
function spam_cron() {
global $base_url;
// send email notifications every 24 hours
$email_timer = variable_get('spam_email_timer', 0);
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)) {
$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();
while ($reported = db_fetch_object($result)) {
$message .= t(" - @num @source\n", array(
'@num' => $reported->count,
'@source' => format_plural($reported->count, $reported->source, $reported->source . 's'),
));
$urls[] = $base_url . url("admin/content/{$reported->source}/list/reported");
}
$message .= t("\n Please review this reported spam by visiting the following @url:\n", array(
'@url' => format_plural(sizeof($urls), 'url', 'urls'),
));
foreach ($urls as $url) {
$message .= " {$url}\n";
}
spam_mail(t('[@sitename] Spam reported', array(
'@sitename' => variable_get('site_name', 'drupal'),
)), "{$message}");
}
}
// expire spam content that is older than we're configured to keep.
if ($expire = variable_get('spam_expire_time', 1209600)) {
$result = db_query('SELECT source, id FROM {spam_tracker} WHERE timestamp < %d AND probability >= %d', time() - $expire, variable_get('spam_threshold', 80));
while ($content = db_fetch_object($result)) {
/* external content types (other than 'node' or 'comment') _must_ provide
* a spam_delete_<type>() function.
*/
spam_log(SPAM_LOG, t('spam_cron: deleting @source', array(
'@source' => $content->source,
)), $content->source, $content->id);
$function = "spam_delete_{$content->source}";
$function($content->id);
}
}
// clean expired spam logs
if ($flush = variable_get('spam_flush_log_timer', 259200)) {
db_query('DELETE FROM {spam_log} WHERE timestamp < %d', time() - $flush);
db_query('DELETE FROM {spam_reported} WHERE timestamp < %d', time() - $flush);
}
}