Index: forward.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/forward/forward.module,v
retrieving revision 1.50
diff -u -r1.50 forward.module
--- forward.module	13 Jul 2007 19:45:25 -0000	1.50
+++ forward.module	17 Jul 2007 15:33:34 -0000
@@ -21,7 +21,7 @@
  * Permissions
  */
 function forward_perm() {
-  return array('access forward', 'administer forward');
+  return array('access forward', 'administer forward','access forward path','access forward referrer');
 }
 
 /**
@@ -39,6 +39,22 @@
       'type'     => MENU_CALLBACK
     );
     $items[] = array(
+      'path'     => 'forward/path',
+      'title'    => t('Forward this page'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('forward_form','path',FALSE),
+      'access'   => (user_access('access forward path')),
+      'type'     => MENU_CALLBACK
+    );
+    $items[] = array(
+      'path'     => 'forward/referrer',
+      'title'    => t('Forward this page'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('forward_form','referrer',FALSE),
+      'access'   => (user_access('access forward referrer')),
+      'type'     => MENU_CALLBACK
+    );
+    $items[] = array(
       'path'     => 'admin/logs/forward',
       'description'  => 'Track forwarded posts',
       'title'    => t('Forward tracking'),
@@ -229,6 +245,64 @@
     '#rows' => 4,
     '#description' => t('This message will be postpended as a footer message to the email.'),
   );
+  $form['forward_path_values'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Forward Path Form Default Values'),
+    '#collapsible' => true,
+    '#collapsed' => true
+  );
+  $form['forward_path_values']['forward_pathsubject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Forward Path Message Subject'),
+    '#default_value' => variable_get('forward_pathsubject', t('!name has forwarded a page to you from !site')),
+    '#size' => 40,
+    '#maxlength' => 256,
+    '#description' => t('Email subject line.  The sender\'s name will appear in place of !name in the subject.  The web site name will be inserted in place of !site.'),
+  );
+  $form['forward_path_values']['forward_pathmessage'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Forward Path Message Body'),
+    '#default_value' => variable_get('forward_pathmessage', t('!name thought you would like to see this page from the !site web site.')),
+    '#cols' => 40,
+    '#rows' => 10,
+    '#description' => t('Email message body.  The sender\'s name will appear in place of !name in the message body.  The web site name will be inserted in place of !site.  The sender will be able to add their own message after this.'),
+  );
+  $form['forward_referrer_values'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Forward Referrer Form Default Values'),
+    '#collapsible' => true,
+    '#collapsed' => true
+  );
+  $form['forward_referrer_values']['forward_referrerdomains'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Forward Referrer Allowed Domains'),
+    '#default_value' => variable_get('forward_referrerdomains', ''),
+    '#size' => 40,
+    '#maxlength' => 256,
+    '#description' => t('Allowed domains, comma-separated. Unless specifically listed here, with exact full domain, the forward request will be denied.'),
+  );
+  $form['forward_referrer_values']['forward_referrersubject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Forward Referrer Message Subject'),
+    '#default_value' => variable_get('forward_referrersubject', t('!name has forwarded a page to you from !site')),
+    '#size' => 40,
+    '#maxlength' => 256,
+    '#description' => t('Email subject line.  The sender\'s name will appear in place of !name in the subject.  The referred web site url will be inserted in place of !site.'),
+  );
+  $form['forward_referrer_values']['forward_referrermessage'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Forward Referrer Message Body'),
+    '#default_value' => variable_get('forward_referrermessage', t('!name thought you would like to see this page from the !site web site.')),
+    '#cols' => 40,
+    '#rows' => 10,
+    '#description' => t('Email message body.  The sender\'s name will appear in place of !name in the message body.  The referred web site url will be inserted in place of !site.  The sender will be able to add their own message after this.'),
+  );
+  $form['forward_dynamic_values'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Forward Form Dynamic Content'),
+    '#collapsible' => true,
+    '#collapsed' => false
+  );
   $dyn_options = array(
     'node' => t('Latest Blog Articles'),
     'user' => t('Latest Users'),
@@ -236,7 +310,7 @@
     'popular' => t('Most Popular Content'),
     'none' => t('None')
   );
-  $form['forward_default_values']['forward_dynamic_block'] = array(
+  $form['forward_dynamic_values']['forward_dynamic_block'] = array(
     '#type' => 'radios',
     '#title' => t('Dynamic Block'),
     '#default_value' => variable_get('forward_dynamic_block', 'none'),
@@ -264,18 +338,65 @@
 /**
  * Form
  */
