Index: INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tellafriend/INSTALL.txt,v
retrieving revision 1.1
diff -u -r1.1 INSTALL.txt
--- INSTALL.txt	31 Jan 2005 19:25:55 -0000	1.1
+++ INSTALL.txt	25 Apr 2007 16:58:16 -0000
@@ -1,22 +1,23 @@
-TELLAFRIEND MODULE - INSTALL
+TELLAFRIEND MODULE - README
 ---------------------------
 
-This module creates a "tell-a-friend" page to direct traffic towards your site.
+This module creates a "tell-a-friend" page(located at http://www.example.com/drupal/?q=tellafriend) to direct traffic towards your site.
 
 Requirements
 ------------
 
-This module tested with Drupal 4.5.2. No database modifications required.
+This module tested with Drupal 5.1. No database modifications required.
 
 
 Installation
 ------------
 
-1. Drop file in Modules directory.
-2. Set all settings in Settings->Tellafriend
-3. Page exists at path 'tellafriend'. Change with a URL alias if you'd like.
+1. Install the module.
+2. Set all settings in Administer -> Site configuration -> Tell a friend.
+3. Form page exists at path 'http://www.example.com/drupal/?q=tellafriend'. Change with a URL alias if you had like to.
 
 
-Author
-------
-sbulua <sbulua@middlebury.edu>
+Authors
+------------
+Version 4.5.2 author: sbulua <sbulua@middlebury.edu>
+Upgrade for 5.x: Gurpartap Singh - http://drupal.org/user/41470
\ No newline at end of file
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tellafriend/README.txt,v
retrieving revision 1.1
diff -u -r1.1 README.txt
--- README.txt	31 Jan 2005 19:25:55 -0000	1.1
+++ README.txt	25 Apr 2007 16:58:10 -0000
@@ -1,22 +1,23 @@
 TELLAFRIEND MODULE - README
 ---------------------------
 
-This module creates a "tell-a-friend" page to direct traffic towards your site.
+This module creates a "tell-a-friend" page(located at http://www.example.com/drupal/?q=tellafriend) to direct traffic towards your site.
 
 Requirements
 ------------
 
-This module tested with Drupal 4.5.2. No database modifications required.
+This module tested with Drupal 5.1. No database modifications required.
 
 
 Installation
 ------------
 
-1. Drop file in Modules directory.
-2. Set all settings in Settings->Tellafriend
-3. Page exists at path 'tellafriend'. Change with a URL alias if you'd like.
+1. Install the module.
+2. Set all settings in Administer -> Site configuration -> Tell a friend.
+3. Form page exists at path 'http://www.example.com/drupal/?q=tellafriend'. Change with a URL alias if you had like to.
 
 
-Author
-------
-sbulua <sbulua@middlebury.edu>
\ No newline at end of file
+Authors
+------------
+Version 4.5.2 author: sbulua <sbulua@middlebury.edu>
+Upgrade for 5.x: Gurpartap Singh - http://drupal.org/user/41470
\ No newline at end of file
Index: tellafriend.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tellafriend/tellafriend.module,v
retrieving revision 1.3
diff -u -r1.3 tellafriend.module
--- tellafriend.module	3 Feb 2005 22:36:39 -0000	1.3
+++ tellafriend.module	25 Apr 2007 22:38:56 -0000
@@ -1,49 +1,51 @@
 <?php
+// $Id: $
 
-//activate line below if you need to change smtp server
-ini_set('SMTP', variable_get('tellafriend_server', '') );
-
-global $tellafriend_validated;
-
-function valid_email($address)
-{
-  // check an email address is possibly valid
-  if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $address))
-    return true;
-  else
-    return false;
-}
-
-
+ini_set('SMTP', variable_get('tellafriend_server', 'localhost'));
 
 /**
  * Implementation of hook_help().
  */
 function tellafriend_help($section) {
   switch ($section) {
-    case 'admin/help#poll':
-      return t("Access page at: tellafriend");
-    case 'admin/modules#description':
-      return t("Allows you to create a Tell-a-Friend page to spread the word about your site.");
+    case 'admin/help#tellafriend':
+      global $base_url;
+      return t("Access <em>Tell a friend</em> page at: !path", array('!path' => l($base_url . urldecode('/?q=tellafriend'), 'tellafriend')));
   }
 }
 
 /**
+ * Implementation of hook_perm().
+ */
+function tellafriend_perm() {
+  return array('access tellafriend form');
+}
+
+/**
 * Implementation of hook_menu().
 */
 function tellafriend_menu() {
   $items = array();
 
-  $items[] = array('path' => 'tellafriend', 'title' => t(variable_get('tellafriend_pagetitle',0)),
-    'access' => TRUE,
-    'callback' => 'tellafriend_page',
-    'type' => MENU_CALLBACK);
-
-  $items[] = array('path' => 'tellafriend/send',
-      'title' => t(variable_get('tellafriend_pagetitle',0)),
-      'callback' => 'tellafriend_send',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK);
+  //if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/settings/tellafriend',
+      'title' => t('Tell a friend'),
+      'description' => t('Control the contents of <em>Tell a friend</em> e-mail message.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'tellafriend_settings',
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM,
+    );
+    $items[] = array(
+      'path' => 'tellafriend',
+      'title' => variable_get('tellafriend_pagetitle', t('Tell a friend')),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'tellafriend_page',
+      'access' => user_access('access tellafriend form'),
+      'type' => MENU_SUGGESTED_ITEM,
+    );
+  //}
 
   return $items;
 }
