comment_notify.module 23.9 KB
Newer Older
1 2 3 4 5
<?php
// $Id$

/**
 * @file
6 7
 *
 * This module provides comment follow-up e-mail notification for anonymous and registered users.
8 9
 */

10 11 12 13 14
define('COMMENT_NOTIFY_DISABLED', 0);
define('COMMENT_NOTIFY_NODE', 1);
define('COMMENT_NOTIFY_COMMENT', 2);


15
define('AUTHOR_MAILTEXT',
16
'Hi [comment:node:author],
17

18
You have received a comment on: "[node:title]"
19

20 21 22 23 24
----
[comment:title]
[comment:body]
----

25
You can view the comment at the following url
26
[comment:url]
27

28 29
You will receive emails like this for all replies to your posts. You can
disable this by logging in and changing the settings on your user account at
30
[comment:node:author:edit-url].
31

32
-- [site:name] team
33
[site:url]');
34

35
define('DEFAULT_MAILTEXT',
36
'Hi [user:name],
37

38
[comment:name] has commented on: "[node:title]"
39 40

----
41 42
[comment:title]
[comment:body]
43 44 45
----

You can view the comment at the following url
46
[comment:url]
47

48
You can stop receiving emails when someone replies to this post,
49
by going to [comment:unsubscribe-url]
50

51
You can set up auto-following feature for all future posts
52
by creating your own user with a few clicks here [site:login-url]
53

54
-- [site:name] team
55 56
[site:url]');

57

58

59
/**
60
 * Provide an array of available options for notification on a comment.
61
 */
62 63 64 65 66 67 68
function _comment_notify_options() {
  $total_options = array(
    COMMENT_NOTIFY_NODE     => t('All comments'),
    COMMENT_NOTIFY_COMMENT  => t('Replies to my comment')
  );

  $available_options = array();
69
  $options = variable_get('comment_notify_available_alerts', drupal_map_assoc(array(COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT)));
70 71 72 73
  foreach ($options as $key => $available) {
    if ($key == $available) {
      $available_options[$available] = $total_options[$available];
    }
74
  }
75 76

  return $available_options;
77 78
}

79 80

function comment_notify_form_comment_form_alter(&$form, &$form_state, $form_id) {
81

82
  global $user;
83 84 85
  if (!(user_access('subscribe to comments') || user_access('administer comments'))) {
    return;
  }
86

87 88 89 90 91 92
  // Only add the checkbox if this is an enabled content type
  $node = node_load($form['nid']['#value'] ? $form['nid']['#value'] : $form['nid']['#default_value']);
  $enabled_types = variable_get('comment_notify_node_types', drupal_map_assoc(array($node->type)));
  if (empty($enabled_types[$node->type])) {
    return;
  }
93

94
  $available_options = _comment_notify_options();
95

96 97
  drupal_add_css(drupal_get_path('module', 'comment_notify') . '/comment_notify.css');
  drupal_add_js(drupal_get_path('module', 'comment_notify') . '/comment_notify.js');
98

99
  // Add the checkbox for anonymous users.
100 101
  if ($user->uid == 0) {
    // If anonymous user's can't enter their e-mail don't tempt them with the checkbox.
102
    if (empty($form['author']['mail'])) {
103
      return;
104
    }
105
    $form['#validate'][] = 'comment_notify_comment_validate';
106
  }
107 108
  module_load_include('inc', 'comment_notify', 'comment_notify');
  $preference = comment_notify_get_user_comment_notify_preference($user->uid);
109

110 111
  // If you want to hide this on your site see http://drupal.org/node/322482
  $form['notify_settings'] = array(
112 113
      '#prefix' => '<div class="clear-block">',
      '#suffix' => '</div>',
114
      '#weight' => 0,
115
  );
116

117
  $form['notify_settings']['notify'] = array(
118 119
      '#type' => 'checkbox',
      '#title' => t('Notify me when new comments are posted'),
120
      '#default_value' => (bool) $preference,
121
  );
122

123 124
  if (count($available_options) > 1) {
    $form['notify_settings']['notify_type'] = array(
125 126 127
        '#type' => 'radios',
        '#options' => $available_options,
        '#default_value' => $preference,
128 129 130 131
    );
  }
  else {
    $form['notify_settings']['notify_type'] = array(
132 133
        '#type' => 'hidden',
        '#value' => key($available_options),
134 135 136 137 138 139
    );
  }
  $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 ($form['cid']['#value'] != '') {
140
    module_load_include('inc', 'comment_notify', 'comment_notify');
141 142 143 144
    $notify = comment_notify_get_notification_type($form['cid']['#value']);
    $form['notify_settings']['notify']['#default_value'] = $notify;
    if (count($available_options) > 1) {
      $form['notify_settings']['notify_type']['#default_value'] = $notify;
145
    }
146 147
    else {
      $form['notify_settings']['notify_type']['#default_value'] = key($available_options);
148
    }
149 150
  }
}
151

152
/**
153
 * Implements hook_permission().
154
 */
155 156 157 158 159 160 161 162 163 164 165
function comment_notify_permission() {
  return array(
    'administer comment notify' => array(
      'title' => 'Administer Comment Notify',
      'description' => 'Change global comment notification settings.',
  ),
    'subscribe to comments' => array(
      'title' => 'Subscribe to comment notifications',
      'description' => 'Subscribe to recieve notifications when new comments are posted.',
  ),
  );
166
}
167 168

/**
169
 * Implements hook_menu().
170
 */
171 172
function comment_notify_menu() {

173
  $items['admin/config/people/comment_notify'] = array(
174
    'title' => 'Comment notify',
175 176 177
    'description' => 'Configure settings for e-mails about new comments.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('comment_notify_settings'),
178
    'access arguments' => array('administer comment notify'),
179
    'type' => MENU_NORMAL_ITEM,
180
  );
181
  $items['admin/config/people/comment_notify/settings'] = array(
182 183 184 185
    'title' => 'Settings',
    'description' => 'Configure settings for e-mails about new comments.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('comment_notify_settings'),
186
    'access arguments' => array('administer comment notify'),
187 188
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
189

190
  $items['admin/config/people/comment_notify/unsubscribe'] = array(
191 192 193 194 195
    'title' => 'Unsubscribe',
    'description' => 'Unsubscribe an email from all notifications.',
    'weight' => 2,
    'page callback' => 'drupal_get_form',
    'page arguments' => array('comment_notify_unsubscribe'),
196
    'access arguments' => array('administer comment notify'),
197 198
    'type' => MENU_LOCAL_TASK,
  );
199 200 201 202
  $items['comment_notify/disable/%'] = array(
    'title' => 'Disable comment notification',
    'page callback' => 'comment_notify_disable_page',
    'page arguments' => array(2),
203 204 205
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );
206 207 208 209

  return $items;
}

210 211 212
/**
 * Page callback to allow users to unsubscribe simply by visiting the page.
 */
213
function comment_notify_disable_page($hash) {
214
  module_load_include('inc', 'comment_notify', 'comment_notify');
215 216
  if (comment_notify_unsubscribe_by_hash($hash)) {
    drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.'));
217 218
  }
  else {
219 220
    drupal_set_message(t('Sorry, there was a problem unsubscribing from notifications.'));
  }
221
  return ' ';
222 223
}

224 225

function comment_notify_comment_validate($comment) {
226
  global $user;
227 228
  // 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.
229
  if (!$user->uid && $comment['notify_settings']['notify']['#value'] && empty($comment['author']['mail']['#value'])) {
230 231 232
    form_set_error('mail', t('If you want to subscribe to comments you must supply a valid e-mail address.'));
  }
}
233

234 235 236 237
function comment_notify_comment_publish($comment) {
  // And send notifications - the real purpose of the module.
  _comment_notify_mailalert($comment);
}
238

239 240 241
/**
 * Implements hook_comment_update().
 */
242
function comment_notify_comment_update($comment) {
243
  module_load_include('inc', 'comment_notify', 'comment_notify');
244

245
  // In case they have changed their status, save it in the database.
246 247 248
  if (isset($comment->notify_type)) {
    comment_notify_update_notification($comment->cid, $comment->notify_type);
  }
249 250 251 252 253 254 255 256
  // And send notifications - the real purpose of the module.
  if ($comment->status == COMMENT_PUBLISHED) {
    _comment_notify_mailalert($comment);
  }

}

function comment_notify_comment_insert($comment) {
257
  module_load_include('inc', 'comment_notify', 'comment_notify');
258

259
  global $user;
260 261 262 263
  // 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 from their mail and comment identifier.
264 265 266
  $mail = empty($comment->mail) ? $user->mail : $comment->mail;
  $notify_hash = drupal_get_token($mail . $comment->cid);

267
  if (!empty($comment->notify)) {
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
    $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);
284 285 286
  }
}

287
function comment_notify_comment_delete($comment) {
288
  module_load_include('inc', 'comment_notify', 'comment_notify');
289 290 291 292
  comment_notify_remove_all_notifications($comment->cid);
}


293
/**
294
 * Implement hook_form_alter().
295
 */
296
function comment_notify_form_alter(&$form, &$form_state, $form_id) {
297
  module_load_include('inc', 'comment_notify', 'comment_notify');
298

299 300 301
  if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) {
    return;
  }
302
  elseif ($form['#user_category'] != 'account') {
303 304 305 306 307 308 309 310 311 312
    return;
  }

  $user = $form['#user'];
  if ($user->comment_notify_settings) {
    $node_notify = $user->comment_notify_settings->node_notify;
    $comment_notify = $user->comment_notify_settings->comment_notify;
  }

  $form['comment_notify_settings'] = array(
313 314 315 316
    '#type' => 'fieldset',
    '#title' => t('Comment follow-up notification settings'),
    '#weight' => 4,
    '#collapsible' => TRUE
317 318 319 320
  );

  // Only show the node followup UI if the user has permission to create nodes.
  $nodes = FALSE;
321 322
  foreach (node_type_get_names() as $type => $name) {
    if (node_access('create', $type)) {
323 324 325 326 327 328 329
      $nodes = TRUE;
      break;
    }
  }

  if (user_access('administer nodes') || $nodes) {
    $form['comment_notify_settings']['node_notify'] = array(
330 331 332 333
      '#type' => 'checkbox',
      '#title' => t('Receive node follow-up notification e-mails'),
      '#default_value' => isset($node_notify) ? $node_notify : comment_notify_variable_registry_get('node_notify_default_mailalert'),
      '#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.')
334 335 336 337
    );
  }
  else {
    $form['comment_notify_settings']['node_notify'] = array(
338 339
      '#type' => 'hidden',
      '#value' => COMMENT_NOTIFY_DISABLED,
340 341
    );
  }
342

343 344 345
  $available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
  $available_options += _comment_notify_options();
  $form['comment_notify_settings']['comment_notify'] = array(
346 347 348 349 350
    '#type' => 'select',
    '#title' => t('Receive comment follow-up notification e-mails'),
    '#default_value' => isset($comment_notify) ? array($comment_notify) : array(comment_notify_variable_registry_get('comment_notify_default_registered_mailalert')),
    '#options' => $available_options,
    '#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.")
351 352 353 354
  );
  return $form;
  // Construct the user form
}
355

