### Eclipse Workspace Patch 1.0
#P CVS simplenews HEAD
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/README.txt,v
retrieving revision 1.2
diff -u -r1.2 README.txt
--- README.txt	19 Dec 2006 20:34:41 -0000	1.2
+++ README.txt	8 May 2007 20:54:00 -0000
@@ -39,9 +39,7 @@
 - Enable the module by navigating to Administer -> Site building -> Modules.
 
 - Grant the proper access to user accounts under Administer -> User management
-  -> Access control. The most important setting is "access newsletters" for
-  all roles, including "anonymous user" if you want links to be displayed in
-  the Simplenews block to everyone.
+  -> Access control. 
 
 - Enable the Simplenews block by navigating to Administer -> Site building ->
   Blocks.
@@ -50,7 +48,26 @@
   Newsletters -> Settings.
 
 ------------
+Simplenews block
+------------
+
+Simplenews blocks are configured using the configure link of appropriate block on 
+the blocks admin page (Administer -> Site building -> Blocks). Using the block 
+specific settings the content of the block can be determined.
+
+Permission "subscribe to newsletters" is required to enable the subscription form 
+in the simplenews block or to enable the link to the subscription form.
+Links (to previous issues, previous issues and RSS-feed) are only displayed to 
+users who have "view links in block" privileges.
+
+More control over the content of simplenews blocks is possible using the block 
+theming. Additional variables are available for custom features:
+  $block['subscribed'] is TRUE if user is subscribed to the newsletter
+  $block['user'] is TRUE if the user is logged in (authenticated)
+  $block['tid'] is the term id number of the newsletter
+
+------------
 Credits
 ------------
-Written by
-  - Dries Knapen <drieske AT hotmail DOT com>
+Originally written by Dries Knapen.
+Currently maintained by RobRoy and Sutharsan.
Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.62
diff -u -r1.62 simplenews.module
--- simplenews.module	7 May 2007 19:27:18 -0000	1.62
+++ simplenews.module	8 May 2007 20:54:04 -0000
@@ -598,49 +598,122 @@
 /**
  * Implementation of hook_block().
  */