@@ -53,166 +55,195 @@
  * Implementation of hook_settings().
  */
 function tellafriend_settings() {
+  global $base_url;
+  $form = array();
 
-    if (variable_get('tellafriend_server', 0)==""){
-		variable_set('tellafriend_server','localhost');
-	}
+  $form['tellafriend_general'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('General settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['tellafriend_general']['tellafriend_pagetitle'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Page title'),
+    '#default_value' => variable_get('tellafriend_pagetitle', t('Tell a friend')),
+    '#size' => 70,
+    '#maxlength' => 200,
+    '#description' => t('Title of the <em>Tell a friend</em> page.'),
+  );
+  $form['tellafriend_general']['tellafriend_topmessage'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Top Message'),
+    '#default_value' => variable_get('tellafriend_topmessage', t('Spread the word about !site by telling your friend(s) about it!', array('!site' => variable_get('site_name', 'Drupal')))),
+    '#size' => 70,
+    '#rows' => 5,
+    '#description' => t('A description or information shown above the <em>Tell a friend</em> form.'),
+  );
+  $form['tellafriend_general']['tellafriend_success'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Success redirect path'),
+    '#default_value' => variable_get('tellafriend_success', variable_get('site_frontpage', 'node')),
+    '#size' => 70,
+    '#maxlength' => 200,
+    '#description' => t('This is where the script will redirect the user after the e-mail is successfully sent.'),
+  );
+  $form['tellafriend_general']['tellafriend_server'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Server name'),
+    '#default_value' => variable_get('tellafriend_server', 'localhost'),
+    '#size' => 70,
+    '#maxlength' => 200,
+    '#description' => t('SMTP server name. Default is <em>localhost</em>.'),
+  );
+  $form['tellafriend_mail'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('E-mail template'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['tellafriend_mail']['tellafriend_fromaddress'] = array(
+    '#type' => 'textfield',
+    '#title' => t('From address'),
+    '#default_value' => variable_get('tellafriend_fromaddress', ''),
+    '#size' => 70,
+    '#maxlength' => 200,
+    '#description' => t("This is the address the e-mail will come from. Site e-mail address is %sitemail. Leave blank to use sender's e-mail address", array('%sitemail' => variable_get('site_mail', ini_get('sendmail_from')))),
+  );
+  $form['tellafriend_mail']['tellafriend_subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Email Subject'),
+    '#default_value' => variable_get('tellafriend_subject', '!sendername has invited you to !sitename!'),
+    '#size' => 70,
+    '#maxlength' => 200,
+    '#description' => t('This is the e-mail subject. Available placeholders: <em>!sitename, !sitelink, !sitemail, !sendername, !sendermail</em>.'),
+  );
+  $form['tellafriend_mail']['tellafriend_message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Message Text'),
+    '#default_value' => variable_get('tellafriend_message', 'You are invited to check out !sitename at !sitelink'),
+    '#cols' => 70,
+    '#rows' => 5,
+    '#description' => t('This is the text of the sent message. Use plain text only. Available placeholders: <em>!sitename, !sitelink, !sitemail, !sendername, !sendermail</em>.'),
+  );
+  $form['tellafriend_mail']['tellafriend_closing'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Closing'),
+    '#default_value' => variable_get('tellafriend_closing', 'Sincerely,'),
+    '#size' => 70,
+    '#maxlength' => 200,
+    '#description' => t('Love, Sincerely, etc...'),
+  );
 
-    if (variable_get('tellafriend_closing', 0)==""){
-		variable_set('tellafriend_closing','Sincerely,');
-	}
-
-  $output = form_textarea(t('Message Text'), 'tellafriend_message', variable_get('tellafriend_message', ''), 70, 5, t('This is the text of the sent message. Use plain text only'),'', TRUE);
-  $output.= form_textfield(t('Page Title'), 'tellafriend_pagetitle', variable_get('tellafriend_pagetitle', ''), 70, 200, t('This is the title of the page'),'', TRUE);
-  $output.= form_textfield(t('Email Subject'), 'tellafriend_subject', variable_get('tellafriend_subject', ''), 70, 200, t('This is the subject. Sender\'s name will come first, as in "[Bob Smith] wants you to go to my site!" No need to include space'),'', TRUE);
-  $output.= form_textfield(t('From address'), 'tellafriend_fromaddress', variable_get('tellafriend_fromaddress', ''), 70, 200, t('This is the address that e-mail will come from'),'', TRUE);
-  $output.= form_textfield(t('Top Message'), 'tellafriend_topmessage', variable_get('tellafriend_topmessage', ''), 70, 200, t('This is the page description.'),'', TRUE);
-  $output.= form_textfield(t('Success Page'), 'tellafriend_success', variable_get('tellafriend_success', ''), 70, 200, t('This is where the script will redirect the user upon success.'),'', TRUE);
-  $output.= form_textfield(t('Closing'), 'tellafriend_closing', variable_get('tellafriend_closing', ''), 70, 200, t('Love, Sincerely, etc...'),'', TRUE);
-  $output.= form_textfield(t('Server name'), 'tellafriend_server', variable_get('tellafriend_server', ''), 70, 200, t('SMTP server name. Set to localhost for default.'),'', TRUE);
-
-  return $output;
+  return system_settings_form($form);
 }
 
 /**
- * Generates the form for the page
+ * Generates the form for the page.
  */
