--- comment_notify.module.old Tue Mar 25 14:30:48 2008 +++ comment_notify.module Wed Mar 26 11:57:40 2008 @@ -1,5 +1,6 @@ 'fieldset', - '#title' => t('Comment is not posted yet - please click post button to confirm your post'), - '#weight' => -99, - '#collapsible' => FALSE - ); - - $form['submitextra']['submit'] = array( - '#type' => 'submit', - '#value' => t('Post comment'), - '#weight' => -20 - ); - } - } - - if (($user->uid == 0) || (variable_get('comment_notify_regged_checkbox', TRUE))) { - $form['notify'] = array( + #if anonymous and anonymous can post their email address OR not anonymous and allowed to register per node + if ((($user->uid == 0) && (variable_get('comment_anonymous', COMMENT_ANONYMOUS_MAYNOT_CONTACT) != COMMENT_ANONYMOUS_MAYNOT_CONTACT)) || + (($user->uid != 0) && (variable_get('comment_notify_regged_checkbox', TRUE)))) { + $form['notify'] = array( '#type' => 'checkbox', - '#title' => t('Notify me of follow-up comments posted here.'), - '#default_value' => ($user->uid != 0) ? $user->comment_notify_mailalert : variable_get('comment_notify_default_anon_mailalert', TRUE) + '#title' => t('Notify me of follow-up comments.'), + '#default_value' => ($user->uid != 0) ? (isset($user->comment_notify_mailalert) ? $user->comment_notify_mailalert : 1) : variable_get('comment_notify_default_anon_mailalert', TRUE), + '#description' => t('Your selection will override any you previously submitted for this page or thread.'), + '#weight' => 15 ); } else { @@ -221,11 +210,23 @@ '#collapsible' => TRUE ); + $form['comment_notify_settings']['node_notify_mailalert'] = array( + '#type' => 'checkbox', + '#title' => t('Receive node follow-up notification e-mails'), + '#default_value' => isset($edit['node_notify_mailalert']) ? $edit['node_notify_mailalert'] : 1, + '#description' => t('Check this box to receive an e-mail notification for follow-ups on your nodes (pages, forum topics, etc). You can not disable notifications for individual threads.') + ); + $form['comment_notify_settings']['comment_notify_mailalert'] = array( '#type' => 'checkbox', '#title' => t('Receive comment follow-up notification e-mails'), '#default_value' => isset($edit['comment_notify_mailalert']) ? $edit['comment_notify_mailalert'] : 1, - '#description' => t('Check this box to receive e-mail notification for follow-up comments to comments you posted. You can later disable this on a post-by-post basis... so if you leave this to YES, you can still disable follow-up notifications for comments you don\'t want follow-up mails anymore - i.e. for very popular posts.') + '#description' => t('Check this box to receive an e-mail notification for follow-ups on your comments. If this is selected, you can still disable notifications for individual threads.') + ); + + $form['comment_notify_settings']['comment_notify_information'] = array( + '#type' => 'markup', + '#value' => t('* If you comment on your own node with both options selected, you will only receive one notification per instance.') ); return $form; @@ -237,8 +238,7 @@ function _comment_notify_mailalert($comment) { $comment = (object) $comment; - global $locale; - global $base_url; + global $locale, $base_url, $user; $initial_locale = $locale; @@ -262,6 +262,35 @@ } $from = variable_get('site_mail', ini_get('sendmail_from')); + $count = 0; + $sent_to = array(); + $subject = t('[!site Comment] !title', array('!site' => variable_get('site_name', 'drupal'), '!title' => $node->title)); + + $author = user_load(array('uid'=>$node->uid)); + #send to a subscribed author - if author did not establish their choice, we assume the default is yes - and ignore triggers by self + if ((!isset($author->node_notify_mailalert) || $author->node_notify_mailalert == 1) && ($user->mail != $author->mail)){ + $message = t( + variable_get('node_notify_default_mailtext', AUTHOR_MAILTEXT), + array( + '!commname' => $commname, + '!commtext' => $commtext, + '!commsubj' => $commsubj, + '!comment_url' => url('node/'. $nid, NULL, NULL, 1) .'#comment-'. $cid, + '!node_title' => $node->title, + '!node_teaser' => $node->teaser, + '!mission' => variable_get('site_mission', ''), + '!node_body' => $node->body, + '!name' => $author->name, + '!site' => variable_get('site_name', 'drupal'), + '!uri' => $base_url, + '!uri_brief' => substr($base_url, strlen('http://')), + '!date' => format_date(time()), + '!login_uri' => url('user', NULL, NULL, 1), + '!edit_uri' => url('user/'. $alert->uid .'/edit', NULL, NULL, 1) + ) + ); + drupal_mail('node_notify_mail', $author->mail, $subject, $message, $from, array()); + } $result = db_query('SELECT DISTINCT c.cid, u.init, c.uid, c.name, c.nid, IF(length(c.mail) < 1, ifnull(u.mail, u.init), c.mail) mail, c.uid, c.name, max(cid) cid, md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid)) mymd5 FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid = c.uid @@ -272,9 +301,6 @@ $nid ); - $count = 0; - $sent_to = array(); - while ($alert = db_fetch_object($result)) { if ($alert->mail != $comment_mail && !in_array($alert->mail, $sent_to) && $alert->uid != $comment->uid) { @@ -282,7 +308,6 @@ $locale = $user->language; } - $subject = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal'))); $message = t( variable_get('comment_notify_default_mailtext', DEFAULT_MAILTEXT), array( @@ -305,9 +330,11 @@ ) ); - drupal_mail('comment_notify_mail', $alert->mail, $subject, $message, $from, array()); - $count++; - + #skip sending to a subscribed author who is also a commenter - if author did not establish their choice, we assume the default is yes - and ignore triggers by self + if (((!isset($author->node_notify_mailalert) || $author->node_notify_mailalert == 1) && ($alert->mail != $author->mail)) && ($alert->mail != $user->mail)){ + drupal_mail('comment_notify_mail', $alert->mail, $subject, $message, $from, array()); + $count++; + } if ($alert->uid != 0) { $mylink = l($alert->mail , 'user/'. $alert->uid .'/edit'); } @@ -345,7 +372,7 @@ $form['comment_notify_settings']['comment_notify_default_mailtext'] = array( '#type' => 'textarea', - '#title' => t('Default mail text for sending out the notifications.'), + '#title' => t('Default mail text for sending out notifications to commenters.'), '#description' => t( 'You can use the following variables to be replaced: ' ), '#default_value' => variable_get('comment_notify_default_mailtext', t(DEFAULT_MAILTEXT)), + '#return_value' => 1, + '#cols' => 80, + '#rows' => 15 + ); + + $form['comment_notify_settings']['node_notify_default_mailtext'] = array( + '#type' => 'textarea', + '#title' => t('Default mail text for sending out the notifications to node authors.'), + '#description' => t( + 'You can use the following variables to be replaced: + ' + ), + '#default_value' => variable_get('node_notify_default_mailtext', t(AUTHOR_MAILTEXT)), '#return_value' => 1, '#cols' => 80, '#rows' => 15