Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/commentmail/README.txt,v retrieving revision 1.3 diff -u -p -r1.3 README.txt --- README.txt 10 Feb 2007 17:27:31 -0000 1.3 +++ README.txt 24 Feb 2008 19:23:54 -0000 @@ -10,4 +10,4 @@ administrator(s) when new comments are p email allows quick approval, editing, deletion, and/or banning of the poster's IP address (good for spam). -Module currently works with Drupal 5. \ No newline at end of file +Module currently works with Drupal 6. \ No newline at end of file Index: commentmail.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/commentmail/commentmail.info,v retrieving revision 1.1 diff -u -p -r1.1 commentmail.info --- commentmail.info 10 Feb 2007 17:27:31 -0000 1.1 +++ commentmail.info 24 Feb 2008 19:23:54 -0000 @@ -1,3 +1,4 @@ ; $Id: commentmail.info,v 1.1 2007/02/10 17:27:31 timcn Exp $ name = Comment Mail description = Sends an email message when comments are posted to the site. +core = 6.x \ No newline at end of file Index: commentmail.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/commentmail/commentmail.module,v retrieving revision 1.12 diff -u -p -r1.12 commentmail.module --- commentmail.module 18 Mar 2007 12:45:53 -0000 1.12 +++ commentmail.module 24 Feb 2008 19:23:54 -0000 @@ -43,39 +43,28 @@ Comment administration: @admin_url"); /** * Implementation of hook_menu() */ -function commentmail_menu($may_cache) { - $items = array(); - - if ($may_cache) { - $access = user_access('administer comments'); - - $items[] = array( - 'title' => t('Comment mail'), - 'path' => 'admin/settings/commentmail', - 'description' => t('Settings for the comment mail module.'), - 'access' => $access, - 'callback' => 'drupal_get_form', - 'callback arguments' => array('commentmail_admin_settings'), - ); - - $items[] = array( - 'title' => t('Approve comment'), - 'path' => 'comment/approve', - 'access' => $access, - 'callback' => 'drupal_get_form', - 'callback arguments' => array('commentmail_approve'), - 'type' => MENU_CALLBACK, - ); - - $items[] = array( - 'title' => t('Delete comment and ban user'), - 'path' => 'comment/deleteban', - 'access' => $access, - 'callback' => 'drupal_get_form', - 'callback arguments' => array('commentmail_deleteban'), - 'type' => MENU_CALLBACK, - ); - } +function commentmail_menu() { + $items['admin/settings/commentmail'] = array( + 'title' => t('Comment mail'), + 'description' => t('Settings for the comment mail module.'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('commentmail_admin_settings'), + 'access arguments' => array('administer comments'), + ); + $items['comment/approve'] = array( + 'title' => t('Approve comment'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('commentmail_approve'), + 'access arguments' => array('administer comments'), + 'type' => MENU_CALLBACK, + ); + $items['comment/deleteban'] = array( + 'title' => t('Delete comment and ban user'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('commentmail_deleteban'), + 'access arguments' => array('administer comments'), + 'type' => MENU_CALLBACK, + ); return $items; } @@ -175,73 +164,88 @@ function commentmail_admin_settings() { */ function commentmail_comment($comment, $op) { if ($op == 'insert') { - // Load the real comment object from the database - $comment_obj = _comment_load($comment['cid']); - // Decide what to do based on the user's setting switch (variable_get('commentmail_mode', 'approval')) { // Mails should only be sent for unpublished comments case 'approval': - if ($comment_obj->status == 0) { + if ($comment['status'] == 0) { // Don't send a mail because the comment is already published break; } - // Fallthrough for unpublished comments + // Fallthrough for unpublished comments // Mails should be sent for all new comments, regardless of their status case 'all': $recipient = variable_get('commentmail_to', variable_get('site_mail', FALSE)); - // Only send a mail if a recipient has been specified if ($recipient) { - // Load the node to get the title - $node = node_load($comment_obj->nid); - - if ($comment_obj->status == COMMENT_NOT_PUBLISHED) { - $text = variable_get('commentmail_mail_approve', t(COMMENTMAIL_DEFAULT_APPROVE)); - } - else { - $text = variable_get('commentmail_mail_notify', t(COMMENTMAIL_DEFAULT_NOTIFY)); - } - - // If the user is logged in, - if ($comment_obj->uid) { - $account = user_load(array('uid' => $comment_obj->uid)); - $comment_obj->mail = $account->mail; - $comment_obj->homepage = $account->homepage; - } - - $body = strtr($text, array( - '@site' => variable_get('site_name', 'Drupal'), - '@node' => $node->title, - '@approval_url' => url('comment/approve/'. $comment_obj->cid, NULL, NULL, TRUE), - '@delete_url' => url('comment/delete/'. $comment_obj->cid, NULL, NULL, TRUE), - '@ban_url' => url('comment/deleteban/'. $comment_obj->cid, NULL, NULL, TRUE), - '@edit_url' => url('comment/edit/'. $comment_obj->cid, NULL, NULL, TRUE), - '@queue_url' => url('admin/comment/list/approval', NULL, NULL, TRUE), - '@view_url' => url('node/'. $node->nid, NULL, 'comment-'. $comment_obj->cid, TRUE), - '@admin_url' => url('admin/content/comment', NULL, NULL, TRUE), - '@host' => $comment_obj->hostname, - '@user' => $comment_obj->name, - '@mail' => $comment_obj->mail, - '@homepage' => $comment_obj->homepage, - '@comment' => $comment_obj->comment, - )); - - drupal_mail( - 'commentmail-notify-'. $comment_obj->cid, - $recipient, - t('[@site] New Comment posted on "@title"', array('@title' => check_plain($node->title), '@site' => variable_get('site_name', 'Drupal'))), - $body, - variable_get('site_mail', NULL) - ); + drupal_mail('commentmail', 'notice', $recipient, $language, array('comment' => $comment)); } else { - watchdog('commentmail', t('Site mail address is not configured.'), WATCHDOG_ERROR); + watchdog('commentmail', 'Site mail address is not configured.', array(), WATCHDOG_ERROR); } } } } +/** + * Implementataion of hook_mail(). + */ +function commentmail_mail($key, &$message, $params) { + $comment = $params['comment']; + $language = $message['language']; + // Load the node to get the title + $node = node_load($comment['nid']); + + if ($comment['status'] == COMMENT_NOT_PUBLISHED) { + $text = variable_get('commentmail_mail_approve', t(COMMENTMAIL_DEFAULT_APPROVE)); + } + else { + $text = variable_get('commentmail_mail_notify', t(COMMENTMAIL_DEFAULT_NOTIFY)); + } + + // If the user is logged in, + if ($comment['uid']) { + $account = user_load(array('uid' => $comment['uid'])); + $comment['mail'] = $account->mail; + $comment['homepage'] = $account->homepage; + } + + $body = strtr($text, array( + '@site' => variable_get('site_name', 'Drupal'), + '@node' => $node->title, + '@approval_url' => url('comment/approve/'. $comment['cid'], array('absolute' => TRUE)), + '@delete_url' => url('comment/delete/'. $comment['cid'], array('absolute' => TRUE)), + '@ban_url' => url('comment/deleteban/'. $comment['cid'], array('absolute' => TRUE)), + '@edit_url' => url('comment/edit/'. $comment['cid'], array('absolute' => TRUE)), + '@queue_url' => url('admin/comment/list/approval', array('absolute' => TRUE)), + '@view_url' => url('node/'. $node->nid, array('fragment' => 'comment-'. $comment['cid'], 'absolute' => TRUE)), + '@admin_url' => url('admin/content/comment', array('absolute' => TRUE)), + '@host' => $comment['hostname'], + '@user' => $comment['name'], + '@mail' => $comment['mail'], + '@homepage' => $comment['homepage'], + '@comment' => $comment['comment'], + )); + + // Put the actual email together now. + switch($key) { + case 'notice': + $message['subject'] = t('[@site] New Comment posted on "@title"', array('@title' => check_plain($node->title), '@site' => variable_get('site_name', 'Drupal')), $language->language); + $message['body'] = $body; + break; + } + + + /* stuff from the old function + drupal_mail( + 'commentmail-notify-'. $comment['cid'], + $recipient, + t('[@site] New Comment posted on "@title"', array('@title' => check_plain($node->title), '@site' => variable_get('site_name', 'Drupal'))), + $body, + variable_get('site_mail', NULL) + ); + */ +} function commentmail_approve($cid) { @@ -266,8 +270,8 @@ function commentmail_approve($cid) { } } -function commentmail_approve_submit($form_id, $form_values) { - $comment = _comment_load($form_values['cid']); +function commentmail_approve_submit($form, &$form_state) { + $comment = _comment_load($form_state['values']['cid']); $comment->status = 0; if (comment_save((array)$comment)) { @@ -299,8 +303,8 @@ function commentmail_deleteban($cid) { } -function commentmail_deleteban_submit($form_id, $form_values) { - $comment = _comment_load($form_values['cid']); +function commentmail_deleteban_submit($form, &$form_state) { + $comment = _comment_load($form_state['values']['cid']); // Delete comment and its replies. _comment_delete_thread($comment); @@ -312,7 +316,7 @@ function commentmail_deleteban_submit($f cache_clear_all(); // Now, ban the user - $aid = db_next_id('{access}_aid'); + $aid = db_last_insert_id('access_aid', 'aid'); db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', 'host', 0)", $aid, $comment->hostname); drupal_set_message(t('The host %host has been banned.', array('%host' => $comment->hostname)));