356 357 358 359 360
function comment_notify_user_update(&$edit, $account, $category) {
  if ($category != 'account') {
    return;
  }
  if (isset($edit['node_notify']) && isset($edit['comment_notify'])) {
361
    module_load_include('inc', 'comment_notify', 'comment_notify');
362

363 364 365 366 367 368 369
    // Save the values of node_notify_mailalert and comment_notify_mailalert
    // to {comment_notify_user_settings}.
    comment_notify_set_user_notification_setting($account->uid, $edit['node_notify'], $edit['comment_notify']);
  }
  // Unset them from $user so they don't also get saved into {users}.data.
  unset($edit['node_notify']);
  unset($edit['comment_notify']);
370

371
}
372

373
function comment_notify_user_load($users) {
374
  module_load_include('inc', 'comment_notify', 'comment_notify');
375

376
  // @todo: Why would we want to load this on every user load?
377 378 379
  foreach ($users as &$user) {
    $user->comment_notify_settings = comment_notify_get_user_notification_setting($user->uid);
  }
380

381
  return;
382 383
}

384
function comment_notify_user_cancel(&$edit, $account, $method) {
385
  module_load_include('inc', 'comment_notify', 'comment_notify');
386 387 388
  comment_notify_delete_user_notification_setting($account->uid);
}

