diff --git a/README.txt b/README.txt index af17c4c..dcfa89f 100644 --- a/README.txt +++ b/README.txt @@ -1,18 +1,22 @@ + Module description ================== -This module works with the simplenews module to allow you to automatically generate digest emails to subscribed users. The emails contain a simple listing of links, grouped by node type, to nodes posted on the site since the last time a digest newsletter was sent out. T -he following can be configured: +This module works with the simplenews module to allow you to automatically +generate digest emails to subscribed users. The emails contain a simple listing +of links, grouped by node type, to nodes posted on the site since the last time +a digest newsletter was sent out. +The following can be configured: 1) How frequently the digest newsletter gets sent (days/weeks/months) 2) Which newsletter should act as the digest newsletter -3) Which node types and taxonomy terms to send +3) Which node types and taxonomy terms to send 4) How node types should be labeled in the newsletter 5) What time of day the newsletter should be sent out Example use =========== -Let's say you want to send out a newsletter every two weeks on Friday at midnight. Go to admin -> content management -> newsletters -> settings -> digest newsletter settings. - +Let's say you want to send out a newsletter every two weeks on Friday at +midnight. Go to admin -> content management -> newsletters -> settings -> digest newsletter settings. 1) Select the newsletter you wish to use for the digest newsletter 2) Set the time of day you wish the newsletter to go out to 00:00. 3) For the frequency settings, select "Week", "2", and under the "Weekly Settings", select "Friday" @@ -21,9 +25,9 @@ Let's say you want to send out a newsletter every two weeks on Friday at midnigh Installation ============ -Simply drop the module in /sites/all/modules and enable. No database table is needed for this module. +Simply drop the module in /sites/all/modules and enable. No database table is +needed for this module. TODO ==== --Make the email a little nicer to look at. --If no terms are selected, default to all terms in a vocabulary for the selected node types +- Make the email a little nicer to look at. diff --git a/simplenews_digest.info b/simplenews_digest.info index 0ec628b..da8cea0 100644 --- a/simplenews_digest.info +++ b/simplenews_digest.info @@ -1,11 +1,7 @@ name = Simplenews Digest -description = Packages up recently published stories into a newsletter and sends them via simplenews module at regularly scheduled intervals. +description = Packages up links to recently published content into a SimpleNews newsletter and sends it out to all subscribers at configurable intervals. dependencies[] = simplenews package = Mail core = 6.x -; Information added by drupal.org packaging script on 2009-01-04 -version = "6.x-1.x-dev" -core = "6.x" -project = "simplenews_digest" -datestamp = "1231028043" +version = "6.x-1.x-dev" diff --git a/simplenews_digest.module b/simplenews_digest.module index ff8b8d3..0329450 100644 --- a/simplenews_digest.module +++ b/simplenews_digest.module @@ -5,8 +5,8 @@ function simplenews_digest_menu() { $items = array(); $items['admin/settings/simplenews/digest_settings'] = array( - 'title' => 'Digest settings', - 'type' => MENU_NORMAL_ITEM, + 'title' => 'Newsletter digest', + 'type' => MENU_LOCAL_TASK, 'access arguments' => array('administer digest settings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('simplenews_digest_settings'), @@ -82,16 +82,31 @@ function simplenews_digest_settings() { '#type' => 'item', '#value' => simplenews_digest_get_status(), ); + + $form['timer_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Modify time keeping records'), + '#description' => 'For testing purposes only! Modify the date/time the system thinks that the digest newsletter was laslt sent out, as shown in the first line above. Start and end dates/times of the content selection process are based on it in combination with the hour and frequency settings below.' + ); + $timezone = variable_get('date_default_timezone', 0); + $last_time_sent = variable_get('simplenews_digest_last_time_sent', 0); + $form['timer_settings']['simplenews_digest_last_time_sent'] = array( + '#type' => 'textfield', + '#title' => 'Set time digest newsletter was last sent', + '#size' => 12, + '#description' => "System record currently shows $last_time_sent, i.e. ". gmdate('M j, Y h:i:s a', $last_time_sent + $timezone - 1) .'. This number is a Unix timestamp, ie. number of seconds. Example: 24 hours ago corresponds to '. (int)(time() - 24*60*60) . '. Use 0 to reset to module install time.', + '#default_value' => $last_time_sent + ); + $form['digest'] = array( '#type' => 'fieldset', '#title' => 'Digest newsletter selection', ); - foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) { $options[$newsletter->tid] = $newsletter->name; } $newsletters = $options; - $newsletter = (string)array_shift(array_keys($newsletters)); // Pick first newsletter if none selected + $newsletter = empty($options) ? NULL : (string)array_shift(array_keys($newsletters)); // Pick first newsletter if none selected $form['digest']['simplenews_digest_newsletter'] = array( '#type' => 'radios', '#title' => 'Newsletter', @@ -205,7 +220,8 @@ function simplenews_digest_settings() { asort($content_types); $form['digest_content']['simplenews_digest_content_types'] = array( '#type' => 'checkboxes', - '#title' => 'Send only the following types of content in the newsletter', + '#title' => 'Include only recently created content of the followinig types in the digest newsletter', + '#description' => 'Tick one or more content types.', '#options' => $content_types, '#default_value' => variable_get('simplenews_digest_content_types', array()), ); @@ -213,7 +229,8 @@ function simplenews_digest_settings() { '#type' => 'select', '#multiple' => TRUE, '#size' => 20, - '#title' => 'Send only content from these categories', + '#title' => 'Narrow down the selection above by restricting content to these categories only', + '#description' => 'Select zero or more category terms. Hold down the CTRL key to select more than one.', '#default_value' => variable_get('simplenews_digest_terms', 0), '#options' => taxonomy_form_all(), ); @@ -238,13 +255,13 @@ function simplenews_digest_get_status() { // Generate output for display if ($last_time_sent) { - $output .= '
Nodes created before: ' . gmdate('M j, Y h:i:s a', $last_time_sent + $timezone - 1) . ' have been sent.
'; + $output .= 'before ' . gmdate('M j, Y h:i:s a', $last_time_sent + $timezone - 1) . ' has been sent.
'; } else { $output .= '' . t('No digest newsletters have been sent.') . '
'; } if ($start_time) { - $output .= 'Newer nodes created between ' . gmdate('M j, Y h:i:s a', $start_time + $timezone) . ' and ' . gmdate('M j, Y h:i:s a', $end_time + $timezone) . ' will be sent out on a cron run per the settings below.
'; + $output .= 'Content created between ' . gmdate('M j, Y h:i:s a', $start_time + $timezone) . ' and ' . gmdate('M j, Y h:i:s a', $end_time + $timezone) . ' will be sent out on a cron run per the settings below.
'; } else { $output .= '' . t('No digest newsletters will be sent until you configure and save the digest newsletter settings below.') . '
'; @@ -407,13 +424,12 @@ function simplenews_digest_inject_node($current_time, $start_time, $end_time) { //rdpw($newsletter['body']); //debug //return; //debug; - $newsletter_tid = array($newsletter_term); $term = taxonomy_get_term($newsletter_term); if($newsletter['body']) { // Don't send anything unless there are new nodes $node->body = $newsletter['body']; $node->uid = 1; - $node->title = $term->name; + $node->title = $term->name . t(' [digest]'); $node->type = 'simplenews'; $node->teaser = node_teaser($node->body); $node->filter = variable_get('filter_default_format', 1); @@ -423,13 +439,22 @@ function simplenews_digest_inject_node($current_time, $start_time, $end_time) { $node->comment = 0; $node->created = time(); $node->changed = time(); - $node->taxonomy = $newsletter_tid; -// $node->send = 1; - $node->s_format = variable_get('simplenews_digest_format', 'plain'); + $node->taxonomy = array($term->vid => $term->tid); $node->priority = 0; $node->receipt = 0; - $node->simplenews = array('send' => SIMPLENEWS_COMMAND_SEND_NOW); // Necessary to send out the newsletter without further user interaction. + $node->simplenews = array( + 'tid' => $term->tid, + 's_status' => SIMPLENEWS_STATUS_SEND_PENDING, + 'advanced' => array( + 's_format' => variable_get('simplenews_digest_format', 'plain'), + 'priority' => 0, + 'receipt' => 0 + ) + ); node_save($node); + + module_load_include('inc', 'simplenews', 'includes/simplenews.mail'); + simplenews_send_node($node); } // Set and calculate new last, start, and end times @@ -458,9 +483,6 @@ function simplenews_digest_select_nodes($newsletter) { "WHERE t.tid IN ($term_placeholders) AND n.type IN ($type_placeholders) AND n.created >= %d AND n.created < %d AND n.status = 1 " . "ORDER BY n.created DESC"; $qs = db_query($query, array_merge($selected_terms, $selected_content_types, array($newsletter['start_time'], $newsletter['end_time']))); - //while($node = db_fetch_object($result)) { //debug - //print 'hi'; //debug - //} //debug } else { $query = "SELECT DISTINCT nid, type, title from {node} " . "WHERE type IN ($type_placeholders) AND created >= %d AND created < %d AND status = 1 " . @@ -471,12 +493,21 @@ function simplenews_digest_select_nodes($newsletter) { while ($obj = db_fetch_object($qs)) { $result[] = $obj; } - + + $timezone = variable_get('date_default_timezone', 0); + $start_time = gmdate('M j, Y h:i:s a', $newsletter['start_time'] + $timezone); + $end_time = gmdate('M j, Y h:i:s a', $newsletter['end_time'] + $timezone); + watchdog('simplenews_digest', t('@count nodes selected for the digest newsletter for the period %start to %end.', + array('@count' => count($result), + '%start' => $start_time, + '%end' => $end_time + ) + )); return $result; } // Generate the body of the newsletter -function theme_simplenews_digest_format_newsletter(&$newsletter) { +function theme_simplenews_digest_format_newsletter($newsletter) { // Get sections of newsletter, each section is a listing of links to nodes sorted by content type/date $content_types = variable_get('simplenews_digest_content_types', 0); $output_by_type = array(); @@ -485,7 +516,7 @@ function theme_simplenews_digest_format_newsletter(&$newsletter) { foreach ($newsletter['new_nodes'] as $node) { foreach($selected_content_types as $type) { if($node->type == $type) { - $output_by_type[$type] .= simplenews_digest_create_node_link($node) . "\n\n"; + $output_by_type[$type] .= "\n