-function tellafriend_form() {
-    $edit = $_POST['edit'];
-    $tellafriend_email = $edit['tellafriend_email'];
-    $tellafriend_name = $edit['tellafriend_name'];
-    $tellafriend_addresses = $edit['tellafriend_addresses'];
-    $tellafriend_personal = $edit['tellafriend_personal'];
-
-
-  $form .= '<div class="tellafriend-form">';
-  $form .= '<p class="top-message">' . variable_get('tellafriend_topmessage', '') . '</p>';
-  $form .= form_textfield(t('Your name'), 'tellafriend_name', $tellafriend_name, 70, 128, t('Your name as it will appear in the sent e-mail.'), '', TRUE);
-  $form .= form_textfield(t('Your e-mail address'), 'tellafriend_email', $tellafriend_email, 70, 128, t('Your e-mail address as it will appear in the sent e-mail.'),'', TRUE);
-  $form .= form_textarea(t("Your friend's e-mail addresses, separated by commas"), 'tellafriend_addresses', $tellafriend_addresses, 70, 5, t('Seperate addresses with commas.'), '', TRUE);
-  $form .= form_textarea(t("Personal message"), 'tellafriend_personal', $tellafriend_personal, 70, 5, t('Adds a personal message to the top of the email.'));
-// textarea: $output .= $func($field->title, $field->name, $value, 64, 5, $field->explanation . $error);
-  $form .= form_submit(t('Send!'), 'send');
-
-
-  $form .= "<h2>Message to be sent:</h2><br>" . nl2br(variable_get('tellafriend_message', 0)) . '<br></div>';
-
-  $output .= form($form, 'post', url('tellafriend/send'));
-
-
-
-  return $output;
-}
-
-//Process a form, send it using php mail
-//Process a form, send it using php mail
-function tellafriend_send() {
-
-
-
-    $edit = $_POST['edit'];
-    $tellafriend_email = $edit['tellafriend_email'];
-    $tellafriend_name = $edit['tellafriend_name'];
-    $tellafriend_addresses = $edit['tellafriend_addresses'];
-    $tellafriend_personal = $edit['tellafriend_personal'];
-
-    //tellafriend_validate();
-
-    $tellafriend_fromaddress = variable_get('tellafriend_fromaddress', 0);
-
-    $tellafriend_pieces = explode(",", $tellafriend_addresses);
-
-    $tellafriend_subject = stripslashes($tellafriend_name) . " " . stripslashes(variable_get('tellafriend_subject', 0));
-    if(strlen($tellafriend_personal)) {
-    	$email_output .= "Personal Message: " . $tellafriend_personal . "\n----------------------\n\n";
-    }
-
-    $tellafriend_closing = variable_get('tellafriend_closing', 0);
-    $email_output.= variable_get('tellafriend_message', 0) . "\n\n$tellafriend_closing \n\n" . $tellafriend_name . "\n" . $tellafriend_email;
-
-   if (tellafriend_validate()) {
-
-		foreach ($tellafriend_pieces as $v) {
-
-			$sendaddress = stripslashes(trim($v));
-     		mail($sendaddress,$tellafriend_subject,$email_output,"From: $tellafriend_fromaddress");
-		}
+function tellafriend_page() {
+  global $user;
+  global $base_url;
+  $placeholder_values = array('!sitename' => variable_get('site_name', 'Drupal'),'!sitelink' => $base_url,'!sitemail' => variable_get('site_mail', ini_get('sendmail_from')), '!sendername' => $form_values['tellafriend_name'], '!sendermail' => $form_values['tellafriend_email']);
+
+  $form['#token'] = $user->name . $user->mail;
+  $form['tellafriend_information'] = array('#value' => filter_xss_admin(variable_get('tellafriend_topmessage', t('Spread the word about !site by telling your friend(s) about it!', array('!site' => variable_get('site_name', 'Drupal'))))));
+  $form['tellafriend_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Your name'),
+    '#default_value' => ($user->uid ? $user->name : ''),
+    '#size' => 70,
+    '#maxlength' => 255,
+    '#required' => TRUE,
+    '#description' => t('Your name as it will appear in the sent e-mail.'),
+  );
+  $form['tellafriend_email'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Your e-mail address'),
+    '#default_value' => ($user->uid ? $user->mail : ''),
+    '#size' => 70,
+    '#maxlength' => 255,
+    '#required' => TRUE,
+    '#description' => t('Your e-mail address as it will appear in the sent e-mail.'),
+  );
+  $form['tellafriend_addresses'] = array(
+    '#type' => 'textfield',
+    '#title' => t("Your friend's e-mail address"),
+    '#size' => 70,
+    '#maxlength' => 255,
+    '#required' => TRUE,
+    '#description' => t('Seperate multiple e-mail addresses with commas.'),
+  );
+  $form['tellafriend_personal'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Your Personal message'),
+    '#default_value' => t('I found this great web site, which you should really check out!'),
+    '#cols' => 70,
+    '#rows' => 5,
+    '#description' => t('Add your personal message to the e-mail.'),
+  );
+  $form['tellafriend_copy'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Send yourself a copy.'),
+  );
+  $form['tellafriend_message'] = array('#value' => filter_xss_admin("<strong>Message to be sent:</strong><br />" . nl2br(t(variable_get('tellafriend_message', 'You are invited to check out !sitename at !sitelink'), $placeholder_values)) . '<br></div>'));
+  $form['submit'] = array('#type' => 'submit',
+    '#value' => t('Tell now!'),
+  );
 
-       drupal_goto(variable_get('tellafriend_success', ''));
-	}else{
-    	print theme("page", tellafriend_form());
-    }
+  return $form;
 }
 