389 390
/**
 * Private function to send the notifications.
greggles's avatar
greggles committed
391
 *
392 393 394
 * @param $comment
 *   The comment array as found in hook_comment $op = publish.
 */
395
function _comment_notify_mailalert($comment) {
396
  module_load_include('inc', 'comment_notify', 'comment_notify');
397

398
  $comment = (object) $comment;
399
  global $language;
400
  global $base_url;
401
  global $user;
402

403 404 405 406 407 408
  $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.
409
  if (comment_notify_is_notification_already_sent($cid)) {
410 411 412
    return;
  }

413
  $initial_language = $language;
414

415
  if (function_exists('locale')) {
416
    $languages = locale_language_list();
417 418 419
    $languages = $languages['name'];
  }

420
  $node = node_load($nid);
421 422 423 424 425 426 427

  // No mails if this is not an enabled content type.
  $enabled_types = variable_get('comment_notify_node_types', array($node->type => TRUE));
  if (empty($enabled_types[$node->type])) {
    return;
  }

428
  if (!isset($comment->mail)) {
429
    $comment_account = user_load_by_name($comment->name);
430 431 432 433 434
    $comment_mail = $comment_account->mail;
  }
  else {
    $comment_mail = $comment->mail;
  }
435 436 437
  $sent_to = array();

  // Send to a subscribed author if they are not the current commenter
438
  $author = user_load($node->uid);
439

440
  if (!empty($author->comment_notify_settings->node_notify) && $author->node_notify_mailalert == 1 && $user->uid != $author->uid && node_access('view', $node, $author)) {
441 442
    // Get the author's language.
    $language = user_preferred_language($author);
443
    $raw_values = array(
444 445
      'subject' => comment_notify_variable_registry_get('author_subject'),
      'body'  => comment_notify_variable_registry_get('node_notify_default_mailtext'), //JS @todo:change this.
446
    );
447
    foreach ($raw_values as $k => $v) {
448
      $message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user));
449 450
    }

