--- notify.module 2007-07-14 23:54:19.000000000 -0400 +++ notify.module 2008-10-16 16:34:17.000000000 -0400 @@ -23,6 +23,7 @@ function notify_help($section) { */ function notify_admin_settings() { $period = array( + 60 => format_interval(60), 900 => format_interval(900), 1800 => format_interval(1800), 3600 => format_interval(3600), @@ -151,7 +152,7 @@ function notify_user_settings_form($uid return; } - $result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid); + $result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.updates, n.teasers, n.comment FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid); $notify = db_fetch_object($result); $form = array(); if ($notify->mail) { @@ -176,6 +177,12 @@ function notify_user_settings_form($uid '#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']['updates'] = array('#type' => 'radios', + '#title' => t('Notify on updates'), + '#default_value' => $notify->updates, + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t('Include content updates in the notification mail.'), + ); $form['notify_page_detailed']['comment'] = array('#type' => 'radios', '#title' => t('Notify new comments'), '#default_value' => $notify->comment, @@ -194,7 +201,7 @@ function notify_user_settings_form($uid function notify_user_settings_form_submit($form_id, $form_values) { db_query('DELETE FROM {notify} WHERE uid = %d', $form_values['uid']); - db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $form_values['uid'], $form_values['status'], $form_values['node'], $form_values['teasers'], $form_values['comment']); + db_query('INSERT INTO {notify} (uid, status, node, updates, teasers, comment) VALUES (%d, %d, %d, %d, %d, %d)', $form_values['uid'], $form_values['status'], $form_values['node'], $form_values['updates'], $form_values['teasers'], $form_values['comment']); drupal_set_message(t('Notify settings saved.')); } @@ -214,6 +221,7 @@ function notify_admin_users() { $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]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->updates); $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]['attempts'] = array('#type' => 'markup', '#value' => $notify->attempts ? intval($notify->attempts) : 0); @@ -331,12 +339,13 @@ function _notify_send() { _notify_switch_user(); // Store current user // Fetch users with notify enabled - $uresult = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {notify} n 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)); + $uresult = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.updates, n.teasers, n.comment FROM {notify} n 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)); 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. $nresult = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) AND n.created > %d AND n.created <= %d ORDER BY n.created'), $period, time()); $nodes = array(); @@ -344,6 +353,13 @@ function _notify_send() { $nodes[$node->nid] = node_load($node->nid); } + // Fetch updated nodes + $uresult = db_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.status = 1 OR n.moderate = 1) AND n.changed > %d AND n.changed <= %d and n.changed != n.created ORDER BY n.created'), $period, time()); + $unodes = array(); + while ($node = db_fetch_object($uresult)) { + $unodes[$node->nid] = node_load($node->nid); + } + // Fetch new comments. $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 AND c.timestamp <= %d ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period, time()); $comments = array(); @@ -385,11 +401,52 @@ function _notify_send() { // Prepend node e-mail header as long as user could access at least one node. if ($node_count > 0) { $node_body = $separator ."\n" - . t('Recent content - @count', array('@count' => format_plural(count($nodes), '1 new post', '@count new posts'))) ."\n" + . t('Recently added content - @count', array('@count' => format_plural(count($nodes), '1 new post', '@count new posts'))) ."\n" . $separator ."\n\n". $node_body; } } + // Write updated node content to e-mail if user has permissions and nodes are + // ready to be sent. + if ($user->updates && user_access('access content') && count($unodes)) { + + $node_count = 0; + foreach ($unodes as $node) { + // Skip to next if this user is NOT allowed to view this node. + if (!node_access('view', $node)) { + continue; + } + + // TODO: Add functionality to hook into moderation modules? + if ($node->status == 1) { + $status = t('Published'); + } + elseif ($node->status == 0) { + $status = t('Unpublished'); + } + + if ($node_count > 0) { + $unode_body .= $mini_separator ."\n\n"; + } + // The author of the latest revision isn't included in the node object, so we need to get it... + $revisionresult = db_query(db_rewrite_sql('SELECT r.log, r.uid, u.name FROM {node_revisions} r INNER JOIN {users} u ON r.uid = u.uid WHERE r.vid = %d'), $node->vid); + $revision = db_fetch_object($revisionresult); + + $unode_body .= ++$node_count .'. '. t('@title', array('@title' => $node->title)) ."\n"; + $unode_body .= t('@status @type by @author at @time', array('@status' => $status, '@type' => node_get_types('name', $node), '@author' => ($revision->name ? $revision->name .' [ '. url('user/'. $revision->uid, NULL, NULL, TRUE) .' ]' : variable_get('anonymous', 'Anonymous')), '@time' => format_date($node->revision_timestamp, 'small'))) ."\n"; + $unode_body .= t('Log message: @log', array('@log' => ($revision->log ? $revision->log : '--No log message--'))) ."\n"; + $unode_body .= '[ '. url('node/'. $node->nid, NULL, NULL, TRUE) ." ]\n\n"; + $unode_body .= _notify_content($node, $user) ."\n"; + } + + // Prepend node e-mail header as long as user could access at least one node. + if ($node_count > 0) { + $unode_body = $separator ."\n" + . t('Recently updated content - @count', array('@count' => format_plural(count($unodes), '1 updated post', '@count updated posts'))) ."\n" + . $separator ."\n\n". $unode_body; + } + } + // 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)) { @@ -425,14 +482,14 @@ function _notify_send() { } } - $body = $node_body . $comment_body; + $body = $node_body . $unode_body . $comment_body; // If there was anything new, send mail. if ($body) { // Set up initial values for e-mail. $from = variable_get('site_mail', ini_get('sendmail_from')); $from_name = variable_get('site_name', 'Drupal'); - $subject = t('@sitename new content notification for @username', array('@username' => $user->name, '@sitename' => variable_get('site_name', 'Drupal'))); + $subject = t('@sitename new and updated content notification for @username', array('@username' => $user->name, '@sitename' => variable_get('site_name', 'Drupal'))); $body = t('Greetings @user,', array('@user' => $user->name)) ."\n\n". $body; @@ -484,15 +541,15 @@ function _notify_entity_to_utf8($hex, $c . chr(0x80 | ($codepoint & 0x3F)); } else if ($codepoint < 0x10000) { - return chr(0xE0 | ( $codepoint >> 12)) + return chr(0xE0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3F)) - . chr(0x80 | ( $codepoint & 0x3F)); + . chr(0x80 | ($codepoint & 0x3F)); } else if ($codepoint < 0x200000) { - return chr(0xF0 | ( $codepoint >> 18)) + return chr(0xF0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3F)) . chr(0x80 | (($codepoint >> 6) & 0x3F)) - . chr(0x80 | ( $codepoint & 0x3F)); + . chr(0x80 | ($codepoint & 0x3F)); } }