Skip to content
Snippets Groups Projects
Commit cdaae268 authored by Greg Knaddison's avatar Greg Knaddison
Browse files

task #487820 by merlinofchaos: Cleanup of comment_notify code

parent a3de58fd
No related branches found
No related tags found
No related merge requests found
...@@ -53,16 +53,25 @@ define('COMMENT_NOTIFY_NODE', 1); ...@@ -53,16 +53,25 @@ define('COMMENT_NOTIFY_NODE', 1);
define('COMMENT_NOTIFY_COMMENT', 2); define('COMMENT_NOTIFY_COMMENT', 2);
/** /**
* Implementation of hook_help(). * Provide an array of available options for notification on a comment.
*/ */
function comment_notify_help($path, $arg) { function _comment_notify_options() {
switch ($path) { $total_options = array(
case 'admin/modules#description': COMMENT_NOTIFY_NODE => t('All comments'),
return t('Comment follow-up e-mail notification for anonymous and registered users.'); COMMENT_NOTIFY_COMMENT => t('Replies to my comment')
break; );
$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;
}
/** /**
* Insert our checkbox, add a submit button, and populate fields. * Insert our checkbox, add a submit button, and populate fields.
*/ */
...@@ -81,20 +90,11 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) { ...@@ -81,20 +90,11 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) {
return; return;
} }
$available_options = _comment_notify_options();
drupal_add_css(drupal_get_path('module', 'comment_notify') .'/comment_notify.css'); drupal_add_css(drupal_get_path('module', 'comment_notify') .'/comment_notify.css');
drupal_add_js(drupal_get_path('module', 'comment_notify') .'/comment_notify.js'); drupal_add_js(drupal_get_path('module', 'comment_notify') .'/comment_notify.js');
$total_options = array(
COMMENT_NOTIFY_NODE => t('All comments'),
COMMENT_NOTIFY_COMMENT => t('Replies to my comment')
);
$options = variable_get('comment_notify_available_alerts', array(COMMENT_NOTIFY_NODE => COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT => COMMENT_NOTIFY_COMMENT));
foreach ($options as $key => $available) {
if ($key == $available) {
$available_options[$available] = $total_options[$available];
}
}
// Add the checkbox for anonymous users and set the default based on admin settings. // Add the checkbox for anonymous users and set the default based on admin settings.
if ($user->uid == 0) { if ($user->uid == 0) {
// If anonymous user's can't enter their e-mail don't tempt them with the checkbox. // If anonymous user's can't enter their e-mail don't tempt them with the checkbox.
...@@ -109,39 +109,43 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) { ...@@ -109,39 +109,43 @@ function comment_notify_form_alter(&$form, &$form_state, $form_id) {
} }
// If you want to hide this on your site see http://drupal.org/node/322482 // If you want to hide this on your site see http://drupal.org/node/322482
$form['notify_open'] = array('#value' => '<div id="comment-notify">'); $form['notify_settings'] = array(
$form['notify'] = array( '#prefix' => '<div class="clear-block">',
'#suffix' => '</div>',
);
$form['notify_settings']['notify'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Notify me when new comments are posted'), '#title' => t('Notify me when new comments are posted'),
'#default_value' => $preference, '#default_value' => $preference,
); );
if (count($available_options) > 1) { if (count($available_options) > 1) {
$form['notify_type'] = array( $form['notify_settings']['notify_type'] = array(
'#type' => 'radios', '#type' => 'radios',
'#options' => $available_options, '#options' => $available_options,
'#default_value' => $preference, '#default_value' => $preference,
); );
} }
else { else {
$form['notify_type'] = array( $form['notify_settings']['notify_type'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#default_value' => key($available_options), '#default_value' => key($available_options),
); );
} }
$form['notify_settings']['notify_type']['#default_value'] = $preference;
// If this is an existing comment we set the default value based on their selection last time. // If this is an existing comment we set the default value based on their selection last time.
if ($form['cid']['#value'] != '') { if ($form['cid']['#value'] != '') {
$notify = db_result(db_query("SELECT notify FROM {comment_notify} WHERE cid = %d", $form['cid']['#value'])); $notify = db_result(db_query("SELECT notify FROM {comment_notify} WHERE cid = %d", $form['cid']['#value']));
$form['notify']['#default_value'] = $notify; $form['notify_settings']['notify']['#default_value'] = $notify;
if (count($available_options) > 1) { if (count($available_options) > 1) {
$form['notify_type']['#default_value'] = $notify; $form['notify_settings']['notify_type']['#default_value'] = $notify;
} }
else { else {
$form['notify_type']['#default_value'] = key($available_options); $form['notify_settings']['notify_type']['#default_value'] = key($available_options);
} }
} }
$form['notify_close'] = array('#value' => '</div>', '#weight' => 9);
} }
/** /**
...@@ -182,9 +186,10 @@ function comment_notify_menu() { ...@@ -182,9 +186,10 @@ function comment_notify_menu() {
'access arguments' => array('administer comment notify'), 'access arguments' => array('administer comment notify'),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
); );
$items['comment_notify'] = array( $items['comment_notify/disable/%'] = array(
'title' => 'comment notify', 'title' => 'Disable comment notification',
'page callback' => 'comment_notify_page', 'page callback' => 'comment_notify_disable_page',
'page arguments' => array(2),
'access arguments' => array('access content'), 'access arguments' => array('access content'),
'type' => MENU_CALLBACK 'type' => MENU_CALLBACK
); );
...@@ -195,33 +200,11 @@ function comment_notify_menu() { ...@@ -195,33 +200,11 @@ function comment_notify_menu() {
/** /**
* Page callback to allow users to unsubscribe simply by visiting the page. * Page callback to allow users to unsubscribe simply by visiting the page.
*/ */
function comment_notify_page() { function comment_notify_disable_page($hash) {
global $user; db_query("UPDATE {comment_notify} SET notify = 0 WHERE notify_hash = '%s'", $hash);
$op = $_POST['op'];
$edit = $_POST['edit'];
$page_content = ' ';
if (empty($op)) {
$op = arg(1);
}
$arg = arg(2);
switch ($op) {
case 'disable':
$key = $arg;
db_query("UPDATE {comment_notify} SET notify = 0 WHERE notify_hash = '%s'", $arg);
drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.')); drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.'));
$title = t('Disabled comment follow-up notification feature for this post.'); return ' ';
break;
default;
$title = t('Comment notify');
break;
}
drupal_set_title($title);
return $page_content;
} }
/** /**
...@@ -506,12 +489,14 @@ function _comment_notify_mailalert($comment) { ...@@ -506,12 +489,14 @@ function _comment_notify_mailalert($comment) {
db_query('UPDATE {comment_notify} SET notified = 1 WHERE cid = %d', $cid); db_query('UPDATE {comment_notify} SET notified = 1 WHERE cid = %d', $cid);
} }
/**
* Implementation of hook_mail().
*/
function comment_notify_mail($key, &$message, $params) { function comment_notify_mail($key, &$message, $params) {
$message['subject'] = $params['subject']; $message['subject'] = $params['subject'];
$message['body'][] = $params['body']; $message['body'][] = $params['body'];
} }
/** /**
* Callback for an administrative form to unsubscribe users by e-mail address. * Callback for an administrative form to unsubscribe users by e-mail address.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment