You are here

function comment_notify_comment in Comment Notify 5.2

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

Implementation of hook_comment().

File

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

Code

function comment_notify_comment($comment, $op) {
  global $user;
  switch ($op) {
    case 'validate':

      // We assume that if they are non-anonymous then they have a valid mail.
      // For anonymous users, though, we verify that they entered a mail and let comment.module validate it is real.
      if (!$user->uid && $comment['notify'] && empty($comment['mail'])) {
        form_set_error('mail', t('If you want to subscribe to comments you must supply a valid e-mail address.'));
      }
      break;
    case 'publish':

      // The real meat of the module.
      _comment_notify_mailalert($comment);
      break;
    case 'update':

      // In case they have changed their status, save it in the database.
      $sql = 'UPDATE {comment_notify} SET notify = %d WHERE cid = %d';
      db_query($sql, $comment['notify'], $comment['cid']);
      break;
    case 'insert':

      // For new comments, we first build up a string to be used as the identifier for the alert
      $mail = empty($comment['mail']) ? $user->mail : $comment['mail'];
      $notify_hash = drupal_get_token($mail . $comment['cid']);

      // And then save the data.
      db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) values (%d, %d, '%s')", $comment['cid'], $comment['notify'], $notify_hash);
      break;
    case 'delete':
      db_query("DELETE FROM {comment_notify} WHERE cid = %d", $comment->cid);
      break;
  }
}