Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.4
diff -u -F^f -r1.4 simplenews.module
--- simplenews.module	20 Jul 2005 11:16:11 -0000	1.4
+++ simplenews.module	29 Jul 2005 04:51:52 -0000
@@ -230,7 +230,8 @@ function simplenews_load($node) {
  * Implementation of hook_view().
  */
 function simplenews_view(&$node, $teaser = FALSE) {
-  $node = simplenews_replace_vars($node, TRUE);
+  $node->teaser = simplenews_replace_vars($node->teaser, $node);
+  $node->body = simplenews_replace_vars($node->body, $node);
   $node = module_invoke('node', 'prepare', $node, $teaser);
 }
 
@@ -425,34 +426,30 @@ function _sn_send($timer = FALSE) {
   $start_time = sn_time();
   $max_time = variable_get('simplenews_time', 5);
   $max_time = $max_time - 0.5;
+
   $result = db_query('SELECT s.nid, n.created FROM {node} n INNER JOIN {sn_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d ORDER BY n.created ASC', 1);
   while ($nid = db_fetch_object($result)) {
-     $node = module_invoke('node', 'load', array('nid' => $nid->nid));
-    $node = simplenews_replace_vars($node, FALSE);
+    $node = module_invoke('node', 'load', array('nid' => $nid->nid));
+    $node->body = simplenews_replace_vars($node->body, $node);
+    $node = module_invoke('node', 'prepare', $node, FALSE);
+
     if ($node->s_format == 'html') {
-      $node = module_invoke('node', 'prepare', $node, FALSE);
+      $footer_template = variable_get('simplenews_html_footer', '<p>--<br /><a href="%unsubscribe_uri">'.t('Click here to unsubscribe').'</a></p>');
     }
     else {
-      // first do node_prepare() to allow PHP-code to be parsed, then strip remaining HTML-tags
-      $node = module_invoke('node', 'prepare', $node, FALSE);
       $node->body = strip_tags($node->body);
+      $footer_template = variable_get('simplenews_plain_footer', "\n\n--\n".t('Unsubscribe link:').' %unsubscribe_uri');
     }
-    $address_default = variable_get('site_mail', ini_get('sendmail_from'));
-    $name_default = variable_get('site_name', 'drupal');
-    $node->from_address = variable_get('simplenews_from_address', $address_default);
-    $node->from_name = variable_get('simplenews_from_name', $name_default);
+
+    $node->from_address = variable_get('simplenews_from_address', variable_get('site_mail', ini_get('sendmail_from')));
+    $node->from_name = variable_get('simplenews_from_name', variable_get('site_name', 'drupal'));
     $node->encode = '';
+
     $result2 = db_query('SELECT mail, snid FROM {sn_subscriptions} WHERE s_status = %d AND a_status = %d', 0, 1);
     while ($mail = db_fetch_object($result2)) {
-      $md5 = md5($mail->mail);
-      $h = substr($md5, 0, 10).$mail->snid;
-      if ($node->s_format == 'html') {
-        $node->message = $node->body.'<p>--<br />'.l(t('Click here to unsubscribe'), 'newsletterconfirm/remove/'.$h, array(), NULL, NULL, TRUE).'</p>';
-      }
-      else {
-        $node->message = $node->body."\n\n--\n".t('Unsubscribe link:').' '.url('newsletterconfirm/remove/'.$h, NULL, NULL, TRUE);
-      }
+      $node->message = $node->body . simplenews_replace_vars($footer_template, $node, $mail);
       $node->to = $mail->mail;
+      
       if(sn_mail_send($node)) {
         db_query('UPDATE {sn_subscriptions} SET s_status = %d WHERE snid = %d', 1, $mail->snid);
       }
@@ -460,6 +457,7 @@ function _sn_send($timer = FALSE) {
         $message = t('Newsletter "%title" could not be sent to %email.', array('%title'=>check_plain($node->title), '%email'=>$mail->mail));
         watchdog('simplenews', $message, WATCHDOG_ERROR);
       }
+      
       if ($timer) {
         $int_time = sn_time();
       }
@@ -806,6 +804,8 @@ function simplenews_admin_settings() {
   variable_set('simplenews_send', $edit['send']);
   variable_set('simplenews_time', $edit['time']);
   variable_set('simplenews_from_name', $edit['from_name']);
+  variable_set('simplenews_plain_footer', $edit['plain_footer']);
+  variable_set('simplenews_html_footer', $edit['html_footer']);
     //valid_email_address() allows empty address, so check this first
     if ($edit['from_address'] == '') {
       drupal_set_message(t("You have to supply a sender's email address"), 'error');
@@ -846,6 +846,11 @@ function simplenews_admin_settings() {
   $group .= form_textfield(t('From address'), 'from_address', variable_get('simplenews_from_address', $address_default), 30, 35);
   $output .= form_group(t('Sender information'), $group);
   $output .= '<br />';
+
+  $group  = form_textarea(t('HTML Footer'), 'html_footer', variable_get('simplenews_html_footer', '<p>--<br /><a href="%unsubscribe_uri">'.t('Click here to unsubscribe').'</a></p>'), 72, 15);
+  $group .= form_textarea(t('Plain Text Footer'), 'plain_footer', variable_get('simplenews_plain_footer', "\n\n--\n".t('Unsubscribe link:').' %unsubscribe_uri'), 72, 15);
+  $output .= form_group(t('Footer text'), $group);
+  $output .= '<br />';
   
   $max_time = array(1, 2, 3, 4);
   for ($i = 5; $i < ini_get('max_execution_time'); $i=$i+5) {
@@ -971,14 +976,27 @@ function simplenews_confirm_add_user_sel
   return $output;
 }
 
-function simplenews_replace_vars($node, $teaser = TRUE) {
+function simplenews_replace_vars($text, $node = NULL, $mail = NULL) {
   global $base_url;
-  $variables = array('%site' => variable_get('site_name', 'drupal'), '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mymail' => $user->mail, '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE));
-  $node->body = strtr($node->body, $variables);
-  if ($teaser) {
-    $node->teaser = strtr($node->teaser, $variables);
+  global $user;
+  
+  $node_variables = array();
+  $mail_variables = array();
+  $default_variables = array('%site' => variable_get('site_name', 'drupal'), '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mymail' => $user->mail, '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE));
+  
+  if ($node) {
+    $node_variables = array('%archive_uri' => url('taxonomy/term/'.$node->tid.'/all', NULL, NULL, TRUE));
   }
-  return $node;
+  if ($mail) {
+    $h = substr(md5($mail->mail), 0, 10).$mail->snid;
+    $mail_variables = array('%unsubscribe_uri' => url('newsletterconfirm/remove/'.$h, NULL, NULL, TRUE));
+  }
+  
+  $variables = array_merge($node_variables, $mail_variables, $default_variables);
+  
+  $text = strtr($text, $variables);
+
+  return $text;
 }