-function forward_form($nid = null, $nodeapi = FALSE) {
+function forward_form($arg = null, $nodeapi = FALSE) {
   global $base_url, $user;
 
   $form = array();
 
-  if ($nid != '') {
+  if (is_numeric($arg)) {
+    $nid = $arg;
     $emailtype = 'email';
     $form['node'] = array('#type' => 'value', '#value' => node_load((int)$nid));
   }
+  elseif ('referrer' == $arg) {
+    $emailtype = 'referrer';
+    if (count($_POST)) { // carry over the hidden page_url value
+      $url = $_POST['page_url'];
+    }
+    else { 
+      $url = $_SERVER['HTTP_REFERER'];
+    }
+    if (!$url) { // no direct access allowed!
+      drupal_set_message('No direct access to this page!');
+      return drupal_access_denied(); 
+    }
+    else {  // test that referrer domain is explicitly allowed
+      $parsed_url = parse_url($url);
+      $allowed = explode(',',variable_get('forward_referrerdomains', ''));
+      if (!in_array($parsed_url['host'],$allowed)) {
+        drupal_set_message($url.': domain is not an allowed referrer!');
+        # drupal_set_message('%domain is not an allowed referrer!',array('%domain' => $parsed_url['host']));
+        return drupal_access_denied(); 
+      }
+    }
+    $form['message']['page_url'] = array(
+      '#type' => 'hidden',
+      '#value' => $url,
+    );
+  }
+  elseif ('path' == $arg) {
+    $args = explode('/',$_GET['q']);
+    array_shift($args);
+    array_shift($args);
+    $path = implode('/',$args);
+    $emailtype = 'path';
+    $form['message']['page_url'] = array(
+      '#type' => 'hidden',
+      '#value' => $path
+    );
+  }
   else {
     $emailtype = 'postcard';
   }
+  $form['message']['emailtype'] = array(
+    '#type' => 'hidden',
+    '#value' => $emailtype,
+  );
+  $site_name = ($emailtype == 'referrer') ? $url : variable_get('site_name','http://'.$_SERVER['HTTP_HOST']);
+  $form['message']['site_name'] = array(
+    '#type' => 'hidden',
+    '#value' => $site_name
+  );
   
   if ($nodeapi == TRUE) {
     $form['message'] = array(
@@ -316,23 +437,42 @@
     '#attributes' => null,
     '#required' => true,
   );
-  if (($emailtype == 'email') && ($nodeapi == FALSE)) {
-    $form['message']['page'] = array(
-      '#type' => 'item',
-      '#title' => t('You are going to email the following'),
-      '#value' => l($form['node']['#value']->title, "node/" . $form['node']['#value']->nid),
-    );
+  if ($nodeapi == FALSE) {
+    switch($emailtype) {
+      case 'email':
+        $form['message']['page'] = array(
+          '#type' => 'item',
+          '#title' => t('You are going to email the following'),
+          '#value' => l($form['node']['#value']->title, "node/" . $form['node']['#value']->nid),
+        );
+        break;
+      case 'path': 
+        $form['message']['page'] = array(
+          '#type' => 'item',
+          '#title' => t('You are going to email the following url:'),
+          '#value' => url($path,NULL,NULL,TRUE)
+        );
+        break;
+      case 'referrer':
+        $form['message']['page'] = array(
+          '#type' => 'item',
+          '#title' => t('You are going to email the following url:'),
+          '#value' => $url
+        );
+        break;
+    }
   }
+  
   $form['message']['subject'] = array(
     '#type' => 'item',
     '#title' => t('Message Subject'),
-    '#value' => t(variable_get('forward_'. $emailtype .'subject', '!name has sent you a message from !site'), array('!name' => t('(Your Name)'), '!site' => variable_get('site_name', 'drupal'))),
+    '#value' => t(variable_get('forward_'. $emailtype .'_subject', '!name has sent you a message from !site'), array('!name' => t('(Your Name)'), '!site' => $site_name)),
     '#description' => '',
   );
   $form['message']['body'] = array(
     '#type' => 'item',
     '#title' => t('Message Body'),
-    '#value' => t(variable_get('forward_'. $emailtype .'message', '!name thought you would like to see the !site web site.'), array('!name' => t('(Your Name)'), '!site' => variable_get('site_name', 'drupal'))),
+    '#value' => t(variable_get('forward_'. $emailtype .'_message', '!name thought you would like to see the !site web site.'), array('!name' => t('(Your Name)'), '!site' => $site_name)),
     '#description' => '',
   );
   $form['message']['message'] = array(
@@ -432,6 +572,8 @@
 }
 
 function forward_form_submit($form_id, $edit) {
+  global $base_url;
+
   // Prepare the sender:
   $from = $edit['mail'];
   // Compose the body:
@@ -462,12 +604,13 @@
   }
 
   if (!$edit['nid']) {
-    $emailtype = 'postcard';
+    $emailtype = $edit['emailtype'];
     $nid = '';
     $content_title = '';
     $content_name = '';
     $content_teaser = '';
-    $returnurl = drupal_get_path_alias('');
+    $page_title = $edit['page_title'] ? $edit['page_title'] : t('Click here to visit the site.');
+    $page_url = $edit['page_url'] ? $edit['page_url'] : drupal_get_path_alias('');
   }
   else {
     $nid = $edit['nid'];
@@ -475,14 +618,18 @@
     //Get article information.
     $content = node_load($nid);
     $content->teaser = check_markup($content->teaser, $content->format, false);
-    $returnurl = drupal_get_path_alias('node/'. $nid);
+    $page_url = drupal_get_path_alias('node/'. $nid);
+    $page_title = $content->title;
   }
+  $site_name = $edit['site_name'];
   $vars = array(
     'forward_header_image' => variable_get('forward_header_image', ''),
-    'site_name' => variable_get('site_name', 'Drupal'),
+    'site_name' => $site_name,
     'yemail' => $edit['yemail'],
-    'forward_message' => t(variable_get('forward_'. $emailtype .'message', '!name thought you would like to see the !site web site.'), array('!name' => l($edit['yname'], 'mailto:'. $edit['yemail'], null, null, null, true), '!site' => variable_get('site_name', 'drupal'))),
+    'forward_message' => t(variable_get('forward_'. $emailtype .'message', '!name thought you would like to see the !site web site.'), array('!name' => l($edit['yname'], 'mailto:'. $edit['yemail'], null, null, null, true), '!site' => $site_name)),
     'message' => $edit['message'],
+    'page_url' => $page_url,
+    'page_title' => $page_title,
     'base_url' => $base_url,
     'content' => $content,
     'dynamic_content' => $dynamic_content,
@@ -491,7 +638,10 @@
   );
 
   $body = theme('forward_'. $emailtype, $vars);
-  $subject = t(variable_get('forward_'. $emailtype .'subject', '!name has sent you a message from !site'), array('!name' => $edit['yname'], '!site' => variable_get('site_name', 'drupal')));
+  if (!$body) {
+    $body = theme('forward_default', $vars);
+  }
+  $subject = t(variable_get('forward_'. $emailtype .'subject', '!name has sent you a message from !site'), array('!name' => $edit['yname'], '!site' => $site_name));
 
   $from = $edit['yemail'];
   $headers['MIME-Version'] = '1.0';
@@ -512,8 +662,9 @@
 
   flood_register_event('forward');
 
-  drupal_set_message(variable_get('forward_thankyou', t('Thank you for your help in spreading the word about') .' '. variable_get('site_name', 'drupal') .'. '. t('We appreciate your help.')), 'status');
-  return $returnurl;
+  drupal_set_message(variable_get('forward_thankyou', t('Thank you for your help in spreading the word about') .' '. $site_name .'. '. t('We appreciate your help.')), 'status');
+  // return to the page being forwarded
+  return $page_url;
 }
 
 /**
@@ -695,4 +846,4 @@
 
 function _forward_column_width($column, $width = 35) {
   return (strlen($column) > $width ? substr($column, 0, $width) .'...' : $column);
-}
\ No newline at end of file
+}
Index: forward.theme
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/forward/forward.theme,v
retrieving revision 1.5
diff -u -r1.5 forward.theme
--- forward.theme	17 Jan 2007 22:14:12 -0000	1.5
+++ forward.theme	17 Jul 2007 15:33:34 -0000
@@ -69,7 +69,7 @@
  * @param vars
  *   An array of email variables
  */
-function theme_forward_postcard($vars) {
+function theme_forward_default($vars) {
 
   $style = "<style>
      <!--
@@ -102,7 +102,7 @@
         <div class="frm_title">'.t('Message from Sender').':</div>
         <div class="frm_txt">'.$vars['message'].'</div>';}
         $output .= '
-        <div class="links">'.l(t('Click here to visit our site'), 'forward/emailref/'.$vars['nid'],NULL,NULL,NULL,TRUE).'</div>
+        <div class="links">'.l($vars['page_title'], $vars['page_url'],NULL,NULL,NULL,TRUE).'</div>
         <div class="dyn_content"><br />'.$vars['dynamic_content'].'</div>
         <div class="ad_footer"><br />'.$vars['forward_ad_footer'].'<br></div>
       </div>
@@ -114,4 +114,4 @@
   return $output;
 }
 
-?>
\ No newline at end of file
+?>
