You are here

function comment_notify_user in Comment Notify 5.2

Same name and namespace in other branches
  1. 5 comment_notify.module \comment_notify_user()
  2. 6 comment_notify.module \comment_notify_user()

Implementation of hook_user().

File

./comment_notify.module, line 276
This module provides comment follow-up e-mail notification for anonymous and registered users.

Code

function comment_notify_user($type, &$edit, &$user, $category = NULL) {
  switch ($type) {
    case 'form':
      if ($category == 'account' && user_access('subscribe to comments', $user)) {
        $form = array();
        $form['comment_notify_settings'] = array(
          '#type' => 'fieldset',
          '#title' => t('Comment follow-up notification settings'),
          '#weight' => 4,
          '#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'] : FALSE,
          '#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' => 'select',
          '#title' => t('Receive comment follow-up notification e-mails'),
          '#default_value' => isset($edit['comment_notify_mailalert']) ? $edit['comment_notify_mailalert'] : FALSE,
          '#options' => array(
            COMMENT_NOTIFY_DISABLED => t('No notifications'),
            COMMENT_NOTIFY_NODE => t('For all comments on this post'),
            COMMENT_NOTIFY_COMMENT => t('Just for replies to my comment'),
          ),
          '#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."),
        );
        return $form;
      }
      break;
    case 'submit':

      // Save the values of node_notify_mailalert and comment_notify_mailalert
      // to {comment_notify_user_settings}.
      if (db_result(db_query('SELECT uid FROM {comment_notify_user_settings} WHERE uid = %d', $user->uid))) {
        db_query('UPDATE {comment_notify_user_settings} SET node_notify = %d, comment_notify = %d WHERE uid = %d', $edit['node_notify_mailalert'], $edit['comment_notify_mailalert'], $user->uid);
      }
      else {
        db_query('INSERT INTO {comment_notify_user_settings} (uid, node_notify, comment_notify) VALUES (%d, %d, %d)', $user->uid, $edit['node_notify_mailalert'], $edit['comment_notify_mailalert']);
      }

      // Unset them from $user so they don't also get saved into {users}.data.
      unset($edit['node_notify_mailalert']);
      unset($edit['comment_notify_mailalert']);
      break;
    case 'load':
      $user_settings = db_fetch_array(db_query('SELECT node_notify AS node_notify_mailalert, comment_notify AS comment_notify_mailalert FROM {comment_notify_user_settings} WHERE uid = %d', $user->uid));
      if (!empty($user_settings)) {
        foreach ($user_settings as $property => $value) {
          $user->{$property} = $value;
        }
      }
      break;
    case 'delete':
      db_query('DELETE FROM {comment_notify_user_settings} WHERE uid = %d', $user->uid);
      break;
  }
}