451
    drupal_mail('comment_notify', 'comment_notify_mail', $author->mail, $language, $message);
452 453
    $sent_to[] = $author->mail;
  }
454

455
  // For "reply to my comments" notifications, figure out what thread this is.
456
  $thread = comment_notify_get_thread($cid);
457

458
  // 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
459 460
  // Get the list of commenters to notify.
  $watchers = comment_notify_get_watchers($nid);
461

462
  foreach ($watchers as $alert) {
463 464 465
    $umail = empty($alert->umail) ? $alert->uinit : $alert->umail;
    $mail = empty($alert->cmail) ? $umail : $alert->cmail;

466
    $relevant_thread = drupal_substr($thread, 0, drupal_strlen($alert->thread) -1);
467
    if ($alert->notify == COMMENT_NOTIFY_COMMENT && strcmp($relevant_thread . '/', $alert->thread) != 0) {
468
      continue;
469
    }
470

471
    if ($mail != $comment_mail && !in_array($mail, $sent_to) && ($alert->uid != $comment->uid || $alert->uid == 0)) {
472

473 474
      $message = array();
      if (!empty($alert->uid)) {
475
        $recipient_user = user_load($alert->uid);
476 477 478 479
        $language = user_preferred_language($recipient_user);
      }
      else {
        $language = language_default();
480 481 482 483 484
        $recipient_user = drupal_anonymous_user();
      }
      // Make sure they have access to this node before showing a bunch of node information.
      if (!node_access('view', $node, $recipient_user)) {
        continue;
485
      }
486

487
      $raw_values = array(
488 489
        'subject' => comment_notify_variable_registry_get('watcher_subject'),
        'body'  => comment_notify_variable_registry_get('comment_notify_default_mailtext'), //JS @todo:change this var name.
490
      );
491 492

      foreach ($raw_values as $k => $v) {
493
        $message[$k] = token_replace(t($v), array('comment' => $comment, 'node' => $node, 'user' => $user));
494 495 496 497 498 499
      }

      //      array(
      //          '!link1' => url('comment_notify/disable/'. $alert->notify_hash, array('absolute' => TRUE))
      //      )

500
      drupal_mail('comment_notify', 'comment_notify_mail', $mail, $language, $message);
501
      $sent_to[] = $mail;
502

503
      // Make the mail link to user's /edit, unless it's an anonymous user.
504
      if ($alert->uid != 0) {
505
        $user_mail = l($mail, 'user/' . $alert->uid . '/edit');
506 507
      }
      else {
508
        $user_mail = check_plain($mail);
509
      }
510

511
      // Add an entry to the watchdog log.
512 513 514
      watchdog(
        'comment_notify',
        'Notified: !user_mail',
515 516
      array('!user_mail' => $user_mail),
      WATCHDOG_NOTICE,
517 518
      l(t('source comment'), 'node/' . $nid, array(
          'fragment' => 'comment-' . $alert->cid,
519
      ))
520
      );
521

522
      // revert to previous (site default) locale
523
      $language = $initial_language;
524 525
    }
  }