+/**
+ * Implementation of hook_validate().
+ */
+function tellafriend_page_validate($form_id, $form_values) {
+  $tellafriend_personal = $form_values['tellafriend_personal'];
 
-// Implementation of hook_validate().
-
-function tellafriend_validate() {
-	$tellafriend_validated = 0;
-    $edit = $_POST['edit'];
-    $tellafriend_email = $edit['tellafriend_email'];
-    $tellafriend_name = $edit['tellafriend_name'];
-    $tellafriend_addresses = $edit['tellafriend_addresses'];
-    $tellafriend_personal = $edit['tellafriend_personal'];
-
-
-   if (!strlen($tellafriend_name)) {
-        $tellafriend_validated = 1;
-        form_set_error("tellafriend_name", t('Name is required!'));
-
-   }
-
-   if (!valid_email($tellafriend_email)) {
-        $tellafriend_validated = 1;
-        form_set_error("tellafriend_email", t('Email address is not valid!'));
-
-   }
-
-   // check all the email addresses given
-   $tellafriend_pieces = explode(",", $tellafriend_addresses);
-
-   if ((count($tellafriend_pieces)==1) && ($tellafriend_pieces[0]=="")){
-            $tellafriend_validated = 1;
-        	form_set_error("tellafriend_addresses", t('You must enter at least one e-mail address to send to!'));
-
-
-   }else{
-
-
-      foreach ($tellafriend_pieces as $v) {
-
-					$sendaddress = stripslashes(trim($v));
-     				if (!valid_email($sendaddress)) {
-            			form_set_error("tellafriend_addresses", t("Send to address '$sendaddress' is invalid"));
-   						$tellafriend_validated = 1;
-
-            		}
-   	  }
+  if (!valid_email_address($form_values['tellafriend_email'])) {
+    form_set_error('tellafriend_email', t('Your e-mail address is not valid!'));
+  }
+  $addresses = explode(",", $form_values['tellafriend_addresses']);
 
+  foreach ($addresses as $mail) {
+    $sendaddress = stripslashes(trim($mail));
+    if (!valid_email_address($sendaddress)) {
+      $count++;
+      $invalid .= $sendaddress .' ';
     }
-
-
-
-   if ($tellafriend_validated == 1) {
-        return FALSE;
-
-   }else{
-   	return TRUE;
-   }
-
-
-
+  }
+  if ($invalid != '') {
+    form_set_error("tellafriend_addresses", t(format_plural(count($count), '!invalid is invalid send-to e-mail addresses.', '!invalid are invalid send-to e-mail addresses.'), array('!invalid' => $invalid)));
+  }
 }
 
+/**
+ * Implementation of hook_submit().Process the personal contact page form submission.
+ */
+function tellafriend_page_submit($form_id, $form_values) {
+  global $base_url;
+  $placeholder_values = array('!sitename' => variable_get('site_name', 'Drupal'),'!sitelink' => $base_url,'!sitemail' => variable_get('site_mail', ini_get('sendmail_from')), '!sendername' => $form_values['tellafriend_name'], '!sendermail' => $form_values['tellafriend_email']);
+  $closing = variable_get('tellafriend_closing', 'Sincerely,');
+  $from = variable_get('tellafriend_fromaddress', $form_values['tellafriend_email']);
+  $addresses = explode(",", $form_values['tellafriend_addresses']);
+  $subject = stripslashes($form_values['tellafriend_name']) .' '. stripslashes(t(variable_get('tellafriend_subject', '!sendername has invited you to !sitename!'), $placeholder_values));
 
+  if(strlen($form_values['tellafriend_personal'])) {
+    $body .= "\nPersonal Message: " . $form_values['tellafriend_personal'] . "\n----------------------\n\n";
+  }
+  $body .= t(variable_get('tellafriend_message', 'You are invited to check out !sitename at !sitelink'), $placeholder_values) ."\n$closing \n". $form_values['tellafriend_name'] ." - ". $form_values['tellafriend_email'];
 
-function tellafriend_page() {
-
-  $content .= tellafriend_form();
+  foreach ($addresses as $mail) {
+    $sendaddress[] = stripslashes(trim($mail));
+    drupal_mail('tellafriend-page-mail', current($sendaddress), $subject, $body, $from);
+  }
 
-  // print out $content
-  print theme("page", $content);
+  if ($form_values['tellafriend_copy']) {
+    drupal_mail('tellafriend-page-copy', $form_values['tellafriend_email'], $subject, $body, $from);
+  }
 
+  $addresses = implode(', ', $sendaddress);
+  watchdog('mail', t('%sender sent an e-mail to %recepient using <em>Tell a friend</em> form.', array('%sender' => $form_values['name'], '%recepient' => $addresses)));
+  drupal_set_message(t('Thank you! Your message has been sent to: !recepient', array('!recepient' => $addresses)));
+  drupal_goto(variable_get('tellafriend_success', variable_get('site_frontpage', 'node')));
 }
-
-?>
\ No newline at end of file
--- C:/Documents and Settings/Waheguru/Desktop/linux/drupal/contributions/modules/tellafriend/tellafriend.info
+++ C:/Documents and Settings/Waheguru/Desktop/linux/drupal/contributions/modules/tellafriend/tellafriend.info
@@ -0,0 +1,3 @@
+;$Id: $
+name = Tell a friend
+description = Allows you to create a Tell-a-Friend page to spread the word about your site.


