Index: invite.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/Attic/invite.info,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 invite.info
--- invite.info	6 Mar 2007 21:59:08 -0000	1.1.2.2
+++ invite.info	21 Jul 2007 01:18:11 -0000
@@ -1,4 +1,5 @@
 ; $Id: invite.info,v 1.1.2.2 2007/03/06 21:59:08 smk Exp $
 name = Invite
 description = Allows users to send GMail style invitations, and automatically escalates new users who use them to a role of your designation.
+dependencies = token
 package = Mail
Index: invite.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/Attic/invite.install,v
retrieving revision 1.3.2.11
diff -u -r1.3.2.11 invite.install
--- invite.install	20 Jul 2007 23:46:20 -0000	1.3.2.11
+++ invite.install	21 Jul 2007 00:37:29 -0000
@@ -160,3 +160,17 @@
   }
   return $ret;
 }
+
+/**
+ * Switch to token.module.
+ */
+function invite_update_6() {
+  if ($template = variable_get('invite_default_mail_template', NULL)) {
+    $old = array('@site', '@join_link', '@homepage', '@message', '@inviter');
+    $new = array('[site-name]', '[join-link]', '[site-url]', '[invite-message]', '[inviter]');
+    $template = str_replace($old, $new, $template);
+    variable_set('invite_default_mail_template', $template);
+    drupal_set_message(t('The message tokens for the invite module have been successfully converted.'));
+  }
+  return array();
+}
Index: invite.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/invite/Attic/invite.module,v
retrieving revision 1.10.2.46
diff -u -r1.10.2.46 invite.module
--- invite.module	20 Jul 2007 22:33:31 -0000	1.10.2.46
+++ invite.module	21 Jul 2007 01:06:25 -0000
@@ -43,6 +43,8 @@
  * Menu callback; renders invite settings form.
  */
 function _invite_settings() {
+  include(drupal_get_path('module', 'invite') .'/invite_token.inc');
+
   $roles = user_roles(0, 'send invitations');
   if (count($roles) == 0) {
     drupal_set_message(t('Please enable the <em>send invitations</em> permission for at least one role. This can be done at !url.', array('!url' => l('Access control settings', 'admin/user/access'))));
@@ -155,7 +157,7 @@
     '#default_value' => variable_get('invite_subject', t("You've been invited")),
     '#size' => 20,
     '#maxlength' => 64,
-    '#description' => t('Type the subject of the invitation email.'),
+    '#description' => t('Type the subject of the invitation email. Use the syntax [token] if you want to insert a replacement pattern.'),
     '#required' => TRUE,
   );
   
@@ -164,7 +166,16 @@
     '#title' => t('Mail template'),
     '#default_value' => _invite_get_mail_template(),
     '#required' => TRUE,
-    '#description' => t('Use the following placeholders: @site, @homepage, @join_link, @message, @inviter.'),
+    '#description' => t('Use the syntax [token] if you want to insert a replacement pattern.'),
+  );
+  $form['email_settings']['token_help'] = array(
+    '#title' => t('Replacement patterns'),
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['email_settings']['token_help']['help'] = array(
+    '#value' => theme('invite_token_help', array('user', 'profile', 'invite')),
   );
 
   $form['email_settings']['invite_use_users_email'] = array(
@@ -691,14 +702,17 @@
   
   if (is_array($edit['validated_emails'])) {
     foreach ($edit['validated_emails'] as $email) {
-      // Generate code for each mail
-      $code = _invite_create_regcode();
-      $message = trim($edit['message']);
-  
+      // Create the invite object
+      $invite          = new stdClass();
+      $invite->email   = $email;
+      $invite->inviter = $user->name;
+      $invite->message = trim($edit['message']);
+      $invite->code    = _invite_create_regcode();
+
       // Send email
-      if (_invite_send_invite('mail', $user->name, $email, $code, $message)) {
+      if (_invite_send_invite($invite)) {
         db_query("INSERT INTO {invite} (email, reg_code, uid, expiry, message) VALUES ('%s', '%s', %d, %d, '%s')", $email, $code, $user->uid, time()+(variable_get('invite_expiry', 30)*60*60*24), $message);
-        
+
         // Notify other modules
         $args = array('inviter' => $user);
         module_invoke_all('invite', 'invite', $args);
@@ -725,6 +739,36 @@
 }
 
 /**
+ * Implementation of hook_token_values().
+ */
+function invite_token_values($type = 'all', $object = NULL) {
+  $values = array();
+  if ($type == 'invite' && is_object($object)) {
+    // NOTE: Invite is currently only capable of sending plain text emails.
+    // If you intend to change that, you need to properly escape all user input
+    // by adding check_plain() around below values!
+    $values['inviter']        = $object->inviter;
+    $values['invite-message'] = $object->message;
+    $values['invite-mail']    = $object->email;
+    $values['join-link']      = url('user/register/'. $object->code, NULL, NULL, TRUE);
+  }
+  return $values;
+}
+
+/**
+ * Implementation of hook_token_list().
+ */
+function invite_token_list($type = 'all') {
+  if ($type == 'invite' || $type == 'all') {
+    $tokens['invite']['inviter']        = t('The name of the inviting user. <em>Note:</em> This is the same as [user].');
+    $tokens['invite']['invite-message'] = t('The message text of the inviting user for the invitee.');
+    $tokens['invite']['invite-mail']    = t('The email address of the invited user.');
+    $tokens['invite']['join-link']      = t('The link to the registration page of the site.');
+    return $tokens;
+  }
+}
+
+/**
  * Menu callback; deletes an invite record.
  *
  * @param $email
@@ -940,8 +984,8 @@
 /**
  * Prepares and sends an invite to the specified email address.
  */
-function _invite_send_invite($op, $user_name = "[username]", $email ="[recipient-email]", $code = "registration-code", $message = '[your message]'){
-  global $base_url, $user;
+function _invite_send_invite($invite){
+  global $user;
 
   // this next bit sets From and Reply-To headers
   if(!$from = variable_get('invite_manual_from', NULL)) {
@@ -960,28 +1004,26 @@
       $replyto = variable_get('site_mail', ini_get('sendmail_from'));
     }
   }
-  $subject = variable_get('invite_subject',t("You've been invited"));
+  $headers = array('Reply-To' => $replyto);
 
-  $template = _invite_get_mail_template();
-  $site = variable_get('site_name', t('Drupal'));
-  $join_link = url('user/register/'. $code, NULL, NULL, TRUE);
-  $homepage = $base_url;
-  $inviter = $user_name;
-
-  $body = t($template, array('@site' => $site, '@join_link' => $join_link, '@homepage' => $homepage, '@message' => $message, '@inviter' => $inviter));
-
-  switch ($op){
-    case "mail":
-      if (!($success = drupal_mail('invite-mail', $email, $subject, wordwrap($body, 72), $from))) {
-        static $error_shown = FALSE;
-        if (!$error_shown) {
-          drupal_set_message(t('Problems occurred sending the invitation(s). Please contact the site administrator.'), 'error');
-          $error_shown = TRUE;
-        }
-        watchdog('invite', t("Failed sending invitation. To: @email From: @from", array('@email' => $email, '@from' => $from)));
-      }
-      return $success;
+  $subject = variable_get('invite_subject', t("You've been invited"));
+  $body = _invite_get_mail_template();
+
+  // Perform token replacement
+  $types = array('user' => $user, 'profile' => $user, 'invite' => $invite);
+  $subject = token_replace_multiple($subject, $types);
+  $body = token_replace_multiple($body, $types);
+
+  if (!($success = drupal_mail('invite-mail', $invite->email, $subject, wordwrap($body, 72), $from, $headers))) {
+    static $error_shown = FALSE;
+    if (!$error_shown) {
+      drupal_set_message(t('Problems occurred sending the invitation(s). Please contact the site administrator.'), 'error');
+      $error_shown = TRUE;
+    }
+    watchdog('invite', t("Failed sending invitation. To: @email From: @from", array('@email' => $email, '@from' => $from)));
   }
+
+  return $success;
 }
 
 /**
@@ -990,15 +1032,15 @@
  * @return The localized email body.
  */
 function _invite_get_mail_template() {
-  $template = t("Your friend, @inviter has invited you to join @site [@homepage].
+  $template = t("Your friend, [inviter] has invited you to join [site-name] at [site-url].
 
-To become a member of @site, click the link below or paste it into the address bar of your browser. 
+To become a member of [site-name], click the link below or paste it into the address bar of your browser. 
 
-@join_link
+[join-link]
 
 ----------
 
-@message");
+[invite-message]");
 
   return variable_get('invite_default_mail_template', $template);
 }
--- D:/htdocs/test/drupal/drupal-5.0/sites/all/modules/invite/invite_token.inc
+++ D:/htdocs/test/drupal/drupal-5.0/sites/all/modules/invite/invite_token.inc
@@ -0,0 +1,39 @@
+<?php
+// $Id$
+
+/**
+ * For a given context, builds a formatted list of tokens and descriptions
+ * of their replacement values.
+ *
+ * @param type
+ *    The token types to display documentation for. Defaults to 'all'.
+ * @param prefix
+ *    The prefix your module will use when parsing tokens. Defaults to '['
+ * @param suffix
+ *    The suffix your module will use when parsing tokens. Defaults to ']'
+ * @return An HTML table containing the formatting docs.
+ **/
+function theme_invite_token_help($type = 'all', $prefix = '[', $suffix = ']') {
+  token_include();
+
+  // see http://drupal.org/node/127072
+  $full_list = array();
+  foreach ((array)$type as $t) {
+    $full_list = array_merge($full_list, token_get_list($t));
+  }
+  
+  $headers = array(t('Token'), t('Replacement value'));
+  $rows = array();
+  foreach ($full_list as $key => $category) {
+    $rows[] = array(array('data' => drupal_ucfirst($key) . ' ' . t('tokens'), 'class' => 'region', 'colspan' => 2));
+    foreach ($category as $token => $description) {
+      $row = array();
+      $row[] = $prefix . $token . $suffix;
+      $row[] = $description;
+      $rows[] = $row;
+    }
+  }
+
+  $output = theme('table', $headers, $rows, array('class' => 'description'));
+  return $output;
+}


