Newer
Older
<?php
// $Id$
/**
* @file
Greg Knaddison
committed
*
* This module provides comment follow-up e-mail notification for anonymous and registered users.
define('AUTHOR_MAILTEXT',
'Hi !name,
You have received a comment on: "!node_title"
You can view the comment at the following url
!comment_url
You will receive emails like this for all replies to your posts. You can disable this by logging in and going to your account settings.
Webmaster of !site
!mission
!uri');
Greg Knaddison
committed
define('DEFAULT_MAILTEXT',
'Hi !name,
Greg Knaddison
committed
!commname has commented on: "!node_title"
The post is about
----
Greg Knaddison
committed
!node_teaser
----
You can view the comment at the following url
Greg Knaddison
committed
!comment_url
You can stop receiving emails when someone replies to this post,
Greg Knaddison
committed
by going to !link1
If you have auto-following enabled in your account, you will receive emails like this for all replies to a blog post you commented on. You can disable this by logging in and going to your account settings or unchecking the flag at the time you post the comment.
You can set up auto-following feature for all future posts
Greg Knaddison
committed
by creating your own user with a few clicks here !uri/user/register
Thanks for your feedback,
Greg Knaddison
committed
Webmaster of !site
!mission
!uri');
Greg Knaddison
committed
define('COMMENT_NOTIFY_DISABLED', 0);
define('COMMENT_NOTIFY_NODE', 1);
define('COMMENT_NOTIFY_COMMENT', 2);
* Provide an array of available options for notification on a comment.
function _comment_notify_options() {
$total_options = array(
COMMENT_NOTIFY_NODE => t('All comments'),
COMMENT_NOTIFY_COMMENT => t('Replies to my comment')
);
$available_options = array();
$options = variable_get('comment_notify_available_alerts', array(COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT));
foreach ($options as $key => $available) {
if ($key == $available) {
$available_options[$available] = $total_options[$available];
}
return $available_options;
Greg Knaddison
committed
/**
Greg Knaddison
committed
* Insert our checkbox, add a submit button, and populate fields.
Greg Knaddison
committed
function comment_notify_form_alter(&$form, &$form_state, $form_id) {
global $user;
// Only do alter the form if it's a comment form and the user has the permission to subscribe
if ($form_id != 'comment_form' || !user_access('subscribe to comments')) {
Greg Knaddison
committed
return;
}
// Only add the checkbox if this is an enabled content type
$node = node_load($form['nid']['#value']);
Greg Knaddison
committed
$enabled_types = variable_get('comment_notify_node_types', array($node->type => TRUE));
if (empty($enabled_types[$node->type])) {
return;
Greg Knaddison
committed
}
$available_options = _comment_notify_options();
Greg Knaddison
committed
drupal_add_css(drupal_get_path('module', 'comment_notify') .'/comment_notify.css');
drupal_add_js(drupal_get_path('module', 'comment_notify') .'/comment_notify.js');
Greg Knaddison
committed
// Add the checkbox for anonymous users and set the default based on admin settings.
Greg Knaddison
committed
if ($user->uid == 0) {
Greg Knaddison
committed
// If anonymous user's can't enter their e-mail don't tempt them with the checkbox.
Greg Knaddison
committed
if (empty($form['mail'])) {
return;
}
Greg Knaddison
committed
$preference = variable_get('comment_notify_default_anon_mailalert', COMMENT_NOTIFY_DISABLED);
Greg Knaddison
committed
}
Greg Knaddison
committed
else {
$user_preference = db_result(db_query("SELECT comment_notify FROM {comment_notify_user_settings} WHERE uid = %d", $user->uid));
$preference = strlen($user_preference) ? $user_preference : variable_get('comment_notify_default_registered_mailalert', COMMENT_NOTIFY_DISABLED);
Greg Knaddison
committed
}
Greg Knaddison
committed
// If you want to hide this on your site see http://drupal.org/node/322482
$form['notify_settings'] = array(
'#prefix' => '<div class="clear-block">',
'#suffix' => '</div>',
);
$form['notify_settings']['notify'] = array(
Greg Knaddison
committed
'#type' => 'checkbox',
'#title' => t('Notify me when new comments are posted'),
'#default_value' => $preference,
);
if (count($available_options) > 1) {
$form['notify_settings']['notify_type'] = array(
'#type' => 'radios',
'#options' => $available_options,
Greg Knaddison
committed
'#default_value' => $preference,
);
}
else {
$form['notify_settings']['notify_type'] = array(
'#type' => 'hidden',
Greg Knaddison
committed
'#default_value' => key($available_options),
);
}
$form['notify_settings']['notify_type']['#default_value'] = $preference;
Greg Knaddison
committed
Greg Knaddison
committed
// If this is an existing comment we set the default value based on their selection last time.
Greg Knaddison
committed
if ($form['cid']['#value'] != '') {
Greg Knaddison
committed
$notify = db_result(db_query("SELECT notify FROM {comment_notify} WHERE cid = %d", $form['cid']['#value']));
$form['notify_settings']['notify']['#default_value'] = $notify;
if (count($available_options) > 1) {
$form['notify_settings']['notify_type']['#default_value'] = $notify;
}
else {
$form['notify_settings']['notify_type']['#default_value'] = key($available_options);
}
Greg Knaddison
committed
}
}
Greg Knaddison
committed
/**
Greg Knaddison
committed
* Implementation of hook_perm().
Greg Knaddison
committed
*/
function comment_notify_perm() {
return array('administer comment notify', 'subscribe to comments');
Greg Knaddison
committed
}
/**
* Implementation of hook_menu().
*/
Greg Knaddison
committed
function comment_notify_menu() {
$items['admin/settings/comment_notify'] = array(
Greg Knaddison
committed
'description' => 'Configure settings for e-mails about new comments.',
'page callback' => 'drupal_get_form',
'page arguments' => array('comment_notify_settings'),
'access arguments' => array('administer comment notify'),
Greg Knaddison
committed
'type' => MENU_NORMAL_ITEM,
Greg Knaddison
committed
);
Greg Knaddison
committed
$items['admin/settings/comment_notify/settings'] = array(
Greg Knaddison
committed
'title' => 'Settings',
'description' => 'Configure settings for e-mails about new comments.',
'page callback' => 'drupal_get_form',
'page arguments' => array('comment_notify_settings'),
'access arguments' => array('administer comment notify'),
Greg Knaddison
committed
'type' => MENU_DEFAULT_LOCAL_TASK,
);
Greg Knaddison
committed
Greg Knaddison
committed
$items['admin/settings/comment_notify/unsubscribe'] = array(
'title' => 'Unsubscribe',
'description' => 'Unsubscribe an email from all notifications.',
'weight' => 2,
'page callback' => 'drupal_get_form',
'page arguments' => array('comment_notify_unsubscribe'),
'access arguments' => array('administer comment notify'),
Greg Knaddison
committed
'type' => MENU_LOCAL_TASK,
);
$items['comment_notify/disable/%'] = array(
'title' => 'Disable comment notification',
'page callback' => 'comment_notify_disable_page',
'page arguments' => array(2),
Greg Knaddison
committed
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
return $items;
}
Greg Knaddison
committed
/**
* Page callback to allow users to unsubscribe simply by visiting the page.
*/
function comment_notify_disable_page($hash) {
db_query("UPDATE {comment_notify} SET notify = 0 WHERE notify_hash = '%s'", $hash);
drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.'));
return ' ';
Greg Knaddison
committed
/**
Greg Knaddison
committed
* Implementation of hook_comment().
*/
function comment_notify_comment($comment, $op) {
global $user;
Greg Knaddison
committed
// In theory, the update or insert operations are duplicates with publish which
// would lead to duplicate messages. _comment_notify_mailalert() protects against that.
Greg Knaddison
committed
switch ($op) {
Greg Knaddison
committed
case 'validate':
Greg Knaddison
committed
// 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.
Greg Knaddison
committed
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;
Greg Knaddison
committed
case 'publish':
// And send notifications - the real purpose of the module.
_comment_notify_mailalert($comment);
break;
Greg Knaddison
committed
case 'update':
Greg Knaddison
committed
// In case they have changed their status, save it in the database.
Greg Knaddison
committed
$sql = 'UPDATE {comment_notify} SET notify = %d WHERE cid = %d';
Greg Knaddison
committed
if ($comment['notify']) {
db_query($sql, $comment['notify_type'], $comment['cid']);
}
else {
db_query($sql, 0, $comment['cid']);
}
// And send notifications - the real purpose of the module.
if ($comment['status'] == COMMENT_PUBLISHED) {
_comment_notify_mailalert($comment);
}
Greg Knaddison
committed
case 'insert':
// For new comments, we first build up a string to be used as the identifier for the alert
Greg Knaddison
committed
$mail = empty($comment['mail']) ? $user->mail : $comment['mail'];
$notify_hash = drupal_get_token($mail . $comment['cid']);
Greg Knaddison
committed
if ($comment['notify']) {
$notify = $comment['notify_type'];
$current = db_result(db_query("SELECT count(1) from {comment_notify_user_settings} WHERE uid = %d", $user->uid));
Greg Knaddison
committed
if ($current == 0 && $user->uid) {
Greg Knaddison
committed
db_query("INSERT INTO {comment_notify_user_settings} (uid, comment_notify) VALUES (%d, %d)", $user->uid, $comment['notify_type']);
}
}
else {
$notify = $comment['notify'];
}
Greg Knaddison
committed
// And then save the data.
Greg Knaddison
committed
db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) values (%d, %d, '%s')", $comment['cid'], $notify, $notify_hash);
// And send notifications - the real purpose of the module.
if ($comment['status'] == COMMENT_PUBLISHED) {
_comment_notify_mailalert($comment);
}
Greg Knaddison
committed
break;
Greg Knaddison
committed
case 'delete':
db_query("DELETE FROM {comment_notify} WHERE cid = %d", $comment->cid);
break;
}
}
/**
* Implementation of hook_user().
*/
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(
Greg Knaddison
committed
'#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.')
);
Greg Knaddison
committed
$available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
$available_options += _comment_notify_options();
$form['comment_notify_settings']['comment_notify_mailalert'] = array(
Greg Knaddison
committed
'#type' => 'select',
Greg Knaddison
committed
'#title' => t('Receive comment follow-up notification e-mails'),
Greg Knaddison
committed
'#default_value' => isset($edit['comment_notify_mailalert']) ? $edit['comment_notify_mailalert'] : variable_get('comment_notify_default_registered_mailalert', COMMENT_NOTIFY_DISABLED),
Greg Knaddison
committed
'#options' => $available_options,
Greg Knaddison
committed
'#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.")
Greg Knaddison
committed
);
return $form;
}
Greg Knaddison
committed
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));
Greg Knaddison
committed
if (!empty($user_settings)) {
foreach ($user_settings as $property => $value) {
$user->$property = $value;
}
Greg Knaddison
committed
}
break;
case 'delete':
db_query('DELETE FROM {comment_notify_user_settings} WHERE uid = %d', $user->uid);
break;
Greg Knaddison
committed
break;
}
}
Greg Knaddison
committed
/**
* Private function to send the notifications.
Greg Knaddison
committed
* @param $comment
* The comment array as found in hook_comment $op = publish.
*/
Greg Knaddison
committed
function _comment_notify_mailalert($comment) {
$comment = (object) $comment;
Greg Knaddison
committed
global $language;
global $base_url;
global $user;
Greg Knaddison
committed
$nid = $comment->nid;
$cid = $comment->cid;
// Check to see if a notification has already been sent for this
// comment so that edits to a comment don't trigger an additional
// notification.
if (db_result(db_query('SELECT cid from {comment_notify} WHERE cid = %d AND notified = %d', $cid, 1))) {
return;
}
Greg Knaddison
committed
$initial_language = $language;
Greg Knaddison
committed
if (function_exists('locale')) {
Greg Knaddison
committed
$languages = locale_language_list();
$languages = $languages['name'];
}
Greg Knaddison
committed
$node = node_load($nid);
if (!isset($comment->mail)) {
Greg Knaddison
committed
$comment_account = user_load(array('name' => $comment->name));
Greg Knaddison
committed
$comment_mail = $comment_account->mail;
}
else {
$comment_mail = $comment->mail;
}
$sent_to = array();
// Send to a subscribed author if they are not the current commenter
$author = user_load(array('uid' => $node->uid));
Greg Knaddison
committed
if (!empty($author->node_notify_mailalert) && $author->node_notify_mailalert == 1 && $user->uid != $author->uid) {
// Get the author's language.
$language = user_preferred_language($author);
$message['subject'] = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal')));
$message['body'] = t(
variable_get('node_notify_default_mailtext', AUTHOR_MAILTEXT),
array(
Greg Knaddison
committed
'!commname' => $comment->name,
'!commtext' => $comment->comment,
'!commsubj' => $comment->subject,
Greg Knaddison
committed
'!comment_url' => url('node/'. $nid, array('absolute' => TRUE, 'fragment' => 'comment-'. $cid)),
'!node_title' => $node->title,
'!node_teaser' => $node->teaser,
'!mission' => variable_get('site_mission', ''),
'!node_body' => $node->body,
'!name' => $author->name,
'!site' => variable_get('site_name', 'drupal'),
'!uri' => $base_url,
'!uri_brief' => preg_replace('!^https?://!', '', $base_url),
'!date' => format_date(time()),
'!login_uri' => url('user', array('absolute' => TRUE)),
Greg Knaddison
committed
'!edit_uri' => url('user/'. $author->uid .'/edit', array('absolute' => TRUE))
)
);
drupal_mail('comment_notify', 'comment_notify_mail', $author->mail, $language, $message);
$sent_to[] = $author->mail;
}
Greg Knaddison
committed
Greg Knaddison
committed
// For "reply to my comments" notifications, figure out what thread this is.
$thread = db_result(db_query("SELECT thread FROM {comments} WHERE cid = %d", $cid));
//Get the list of commenters to notify
Greg Knaddison
committed
$result = db_query("SELECT DISTINCT c.cid, c.uid, c.name, c.nid, c.mail AS cmail, u.mail AS umail, u.init AS uinit, c.uid, c.name, cn.notify, cn.notify_hash, c.thread
Greg Knaddison
committed
FROM {comments} c INNER JOIN {comment_notify} cn on c.cid = cn.cid LEFT OUTER JOIN {users} u ON c.uid = u.uid
Greg Knaddison
committed
WHERE nid = %d AND cn.notify > 0 AND c.status = 0 AND (u.status = 1 OR u.uid = 0)", $nid
Greg Knaddison
committed
);
Greg Knaddison
committed
// TODO? the original big query had stuff making sure the mail was populated and contained .+@.+ Perhaps check for that here and set notify = 0 if that is the case for this cid
Greg Knaddison
committed
while ($alert = db_fetch_object($result)) {
Greg Knaddison
committed
$umail = empty($alert->umail) ? $alert->uinit : $alert->umail;
$mail = empty($alert->cmail) ? $umail : $alert->cmail;
Greg Knaddison
committed
$relevant_thread = substr($thread, 0, drupal_strlen($alert->thread) -1);
if ($alert->notify == COMMENT_NOTIFY_COMMENT && strcmp($relevant_thread . '/', $alert->thread) != 0) {
Greg Knaddison
committed
continue;
Greg Knaddison
committed
}
Greg Knaddison
committed
if ($mail != $comment_mail && !in_array($mail, $sent_to) && $alert->uid != $comment->uid) {
Greg Knaddison
committed
$message = array();
if (!empty($alert->uid)) {
$recipient_user = user_load(array('uid' => $alert->uid));
Greg Knaddison
committed
$language = user_preferred_language($recipient_user);
}
else {
$language = language_default();
Greg Knaddison
committed
}
Greg Knaddison
committed
$message['subject'] = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal')));
Greg Knaddison
committed
$message['body'] = t(
Greg Knaddison
committed
variable_get('comment_notify_default_mailtext', DEFAULT_MAILTEXT),
array(
Greg Knaddison
committed
'!commname' => $comment->name,
'!commtext' => $comment->comment,
'!commsubj' => $comment->subject,
Greg Knaddison
committed
'!comment_url' => url('node/'. $nid, array('absolute' => TRUE, 'fragment' => 'comment-'. $cid)),
Greg Knaddison
committed
'!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' => preg_replace('!^https?://!', '', $base_url),
Greg Knaddison
committed
'!date' => format_date(time()),
Greg Knaddison
committed
'!login_uri' => url('user', array('absolute' => TRUE)),
'!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)),
'!link1' => url('comment_notify/disable/'. $alert->notify_hash, array('absolute' => TRUE))
Greg Knaddison
committed
)
Greg Knaddison
committed
);
Greg Knaddison
committed
drupal_mail('comment_notify', 'comment_notify_mail', $mail, $language, $message);
Greg Knaddison
committed
$sent_to[] = $mail;
// Make the mail link to user's /edit, unless it's an anonymous user.
Greg Knaddison
committed
if ($alert->uid != 0) {
$user_mail = l($mail, 'user/'. $alert->uid .'/edit');
Greg Knaddison
committed
}
else {
$user_mail = check_plain($mail);
Greg Knaddison
committed
}
// Add an entry to the watchdog log.
watchdog(
'comment_notify',
'Notified: !user_mail',
array('!user_mail' => $user_mail),
WATCHDOG_NOTICE,
l(t('source comment'), 'node/'. $nid, array(
'fragment' => 'comment-'. $alert->cid,
))
);
Greg Knaddison
committed
// revert to previous (site default) locale
Greg Knaddison
committed
$language = $initial_language;
Greg Knaddison
committed
// Record that a notification was sent for this comment so that
// notifications aren't sent again if the comment is later edited.
db_query('UPDATE {comment_notify} SET notified = 1 WHERE cid = %d', $cid);
/**
* Implementation of hook_mail().
*/
Greg Knaddison
committed
function comment_notify_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
Greg Knaddison
committed
$message['body'][] = $params['body'];
Greg Knaddison
committed
}
Greg Knaddison
committed
/**
Greg Knaddison
committed
* Callback for an administrative form to unsubscribe users by e-mail address.
Greg Knaddison
committed
*/
function comment_notify_unsubscribe() {
$form['comment_notify_unsubscribe'] = array();
$form['comment_notify_unsubscribe']['email_to_unsubscribe'] = array(
'#type' => 'textfield',
'#title' => t('Email to unsubscribe'),
);
$form['comment_notify_unsubscribe']['submit'] = array(
'#type' => 'submit',
'#value' => t('Unsubscribe this e-mail'),
);
return $form;
}
Greg Knaddison
committed
/**
Greg Knaddison
committed
* Based on admin submit, do the actual unsubscribe from notifications.
Greg Knaddison
committed
*/
Greg Knaddison
committed
function comment_notify_unsubscribe_submit($form, &$form_state) {
$email = trim($form_state['values']['email_to_unsubscribe']);
Greg Knaddison
committed
// If they have a uid, use that, otherwise update comments directly
Greg Knaddison
committed
$result = db_result(db_query_range("SELECT uid FROM {users} WHERE mail = '%s'", $email, 0, 1));
Greg Knaddison
committed
if ($result > 0) {
Greg Knaddison
committed
$comments = db_result(db_query("SELECT COUNT(1) FROM {comments} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid WHERE c.uid = %d AND cn.notify > 0", $result));
Greg Knaddison
committed
db_query("UPDATE {comment_notify} SET notify = 0 WHERE cid IN (SELECT cid FROM {comments} WHERE uid = %d)", $result);
Greg Knaddison
committed
}
else {
Greg Knaddison
committed
$comments = db_result(db_query("SELECT COUNT(1) FROM {comments} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid WHERE c.mail = '%s' AND cn.notify > 0", $email));
Greg Knaddison
committed
db_query("UPDATE {comment_notify} SET notify = 0 WHERE cid IN (SELECT cid FROM {comments} WHERE mail = '%s')", $email);
Greg Knaddison
committed
}
// Update the admin about the state of this comment notification subscription.
if ($comments == 0) {
drupal_set_message(t("There were no active comment notifications for that email."));
}
else {
drupal_set_message(format_plural($comments, "Email unsubscribed from 1 comment notification.",
"Email unsubscribed from @count comment notifications."));
}
}
Greg Knaddison
committed
/*
* Page callback for administrative settings form.
*/
Greg Knaddison
committed
function comment_notify_settings() {
$form['comment_notify_settings'] = array();
// Only perform comment_notify for certain node types (default, all)
Greg Knaddison
committed
$enabled_types = variable_get('comment_notify_node_types', FALSE);
Greg Knaddison
committed
$anonymous_problems = '';
foreach (node_get_types('names') as $type => $name) {
$checkboxes[$type] = check_plain($name);
$default[] = $type;
Greg Knaddison
committed
// If they don't have the ability to leave contact info, then we make a report
if (isset($enabled_types[$type]) && $enabled_types[$type] && variable_get('comment_anonymous_'. $type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
Greg Knaddison
committed
$account = user_load(array('uid' => 0));
if (user_access('subscribe to comments', $account)) {
Greg Knaddison
committed
$anonymous_problems[] = l(t('@content-type', array('@content-type' => $name)), 'admin/content/node-type/'. $type);
}
}
}
Greg Knaddison
committed
if (!empty($anonymous_problems)) {
drupal_set_message(t('Anonymous commenters have the permission to subscribe to comments but cannot leave their contact infromation on the following content types: !types. You should either disable subscriptions on those types here, revoke the permission for anonymous users, or enable anonymous users to leave their contact information in the comment settings.', array('!types' => implode(', ', $anonymous_problems))));
}
$form['comment_notify_settings']['comment_notify_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content types to enable for comment notification'),
'#default_value' => variable_get('comment_notify_node_types', $default),
'#options' => $checkboxes,
'#description' => t('Comments on content types enabled here will have the option of comment notification.'),
);
Greg Knaddison
committed
$form['comment_notify_settings']['comment_notify_available_alerts'] = array(
'#type' => 'checkboxes',
'#title' => t('Available subscription modes'),
Greg Knaddison
committed
'#return_value' => 1,
Greg Knaddison
committed
'#default_value' => variable_get('comment_notify_available_alerts', array(COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT)),
'#description' => t('Choose which notification subscription styles are available for users'),
Greg Knaddison
committed
'#options' => array(
Greg Knaddison
committed
COMMENT_NOTIFY_NODE => t('All comments'),
COMMENT_NOTIFY_COMMENT => t('Replies to my comment')
Greg Knaddison
committed
)
);
Greg Knaddison
committed
$available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
$available_options += _comment_notify_options();
Greg Knaddison
committed
$form['comment_notify_settings']['comment_notify_default_anon_mailalert'] = array(
Greg Knaddison
committed
'#type' => 'select',
'#title' => t('Default state for the notification selection box for anonymous users'),
Greg Knaddison
committed
'#return_value' => 1,
Greg Knaddison
committed
'#default_value' => variable_get('comment_notify_default_anon_mailalert', COMMENT_NOTIFY_NODE),
'#options' => $available_options,
);
$form['comment_notify_settings']['comment_notify_default_registered_mailalert'] = array(
'#type' => 'select',
'#title' => t('Default state for the notification selection box for registered users'),
Greg Knaddison
committed
'#return_value' => 1,
'#default_value' => variable_get('comment_notify_default_registered_mailalert', COMMENT_NOTIFY_NODE),
'#description' => t('This flag presets the flag for the follow-up notification on the form that anon users will see when posting a comment'),
'#options' => $available_options,
Greg Knaddison
committed
);
Greg Knaddison
committed
Greg Knaddison
committed
$form['comment_notify_settings']['comment_notify_default_mailtext'] = array(
'#type' => 'textarea',
'#title' => t('Default mail text for sending out notifications to commenters'),
Greg Knaddison
committed
'#description' => t(
'You can use the following variables to be replaced:
Greg Knaddison
committed
<li>!commname = the username who posted the comment
<li>!commtext = the text of the posted comment
<li>!commsubj = the subject of the posted comment
<li>!comment_url = the full url of the post and comment - note: if you have paging enabled, this does not work correct - set your max comments per page so that all fit on one page or reverse order them
<li>!node_title = the title of the node that was commented on
<li>!node_teaser = the teaser of the node that was commented on
<li>!node_body = the body of the node that was commented on
<li>!mission = site_mission text
<li>!name = username receiving the alert
<li>!site = your site
<li>!uri = base_url of site
<li>!uri_brief = base_url of site w/o http
<li>!date = the current time
<li>!login_uri uri to login the user
<li>!edit_uri = uri to edit user profile
<li>!link1 the QUICKLINK to disable future follow-up notifications for the user
Greg Knaddison
committed
</ul>'
),
'#default_value' => variable_get('comment_notify_default_mailtext', t(DEFAULT_MAILTEXT)),
'#return_value' => 1,
'#cols' => 80,
'#rows' => 15
);
$form['comment_notify_settings']['node_notify_default_mailtext'] = array(
'#type' => 'textarea',
'#title' => t('Default mail text for sending out the notifications to node authors'),
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
'#description' => t(
'You can use the following variables to be replaced:
<ul>
<li>!commname = the username who posted the comment
<li>!commtext = the text of the posted comment
<li>!commsubj = the subject of the posted comment
<li>!comment_url = the full url of the post and comment - note: if you have paging enabled, this does not work correct - set your max comments per page so that all fit on one page or reverse order them
<li>!node_title = the title of the node that was commented on
<li>!node_teaser = the teaser of the node that was commented on
<li>!node_body = the body of the node that was commented on
<li>!mission = site_mission text
<li>!name = username receiving the alert
<li>!site = your site
<li>!uri = base_url of site
<li>!uri_brief = base_url of site w/o http
<li>!date = the current time
<li>!login_uri uri to login the user
<li>!edit_uri = uri to edit user profile
</ul>'
),
'#default_value' => variable_get('node_notify_default_mailtext', t(AUTHOR_MAILTEXT)),
'#return_value' => 1,
'#cols' => 80,
'#rows' => 15
);
Greg Knaddison
committed
$form['#validate'] = array('comment_notify_settings_validate');
Greg Knaddison
committed
return system_settings_form($form);
Greg Knaddison
committed
}
Greg Knaddison
committed
function comment_notify_settings_validate($form, &$form_state) {
$sum_enabled = 0;
foreach ($form_state['values']['comment_notify_available_alerts'] as $enabled) {
$sum_enabled += $enabled;
}
if (!$sum_enabled) {
form_set_error('comment_notify_available_alerts', 'You must enable at least one subscription mode.');
}
}