Index: emailpage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/emailpage/emailpage.module,v
retrieving revision 1.3
diff -u -r1.3 emailpage.module
--- emailpage.module	26 Oct 2004 10:08:05 -0000	1.3
+++ emailpage.module	25 Sep 2005 09:41:53 -0000
@@ -1,21 +1,25 @@
 <?php
 /* $Id: emailpage.module,v 1.3 2004/10/26 10:08:05 nick Exp $ */
 
+define('EMAILPAGE_SUBJECT_LINE', variable_get('emailpage_subject_line', t("thought you'd like to see this")));
+define('EMAILPAGE_TITLE', t('Email this page to a friend'));
+define('EMAILPAGE_MESSAGE', variable_get('emailpage_message', t('%someone thought you would like this page')."\n"));
+
 function emailpage_help($section) {
-  if ($section == "admin/modules#description") {
-    return t("Provides and \"email this page\" link to all nodes");
+  if ($section == 'admin/modules#description') {
+    return t('Provides and "email this page" link to all nodes');
   }
 }
 
 function emailpage_perm() {
-  return array("administer emailpage"); 
+  return array('administer emailpage'); 
 }
 
 function emailpage_menu($may_cache) {
   global $user;
   $items=array();
   if ($may_cache) {
-    $items[]=array('path' => "emailpage", 'title'=>t("email this page"),access=>1,'type'=>MENU_CALLBACK,'callback'=>'emailpage_page');
+    $items[]=array('path' => 'emailpage', 'title' => t('email this page'), access => 1, 'type' => MENU_CALLBACK, 'callback' => 'emailpage_page');
   }
   return $items;
 }
@@ -26,36 +30,37 @@
 
   // This var is set in the settings section under the admin/modules/emailpage section
   // It shows 'email this $nodetype' or 'email this page'
-  $e_l_t=variable_get('emailpage_link_type', 0);
+  $e_l_t = variable_get('emailpage_link_type', 0);
   if($e_l_t) {
-    if($type == "comment") {
-      $e_l_t = "comment";
-      $links[] = l(t("email this ".$e_l_t), "emailpage&nid=$node->nid&cid=$node->cid", array("title" => t("Email this page to a friend")), NULL);
+    if($type == 'comment') {
+      $e_l_t = 'comment';
+      $links[] = l(t('email this %type', array('%type' => t($e_l_t))), "emailpage&nid=$node->nid&cid=$node->cid", array('title' => EMAILPAGE_TITLE), NULL);
       return $links;
     }
     $e_l_t=$node->type;
-  } else $e_l_t="page";
+  } else {
+    $e_l_t = 'page';
+  }
 
     
   if($main) {  // not on an index page
     if(variable_get('emailpage_show_on_main', 0)) {  
-      $links[] = l(t("email this ".$e_l_t), "emailpage&nid=$node->nid", array("title" => t("Email this page to a friend")), NULL);
+      $links[] = l(t('email this %type', array('%type' => t($e_l_t))), "emailpage&nid=$node->nid", array('title' => EMAIL_PAGE_TITLE), NULL);
       return $links;
     }
   } else { // not on a main page
-    $links[] = l(t("email this ".$e_l_t), "emailpage&nid=$node->nid", array("title" => t("Email this page to a friend")), NULL);                                                                          return $links;
+    $links[] = l(t("email this ".$e_l_t), "emailpage&nid=$node->nid", array("title" => EMAILPAGE_TITLE), NULL);                                                                          return $links;
   }
 }
 
 function emailpage_page() {
   global $base_url;
 
-
   // first we check to see if they have reached the emailpage_flood_control limit
   // which is set in the settings.
   if($_COOKIE['emailpage_flood_count'] >= variable_get('emailpage_flood_control', 10)) {
-    $content=variable_get('emailpage_flood_error_msg', t("Sorry, you have reached the maximum number of emails allowed per user. Please try later"));
-    print theme("page", $content);
+    $content = variable_get('emailpage_flood_error_msg', t('Sorry, you have reached the maximum number of emails allowed per user. Please try again later'));
+    print theme('page', $content);
     return;
   }
 
@@ -72,7 +77,7 @@
       }
       // Set the refering page in a cookie
       // 5mins should be enuf for anyone to put in a valid email address ;-)
-      setcookie('referer', $nodelink, time()+300, '/', ".".$host['host']);
+      setcookie('referer', $nodelink, time()+300, '/', '.'.$host['host']);
     } else {
       $nodelink=$base_url;
     }
