diff -urNp website/notify/notify.install notify-enh/notify.install --- website/notify/notify.install 2006-07-20 14:49:21.000000000 -0700 +++ notify-enh/notify.install 2006-11-17 14:44:25.000000000 -0800 @@ -39,3 +39,10 @@ function notify_install() { drupal_set_message(t('Table installation for the Notify module was unsuccessful. The tables may need to be installed by hand.'), 'error'); } } + +// Fix for scheduled-publishing bug (http://drupal.org/node/67475) +function notify_update_1() { + $ret[] = update_sql("UPDATE {system} SET weight = 9 WHERE name = 'notify'"); + return $ret; +} + diff -urNp website/notify/notify.module notify-enh/notify.module --- website/notify/notify.module 2006-08-11 14:24:47.000000000 -0700 +++ notify-enh/notify.module 2006-11-17 15:56:28.000000000 -0800 @@ -59,7 +59,70 @@ function notify_settings() { '#options' => array(t('Disabled'), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20), ); - return $form; + $form['notify_settings']['notify_allow_content'] = array( + '#type' => 'checkbox', + '#title' => t('Let users see content in notifications'), + '#default_value' => variable_get('notify_allow_content', 1), + '#description' => t('If this setting is disabled, users will not be able to choose to see content in their notifications. Only the master enable switch will be available, and users will not be notified of new comments.'), + ); + + $form['notify_nodetypes'] = array( + '#type' => 'fieldset', + '#title' => 'Node types', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('What types of content to send notifications for.'), + ); + + foreach (node_get_types() as $type) { + $varname = t('notify_type_%type', array('%type' => $type)); + $form['notify_nodetypes'][$varname] = array( + '#type' => 'checkbox', + '#title' => $type, + '#default_value' => variable_get($varname, 0), + ); + } + $form['notify_newusers'] = array( + '#type' => 'fieldset', + '#title' => t('Settings for new users'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#description' => t('New users will have their notification settings pre-set to these defaults.'), + ); + + $form['notify_newusers']['notify_enabled'] = array( + '#type' => 'radios', + '#title' => t('Enable e-mail notification'), + '#default_value' => variable_get('notify_enabled', 0), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Receive periodic e-mails when new content is posted.'), + ); + + $form['notify_newusers']['notify_content'] = array( + '#type' => 'radios', + '#title' => t('Notify of new content'), + '#default_value' => variable_get('notify_content', 0), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Include new content in notification.'), + ); + + $form['notify_newusers']['notify_teasers'] = array( + '#type' => 'radios', + '#title' => t('Content'), + '#default_value' => variable_get('notify_teasers', 0), + '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')), + '#description' => t('Amount of content to include in notification.'), + ); + + $form['notify_newusers']['notify_comment'] = array( + '#type' => 'radios', + '#title' => t('Notify of new comments'), + '#default_value' => variable_get('notify_comment', 0), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Include new comments in notification.'), + ); + + return $form; } /** @@ -81,6 +144,14 @@ function notify_user($type, &$edit, &$us case 'delete': db_query('DELETE FROM {notify} WHERE uid = %d', $user->uid); break; + case 'insert': + // Set a new user's notification settings to the default states. + $enabled = variable_get('notify_enabled',0); + $content = variable_get('notify_content',0); + $teasers = variable_get('notify_teasers',0); + $comment = variable_get('notify_comment',0); + db_query('INSERT {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $user->uid, $enabled, $content, $teasers, $comment); + break; } } @@ -135,23 +206,38 @@ function notify_page($uid = 0) { function notify_admin() { $result = db_query('SELECT u.uid, u.name, u.mail, n.* FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE n.status = 1 AND u.status = 1 ORDER BY u.name'); + $allow_content = variable_get('notify_allow_content', 1); + $form = array(); $form['#tree'] = TRUE; $form['#theme'] = 'notify_admin_default'; + $form['status'] = array('#type' => 'fieldset', '#title' => t('Notification times')); + $form['status']['lastnotify'] = array('#value' => t('Last notification: %last', array('%last' => format_date(variable_get('notify_send_last',0)))), '#prefix' => '
', '#suffix' => '
'); + $form['status']['nextnotify'] = array('#value' => t('Next notification: %next', array('%next' => format_date(variable_get('notify_send_last',0) + variable_get('notify_send', 86400)))), '#prefix' => '
', '#suffix' => '
'); $form['info'] = array('#type' => 'markup', '#value' => ''. t('The following table shows all users that have notifications enabled.') .''); while ($notify = db_fetch_object($result)) { $form['users'][$notify->uid]['name'] = array('#type' => 'markup', '#value' => theme('username', $notify)); $form['users'][$notify->uid]['mail'] = array('#type' => 'markup', '#value' => $notify->mail); - $form['users'][$notify->uid]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->node); - $form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body'))); - $form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment); + $form['users'][$notify->uid]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->node, '#attributes' => $allow_content ? '' : array('disabled' => 'disabled')); + $form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')), '#attributes' => $allow_content ? '' : array('disabled' => 'disabled')); + $form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment, '#attributes' => $allow_content ? '' : array('disabled' => 'disabled')); $form['users'][$notify->uid]['attempts'] = array('#type' => 'markup', '#value' => $notify->attempts ? intval($notify->attempts) : 0); } $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); $form['submitandsendnow'] = array('#type' => 'submit', '#value' => t('Save and send now')); + // Set uninitialized users to defaults (for first invocation) + $uninitialized = db_query('SELECT u.uid FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE n.uid IS NULL'); + while ($u = db_fetch_object($uninitialized)) { + $enabled = variable_get('notify_enabled',0); + $content = variable_get('notify_content',0); + $teasers = variable_get('notify_teasers',0); + $comment = variable_get('notify_comment',0); + db_query('INSERT {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $u->uid, $enabled, $content, $teasers, $comment); + } + return drupal_get_form('notify_admin', $form); } @@ -187,7 +273,8 @@ function notify_admin_submit($form_id, $ * Theme function to theme the admin user settings form in a table format. */ function theme_notify_admin_default($form) { - $output = form_render($form['info']); + $output = form_render($form['status']); + $output .= form_render($form['info']); $header = array (t('username'), t('e-mail address'), t('content'), t('teasers'), t('comment'), t('failed attempts')); $rows = array(); @@ -230,11 +317,12 @@ function _notify_page($uid) { if ($notify->mail) { $form['notify_page_master'] = array('#type' => 'fieldset','#title' => t('Master switch')); $form['notify_page_master']['status'] = array('#type' => 'radios', '#title' => t('Notify status'), '#default_value' => $notify->status, '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Do you wish to receive periodic e-mails when new content is posted?')); - - $form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings')); - $form['notify_page_detailed']['node'] = array('#type' => 'radios', '#title' => t('Notify new content'), '#default_value' => $notify->node, '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Include new content in the notification mail.')); - $form['notify_page_detailed']['teasers'] = array('#type' => 'radios', '#title' => t('Content'), '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')), '#description' => t('Select the amount of each post that you would like to see in your notification e-mails.')); - $form['notify_page_detailed']['comment'] = array('#type' => 'radios', '#title' => t('Notify new comments'), '#default_value' => $notify->comment, '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Include new comments in the notification mail.')); + if(variable_get('notify_allow_content', 1)) { + $form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings')); + $form['notify_page_detailed']['node'] = array('#type' => 'radios', '#title' => t('Notify new content'), '#default_value' => $notify->node, '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Include new content in the notification mail.')); + $form['notify_page_detailed']['teasers'] = array('#type' => 'radios', '#title' => t('Content'), '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')), '#description' => t('Select the amount of each post that you would like to see in your notification e-mails.')); + $form['notify_page_detailed']['comment'] = array('#type' => 'radios', '#title' => t('Notify new comments'), '#default_value' => $notify->comment, '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Include new comments in the notification mail.')); + } $form['submit'] = array('#type' => 'submit', '#value' => t('Save settings')); } else { @@ -306,11 +394,20 @@ function _notify_send() { 'INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5)); + // Get the settings for which node types trigger notification + $nodetypes = array(); + foreach (node_get_types() as $type) { + $varname = t('notify_type_%type', array('%type' => $type)); + $nodetypes[$type] = variable_get($varname, 0); + } + + $allow_content = variable_get('notify_allow_content', 1); + while ($user = db_fetch_object($uresult)) { // Switch current user to this account to use node_access functions, etc. _notify_switch_user($user->uid); - // Fetch all new nodes and 'load' it to get proper body, etc. + // Fetch all new nodes and load them to get proper body, etc. $nresult = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) ' . 'AND n.created > %d ORDER BY n.created'), $period); $nodes = array(); @@ -318,15 +415,16 @@ function _notify_send() { $nodes[$node->nid] = node_load($node->nid); } - // Fetch new comments - $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.pid, u.name FROM {comments} c ' . - 'INNER JOIN {users} u ON u.uid = c.uid WHERE c.status = %d AND c.timestamp > %d ' . - 'ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period); - $comments = array(); - while ($comment = db_fetch_object($cresult)) { - $comments[$comment->nid][] = $comment; + // Fetch new comments if users can see content. + if ($allow_content) { + $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.name FROM {comments} c ' . + 'WHERE c.status = %d AND c.timestamp > %d ' . + 'ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period); + $comments = array(); + while ($comment = db_fetch_object($cresult)) { + $comments[$comment->nid][] = $comment; + } } - $node_body = ''; $comment_body = ''; @@ -335,8 +433,10 @@ function _notify_send() { $node_count = 0; foreach ($nodes as $node) { + $ntype = _node_names('name', $node); // Skip to next if this user is NOT allowed to view this node - if (!node_access('view', $node)) { + // or if this node type doesn't trigger notifications. + if (!node_access('view', $node) || !$nodetypes[$ntype]) { continue; } @@ -354,10 +454,14 @@ function _notify_send() { if ($node_count > 0) { $node_body .= $mini_separator . "\n\n"; } - $node_body .= ++$node_count.'. '.t('%title', array('%title' => $node->title)) ."\n"; - $node_body .= t('%status %type by %author', array('%status' => $status, '%type' => _node_names('name', $node), '%author' => ($node->name ? $node->name : variable_get('anonymous', 'Anonymous')))) ."\n"; - $node_body .= '[ '. url('node/'.$node->nid, NULL, NULL, TRUE) ." ]\n\n"; - $node_body .= _notify_content($node, $user). "\n"; + $node_count++; + // If users allowed to see content, give at least the title, type, status, and author + if($allow_content) { + $node_body .= $node_count.'. '.t('%title', array('%title' => $node->title)) ."\n"; + $node_body .= t('%status %type by %author', array('%status' => $status, '%type' => $ntype, '%author' => ($node->name ? $node->name : variable_get('anonymous', 'Anonymous')))) ."\n"; + $node_body .= '[ '. url('node/'.$node->nid, NULL, NULL, TRUE) ." ]\n\n"; + $node_body .= _notify_content($node, $user). "\n"; + } } // Prepend node e-mail header as long as user could access at least one node @@ -369,7 +473,7 @@ function _notify_send() { } // Write new comments to e-mail if user has permissions and there are comments to be sent - if ($user->comment && user_access('access comments') && count($comments)) { + if ($allow_content && $user->comment && user_access('access comments') && count($comments)) { $total_comment_count = 0; $nid_old = 0; foreach ($comments as $nid => $comment) { @@ -379,8 +483,10 @@ function _notify_send() { $nodes[$nid] = node_load($nid); } - // Don't show comments if we're not allowed to view this node. - if (!node_access('view', $nodes[$nid], $user->uid)) { + $ntype = _node_names('name', $nodes[$nid]); + // Skip if user can't access the parent node or if this node type + // doesn't generate notifications. + if (!node_access('view', $nodes[$nid]) || !$nodetypes[$ntype]) { continue; } @@ -390,7 +496,7 @@ function _notify_send() { $comment_body .= t('%count new comments attached to %type posted by %author: %title', array('%count' => count($comment), '%title' => $nodes[$nid]->title, - '%type' => _node_names('name', $nodes[$nid]), '%author' => + '%type' => $ntype, '%author' => ($nodes[$nid]->name ? $nodes[$nid]->name : variable_get('anonymous', 'Anonymous'))))."\n"; $nid_old = $nid;