function _comment_notify_mailalert in Comment Notify 5
Same name and namespace in other branches
- 8 comment_notify.module \_comment_notify_mailalert()
- 5.2 comment_notify.module \_comment_notify_mailalert()
- 6 comment_notify.module \_comment_notify_mailalert()
- 7 comment_notify.module \_comment_notify_mailalert()
1 call to _comment_notify_mailalert()
- comment_notify_comment in ./
comment_notify.module - implement hook_comment and check the publish status
File
- ./
comment_notify.module, line 255 - This module provides comment follow-up e-mail notification for anonymous and registered users.
Code
function _comment_notify_mailalert($comment) {
$comment = (object) $comment;
global $locale;
global $base_url;
$initial_locale = $locale;
if (function_exists('locale')) {
$languages = locale_supported_languages();
$languages = $languages['name'];
}
$nid = $comment->nid;
$cid = $comment->cid;
$commname = $comment->name;
$commtext = $comment->comment;
$commsubj = $comment->subject;
$node = node_load($nid);
if (!isset($comment->mail)) {
$comment_account = user_load(array(
'name' => $commname,
));
$comment_mail = $comment_account->mail;
}
else {
$comment_mail = $comment->mail;
}
$from = variable_get('site_mail', ini_get('sendmail_from'));
$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
WHERE nid = %d AND notify = 1 AND c.status = 0
AND LENGTH(IF(LENGTH(c.mail) < 1, ifnull(u.mail, u.init), c.mail)) > 1
AND IF(LENGTH(c.mail) < 1, ifnull(u.mail, u.init), c.mail) like \'%@%.%\'
GROUP BY IF(LENGTH(c.mail) < 1, ifnull(u.mail, u.init), c.mail), c.name', $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) {
if (function_exists('locale') && $languages[$user->language]) {
$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(
'!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' => $alert->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),
'!link1' => url('comment_notify/disable/' . $alert->mymd5, NULL, NULL, 1),
));
drupal_mail('comment_notify_mail', $alert->mail, $subject, $message, $from, array());
$count++;
$sent_to[] = $alert->mail;
if ($alert->uid != 0) {
$watchdog_message = t('Notified: <a href="!url">@user_mail</a>', array(
'!url' => url('user/' . $alert->uid . '/edit'),
'@user_mail' => $alert->mail,
));
}
else {
$watchdog_message = t('Notified @user_mail', array(
'@user_mail' => $alert->mail,
));
}
// Add an entry to the watchdog log.
watchdog('comment_notify', $watchdog_message, WATCHDOG_NOTICE, l(t('source comment'), 'node/' . $nid, NULL, NULL, 'comment-' . $alert->cid));
// revert to previous (site default) locale
$locale = $initial_locale;
}
}
}