@@ -83,45 +88,45 @@
   //  we need to check if the form has been posted..
   if($_POST) {
     if(!user_validate_mail($_POST['edit']['emailpage_addy']) && $_POST['edit']['emailpage_sender'] && $_COOKIE['referer']) {  // all is well, so lets send it!
-      $headers="Reply-To: ".variable_get('emailpage_sender_addy', "")."\r\nFrom: ".variable_get('emailpage_sender_addy', "")."\r\n";
-      mail($_POST['edit']['emailpage_addy'], $_POST['edit']['emailpage_sender']." ".variable_get('emailpage_subject_line', "thought you'd like to see this"), $_COOKIE['referer']."\n\n".$_POST['edit']['emailpage_sender']." ".wordwrap(variable_get('emailpage_message',"someone thought you would like this page\n"), 72), $headers);
+      $headers = 'Reply-To: '. variable_get('emailpage_sender_addy', ''). "\r\nFrom: ". variable_get('emailpage_sender_addy', ''). "\r\n";
+      mail($_POST['edit']['emailpage_addy'], $_POST['edit']['emailpage_sender'].' '. EMAILPAGE_SUBJECT_LINE, $_COOKIE['referer']. "\n\n". wordwrap(str_replace('%someone', $_POST['edit']['emailpage_sender'], EMAILPAGE_MESSAGE), 72), $headers);
 
       // Delete the cookie
       // If we dont do this, sending other pages becomes messy.
-      setcookie('referer', "", time()-3600, '/', ".".$host['host']);
+      setcookie('referer', '', time()-3600, '/', '.'.$host['host']);
 
       // Increase the emailpage_flood_control cookie (check settings)
       setcookie('emailpage_flood_count', $_COOKIE['emailpage_flood_count']+1, time()+7200, '/', ".".$host['host']);
 
-      $content=variable_get('emailpage_success_msg', "Success!");
+      $content=variable_get('emailpage_success_msg', t('Success!'));
       variable_set('emailpage_total', variable_get('emailpage_total', 0)+1);
-	drupal_goto();
+      drupal_goto();
       return;
       
     } else {
     
-      $error="<p class=\"error\">You must supply your name and a valid email address</p>";
-      $form.=form_textfield(t("Your Name"), "emailpage_sender", $_POST['edit']['emailpage_sender'], 20, 30);
-      $form.=form_textfield(t("Address to send to"), "emailpage_addy", $_POST['edit']['emailpage_addy'], 20, 30);
-      $form.=form_submit("Send it Now!","");
-      $content.=$error;
-      $content.=form($form, "post", url("emailpage"));
-      $content.="<h2>Example  Email</h2>\n";
-      $content.="<p><strong>Subject: </strong>[Your Name] ".variable_get('emailpage_subject_line', "thought you'd like to see this")."</p>\n\n<p>".$nodelink."</p>\n\n<p>[Your Name] ".nl2br(variable_get('emailpage_message',"someone thought you would like this page\n"))."</p>";
-      print theme("page", $content);
+      $error = '<p class="error">'. t('You must supply your name and a valid email address.').'</p>';
+      $form .= form_textfield(t('Your Name'), 'emailpage_sender', $_POST['edit']['emailpage_sender'], 20, 30);
+      $form .= form_textfield(t('Address to send to'), 'emailpage_addy', $_POST['edit']['emailpage_addy'], 20, 30);
+      $form .= form_submit(t('Send it Now!'));
+      $content .= $error;
+      $content .= form($form, 'post', url('emailpage'));
+      $content .= '<h2>'. t('Example Email')."</h2>\n";
+      $content .= '<p><strong>'. t('Subject'). ': </strong>['. t('Your Name').'] '.EMAILPAGE_SUBJECT_LINE."</p>\n\n<p>".$nodelink."</p>\n\n<p>[".t('Your Name').'] '.nl2br(EMAILPAGE_MESSAGE).'</p>';
+      print theme('page', $content);
 
     }
   } 
 
   if(!$_POST) {
-    $form.=form_textfield(t("Your Name"), "emailpage_sender", $_POST['edit']['emailpage_sender'], 20, 30);
-    $form.=form_textfield(t("Address to send to"), "emailpage_addy", $_POST['edit']['emailpage_addy'], 20, 30);
-    $form.=form_submit("Send it Now!","");
-    $content.=form($form, "post", url("emailpage"));
-    $content.="<h2>Example  Email</h2>\n";
-    $content.="<p><strong>Subject: </strong>[Your Name] ".variable_get('emailpage_subject_line', "thought you'd like to see this")."</p>\n\n<p>".$nodelink."</p>\n\n<p>[Your Name] ".nl2br(variable_get('emailpage_message',"someone thought you would like this page\n"))."</p>";
+    $form .= form_textfield(t('Your Name'), 'emailpage_sender', $_POST['edit']['emailpage_sender'], 20, 30);
+    $form .= form_textfield(t('Address to send to'), 'emailpage_addy', $_POST['edit']['emailpage_addy'], 20, 30);
+    $form.=form_submit(t('Send it Now!'));
+    $content.=form($form, 'post', url('emailpage'));
+    $content .= '<h2>'. t('Example  Email'). "</h2>\n";
+    $content .= '<p><strong>'. t('Subject'). ': </strong>['. t('Your Name'). '] '. EMAILPAGE_SUBJECT_LINE. "</p>\n\n<p>". $nodelink. "</p>\n\n<p>[". t('Your Name'). '] '. nl2br(EMAILPAGE_MESSAGE). '</p>';
 
-    print theme("page", $content);
+    print theme('page', $content);
   }
 }
 
