--- forward.module	2007-10-13 13:41:39.000000000 -0400
+++ forward.module	2007-10-19 13:24:34.000000000 -0400
@@ -121,7 +121,7 @@ function forward_admin_settings() {
     '#type' => 'select',
     '#title' => t('Form Type'),
     '#default_value' => variable_get('forward_form_type', 'link'),
-    '#options' => array('link' => 'link', 'form' => 'form'),
+    '#options' => array('link' => 'link', 'form' => 'form', "block_link" => "block_link", "block_form" => "block_form"),
     '#description' => t('Select link for a forward this page link or form to use a collapsible forwarding form.'),
   );
   $form['forward_options']['forward_flood_control'] = array(
@@ -384,8 +384,94 @@ function forward_form($nid = null, $node
   return $form;
 }
 
+function forward_form_block_body() {
+  global $user;
+  $form['message'] = array(
+	'#type' => 'fieldset',
+	'#title' => t('Forward this page to a friend'),
+	'#description' => '',
+	'#collapsed' => true,
+	'#collapsible' => true,
+  );
+  $form['message']['yemail'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Your Email'),
+    '#default_value' => $user->mail,
+//    '#size' => 58,
+    '#maxlength' => 256,
+    '#description' => NULL,
+    '#attributes' => NULL,
+    '#required' => TRUE,
+  );
+  $form['message']['yname'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Your Name'),
+    '#default_value' => $user->name,
+//    '#size' => 58,
+    '#maxlength' => 256,
+    '#description' => NULL,
+    '#attributes' => NULL,
+    '#required' => TRUE,
+  );
+  $form['message']['recipients'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Send To'),
+    '#default_value' => str_replace('\n', ', ', $recipients),
+    '#size' => 58,
+    '#description' => t('Enter multiple addresses by separateing them with commas.'),
+    '#attributes' => NULL,
+    '#required' => TRUE,
+  );
+  $form['message']['subject'] = array(
+    '#type' => 'hidden',
+    '#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'))),
+    '#description' => '',
+  );
+  $form['message']['body'] = array(
+    '#type' => 'hidden',
+    '#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'))),
+    '#description' => '',
+  );
+  $form['message']['message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Your Personal Message'),
+    '#default_value' => '',
+    '#cols' => 50,
+    '#rows' => 10,
+    '#description' => '',
+    '#attributes' => NULL,
+    '#required' => TRUE,
+  );
+	if (is_numeric(arg(1))) {
+		$node= node_load(arg(1));
+	  $form['message']['nid'] = array(
+	    '#type' => 'hidden',
+	    '#value' => $node->nid,
+	  );
+	}
+	$form['#validate'] = array(
+		'forward_form_validate' => array()
+	);
+	$form['#submit'] = array(
+		'forward_form_submit' => array()
+	);
+	$form['message']['forward_footer'] = array(
+    '#type' => 'hidden',
+    '#value' => variable_get('forward_footer', ''),
+  );
+  $form['message']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Send Message'),
+  );
+
+  $form['#method'] = 'post';
+  return $form;
+}
+
 /**
- * Generate nodeapi integration, foward signup
+ * Generate nodeapi integration, forward signup
  */
 function forward_nodeapi(&$node, $op, $teaser = 0) {
   if ((variable_get('forward_form_type', 'link') == 'form') && (!$node->in_preview) && (variable_get('forward_display_'. $node->type, '1') == 1) && (!$teaser || variable_get('forward_show_teasers', 0))) {
@@ -396,6 +482,8 @@ function forward_nodeapi(&$node, $op, $t
         break;
     }
   }
+  elseif ((variable_get('forward_form_type', 'link') == 'block_form') && (!$node->in_preview) && (variable_get('forward_display_'. $node->type, '1') == 1) && (!$teaser || variable_get('forward_show_teasers', 0))) {
+  }
 }
 
 function forward_form_validate($form_id, &$form) {
@@ -642,55 +730,104 @@ function forward_block($op = 'list', $de
   switch ($op) {
     case 'list':
       $blocks[0]['info'] = t('Most Emailed');
+      $blocks[1]['info'] = t('Forward');
       return $blocks;
     case 'configure':
-      $block_options = array(
-        'today' => t('Most Emailed Today'),
-        'week' => t('Most Emailed This Week'),
-        'allTime' => t('Most Emailed of All Time'),
-        'recent' => t('Most Recently Emailed')
-      );
-      $form['forward_block_type'] = array(
-        '#type' => 'radios',
-        '#title' => t('Block Type'),
-        '#default_value' => variable_get('forward_block_type', " "),
-        '#options' => $block_options,
-        '#description' => t('Choose the block type'),
-        '#required' => null,
-        '#attributes' => true,
-      );
-      return $form;
+	  $form = array();
+	  switch ($delta) {
+	    case '0':
+		  $block_options = array(
+			'today' => t('Most Emailed Today'),
+			'week' => t('Most Emailed This Week'),
+			'allTime' => t('Most Emailed of All Time'),
+			'recent' => t('Most Recently Emailed')
+		  );
+		  $form['forward_block_type'] = array(
+			'#type' => 'radios',
+			'#title' => t('Block Type'),
+			'#default_value' => variable_get('forward_block_type', " "),
+			'#options' => $block_options,
+			'#description' => t('Choose the block type'),
+			'#required' => null,
+			'#attributes' => true,
+		  );
+	  }
+	  return $form;
     case 'save':
-      variable_set('forward_block_type', $edit['forward_block_type']);
-      break;
+	  switch ($delta) {
+		case '0':
+		  variable_set('forward_block_type', $edit['forward_block_type']);
+	      break;
+	  }
     case 'view':
       if (user_access('access content')) {
-        switch (variable_get('forward_block_type', 'allTime')) {
-          case 'today':
-            $pastday = time()-(24 * 60 * 60);
-            $query="SELECT n.nid, n.title, count(*) AS cnt FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type='sent' AND n.status=1 AND timestamp > ". $pastday .' GROUP BY n.nid, n.title ORDER BY cnt DESC';
-            $block['subject'] = t("Today's Most Emailed");
-            $block['content'] = node_title_list(db_query_range($query, 0, 5));
-            break;
-          case 'week':
-            $pastweek = time()-(7 * 24 * 60 * 60);
-            $query="SELECT n.nid, n.title, count(*) AS cnt FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type='sent' AND n.status=1 AND timestamp > ". $pastweek .' GROUP BY n.nid, n.title ORDER BY cnt DESC';
-            $block['subject'] = t("This Week's Most Emailed");
-            $block['content'] = node_title_list(db_query_range($query, 0, 5));
-            break;
-          case 'allTime':
-            $query="SELECT n.nid, n.title, count(*) AS cnt FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type='sent' AND n.status=1 GROUP BY n.nid, n.title ORDER BY cnt DESC";
-            $block['subject'] = t("Most Emailed");
-            $block['content'] = node_title_list(db_query_range($query, 0, 5));
-            break;
-          case 'recent':
-            $query="SELECT DISTINCT n.nid, n.title FROM {node} n LEFT JOIN {forward_log} s ON s.nid = n.nid WHERE s.timestamp <> '0' AND s.type='SENT' AND n.status = 1 ORDER BY s.timestamp DESC";
-            $block['subject'] = t("Most Recently Emailed");
-            $block['content'] = node_title_list(db_query_range($query, 0, 5));
-            break;
-        }
-        return $block;
-      }
+	  switch ($delta) {
+		case '0':
+		  if (user_access('access content')) {
+	        switch (variable_get('forward_block_type','allTime')) {
+	          case 'today':
+	            $pastday = time()-(24 * 60 * 60);
+	            $query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" AND timestamp > '.$pastday.' GROUP BY n.nid DESC';
+	            $block['subject'] = t("Today's Most Emailed");
+	            $block['content'] = node_title_list(db_query_range($query, 0, 5));
+	            break;
+	          case 'week':
+	            $pastweek = time()-(7 * 24 * 60 * 60);
+	            $query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" AND timestamp > '.$pastweek.' GROUP BY n.nid DESC';
+	            $block['subject'] = t("This Week's Most Emailed");
+	            $block['content'] = node_title_list(db_query_range($query, 0, 5));
+	            break;
+	          case 'allTime':
+	            $query='SELECT n.nid, n.title, count(*) FROM {forward_log} s LEFT JOIN {node} n ON s.nid = n.nid WHERE s.type="sent" GROUP BY n.nid DESC';
+	            $block['subject'] = t("Most Emailed");
+	            $block['content'] = node_title_list(db_query_range($query, 0, 5));
+	            break;
+	          case 'recent':
+	            $query="SELECT DISTINCT n.nid, n.title FROM {node} n LEFT JOIN {forward_log} s ON s.nid = n.nid WHERE s.timestamp <> '0' AND s.type='SENT' AND n.status = 1 ORDER BY s.timestamp DESC";
+	            $block['subject'] = t("Most Recently Emailed");
+	            $block['content'] = node_title_list(db_query_range($query, 0, 5));
+	            break;
+	        }
+	        return $block;
+	      }
+		break;
+		case '1':
+		  if (user_access('access forward') && variable_get('forward_form_type', 'link') == "block_link" && !$node->in_preview) {
+			$forward_link_type = variable_get('forward_link_type', 0);
+			if ($forward_link_type) {
+			  if ($type == 'comment') {
+			    $forward_link_type = 'comment';
+			  }
+			  else {
+				$forward_link_type = $node->type;}
+			  }
+			  else {
+				$forward_link_type = 'page';
+			  }
+
+			  // Work out if this is a node page.  We don't want to go adding
+			  // links anywhere but on the front page or on nodes.  Without 
+			  // this logic, pages such as /event end up with an "email this page" link
+			  // that does not actually email that page.
+			  $path = drupal_get_normal_path($_GET['q']);
+			  list($node_url, $nid) = array_values(explode('/', $path));
+
+			  if ($node_url == 'node' && (!$main || variable_get('forward_show_on_main', 0)) && $nid != NULL) {
+			    $link = l(t('Email this !type', array('!type' => $forward_link_type)), 'forward/'.$nid, array('title' => t('Forward this page to a friend'), 'class' => 'forward-page'));
+			    $block['subject'] = t("Forward");
+			    $block['content'] = $link;
+			}
+			return $block;
+		  }
+		  if (user_access('access forward') && variable_get('forward_form_type', 'link') == "block_form" && !$node->in_preview) {
+				$output = drupal_get_form('forward_form_block_body');
+				$block['subject'] = t("Forward");
+				$block['content'] = $output;
+			return $block;
+		  }
+		break;
+	  }
+	}
   }
 }
 
@@ -714,4 +851,4 @@ function forward_top5_list($query, $base
 
 function _forward_column_width($column, $width = 35) {
   return (strlen($column) > $width ? substr($column, 0, $width) .'...' : $column);
-}
\ No newline at end of file
+}
