Index: notify_by_views.module =================================================================== --- notify_by_views.module (revision 2869) +++ notify_by_views.module (working copy) @@ -155,6 +155,12 @@ '#default_value' => variable_get('notify_by_views_default_schedule','never'), '#required' => TRUE, ); + + $form['notify_by_views_set']['notify_by_views_send_html_mail'] = array( + '#type' => 'checkbox', + '#title' => t('Send HTML e-mails'), + '#default_value' => variable_get('notify_by_views_send_html_mail', FALSE), + ); $form['notify_send']['#description'] = $form['notify_send']['#description'] . t(" If using Notify_by_Views, you can set this to 'Never' because user selected settings will be used."); } @@ -299,6 +305,8 @@ return; } + $html = variable_get('notify_by_views_send_html_mail', FALSE); + if (!is_array($nodes)) { $nodes = array($nodes->nid => $nodes); } @@ -320,6 +328,7 @@ if ($frequency == 'weekly' && $user->last_mailing + 604800 > time()) { continue; } + // Switch current user to this account to use node_access functions, etc. _notify_switch_user($user->uid); @@ -337,16 +346,16 @@ $comment_body = ''; $included_nodes = notify_by_views_included($user, $view_name); + // Get a template. + $template = variable_get("notify_by_views_{$view_name}_template", _notify_by_views_default_text()); + // Break up template into its parts. + $tpl = explode('!section',$template); + // Write new node content to e-mail if user has permissions and nodes are // ready to be sent. if (user_access('access content') && count($included_nodes)) { $node_count = 0; - //get a template - $template = variable_get("notify_by_views_{$view_name}_template", _notify_by_views_default_text()); - //break up template into its parts - $tpl = explode('!section',$template); - foreach ($included_nodes as $nid) { $node = $nodes[$nid]; // Skip to next if this user is NOT allowed to view this node. @@ -454,12 +463,31 @@ $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'))); - $body = strtr($tpl[0], array('!uname' => $user->name)) . $body; //add template header + // Get replacement tokens from other modules. + $tokens['!uname'] = $user->name; + $tokens = array_merge($tokens, module_invoke_all('notify_by_views_template_tokens', $html, $user->last_mailing)); + + // Set up the message header. + $header = $tpl[0]; + $header = strtr($header, $tokens); + // Set up the message footer. + $footer = $tpl[3]; + $footer = strtr($footer, $tokens); + + // Set up the complete message body. + $body = $header . $body; // Add template header. + $body .= "\n". $footer; // Add on the footer. $body .= "\n". t('This is an automatic e-mail from @sitename.', array('@sitename' => variable_get('site_name', 'Drupal')))."\n"; $body .= t('To stop receiving these e-mails, change your notification preferences at @notify-url', array('@notify-url' => url("user/$user->uid/notify" , NULL, NULL, TRUE)))."\n"; $headers = array();//'From' => "$from_name <$from>"); - + if ($html) { + $body = strtr($body, array("\r\n" => '
', "\n" => '
')); + $headers = array( + 'Content-Type' => 'text/html; charset=UTF-8; format=flowed', + ); + } + //Here's where we really send it, unless test is True $success = $test ? TRUE : drupal_mail('notify_by_views_'. $view_name, $user->mail, $subject, wordwrap($body, 72), $from, $headers);