function comment_notify_comment_insert in Comment Notify 7
Same name and namespace in other branches
- 8 comment_notify.module \comment_notify_comment_insert()
Implements hook_comment_insert().
File
- ./
comment_notify.module, line 267 - This module provides comment follow-up e-mail notification for anonymous and registered users.
Code
function comment_notify_comment_insert($comment) {
module_load_include('inc', 'comment_notify', 'comment_notify');
global $user;
// For new comments, we first build up a string to be used as the identifier
// for the alert. This identifier is used to later unsubscribe the user or
// allow them to potentially edit their comment / preferences if they are
// anonymous. The string is built with token and their host and comment
// identifier. It is stored and referenced, we really just need something
// unique/unguessable.
$hostname = isset($comment->hostname) ? $comment->hostname : (isset($user->hostname) ? $user->hostname : '');
$notify_hash = drupal_get_token($hostname . $comment->cid);
if (!empty($comment->notify)) {
$notify = $comment->notify_type;
// If they don't have a preference, save one.
$current = comment_notify_get_user_comment_notify_preference($user->uid);
if ($current == 0 && $user->uid) {
comment_notify_set_user_notification_setting($user->uid, NULL, $comment->notify_type);
}
}
else {
$notify = 0;
}
// And then save the data.
comment_notify_add_notification($comment->cid, $notify, $notify_hash);
// And send notifications - the real purpose of the module.
if ($comment->status == COMMENT_PUBLISHED) {
_comment_notify_mailalert($comment);
}
}