Index: comment_notify/comment_notify.inc
===================================================================
--- comment_notify/comment_notify.inc	(revision 23354)
+++ comment_notify/comment_notify.inc	(working copy)
@@ -1,4 +1,5 @@
 <?php
+// $Id: comment_notify.inc,v 1.4 2010/10/11 01:31:35 greggles Exp $
 
 /**
  * @file
@@ -22,7 +23,7 @@
     // Handle anonymous users with defaults.
     if ($uid == 0) {
       $users[0] = new stdClass();
-      $users[0]->comment_notify = comment_notify_variable_registry_get('default_registered_mailalert');
+      $users[0]->comment_notify = comment_notify_variable_registry_get('default_anon_mailalert');
       $users[0]->node_notify = comment_notify_variable_registry_get('node_notify_default_mailalert');
     }
     else {
Index: comment_notify/comment_notify.module
===================================================================
--- comment_notify/comment_notify.module	(revision 23354)
+++ comment_notify/comment_notify.module	(working copy)
@@ -1,4 +1,5 @@
 <?php
+// $Id: comment_notify.module,v 1.88 2010/10/11 01:31:35 greggles Exp $
 
 /**
  * @file
@@ -298,12 +299,12 @@
   if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) {
     return;
   }
-  elseif ($form['#user_category'] != 'account') {
+  elseif ($form['#user_category'] != 'account' && $form['#user_category'] != 'register') {
     return;
   }
 
   $user = $form['#user'];
-  if ($user->comment_notify_settings) {
+  if (isset ($user->comment_notify_settings)) {
     $node_notify = $user->comment_notify_settings->node_notify;
     $comment_notify = $user->comment_notify_settings->comment_notify;
   }
@@ -317,8 +318,8 @@
 
   // Only show the node followup UI if the user has permission to create nodes.
   $nodes = FALSE;
-  foreach (node_type_get_names() as $type => $name) {
-    if (node_access('create', $type)) {
+  foreach (node_type_get_names() as $type => $description) {
+    if (user_access('create ' . $type . ' content')) {
       $nodes = TRUE;
       break;
     }
@@ -335,7 +336,7 @@
   else {
     $form['comment_notify_settings']['node_notify'] = array(
       '#type' => 'hidden',
-      '#value' => COMMENT_NOTIFY_DISABLED,
+      '#value' => $user->uid ? COMMENT_NOTIFY_DISABLED : comment_notify_variable_registry_get('node_notify_default_mailalert'),
     );
   }
 
@@ -344,7 +345,7 @@
   $form['comment_notify_settings']['comment_notify'] = array(
     '#type' => 'select',
     '#title' => t('Receive comment follow-up notification e-mails'),
-    '#default_value' => isset($comment_notify) ? array($comment_notify) : array(comment_notify_variable_registry_get('comment_notify_default_registered_mailalert')),
+    '#default_value' => isset($comment_notify) ? array($comment_notify) : array(comment_notify_variable_registry_get('default_registered_mailalert')),
     '#options' => $available_options,
     '#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.")
   );
@@ -352,6 +353,22 @@
   // Construct the user form
 }
 
+function comment_notify_user_insert(&$edit, $account, $category) {
+  if ($category != 'account') {
+    return;
+  }
+  if (isset($edit['node_notify']) && isset($edit['comment_notify'])) {
+    module_load_include('inc', 'comment_notify', 'comment_notify');
+
+    // Save the values of node_notify_mailalert and comment_notify_mailalert
+    // to {comment_notify_user_settings}.
+    comment_notify_set_user_notification_setting($account->uid, $edit['node_notify'], $edit['comment_notify']);
+  }
+  // Unset them from $user so they don't also get saved into {users}.data.
+  unset($edit['node_notify']);
+  unset($edit['comment_notify']);
+}
+
 function comment_notify_user_update(&$edit, $account, $category) {
   if ($category != 'account') {
     return;
@@ -366,7 +383,10 @@
   // Unset them from $user so they don't also get saved into {users}.data.
   unset($edit['node_notify']);
   unset($edit['comment_notify']);
+}
 
+function comment_notify_user_delete($account) {
+  db_delete('comment_notify_user_settings')->condition('uid', $account->uid)->execute();
 }
 
 function comment_notify_user_load($users) {
@@ -398,7 +418,6 @@
   global $language;
   global $base_url;
   global $user;
-  $initial_language = $language;
 
   $nid = $comment->nid;
   $cid = $comment->cid;
@@ -410,6 +429,13 @@
     return;
   }
 
+  $initial_language = $language;
+
+  if (function_exists('locale')) {
+    $languages = locale_language_list();
+    $languages = $languages['name'];
+  }
+
   $node = node_load($nid);
 
   // No mails if this is not an enabled content type.
@@ -418,6 +444,7 @@
     return;
   }
 
+  $comment->comment_body[LANGUAGE_NONE][0]['value'] = check_markup ($comment->comment_body[LANGUAGE_NONE][0]['value'], $comment->comment_body[LANGUAGE_NONE][0]['format']);
   if (!isset($comment->mail)) {
     $comment_account = user_load_by_name($comment->name);
     $comment_mail = $comment_account->mail;
@@ -430,7 +457,7 @@
   // Send to a subscribed author if they are not the current commenter
   $author = user_load($node->uid);
 
-  if (!empty($author->comment_notify_settings->node_notify) && $author->node_notify_mailalert == 1 && $user->uid != $author->uid && node_access('view', $node, $author)) {
+  if (!empty($author->comment_notify_settings->node_notify) && $author->comment_notify_settings->node_notify == 1 && $user->uid != $author->uid && node_access('view', $node, $author)) {
     // Get the author's language.
     $language = user_preferred_language($author);
     $raw_values = array(
@@ -438,7 +465,7 @@
       'body'  => comment_notify_variable_registry_get('node_notify_default_mailtext'), //JS @todo:change this.
     );
     foreach ($raw_values as $k => $v) {
-      $message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user));
+      $message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user), array('sanitize' => FALSE));
     }
 
     drupal_mail('comment_notify', 'comment_notify_mail', $author->mail, $language, $message);
@@ -483,9 +510,13 @@
       );
 
       foreach ($raw_values as $k => $v) {
-        $message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user));
+        $message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user), array('sanitize' => FALSE));
       }
 
+      //      array(
+      //          '!link1' => url('comment_notify/disable/'. $alert->notify_hash, array('absolute' => TRUE))
+      //      )
+
       drupal_mail('comment_notify', 'comment_notify_mail', $mail, $language, $message);
       $sent_to[] = $mail;
 
@@ -500,15 +531,15 @@
       // Add an entry to the watchdog log.
       watchdog(
         'comment_notify',
-        'Notified: @user_mail',
-        array('@user_mail' => $user_mail),
+        'Notified: !user_mail',
+      array('!user_mail' => $user_mail),
           WATCHDOG_NOTICE,
           l(t('source comment'), 'node/' . $nid, array(
             'fragment' => 'comment-' . $alert->cid,
           ))
       );
 
-      // Revert to previous (site default) locale.
+      // revert to previous (site default) locale
       $language = $initial_language;
     }
   }
@@ -670,3 +701,4 @@
     form_set_error('comment_notify_available_alerts', 'You must enable at least one subscription mode.');
   }
 }
+
