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

  ViewVC Help
Powered by ViewVC 1.1.2