Index: commentmail.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/commentmail/commentmail.info,v
retrieving revision 1.1
diff -u -F^f -r1.1 commentmail.info
--- commentmail.info 10 Feb 2007 17:27:31 -0000 1.1
+++ commentmail.info 9 Nov 2008 01:52:56 -0000
@@ -1,3 +1,4 @@
-; $Id: commentmail.info,v 1.1 2007/02/10 17:27:31 timcn Exp $
+; $Id$
name = Comment Mail
description = Sends an email message when comments are posted to the site.
+core = 6.x
Index: commentmail.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/commentmail/commentmail.module,v
retrieving revision 1.12.2.7
diff -u -F^f -r1.12.2.7 commentmail.module
--- commentmail.module 24 Oct 2008 17:46:53 -0000 1.12.2.7
+++ commentmail.module 9 Nov 2008 01:52:57 -0000
@@ -1,14 +1,14 @@
t('Quick edit'),
- 'path' => 'comment/qa',
- 'access' => TRUE,
- 'callback' => 'commentmail_quick_approve',
- 'type' => MENU_CALLBACK
- );
-
- $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,
- );
-
- $items[] = array(
- 'title' => t('Quick delete'),
- 'path' => 'comment/quickdelete',
- 'access' => $access,
- 'callback' => 'commentmail_quick_delete',
- 'type' => MENU_CALLBACK
- );
-
- $items[] = array(
- 'title' => t('Quick delete and ban'),
- 'path' => 'comment/quickdeleteban',
- 'access' => $access,
- 'callback' => 'commentmail_quick_deleteban',
- 'type' => MENU_CALLBACK
- );
+function commentmail_menu() {
+ $items['admin/settings/commentmail'] = array(
+ 'title' => 'Comment mail',
+ 'description' => 'Settings for the comment mail module.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('commentmail_admin_settings'),
+ 'access arguments' => array('administer comments'),
+ 'type' => MENU_CALLBACK,
+ );
- }
+ $items['comment/approve/%'] = array(
+ 'title' => t('Approve comment'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('commentmail_approve', 2),
+ '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', 2),
+ 'access arguments' => array('administer comments'),
+ 'type' => MENU_CALLBACK,
+ );
- return $items;
+ return $items;
}
-
-
/**
* Settings page callback function.
*/
@@ -133,9 +98,6 @@ function commentmail_admin_settings() {
@node
The title of the post this comment was submitted for.
- @quick_approve
- The address the recipient can visit to view/edit/delete/approve the comment - recommended.
-
@approval_url
The address the recipient can visit to publish the comment.
@@ -209,7 +171,8 @@ function commentmail_comment($comment, $
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;
}
@@ -220,49 +183,7 @@ function commentmail_comment($comment, $
// 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));
- }
-
- // Check 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,
- '@quick_approve' => url('comment/qa/'. $comment_obj->cid, NULL, NULL, TRUE),
- '@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/content/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,
- '@subject' => $comment_obj->subject,
- '@comment' => $comment_obj->comment,
- ));
-
- drupal_mail(
- 'commentmail-notify-'. $comment_obj->cid,
- $recipient,
- t('[!site] New Comment posted on "!title"', array('!site' => variable_get('site_name', 'Drupal'), '!title' => $node->title)),
- $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);
@@ -273,6 +194,69 @@ function commentmail_comment($comment, $
/**
+ * 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'],
+ '@subject' => $comment['subject'],
+ ));
+
+ // 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)
+ );
+ */
+}
+
+
+
+/**
* Allow quick approval directly from an email.
*
* @param $cid
@@ -419,8 +403,10 @@ function commentmail_approve($cid) {
/**
* Submission handler for comment approval.
*/
-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)) {
@@ -458,8 +444,10 @@ function commentmail_deleteban($cid) {
/**
* Submission handler for comment delete/ban.
*/
-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);
@@ -471,10 +459,11 @@ 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)));
drupal_goto('node/'. $comment->nid);
-}
+}