@@ -130,33 +135,20 @@
   global $base_url;
 
   // only administrators can access this module
-  if (!user_access("admin emailpage")) {
+  if (!user_access('admin emailpage')) {
       return message_access();
   }
 
-  $host=parse_url($base_url);
+  $host = parse_url($base_url);
 
-  $output="<p>Total emails sent to date: <strong>".variable_get('emailpage_total', 1)."</strong></p>\n";
-  $output.=form_radios('Reset the Counter?', 'emailpage_total', variable_get('emailpage_total', 0), array(1 => "Yes", variable_get('emailpage_total', 0) => "No"));
-  $output.=form_radios('Use node type to create link?', 'emailpage_link_type', variable_get('emailpage_link_type', 0), array(1 => "Yes", 0 => "No"), t("If yes, the link will read &quot;email this <em>nodetype</em>&quot;, if no, it will just read &quot;email this page&quot;"));
-  $output.=form_radios('Show link on index pages?', 'emailpage_show_on_main', variable_get('emailpage_show_on_main', 0), array(1 => "Yes", 0 => "No"), t("If yes, the email this page link will show on all teasers on the index pages as well as the individual nodes"));
-  $output.=form_select("Flood Control", "emailpage_flood_control", variable_get('emailpage_flood_control', 10), array(1 => "1", 2 => "2", 3 => "3", 4 => "4", 5 => "5", 6 => "6", 7 => "7", 8 => "8", 9 => "9", 10 => "10"), "How many times a user can use the form in a 2hr period. This prevents abusers from sending out unlimited amounts of unwanted mail from the emailpage module.");
-  $output.=form_textfield(t("Sender Address"), 'emailpage_sender_addy', 
-  variable_get('emailpage_sender_addy', "NoReply@".$host['host']), 30, 40, "The address to send FROM");
-  $output.=form_textfield(t("Subject Line"), 'emailpage_subject_line', 
-  variable_get('emailpage_subject_line', "thought you'd like to see this"), 30, 40, "The subject line will start with the senders name as the first word, you can edit the rest of the line above");
-  $output.=form_textarea(t("Message"), 'emailpage_message', variable_get('emailpage_message', " thought you would like to see the above page\n\n"), 40, 10, "The senders name will appear as the first word followed by the text in the textarea above");
-  $output.=form_textarea(t("Flood Control Error Msg"), 'emailpage_flood_error_msg', variable_get('emailpage_flood_error_msg', "Sorry, you have reached the maximum number of emails allowed per user. Please try later"), 40, 10, "This text appears if a user tries to email a page but has exceeded the flood control limit.");
+  $output = '<p>'. t('Total emails sent to date'). ': <strong>'. variable_get('emailpage_total', 1). "</strong></p>\n";
+  $output .= form_radios(t('Reset the Counter?'), 'emailpage_total', variable_get('emailpage_total', 0), array(1 => t('Yes'), variable_get('emailpage_total', 0) => t('No')));
+  $output .= form_radios(t('Use node type to create link?'), 'emailpage_link_type', variable_get('emailpage_link_type', 0), array(1 => t('Yes'), 0 => t('No')), t("If yes, the link will read &quot;email this <em>nodetype</em>&quot;, if no, it will just read &quot;email this page&quot;"));
+  $output .= form_radios(t('Show link on index pages?'), 'emailpage_show_on_main', variable_get('emailpage_show_on_main', 0), array(1 => t('Yes'), 0 => t('No')), t('If yes, the email this page link will show on all teasers on the index pages as well as the individual nodes'));
+  $output .= form_select(t('Flood Control'), 'emailpage_flood_control', variable_get('emailpage_flood_control', 10), drupal_map_assoc(range(1, 10)), t('How many times a user can use the form in a 2hr period. This prevents abusers from sending out unlimited amounts of unwanted mail from the emailpage module.'));
+  $output .= form_textfield(t('Sender Address'), 'emailpage_sender_addy', variable_get('emailpage_sender_addy', "NoReply@". $host['host']), 30, 40, t('The address to send FROM'));
+  $output .= form_textfield(t('Subject Line'), 'emailpage_subject_line', EMAILPAGE_SUBJECT_LINE, 30, 40, t("The subject line will start with the sender's name as the first word, you can edit the rest of the line above"));
+  $output .= form_textarea(t('Message'), 'emailpage_message', EMAILPAGE_MESSAGE. "\n\n", 40, 10, t("The sender's name will appear instead of the %someone placeholder"));
+  $output .= form_textarea(t('Flood Control Error Messsage'), 'emailpage_flood_error_msg', variable_get('emailpage_flood_error_msg', t('Sorry, you have reached the maximum number of emails allowed per user. Please try later')), 40, 10, t('This text appears if a user tries to email a page but has exceeded the flood control limit.'));
   return $output;
 }
-
-
-
-
-
-
-
-
-
-
-?>