526 527
  // Record that a notification was sent for this comment so that
  // notifications aren't sent again if the comment is later edited.
528 529

  comment_notify_mark_comment_as_notified($cid);
530 531
}

532
/**
533
 * Implements hook_mail().
534
 */
535 536
function comment_notify_mail($key, &$message, $params) {
  $message['subject'] = $params['subject'];
537
  $message['body'][] = $params['body'];
538 539
}

540
/**
541
 * Callback for an administrative form to unsubscribe users by e-mail address.
542
 */
543
function comment_notify_unsubscribe($form, &$form_state) {
544 545 546 547 548 549 550 551 552 553 554
  $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;
}
555

556
/**
557
 * Based on admin submit, do the actual unsubscribe from notifications.
558
 */
559
function comment_notify_unsubscribe_submit($form, &$form_state) {
560
  module_load_include('inc', 'comment_notify', 'comment_notify');
561
  $email = trim($form_state['values']['email_to_unsubscribe']);
562
  $comments = comment_notify_unsubscribe_by_email($email);
563 564 565 566 567 568 569 570 571
  // 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."));
  }
}
572

573 574 575
/*
 * Page callback for administrative settings form.
 */
576
function comment_notify_settings() {
577
  module_load_include('inc', 'comment_notify', 'comment_notify');
578

579
  $form['comment_notify_settings'] = array();
580

581 582
  // Only perform comment_notify for certain node types.
  $enabled_types = comment_notify_variable_registry_get('node_types');
583
  $anonymous_problems = '';
584
  foreach (node_type_get_names() as $type => $name) {
585 586
    $checkboxes[$type] = check_plain($name);
    $default[] = $type;
587 588

    // If they don't have the ability to leave contact info, then we make a report
589
    if (isset($enabled_types[$type]) && $enabled_types[$type] && variable_get('comment_anonymous_' . $type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
590
      $account = drupal_anonymous_user();
591
      if (user_access('subscribe to comments', $account)) {
592
        $anonymous_problems[] = l(t('@content-type', array('@content-type' => $name)), 'admin/structure/types/manage/'. $type);
593 594 595
      }
    }
  }
greggles's avatar
greggles committed
596

597
  if (!empty($anonymous_problems)) {
598
    drupal_set_message(t('Anonymous commenters have the permission to subscribe to comments but cannot leave their contact information 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))), 'status', FALSE);
599 600 601 602
  }

  $form['comment_notify_settings']['comment_notify_node_types'] = array(
    '#type' => 'checkboxes',
603
    '#title' => t('Content types to enable for comment notification'),
604
    '#default_value' => $enabled_types,
605 606 607 608
    '#options' => $checkboxes,
    '#description' => t('Comments on content types enabled here will have the option of comment notification.'),
  );

609 610
  $form['comment_notify_settings']['comment_notify_available_alerts'] = array(
    '#type' => 'checkboxes',
611
    '#title' => t('Available subscription modes'),
612
    '#return_value' => 1,
613
    '#default_value' => comment_notify_variable_registry_get('available_alerts'),
614
    '#description' => t('Choose which notification subscription styles are available for users'),
615
    '#options' => array(
616 617 618
  COMMENT_NOTIFY_NODE     => t('All comments'),
  COMMENT_NOTIFY_COMMENT  => t('Replies to my comment')
  )
619 620
  );

621 622
  $available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
  $available_options += _comment_notify_options();
623
  $form['comment_notify_settings']['comment_notify_default_anon_mailalert'] = array(
624
    '#type' => 'select',
625
    '#title' => t('Default state for the notification selection box for anonymous users'),
626
    '#return_value' => 1,
627
    '#default_value' => comment_notify_variable_registry_get('default_anon_mailalert'),
628 629 630 631 632
    '#options' => $available_options,
  );

  $form['comment_notify_settings']['comment_notify_default_registered_mailalert'] = array(
    '#type' => 'select',
greggles's avatar
greggles committed
633
    '#title' => t('Default state for the notification selection box for registered users'),
634
    '#return_value' => 1,
635
    '#default_value' => comment_notify_variable_registry_get('default_registered_mailalert'),
636 637
    '#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,
638 639
  );

640
  $form['comment_notify_settings']['comment_notify_node_notify_default_mailalert'] = array(
641 642
    '#type' => 'checkbox',
    '#title' => t('Subscribe users to their node follow-up notification emails by default'),
643
    '#default_value' => comment_notify_variable_registry_get('node_notify_default_mailalert'),
644 645 646
    '#description' => t('If this is checked, new users will receive e-mail notifications for follow-ups on their nodes by default until they individually disable the feature.'),
  );

647
  $form['comment_notify_settings']['comment_notify_comment_notify_default_mailtext'] = array(
648
    '#type' => 'textarea',
649
    '#title' => t('Default mail text for sending out notifications to commenters'),
650
    '#default_value' => comment_notify_variable_registry_get('comment_notify_default_mailtext'),
651 652 653 654 655
    '#return_value' => 1,
    '#cols' => 80,
    '#rows' => 15
  );

656
  $form['comment_notify_settings']['comment_notify_node_notify_default_mailtext'] = array(
657
    '#type' => 'textarea',
658
    '#title' => t('Default mail text for sending out the notifications to node authors'),
659
    '#default_value' => comment_notify_variable_registry_get('node_notify_default_mailtext'),
660 661 662 663 664
     '#return_value' => 1,
     '#cols' => 80,
     '#rows' => 15
  );

665 666 667 668 669
  $form['comment_notify_settings']['token_help'] = array(
    '#theme' => 'token_tree',
    '#token_types' => array('comment'),
  );

670 671
  $form['#validate'] = array('comment_notify_settings_validate');

672
  return system_settings_form($form);
673
}
674 675 676 677 678 679 680 681 682 683

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.');
  }
}