-function simplenews_block($op = 'list', $delta = 0) {
-  if ($op == 'list') {
-    $blocks = array();
-    foreach (taxonomy_get_tree(_simplenews_get_vid()) as $newsletter) {
-      $blocks['newsletter-'. $newsletter->tid] = array('info' => t('Newsletter: @title', array('@title' => $newsletter->name)));
-    }
-    return $blocks;
-  }
-  elseif ($op == 'view') {
-    list($type, $tid) = explode('-', $delta);
-    if ($type == 'newsletter') {
-      if ($newsletter = taxonomy_get_term($tid)) {
-        $block['subject'] = check_plain($newsletter->name);
-        $block['content'] = theme('simplenews_block', $newsletter);
+function simplenews_block($op = 'list', $delta = 0, $edit = array()) {
+  list($type, $tid) = explode('-', $delta);
+  
+  switch ($op) {
+    case 'list':
+      $blocks = array();
+      foreach (taxonomy_get_tree(_simplenews_get_vid()) as $newsletter) {
+        $blocks['newsletter-'. $newsletter->tid] = array('info' => t('Newsletter: @title', array('@title' => $newsletter->name)));
+      }
+      return $blocks;
+    case 'configure':
+      $form['simplenews_block_'. $delta]['simplenews_block_m_status_'. $tid] = array('#type' => 'checkbox',
+        '#title' => t('Display block message'),
+        '#return_value' => 1,
+        '#default_value' => variable_get('simplenews_block_m_status_'. $tid, 1),
+      );
+      $form['simplenews_block_'. $delta]['simplenews_block_m_'. $tid] = array('#type' => 'textfield',
+        '#title' => t('Block message'),
+        '#size' => 60,
+        '#maxlength' => 128,
+        '#default_value' => variable_get('simplenews_block_m_'. $tid, t('Stay informed on our latest news!')),
+      );
+      $form['simplenews_block_'. $delta]['simplenews_block_f_'. $tid] = array('#type' => 'checkbox',
+        '#title' => t('Display subscription form'),
+        '#return_value' => 1,
+        '#description' => t('If selected a subscription form is displayed, if not selected a link to the subscription page is displayed.'),
+        '#default_value' => variable_get('simplenews_block_f_'. $tid, 1),
+      );
+      $form['simplenews_block_'. $delta]['simplenews_block_l_'. $tid] = array('#type' => 'checkbox',
+        '#title' => t('Display link to previous issues'),
+        '#return_value' => 1,
+        '#default_value' => variable_get('simplenews_block_l_'. $tid, 1),
+        '#description' => t('Links (to previous issues, previous issues and RSS-feed) are only displayed to users who have "view links in block" privileges.'),
+      );
+      $form['simplenews_block_'. $delta]['simplenews_block_i_status_'. $tid] = array('#type' => 'checkbox',
+        '#title' => t('Display previous issues'),
+        '#return_value' => 1,
+        '#default_value' => variable_get('simplenews_block_i_status_'. $tid, 0),
+      );
+      $form['simplenews_block_'. $delta]['simplenews_block_i_'. $tid] = array('#type' => 'select',
+        '#title' => t('Number of issues to display'),
+        '#options' => drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10)),
+        '#default_value' => variable_get('simplenews_block_i_'. $tid, 5),
+      );
+      $form['simplenews_block_'. $delta]['simplenews_block_r_'. $tid] = array('#type' => 'checkbox',
+        '#title' => t('Display RSS-feed icon'),
+        '#return_value' => 1,
+        '#default_value' => variable_get('simplenews_block_r_'. $tid, 1),
+      );
+      return $form;
+    case 'save':
+        variable_set('simplenews_block_m_status_'. $tid, $edit['simplenews_block_m_status_'. $tid]);
+        variable_set('simplenews_block_m_'. $tid, $edit['simplenews_block_m_'. $tid]);
+        variable_set('simplenews_block_f_'. $tid, $edit['simplenews_block_f_'. $tid]);
+        variable_set('simplenews_block_l_'. $tid, $edit['simplenews_block_l_'. $tid]);
+        variable_set('simplenews_block_i_status_'. $tid, $edit['simplenews_block_i_status_'. $tid]);
+        variable_set('simplenews_block_i_'. $tid, $edit['simplenews_block_i_'. $tid]);
+        variable_set('simplenews_block_r_'. $tid, $edit['simplenews_block_r_'. $tid]);
+        break;
+    case 'view':
+      list($type, $tid) = explode('-', $delta);
+      if ($type == 'newsletter') {
+        if ($newsletter = taxonomy_get_term($tid)) {
+          $block['subject'] = check_plain($newsletter->name);
+          $block['content'] = theme('simplenews_block', _simplenews_block($newsletter->tid));
+        }
       }
-    }
-    return $block;
+      return $block;
   }
 }
-function theme_simplenews_block($newsletter) {
-  $output = '';
-  if (variable_get('simplenews_block_m_status_'. $newsletter->tid, 1)) {
-    $output .= '<p>'. variable_get('simplenews_block_m_'. $newsletter->tid, t('Stay informed on our latest news!')) .'</p>';
+
+/**
+ * Helper function: generate block content before theming
+ * 
+ */
+function _simplenews_block($tid) {
+  global $user;
+  $block = array();
+  $recent = simplenews_recent_newsletters($tid, variable_get('simplenews_block_i_'. $tid, 5));
+  
+  $block['subscribed'] = (simplenews_user_is_subscribed($user->mail, $tid) == TRUE);
+  $block['user'] = !empty($user->uid);
+  $block['tid'] = $tid;
+  $block['message'] = check_plain(variable_get('simplenews_block_m_'. $tid, t('Stay informed on our latest news!')));
+  if (user_access('subscribe to newsletters')) {
+    $block['form'] = drupal_get_form('simplenews_block_form', $tid);
+    $block['subscription-link'] = l(t('Manage my subscriptions'), 'newsletter/subscriptions'); 
   }
-  if (variable_get('simplenews_block_f_'. $newsletter->tid, 1) && user_access('subscribe to newsletters')) {
-    $output .= drupal_get_form('simplenews_block_form', $newsletter->tid);
+  if (user_access('view links in block') || user_access('administer newsletters')) {
+    $block['newsletter-link'] = l(t('Previous issues'), 'taxonomy/term/'. $tid);
+    $block['itemlist'] = theme('item_list', $recent, t('Previous issues'), 'ul', array('class' => 'newsletter-list'));
+    $block['rssfeed'] = theme('feed_icon', url('taxonomy/term/'. $tid .'/0/feed'));
   }
-  if ((!variable_get('simplenews_block_f_'. $newsletter->tid, 1)) && (user_access('subscribe to newsletters')) ){
-    $output .= '<p>'. l(t('Manage my subscriptions'), 'newsletter/subscriptions/'). '</p>';
+
+  return $block;
+}
+
+function theme_simplenews_block($block) {
+  $output = ''; 
+  if (variable_get('simplenews_block_m_status_'. $block['tid'], 1) && !empty($block['message'])) {
+    $output .= "<p>". $block['message'] ."</p>\n";
   }
-  if (user_access('view links in block') || user_access('administer newsletters')) {
-    if (variable_get('simplenews_block_l_'. $newsletter->tid, 1)) {
-      $output .= l(t('Previous issues'), 'taxonomy/term/'. $newsletter->tid);
-    }
-    elseif (variable_get('simplenews_block_i_status_'. $newsletter->tid, 0)) {
-      $output .= t('Previous issues');
-    }
-    if (variable_get('simplenews_block_i_status_'. $newsletter->tid, 0)) {
-      $output .= simplenews_recent_newsletters($newsletter->tid, variable_get('simplenews_block_i_'. $newsletter->tid, 5));
-    }
-    if (variable_get('simplenews_block_r_'. $newsletter->tid, 1)) {
-      $output .= theme('feed_icon', url('taxonomy/term/'. $newsletter->tid .'/0/feed'));
-    }
+  if (variable_get('simplenews_block_f_'. $block['tid'], 1)) {
+    $output .= $block['form'];
+  }
+  else {
+    $output .= "<p>". $block['subscription-link']. "</p>\n";
+  }
+  if (variable_get('simplenews_block_l_'. $block['tid'], 1)) {
+    $output .= $block['newsletter-link'];
+  }
+  if (variable_get('simplenews_block_i_status_'. $block['tid'], 0)) {
+    $output .= $block['itemlist'];
+  }
+  if (variable_get('simplenews_block_r_'. $block['tid'], 1)) {
+    $output .= $block['rssfeed'] ."\n";
   }
   return $output;
 }
@@ -915,14 +988,13 @@
 }
 
 function simplenews_recent_newsletters($tid, $count = 5, $title = NULL) {
-  $result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.created FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {simplenews_newsletters} sn ON n.nid = sn.nid WHERE (t.tid = %d AND n.status = 1 AND sn.s_status > 0) ORDER BY n.created DESC'), $tid, 0, $count);
+  $result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, sn.s_status FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {simplenews_newsletters} sn ON n.nid = sn.nid WHERE (t.tid = %d AND n.status = 1 AND sn.s_status > 0) ORDER BY n.created DESC'), $tid, 0, $count);
   $titles = array();
   while ($item = db_fetch_object($result)) {
-    $titles[] = l($item->title, 'node/'. $item->nid);
-  }
-  if ($titles) {
-    return theme('item_list', $titles, $title);
+    $titles[$item->nid]['data'] = l($item->title, 'node/'. $item->nid);
+    $titles[$item->nid]['class'] = 'newsletter-issue newsletter-'. ($item->s_status > 0)? 'send' : 'created';
   }
+  return $titles;  
 }
 
 /**
