/[drupal]/contributions/modules/comment_notify/comment_notify.module
ViewVC logotype

Contents of /contributions/modules/comment_notify/comment_notify.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.72 - (show annotations) (download) (as text)
Sat Nov 7 18:39:55 2009 UTC (2 weeks, 3 days ago) by greggles
Branch: MAIN
Changes since 1.71: +56 -57 lines
File MIME type: text/x-php
bug #617070 by greggles: Doesn't record subscription when only one subscription type is enabled (and lots more tests)
1 <?php
2 // $Id: comment_notify.module,v 1.71 2009/11/06 23:04:52 greggles Exp $
3
4 /**
5 * @file
6 *
7 * This module provides comment follow-up e-mail notification for anonymous and registered users.
8 */
9
10 define('AUTHOR_MAILTEXT',
11 'Hi !name,
12
13 You have received a comment on: "!node_title"
14
15 You can view the comment at the following url
16 !comment_url
17
18 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.
19
20 Webmaster of !site
21 !mission
22 !uri');
23
24 define('DEFAULT_MAILTEXT',
25 'Hi !name,
26
27 !commname has commented on: "!node_title"
28
29 The post is about
30 ----
31 !node_teaser
32 ----
33
34 You can view the comment at the following url
35 !comment_url
36
37 You can stop receiving emails when someone replies to this post,
38 by going to !link1
39
40 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.
41
42 You can set up auto-following feature for all future posts
43 by creating your own user with a few clicks here !uri/user/register
44
45 Thanks for your feedback,
46
47 Webmaster of !site
48 !mission
49 !uri');
50
51 define('COMMENT_NOTIFY_DISABLED', 0);
52 define('COMMENT_NOTIFY_NODE', 1);
53 define('COMMENT_NOTIFY_COMMENT', 2);
54
55 /**
56 * Provide an array of available options for notification on a comment.
57 */
58 function _comment_notify_options() {
59 $total_options = array(
60 COMMENT_NOTIFY_NODE => t('All comments'),
61 COMMENT_NOTIFY_COMMENT => t('Replies to my comment')
62 );
63
64 $available_options = array();
65 $options = variable_get('comment_notify_available_alerts', drupal_map_assoc(array(COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT)));
66 foreach ($options as $key => $available) {
67 if ($key == $available) {
68 $available_options[$available] = $total_options[$available];
69 }
70 }
71
72 return $available_options;
73 }
74
75 /**
76 * Insert our checkbox, add a submit button, and populate fields.
77 */
78 function comment_notify_form_alter(&$form, &$form_state, $form_id) {
79 global $user;
80
81 // Only alter the form if it's a comment form and the user has the permission to subscribe.
82 if ($form_id == 'comment_form' && (user_access('subscribe to comments') || user_access('administer comments'))) {
83 // Only add the checkbox if this is an enabled content type
84 $node = node_load($form['nid']['#value'] ? $form['nid']['#value'] : $form['nid']['#default_value']);
85 $enabled_types = variable_get('comment_notify_node_types', drupal_map_assoc(array($node->type)));
86 if (empty($enabled_types[$node->type])) {
87 return;
88 }
89
90 $available_options = _comment_notify_options();
91
92 drupal_add_css(drupal_get_path('module', 'comment_notify') .'/comment_notify.css');
93 drupal_add_js(drupal_get_path('module', 'comment_notify') .'/comment_notify.js');
94
95 // Add the checkbox for anonymous users and set the default based on admin settings.
96 if ($user->uid == 0) {
97 // If anonymous user's can't enter their e-mail don't tempt them with the checkbox.
98 if (empty($form['mail'])) {
99 return;
100 }
101 $preference = variable_get('comment_notify_default_anon_mailalert', COMMENT_NOTIFY_DISABLED);
102 }
103 else {
104 $user_preference = db_result(db_query("SELECT comment_notify FROM {comment_notify_user_settings} WHERE uid = %d", $user->uid));
105 $preference = strlen($user_preference) ? $user_preference : variable_get('comment_notify_default_registered_mailalert', COMMENT_NOTIFY_DISABLED);
106 }
107
108 // If you want to hide this on your site see http://drupal.org/node/322482
109 $form['notify_settings'] = array(
110 '#prefix' => '<div class="clear-block">',
111 '#suffix' => '</div>',
112 );
113
114 $form['notify_settings']['notify'] = array(
115 '#type' => 'checkbox',
116 '#title' => t('Notify me when new comments are posted'),
117 '#default_value' => $preference,
118 );
119
120 if (count($available_options) > 1) {
121 $form['notify_settings']['notify_type'] = array(
122 '#type' => 'radios',
123 '#options' => $available_options,
124 '#default_value' => $preference,
125 );
126 }
127 else {
128 $form['notify_settings']['notify_type'] = array(
129 '#type' => 'hidden',
130 '#value' => key($available_options),
131 );
132 }
133 $form['notify_settings']['notify_type']['#default_value'] = $preference;
134
135 // If this is an existing comment we set the default value based on their selection last time.
136 if ($form['cid']['#value'] != '') {
137 $notify = db_result(db_query("SELECT notify FROM {comment_notify} WHERE cid = %d", $form['cid']['#value']));
138 $form['notify_settings']['notify']['#default_value'] = $notify;
139 if (count($available_options) > 1) {
140 $form['notify_settings']['notify_type']['#default_value'] = $notify;
141 }
142 else {
143 $form['notify_settings']['notify_type']['#default_value'] = key($available_options);
144 }
145 }
146 }
147 }
148
149 /**
150 * Implementation of hook_perm().
151 */
152 function comment_notify_perm() {
153 return array('administer comment notify', 'subscribe to comments');
154 }
155
156 /**
157 * Implementation of hook_menu().
158 */
159 function comment_notify_menu() {
160
161 $items['admin/settings/comment_notify'] = array(
162 'title' => 'Comment notify',
163 'description' => 'Configure settings for e-mails about new comments.',
164 'page callback' => 'drupal_get_form',
165 'page arguments' => array('comment_notify_settings'),
166 'access arguments' => array('administer comment notify'),
167 'type' => MENU_NORMAL_ITEM,
168 );
169 $items['admin/settings/comment_notify/settings'] = array(
170 'title' => 'Settings',
171 'description' => 'Configure settings for e-mails about new comments.',
172 'page callback' => 'drupal_get_form',
173 'page arguments' => array('comment_notify_settings'),
174 'access arguments' => array('administer comment notify'),
175 'type' => MENU_DEFAULT_LOCAL_TASK,
176 );
177
178 $items['admin/settings/comment_notify/unsubscribe'] = array(
179 'title' => 'Unsubscribe',
180 'description' => 'Unsubscribe an email from all notifications.',
181 'weight' => 2,
182 'page callback' => 'drupal_get_form',
183 'page arguments' => array('comment_notify_unsubscribe'),
184 'access arguments' => array('administer comment notify'),
185 'type' => MENU_LOCAL_TASK,
186 );
187 $items['comment_notify/disable/%'] = array(
188 'title' => 'Disable comment notification',
189 'page callback' => 'comment_notify_disable_page',
190 'page arguments' => array(2),
191 'access arguments' => array('access content'),
192 'type' => MENU_CALLBACK
193 );
194
195 return $items;
196 }
197
198 /**
199 * Page callback to allow users to unsubscribe simply by visiting the page.
200 */
201 function comment_notify_disable_page($hash) {
202 db_query("UPDATE {comment_notify} SET notify = 0 WHERE notify_hash = '%s'", $hash);
203
204 drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.'));
205 return ' ';
206 }
207
208 /**
209 * Implementation of hook_comment().
210 */
211 function comment_notify_comment($comment, $op) {
212 global $user;
213
214 // In theory, the update or insert operations are duplicates with publish which
215 // would lead to duplicate messages. _comment_notify_mailalert() protects against that.
216 switch ($op) {
217 case 'validate':
218 // We assume that if they are non-anonymous then they have a valid mail.
219 // For anonymous users, though, we verify that they entered a mail and let comment.module validate it is real.
220 if (!$user->uid && $comment['notify'] && empty($comment['mail'])) {
221 form_set_error('mail', t('If you want to subscribe to comments you must supply a valid e-mail address.'));
222 }
223 break;
224 case 'publish':
225 // And send notifications - the real purpose of the module.
226 _comment_notify_mailalert($comment);
227 break;
228 case 'update':
229 // In case they have changed their status, save it in the database.
230 $sql = 'UPDATE {comment_notify} SET notify = %d WHERE cid = %d';
231 if ($comment['notify']) {
232 db_query($sql, $comment['notify_type'], $comment['cid']);
233 }
234 else {
235 db_query($sql, 0, $comment['cid']);
236 }
237 // And send notifications - the real purpose of the module.
238 if ($comment['status'] == COMMENT_PUBLISHED) {
239 _comment_notify_mailalert($comment);
240 }
241 break;
242 case 'insert':
243 // For new comments, we first build up a string to be used as the identifier for the alert
244 $mail = empty($comment['mail']) ? $user->mail : $comment['mail'];
245 $notify_hash = drupal_get_token($mail . $comment['cid']);
246
247 if ($comment['notify']) {
248 $notify = $comment['notify_type'];
249 // If they don't have a preference, save one.
250 $current = db_result(db_query("SELECT count(1) from {comment_notify_user_settings} WHERE uid = %d", $user->uid));
251 if ($current == 0 && $user->uid) {
252 db_query("INSERT INTO {comment_notify_user_settings} (uid, comment_notify) VALUES (%d, %d)", $user->uid, $comment['notify_type']);
253 }
254 }
255 else {
256 $notify = $comment['notify'];
257 }
258 // And then save the data.
259 db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) values (%d, %d, '%s')", $comment['cid'], $notify, $notify_hash);
260
261 // And send notifications - the real purpose of the module.
262 if ($comment['status'] == COMMENT_PUBLISHED) {
263 _comment_notify_mailalert($comment);
264 }
265 break;
266 case 'delete':
267 db_query("DELETE FROM {comment_notify} WHERE cid = %d", $comment->cid);
268 break;
269 }
270 }
271
272 /**
273 * Implementation of hook_user().
274 */
275 function comment_notify_user($type, &$edit, &$user, $category = NULL) {
276 switch ($type) {
277 case 'form':
278 if ($category == 'account' && user_access('subscribe to comments', $user)) {
279 $form = array();
280 $form['comment_notify_settings'] = array(
281 '#type' => 'fieldset',
282 '#title' => t('Comment follow-up notification settings'),
283 '#weight' => 4,
284 '#collapsible' => TRUE
285 );
286
287 // Only show the node followup UI if the user has permission to create nodes.
288 $nodes = FALSE;
289 foreach (node_get_types() as $type) {
290 if (user_access('create '. $type->type .' content')) {
291 $nodes = TRUE;
292 break;
293 }
294 }
295 if (user_access('administer nodes') || $nodes) {
296 $form['comment_notify_settings']['node_notify_mailalert'] = array(
297 '#type' => 'checkbox',
298 '#title' => t('Receive node follow-up notification e-mails'),
299 '#default_value' => isset($edit['node_notify_mailalert']) ? $edit['node_notify_mailalert'] : variable_get('node_notify_default_mailalert', FALSE),
300 '#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.')
301 );
302 }
303 else {
304 $form['comment_notify_settings']['node_notify_mailalert'] = array(
305 '#type' => 'hidden',
306 '#value' => COMMENT_NOTIFY_DISABLED,
307 );
308 }
309
310 $available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
311 $available_options += _comment_notify_options();
312 $form['comment_notify_settings']['comment_notify_mailalert'] = array(
313 '#type' => 'select',
314 '#title' => t('Receive comment follow-up notification e-mails'),
315 '#default_value' => isset($edit['comment_notify_mailalert']) ? $edit['comment_notify_mailalert'] : variable_get('comment_notify_default_registered_mailalert', COMMENT_NOTIFY_DISABLED),
316 '#options' => $available_options,
317 '#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.")
318 );
319 return $form;
320 }
321 break;
322
323 case 'submit':
324 // Save the values of node_notify_mailalert and comment_notify_mailalert
325 // to {comment_notify_user_settings}.
326 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);
327 if (!db_affected_rows()) {
328 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']);
329 }
330
331 // Unset them from $user so they don't also get saved into {users}.data.
332 unset($edit['node_notify_mailalert']);
333 unset($edit['comment_notify_mailalert']);
334 break;
335
336 case 'load':
337 $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));
338 if (!empty($user_settings)) {
339 foreach ($user_settings as $property => $value) {
340 $user->$property = $value;
341 }
342 }
343 break;
344
345 case 'delete':
346 db_query('DELETE FROM {comment_notify_user_settings} WHERE uid = %d', $user->uid);
347 break;
348
349 break;
350 }
351 }
352
353 /**
354 * Private function to send the notifications.
355 *
356 * @param $comment
357 * The comment array as found in hook_comment $op = publish.
358 */
359 function _comment_notify_mailalert($comment) {
360 $comment = (object) $comment;
361 global $language;
362 global $base_url;
363 global $user;
364
365 $nid = $comment->nid;
366 $cid = $comment->cid;
367
368 // Check to see if a notification has already been sent for this
369 // comment so that edits to a comment don't trigger an additional
370 // notification.
371 if (db_result(db_query('SELECT cid from {comment_notify} WHERE cid = %d AND notified = %d', $cid, 1))) {
372 return;
373 }
374
375 $initial_language = $language;
376
377 if (function_exists('locale')) {
378 $languages = locale_language_list();
379 $languages = $languages['name'];
380 }
381
382 $node = node_load($nid);
383
384 // Render up the node and comment.
385 $node_teaser = node_view($node, TRUE, TRUE, FALSE);
386 $node_body = node_view($node, FALSE, TRUE, FALSE);
387 $comment_text = check_markup($comment->comment, $comment->format);
388
389 // No mails if this is not an enabled content type.
390 $enabled_types = variable_get('comment_notify_node_types', array($node->type => TRUE));
391 if (empty($enabled_types[$node->type])) {
392 return;
393 }
394
395 if (!isset($comment->mail)) {
396 $comment_account = user_load(array('name' => $comment->name));
397 $comment_mail = $comment_account->mail;
398 }
399 else {
400 $comment_mail = $comment->mail;
401 }
402 $sent_to = array();
403
404 // Send to a subscribed author if they are not the current commenter
405 $author = user_load(array('uid' => $node->uid));
406 if (!empty($author->node_notify_mailalert) && $author->node_notify_mailalert == 1 && $user->uid != $author->uid && node_access('view', $node, $author)) {
407
408 // Get the author's language.
409 $language = user_preferred_language($author);
410 $message['subject'] = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal')));
411 $message['body'] = t(
412 variable_get('node_notify_default_mailtext', AUTHOR_MAILTEXT),
413 array(
414 '!commname' => $comment->name,
415 '!commtext' => drupal_html_to_text($comment_text),
416 '!commsubj' => $comment->subject,
417 '!comment_url' => url('node/'. $nid, array('absolute' => TRUE, 'fragment' => 'comment-'. $cid)),
418 '!node_title' => $node->title,
419 '!node_teaser' => drupal_html_to_text($node_teaser),
420 '!mission' => variable_get('site_mission', ''),
421 '!node_body' => drupal_html_to_text($node_body),
422 '!name' => $author->name,
423 '!site' => variable_get('site_name', 'drupal'),
424 '!uri' => $base_url,
425 '!uri_brief' => preg_replace('!^https?://!', '', $base_url),
426 '!date' => format_date(time()),
427 '!login_uri' => url('user', array('absolute' => TRUE)),
428 '!edit_uri' => url('user/'. $author->uid .'/edit', array('absolute' => TRUE))
429 )
430 );
431 drupal_mail('comment_notify', 'comment_notify_mail', $author->mail, $language, $message);
432 $sent_to[] = $author->mail;
433 }
434
435 // For "reply to my comments" notifications, figure out what thread this is.
436 $thread = db_result(db_query("SELECT thread FROM {comments} WHERE cid = %d", $cid));
437
438 //Get the list of commenters to notify
439 $result = db_query(db_rewrite_sql("SELECT c.cid, c.nid, c.uid, c.name, c.mail AS cmail, u.mail AS umail, u.init AS uinit, c.uid, c.name, cn.notify, cn.notify_hash, c.thread
440 FROM {comments} c INNER JOIN {comment_notify} cn on c.cid = cn.cid LEFT OUTER JOIN {users} u ON c.uid = u.uid
441 WHERE c.nid = %d AND cn.notify > 0 AND c.status = 0 AND (u.status = 1 OR u.uid = 0)", 'c', 'cid'), $nid
442 );
443 // 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
444
445 while ($alert = db_fetch_object($result)) {
446 $umail = empty($alert->umail) ? $alert->uinit : $alert->umail;
447 $mail = empty($alert->cmail) ? $umail : $alert->cmail;
448
449 $relevant_thread = substr($thread, 0, drupal_strlen($alert->thread) -1);
450 if ($alert->notify == COMMENT_NOTIFY_COMMENT && strcmp($relevant_thread . '/', $alert->thread) != 0) {
451 continue;
452 }
453 if ($mail != $comment_mail && !in_array($mail, $sent_to) && $alert->uid != $comment->uid) {
454 $message = array();
455 if (!empty($alert->uid)) {
456 $recipient_user = user_load(array('uid' => $alert->uid));
457 $language = user_preferred_language($recipient_user);
458 }
459 else {
460 $language = language_default();
461 $recipient_user = drupal_anonymous_user();
462 }
463 // Make sure they have access to this node before showing a bunch of node information.
464 if (!node_access('view', $node, $recipient_user)) {
465 continue;
466 }
467
468 $message['subject'] = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal')));
469 $message['body'] = t(
470 variable_get('comment_notify_default_mailtext', DEFAULT_MAILTEXT),
471 array(
472 '!commname' => $comment->name,
473 '!commtext' => drupal_html_to_text($comment_text),
474 '!commsubj' => $comment->subject,
475 '!comment_url' => url('node/'. $nid, array('absolute' => TRUE, 'fragment' => 'comment-'. $cid)),
476 '!node_title' => $node->title,
477 '!node_teaser' => drupal_html_to_text($node_teaser),
478 '!mission' => variable_get('site_mission', ''),
479 '!node_body' => drupal_html_to_text($node_body),
480 '!name' => $alert->name,
481 '!site' => variable_get('site_name', 'drupal'),
482 '!uri' => $base_url,
483 '!uri_brief' => preg_replace('!^https?://!', '', $base_url),
484 '!date' => format_date(time()),
485 '!login_uri' => url('user', array('absolute' => TRUE)),
486 '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)),
487 '!link1' => url('comment_notify/disable/'. $alert->notify_hash, array('absolute' => TRUE))
488 )
489 );
490 drupal_mail('comment_notify', 'comment_notify_mail', $mail, $language, $message);
491 $sent_to[] = $mail;
492
493 // Make the mail link to user's /edit, unless it's an anonymous user.
494 if ($alert->uid != 0) {
495 $user_mail = l($mail, 'user/'. $alert->uid .'/edit');
496 }
497 else {
498 $user_mail = check_plain($mail);
499 }
500
501 // Add an entry to the watchdog log.
502 watchdog(
503 'comment_notify',
504 'Notified: !user_mail',
505 array('!user_mail' => $user_mail),
506 WATCHDOG_NOTICE,
507 l(t('source comment'), 'node/'. $nid, array(
508 'fragment' => 'comment-'. $alert->cid,
509 ))
510 );
511
512 // revert to previous (site default) locale
513 $language = $initial_language;
514 }
515 }
516 // Record that a notification was sent for this comment so that
517 // notifications aren't sent again if the comment is later edited.
518 db_query('UPDATE {comment_notify} SET notified = 1 WHERE cid = %d', $cid);
519 }
520
521 /**
522 * Implementation of hook_mail().
523 */
524 function comment_notify_mail($key, &$message, $params) {
525 $message['subject'] = $params['subject'];
526 $message['body'][] = $params['body'];
527 }
528
529 /**
530 * Callback for an administrative form to unsubscribe users by e-mail address.
531 */
532 function comment_notify_unsubscribe() {
533 $form['comment_notify_unsubscribe'] = array();
534 $form['comment_notify_unsubscribe']['email_to_unsubscribe'] = array(
535 '#type' => 'textfield',
536 '#title' => t('Email to unsubscribe'),
537 );
538 $form['comment_notify_unsubscribe']['submit'] = array(
539 '#type' => 'submit',
540 '#value' => t('Unsubscribe this e-mail'),
541 );
542 return $form;
543 }
544
545 /**
546 * Based on admin submit, do the actual unsubscribe from notifications.
547 */
548 function comment_notify_unsubscribe_submit($form, &$form_state) {
549 $email = trim($form_state['values']['email_to_unsubscribe']);
550 // If they have a uid, use that, otherwise update comments directly
551 $result = db_result(db_query_range("SELECT uid FROM {users} WHERE mail = '%s'", $email, 0, 1));
552 if ($result > 0) {
553 $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));
554 db_query("UPDATE {comment_notify} SET notify = 0 WHERE cid IN (SELECT cid FROM {comments} WHERE uid = %d)", $result);
555 }
556 else {
557 $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));
558 db_query("UPDATE {comment_notify} SET notify = 0 WHERE cid IN (SELECT cid FROM {comments} WHERE mail = '%s')", $email);
559 }
560 // Update the admin about the state of this comment notification subscription.
561 if ($comments == 0) {
562 drupal_set_message(t("There were no active comment notifications for that email."));
563 }
564 else {
565 drupal_set_message(format_plural($comments, "Email unsubscribed from 1 comment notification.",
566 "Email unsubscribed from @count comment notifications."));
567 }
568 }
569
570 /*
571 * Page callback for administrative settings form.
572 */
573 function comment_notify_settings() {
574 $form['comment_notify_settings'] = array();
575
576 // Only perform comment_notify for certain node types (default, all)
577 $enabled_types = variable_get('comment_notify_node_types', FALSE);
578 $anonymous_problems = '';
579 foreach (node_get_types('names') as $type => $name) {
580 $checkboxes[$type] = check_plain($name);
581 $default[] = $type;
582
583 // If they don't have the ability to leave contact info, then we make a report
584 if (isset($enabled_types[$type]) && $enabled_types[$type] && variable_get('comment_anonymous_'. $type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) == COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
585 $account = user_load(array('uid' => 0));
586 if (user_access('subscribe to comments', $account)) {
587 $anonymous_problems[] = l(t('@content-type', array('@content-type' => $name)), 'admin/content/node-type/'. $type);
588 }
589 }
590 }
591
592 if (!empty($anonymous_problems)) {
593 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))), 'status', FALSE);
594 }
595
596 $form['comment_notify_settings']['comment_notify_node_types'] = array(
597 '#type' => 'checkboxes',
598 '#title' => t('Content types to enable for comment notification'),
599 '#default_value' => variable_get('comment_notify_node_types', $default),
600 '#options' => $checkboxes,
601 '#description' => t('Comments on content types enabled here will have the option of comment notification.'),
602 );
603
604 $form['comment_notify_settings']['comment_notify_available_alerts'] = array(
605 '#type' => 'checkboxes',
606 '#title' => t('Available subscription modes'),
607 '#return_value' => 1,
608 '#default_value' => variable_get('comment_notify_available_alerts', array(COMMENT_NOTIFY_NODE, COMMENT_NOTIFY_COMMENT)),
609 '#description' => t('Choose which notification subscription styles are available for users'),
610 '#options' => array(
611 COMMENT_NOTIFY_NODE => t('All comments'),
612 COMMENT_NOTIFY_COMMENT => t('Replies to my comment')
613 )
614 );
615
616 $available_options[COMMENT_NOTIFY_DISABLED] = t('No notifications');
617 $available_options += _comment_notify_options();
618 $form['comment_notify_settings']['comment_notify_default_anon_mailalert'] = array(
619 '#type' => 'select',
620 '#title' => t('Default state for the notification selection box for anonymous users'),
621 '#return_value' => 1,
622 '#default_value' => variable_get('comment_notify_default_anon_mailalert', COMMENT_NOTIFY_NODE),
623 '#options' => $available_options,
624 );
625
626 $form['comment_notify_settings']['comment_notify_default_registered_mailalert'] = array(
627 '#type' => 'select',
628 '#title' => t('Default state for the notification selection box for registered users'),
629 '#return_value' => 1,
630 '#default_value' => variable_get('comment_notify_default_registered_mailalert', COMMENT_NOTIFY_NODE),
631 '#description' => t('This flag presets the flag for the follow-up notification on the form that anon users will see when posting a comment'),
632 '#options' => $available_options,
633 );
634
635 $form['comment_notify_settings']['node_notify_default_mailalert'] = array(
636 '#type' => 'checkbox',
637 '#title' => t('Subscribe users to their node follow-up notification emails by default'),
638 '#default_value' => variable_get('node_notify_default_mailalert', FALSE),
639 '#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.'),
640 );
641
642
643 $form['comment_notify_settings']['comment_notify_default_mailtext'] = array(
644 '#type' => 'textarea',
645 '#title' => t('Default mail text for sending out notifications to commenters'),
646 '#description' => t(
647 'You can use the following variables to be replaced:
648 <ul>
649 <li>!commname = the username who posted the comment
650 <li>!commtext = the text of the posted comment
651 <li>!commsubj = the subject of the posted comment
652 <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
653 <li>!node_title = the title of the node that was commented on
654 <li>!node_teaser = the teaser of the node that was commented on
655 <li>!node_body = the body of the node that was commented on
656 <li>!mission = site_mission text
657 <li>!name = username receiving the alert
658 <li>!site = your site
659 <li>!uri = base_url of site
660 <li>!uri_brief = base_url of site w/o http
661 <li>!date = the current time
662 <li>!login_uri uri to login the user
663 <li>!edit_uri = uri to edit user profile
664 <li>!link1 the QUICKLINK to disable future follow-up notifications for the user
665 </ul>'
666 ),
667 '#default_value' => variable_get('comment_notify_default_mailtext', t(DEFAULT_MAILTEXT)),
668 '#return_value' => 1,
669 '#cols' => 80,
670 '#rows' => 15
671 );
672
673 $form['comment_notify_settings']['node_notify_default_mailtext'] = array(
674 '#type' => 'textarea',
675 '#title' => t('Default mail text for sending out the notifications to node authors'),
676 '#description' => t(
677 'You can use the following variables to be replaced:
678 <ul>
679 <li>!commname = the username who posted the comment
680 <li>!commtext = the text of the posted comment
681 <li>!commsubj = the subject of the posted comment
682 <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
683 <li>!node_title = the title of the node that was commented on
684 <li>!node_teaser = the teaser of the node that was commented on
685 <li>!node_body = the body of the node that was commented on
686 <li>!mission = site_mission text
687 <li>!name = username receiving the alert
688 <li>!site = your site
689 <li>!uri = base_url of site
690 <li>!uri_brief = base_url of site w/o http
691 <li>!date = the current time
692 <li>!login_uri uri to login the user
693 <li>!edit_uri = uri to edit user profile
694 </ul>'
695 ),
696 '#default_value' => variable_get('node_notify_default_mailtext', t(AUTHOR_MAILTEXT)),
697 '#return_value' => 1,
698 '#cols' => 80,
699 '#rows' => 15
700 );
701
702 $form['#validate'] = array('comment_notify_settings_validate');
703
704 return system_settings_form($form);
705 }
706
707 function comment_notify_settings_validate($form, &$form_state) {
708 $sum_enabled = 0;
709 foreach ($form_state['values']['comment_notify_available_alerts'] as $enabled) {
710 $sum_enabled += $enabled;
711 }
712 if (!$sum_enabled) {
713 form_set_error('comment_notify_available_alerts', 'You must enable at least one subscription mode.');
714 }
715 }

  ViewVC Help
Powered by ViewVC 1.1.2