--- invite.info	Sun Jul 13 02:05:38 2008
+++ invite.info	Thu Jul 31 12:03:54 2008
@@ -1,11 +1,7 @@
-; $Id: invite.info,v 1.1.2.5.2.1 2008/07/10 10:18:06 smk Exp $
+; $Id: invite.info,v 1.1.2.5.2.1 2008/07/10 10:18:06 smk Exp $
 name = Invite
 description = "Allow your users to send and track invitations to join your site."
-dependencies = token
+dependencies[] = token
 package = Invite
-
-; Information added by drupal.org packaging script on 2008-07-13
-version = "5.x-2.x-dev"
-project = "invite"
-datestamp = "1215907537"
-
+version = VERSION
+core = 6.x
\ No newline at end of file
--- invite.install	Thu Jul 10 12:18:06 2008
+++ invite.install	Thu Jul 31 03:33:08 2008
@@ -5,70 +5,121 @@
  * Install the initial schema.
  */
 function invite_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("
-        CREATE TABLE {invite} (
-          reg_code varchar(8) NOT NULL default '',
-          email varchar(100) NOT NULL default '',
-          uid int(10) NOT NULL default '0',
-          invitee int(10) NOT NULL default '0',
-          created int(10) NOT NULL default '0',
-          expiry int(10) NOT NULL default '0',
-          joined int(10) NOT NULL default '0',
-          canceled tinyint(1) NOT NULL default '0',
-          resent tinyint(3) NOT NULL default '0',
-          data text NOT NULL,
-          UNIQUE (reg_code),
-          KEY (email),
-          KEY (uid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;"
-      );
-      db_query("
-        CREATE TABLE {invite_notifications} (
-          uid int(10) NOT NULL default '0',
-          invitee int(10) NOT NULL default '0',
-          UNIQUE (uid, invitee)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;"
-      );
-      break;
-
-    case 'pgsql':
-      db_query("
-        CREATE TABLE {invite} (
-          reg_code VARCHAR(8) NOT NULL DEFAULT '',
-          email VARCHAR(100) NOT NULL DEFAULT '',
-          uid INTEGER NOT NULL DEFAULT 0,
-          invitee INTEGER NOT NULL DEFAULT 0,
-          created INTEGER NOT NULL DEFAULT 0,
-          expiry INTEGER NOT NULL DEFAULT 0,
-          joined INTEGER NOT NULL DEFAULT 0,
-          canceled SMALLINT NOT NULL DEFAULT 0,
-          resent SMALLINT NOT NULL DEFAULT 0,
-          data TEXT NOT NULL DEFAULT '',
-          UNIQUE (reg_code)
-        )"
-      );
-      db_query("CREATE INDEX {invite}_email_idx ON {invite}(email)");
-      db_query("CREATE INDEX {invite}_uid_idx ON {invite}(uid)");
-      db_query("
-        CREATE TABLE {invite_notifications} (
-          uid INTEGER NOT NULL DEFAULT 0,
-          invitee INTEGER NOT NULL DEFAULT 0,
-          UNIQUE (uid, invitee)
-        )"
-      );
-      break;
-  }
-}
-
+  drupal_install_schema('invite');
+}
+
+function invite_schema() {
+  $schema = array();
+
+  $schema['invite'] = array(
+    'description' => t('Lists invitations that have been made.'),
+    'fields' => array(
+      'reg_code' => array(
+        'description' => 'registration code?',
+        'type' => 'varchar',
+        'length' => 8,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'email' => array(
+        'description' => t('Email Address'),
+        'type' => 'varchar',
+        'length' => 100,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'uid' => array(
+        'description' => t('User who invited'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'invitee' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'created' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'expiry' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'joined' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'canceled' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'resent' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'data' => array(
+        'description' => t('?'),
+        'type' => 'text',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+    'unique keys' => array(
+      'reg_code' => array('reg_code'),
+    ),
+    'indexes' => array(
+      'email' => array('email'),
+      'uid'   => array('uid'),
+    ),
+  );
+
+  $schema['invite_notifications'] = array(
+    'description' => t('Stores notifications of invitees'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('User who invited'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'invitee' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'unique keys' => array(
+      'uid_invitee' => array('uid', 'invitee'),
+    )
+  );
+
+  return $schema;
+}
+
 /**
  * Implementation of hook_uninstall().
  */
 function invite_uninstall() {
   // Drop database table
-  db_query('DROP TABLE {invite}');
+  drupal_uninstall_schema('invite');
 
   // Delete variables
   $sql = "DELETE from {variable} WHERE name LIKE '%s%%'";
@@ -120,13 +171,14 @@
 
 function invite_update_1() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite} CHANGE reg_code reg_code VARCHAR(64) UNIQUE NOT NULL");
-      $ret[] = update_sql("ALTER TABLE {invite} ADD INDEX reg_code_idx (reg_code)");
-      break;
-  }
+
+  db_change_field($ret, 'invite', 'reg_code', 'reg_code', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE),
+    array('unique keys' => array(
+        'reg_code' => array('reg_code'),
+      ), 'indexes' => array(
+        'reg_code' => array('reg_code'),
+      ),
+    ));
   return $ret;
 }
 
@@ -135,17 +187,9 @@
  */
 function invite_update_2() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite} DROP INDEX reg_code_idx");
-      $ret[] = update_sql("ALTER TABLE {invite} ADD INDEX (uid)");
-      break;
-    case 'pgsql':
-      $ret[] = update_sql("DROP INDEX reg_code_idx");
-      $ret[] = update_sql("CREATE INDEX {invite}_uid_idx ON {invite} (uid)");
-      break;
-  }
+
+  db_drop_index($ret, 'invite', 'reg_code');
+  db_add_index($ret, 'invite', 'uid', array('uid'));
   return $ret;
 }
 
@@ -155,13 +199,14 @@
 function invite_update_3() {
   $ret = array();
   $result = db_query("SELECT DISTINCT i.uid FROM {invite} i LEFT JOIN {users} u ON i.uid = u.uid WHERE u.uid IS NULL");
-  $count = db_num_rows($result);
+  $count = 0;
   $sql = "DELETE FROM {invite} WHERE uid = %d";
   if (!variable_get('invite_allow_join_delete', 0)) {
     $sql .= " AND timestamp != 0";
   }
   while ($inviter = db_fetch_object($result)) {
     db_query($sql, $inviter->uid);
+    $count++;
   }
   $ret[] = array(
     'query' => strtr('%count orphaned invites have been deleted.', array('%count' => $count)),
@@ -175,15 +220,7 @@
  */
 function invite_update_4() {
   $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite} CHANGE received received tinyint(3) unsigned NOT NULL default '0'");
-      break;
-    case 'pgsql':
-      db_change_column($ret, 'invite', 'received', 'received', 'SMALLINT', array('not null' => TRUE));
-      break;
-  }
+  db_change_field($ret, 'invite', 'received', 'received', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
   // Prevent displaying a whole bunch of messages for old invites
   $ret[] = update_sql("UPDATE {invite} SET received = 1 WHERE mid <> 0");
   return $ret;
@@ -193,16 +230,8 @@
  * Save invite message text.
  */
 function invite_update_5() {
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite} ADD COLUMN message TEXT NOT NULL default ''");
-      break;
-    case 'pgsql':
-      db_add_column($ret, 'invite', 'message', 'TEXT', array('not null' => TRUE, 'default' => "''"));
-      break;
-  }
+  $ret = array();
+  db_add_field($ret, 'invite', 'message', array('type' => 'text', 'not null' => TRUE, 'default' => ''));
   return $ret;
 }
 
@@ -213,9 +242,10 @@
   $ret = array();
   if (variable_get('invite_allow_join_delete', 0)) {
     $result = db_query("SELECT i.mid FROM {invite} i LEFT JOIN {users} u ON i.mid = u.uid WHERE u.uid IS NULL");
-    $count = db_num_rows($result);
+    $count = 0;
     while ($invitee = db_fetch_object($result)) {
       db_query("DELETE FROM {invite} WHERE mid = %d", $invitee->mid);
+      $count++;
     }
     $ret[] = array(
       'query' => strtr('%count orphaned invites have been deleted.', array('%count' => $count)),
@@ -237,7 +267,7 @@
     'query' => 'The message tokens for the invite module have been successfully updated.',
     'success' => TRUE
   );
-  drupal_set_message(strtr('Please note that invite now depends on the %token module.', array('%token' => l('token', 'http://drupal.org/project/token', array('target' => '_blank'), NULL, NULL, TRUE))), 'error');
+  drupal_set_message(strtr('Please note that invite now depends on the %token module.', array('%token' => l('token', 'http://drupal.org/project/token', array('attributes' => array('target' => '_blank'), 'absolute' => TRUE)))), 'error');
   return $ret;
 }
 
@@ -245,32 +275,19 @@
  * Change message to a generic data column and convert existing messages.
  */
 function invite_update_8() {
-  $ret = array();
-
-  // Add column data first
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite} ADD COLUMN data TEXT NOT NULL");
-      break;
-    case 'pgsql':
-      db_add_column($ret, 'invite', 'data', 'TEXT', array('not null' => TRUE, 'default' => "''"));
-      break;
-  }
-
-  // Convert existing messages
-  $result = db_query("SELECT reg_code, message FROM {invite} WHERE message <> ''");
-  while ($row = db_fetch_object($result)) {
-    if (substr($row->message, 0, 2) == 'a:') {
-      // Already serialized
-      continue;
-    }
-    $data = array('subject' => NULL, 'message' => $row->message);
-    db_query("UPDATE {invite} SET data = '%s' WHERE reg_code = '%s'", serialize($data), $row->reg_code);
-  }
-
-  // Finally drop column message
-  $ret[] = update_sql("ALTER TABLE {invite} DROP message");
+  $ret = array();
+  db_change_field($ret, 'invite', 'message', 'data', array('type' => 'text', 'not null' => TRUE, 'default' => ''));
+
+  // Convert existing messages
+  $result = db_query("SELECT reg_code, data FROM {invite} WHERE data <> ''");
+  while ($row = db_fetch_object($result)) {
+    if (substr($row->message, 0, 2) == 'a:') {
+      // Already serialized
+      continue;
+    }
+    $data = array('subject' => NULL, 'message' => $row->data);
+    db_query("UPDATE {invite} SET data = '%s' WHERE reg_code = '%s'", serialize($data), $row->reg_code);
+  }
 
   return $ret;
 }
@@ -375,27 +392,14 @@
  * 4. Added resent column.
  */
 function invite_update_200() {
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite} DROP PRIMARY KEY, ADD INDEX email (email)");
-      $ret[] = update_sql("ALTER TABLE {invite} CHANGE mid invitee int(10) NOT NULL default '0'");
-      $ret[] = update_sql("ALTER TABLE {invite} CHANGE timestamp joined int(10) NOT NULL default '0'");
-      $ret[] = update_sql("ALTER TABLE {invite} ADD created int(10) NOT NULL default '0'");
-      $ret[] = update_sql("ALTER TABLE {invite} ADD canceled tinyint(1) NOT NULL default '0'");
-      $ret[] = update_sql("ALTER TABLE {invite} ADD resent tinyint(3) NOT NULL default '0'");
-      break;
-    case 'pgsql':
-      $ret[] = update_sql("ALTER TABLE {invite} DROP CONSTRAINT {invite}_pkey");
-      $ret[] = update_sql("CREATE INDEX {invite}_email_idx ON {invite}(email)");
-      db_change_column($ret, 'invite', 'mid', 'invitee', 'INTEGER', array('not null' => TRUE, 'default' => 0));
-      db_change_column($ret, 'invite', 'timestamp', 'joined', 'INTEGER', array('not null' => TRUE, 'default' => 0));
-      db_add_column($ret, 'invite', 'created', 'INTEGER', array('default' => 0, 'not null' => TRUE));
-      db_add_column($ret, 'invite', 'canceled', 'SMALLINT', array('default' => 0, 'not null' => TRUE));
-      db_add_column($ret, 'invite', 'resent', 'SMALLINT', array('default' => 0, 'not null' => TRUE));
-      break;
-  }
+  $ret = array();
+  db_drop_primary_key($ret, 'invite'); // drop primary key.
+  db_add_index($ret, 'invite', 'email', array('email'));
+  db_change_field($ret, 'invite', 'mid', 'invitee', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_change_field($ret, 'invite', 'timestamp', 'joined', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'invite', 'created', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'invite', 'cancelled', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'invite', 'resent', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
   return $ret;
 }
 
@@ -403,32 +407,33 @@
  * Revamped notification system.
  */
 function invite_update_201() {
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("
-        CREATE TABLE {invite_notifications} (
-          uid int(10) NOT NULL default '0',
-          invitee int(10) NOT NULL default '0',
-          KEY (uid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;"
-      );
-      break;
-    case 'pgsql':
-      $ret[] = update_sql("
-        CREATE TABLE {invite_notifications} (
-          uid INTEGER NOT NULL DEFAULT 0,
-          invitee INTEGER NOT NULL DEFAULT 0
-        )"
-      );
-      $ret[] = update_sql("CREATE INDEX {invite_notifications}_uid_idx ON {invite_notifications}(uid)");
-      break;
-  }
+  $ret = array();
+  db_create_table($ret, 'invite_notifications', array(
+    'description' => t('Stores notifications of invitees'),
+    'fields' => array(
+      'uid' => array(
+        'description' => t('User who invited'),
+        'type' => 'int',
+        //'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'invitee' => array(
+        'description' => t('?'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'indexes' => array(
+      'uid' => array('uid'),
+    )
+  ));
   // Convert old data
   db_query("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, invitee FROM {invite} WHERE joined != 0 AND received = 0");
   // Drop old column
-  $ret[] = update_sql("ALTER TABLE {invite} DROP received");
+  //$ret[] = update_sql("ALTER TABLE {invite} DROP received");
+  db_drop_field($ret, 'invite', 'received');
   return $ret;
 }
 
@@ -436,17 +441,29 @@
  * Optimize index of notification table.
  */
 function invite_update_202() {
-  $ret = array();
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      $ret[] = update_sql("ALTER TABLE {invite_notifications} DROP INDEX uid,  ADD UNIQUE uid_invitee (uid, invitee)");
-      break;
-
-    case 'pgsql':
-      $ret[] = update_sql("DROP INDEX {invite_notifications}_uid_idx");
-      $ret[] = update_sql("CREATE UNIQUE INDEX {invite_notifications}_uid_invitee_key ON {invite_notifications}(uid, invitee)");
-      break;
-  }
+  $ret = array();
+  db_drop_index($ret, 'invite_notifications', 'uid');
+  db_add_unique_key($ret, 'invite_notifications', 'uid_invitee', array('uid', 'invitee'));
+}
+
+/**
+ * normalize things for Drupal 6.
+ *
+ * a) Change uid field to be an unsigned int, as per user module.
+ *
+ * @return unknown
+ */
+function invite_update_6000() {
+  $ret = array();
+  db_drop_index($ret, 'invite', 'uid');
+  db_change_field($ret, 'invite', 'uid', 'uid', array('type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0), array('indexes' => array('uid' => array('uid'))));
+  db_drop_index($ret, 'invite_notifications', 'uid_invitee');
+  db_change_field($ret, 'invite_notifications', 'uid', 'uid', array('type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0), array('unique keys' => array('uid_invitee' => array('uid', 'invitee'))));
   return $ret;
 }
--- invite.module	Sat Jul 12 23:40:14 2008
+++ invite.module	Thu Jul 31 12:11:41 2008
@@ -27,9 +27,12 @@
  *
  * Returns appropriate help text for all three invite status pages.
  */
-function invite_help($section) {
-  if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'invites') {
+function invite_help($path, $arg) {
+  /*if ($arg[0] == 'user' && is_numeric($arg[1]) && $arg[2] == 'invites') {
     return _invite_user_help($section, arg(1));
+  }*/
+  if (strpos($path, 'user/%user/invites') === 0) {
+    return _invite_user_help($path, $arg[1]);
   }
   else if ($section == 'admin/help#invite') {
     return _invite_module_help();
@@ -44,16 +47,16 @@
  * @param $uid
  *   A user profile id.
  */
-function _invite_user_help($section, $uid) {
-  switch ($section) {
-    case "user/$uid/invites":
-    case "user/$uid/invites/accepted":
+function _invite_user_help($path, $uid) {
+  switch ($path) {
+    case "user/%user/invites":
+    case "user/%user/invites/accepted":
       $output = '<p>'. t("The invitations shown on this page have been used to join the site. Clicking on an e-mail address takes you to the user's profile page.");
       break;
-    case "user/$uid/invites/pending":
+    case "user/%user/invites/pending":
       $output = '<p>'. t("The invitations shown on this page haven't been accepted yet.");
       break;
-    case "user/$uid/invites/expired":
+    case "user/%user/invites/expired":
       $output = '<p>'. t('The invitations shown on this page have not been used to register on the site within the expiration period of @count days.', array('@count' => variable_get('invite_expiry', 30)));
       break;
     default:
@@ -89,140 +92,159 @@
 }
 
 /**
+ * Implements hook_init().
+ *
+ */
+function invite_init() {
+  // Notify current user about newly joined invitees.
+  if (!empty($user->invite_sent) && !module_invoke('throttle', 'status')) {
+    invite_notify($user->uid);
+  }
+}
+
+/**
  * Implementation of hook_menu().
  */
-function invite_menu($may_cache) {
+function invite_menu() {
   global $user;
-  $items = array();
-
-  $send_access = user_access('send invitations');
-  $track_access = user_access('track invitations');
-  $admin_access = user_access('administer site configuration');
-
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/user/invite',
-      'title' => t('Invites'),
-      'callback' => 'invite_admin_overview',
-      'access' => $admin_access,
-      'type' => MENU_NORMAL_ITEM,
-    );
-    $items[] = array(
-      'path' => 'admin/user/invite/list',
-      'title' => t('Inviters'),
-      'access' => $admin_access,
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'weight' => -5,
-    );
-    $items[] = array(
-      'path' => 'admin/user/invite/settings',
-      'title' => t('Settings'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'invite_settings',
-      'access' => $admin_access,
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 5,
-    );
-    $items[] = array(
-      'path' => 'invite',
-      'title' => variable_get('invite_page_title', t('Invite a friend')),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('invite_form', 'page', array()),
-      'access' => $send_access,
-      'type' => MENU_NORMAL_ITEM,
-    );
-    $items[] = array(
-      'path' => 'invite/accept',
-      'callback' => 'invite_controller',
-      'access' => TRUE,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'invite/withdraw',
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('invite_cancel'),
-      'access' => $track_access,
-      'type' => MENU_CALLBACK,
-    );
-  }
-  else {
-    // Notify current user about newly joined invitees.
-    if (!empty($user->invite_sent) && !module_invoke('throttle', 'status')) {
-      invite_notify($user->uid);
-    }
+  $items = array();
+
+  $send_access = array('send invitations');
+  $track_access = array('track invitations');
+  $admin_access = array('administer site configuration');
+
+
+  $items['admin/user/invite'] = array(
+    'title' => 'Invites',
+    'page callback' => 'invite_admin_overview',
+    'access arguments' => $admin_access,
+    'type' => MENU_NORMAL_ITEM,
+    'file' => 'invite_admin.inc',
+  );
+  $items['admin/user/invite/list'] = array(
+    'title' => 'Inviters',
+    'access arguments' => $admin_access,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -5,
+  );
+  $items['admin/user/invite/settings'] = array(
+    'title' => 'Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_settings'),
+    'access arguments' => $admin_access,
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 5,
+    'file' => 'invite_admin.inc',
+  );
+  $items['invite'] = array(
+    'title' => variable_get('invite_page_title',  'Invite a friend'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_form', 'page', array()),
+    'access arguments' => $send_access,
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['invite/accept'] = array(
+    'page callback' => 'invite_controller',
+    'access callback' => 'invite_accept_public',
+    'type' => MENU_CALLBACK,
+  );
+  $items['invite/withdraw'] = array(
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_cancel'),
+    'access arguments' => $track_access,
+    'type' => MENU_CALLBACK,
+  );
 
-    if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid) {
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites',
-        'title' => t('Track invitations'),
-        'callback' => 'invite_user_overview',
-        'access' => $track_access,
-        'type' => MENU_LOCAL_TASK,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/accepted',
-        'title' => t('Accepted'),
-        'callback' => 'invite_user_overview',
-        'callback arguments' => array('accepted'),
-        'access' => $track_access,
-        'type' => MENU_DEFAULT_LOCAL_TASK,
-        'weight' => -5,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/pending',
-        'title' => t('Pending'),
-        'callback' => 'invite_user_overview',
-        'callback arguments' => array('pending'),
-        'access' => $track_access,
-        'type' => MENU_LOCAL_TASK,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/expired',
-        'title' => t('Expired'),
-        'callback' => 'invite_user_overview',
-        'callback arguments' => array('expired'),
-        'access' => $track_access,
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 5,
-      );
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/invites/new',
-        'title' => t('New invitation'),
-        'callback' => 'drupal_get_form',
-        'callback arguments' => array('invite_form', 'page', array()),
-        'access' => $send_access,
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 10,
-      );
-    }
-    else if (arg(2) == 'invite' && arg(3) == 'details' && arg(4)) {
-      if ($account = user_load(array('uid' => arg(4)))) {
-        $items[] = array(
-          'path' => 'admin/user/invite/details/'. arg(4),
-          'title' => t('Invitees of @name', array('@name' => $account->name)),
-          'callback' => 'invite_admin_details',
-          'callback arguments' => array(arg(4)),
-          'access' => $admin_access,
-          'type' => MENU_LOCAL_TASK,
-        );
-      }
-    }
-    else if (arg(0) == 'invite' && arg(1) == 'resend' && arg(2)) {
-      $items[] = array(
-        'path' => 'invite/resend/'. arg(2),
-        'title' => t('Resend invitation'),
-        'callback' => 'invite_resend',
-        'callback arguments' => array(arg(2)),
-        'access' => $send_access,
-        'type' => MENU_CALLBACK,
-      );
-    }
-  }
+  $items['user/%user/invites'] = array(
+    'title' => 'Track invitations',
+    'page callback' => 'invite_user_overview',
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'invite_admin.inc',
+  );
+  $items['user/%user/invites/accepted'] = array(
+    'title' => 'Accepted',
+    'page callback' => 'invite_user_overview',
+    'page arguments' => array('accepted'),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -5,
+    'file' => 'invite_admin.inc',
+  );
+  $items['user/%user/invites/pending'] = array(
+    'title' => 'Pending',
+    'page callback' => 'invite_user_overview',
+    'page arguments' => array('pending'),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'invite_admin.inc',
+  );
+  $items['user/%user/invites/expired'] = array(
+    'title' => 'Expired',
+    'page callback' => 'invite_user_overview',
+    'page arguments' => array('expired'),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('track invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 5,
+    'file' => 'invite_admin.inc',
+  );
+  $items['user/%user/invites/new'] = array(
+    'title' => 'New invitation',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('invite_form', 'page', array()),
+    'access callback' => 'invite_access_callback',
+    'access arguments' => array('send invitations', 1),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 10,
+  );
+  $items['admin/user/invite/details/%user'] = array(
+    'title' => 'Invitees',
+    'page callback' => 'invite_admin_details',
+    'page arguments' => array(4),
+    'access arguments' => $admin_access,
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'invite_admin.inc',
+  );
+
+  // Invite Resend path - wildcard is an invite code.
+  $items['invite/resend/%'] = array(
+    'title' => 'Resend invitation',
+    'page callback' => 'invite_resend',
+    'page arguments' => array(2),
+    'access arguments' => array('send invitations'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }
 
 /**
+ * Menu Access helper function that allows us to easily mark menu items as publicly accessible.
+ *
+ * @return unknown
+ */
+function invite_accept_public() {
+  return TRUE;
+}
+
+/**
+ * Menu Access helper function that ensures that the user/%user/invites links are only visible if you have permission and it's your account.
+ *
+ * @param unknown_type $permission
+ * @param unknown_type $account
+ * @return unknown
+ */
+function invite_access_callback($permission, $account) {
+  global $user;
+
+  return ($account->uid == $user->uid && user_access($permission));
+}
+
+/**
  * Displays a notification message when an invited user has registered.
  *
  * @param $uid
@@ -262,7 +284,7 @@
 /**
  * Implementation of hook_form_alter().
  */
-function invite_form_alter($form_id, &$form) {
+function invite_form_alter(&$form, $form_state, $form_id) {
   switch ($form_id) {
     case 'user_admin_settings':
       // Add new registration mode.
@@ -312,7 +334,7 @@
       // Remove temptation for non members to try and register.
       if (variable_get('user_register', 1) === '1-inviteonly') {
         $new_items = array();
-        $new_items[] = l(t('Request new password'), 'user/password', array('title' => t('Request new password via e-mail.')));
+        $new_items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
         $form['links']['#value'] = theme('item_list', $new_items);
       }
       break;
@@ -500,7 +522,7 @@
  */
 function invite_block($op = 'list', $delta = 0, $edit = array()) {
   if ($op == 'list') {
-    $blocks[0] = array('info' => t('Invite a friend'));
+    $blocks[0] = array('info' => t('Invite a friend'), 'cache' => BLOCK_CACHE_PER_ROLE);
     return $blocks;
   }
   else if ($op == 'view') {
@@ -528,11 +550,11 @@
  * @return
  *   A form definition.
  */
-function invite_form($op = 'page', $edit = array()) {
+function invite_form(&$form_state, $op = 'page', $edit = array()) {
   global $user;
 
-  if (!is_array($edit)) {
-    $edit = (array)$edit;
+  if (!is_array($edit)) {
+    $edit = (array)$edit;
   }
 
   $remaining_invites = invite_get_remaining_invites($user);
@@ -543,7 +565,7 @@
       $form['#access'] = FALSE;
       return $form;
     }
-    else if (!$edit) {
+    else if (!$edit) {
       // Deny access when NOT resending an invite.
       drupal_set_message(t("Sorry, you've reached the maximum number of invitations."), 'error');
       drupal_goto(referer_uri());
@@ -552,11 +574,11 @@
 
   $form['resent'] = array(
     '#type' => 'value',
-    '#value' => $edit ? $edit['resent'] + 1 : 0,
+    '#value' => $edit ? $edit['resent'] + 1 : 0,
   );
   $form['reg_code'] = array(
     '#type' => 'value',
-    '#value' => $edit ? $edit['reg_code'] : NULL,
+    '#value' => $edit ? $edit['reg_code'] : NULL,
   );
   if ($remaining_invites != INVITE_UNLIMITED) {
     $form['remaining_invites'] = array(
@@ -567,7 +589,7 @@
   switch ($op) {
     case 'page':
     default:
-      $form += invite_page_form($remaining_invites, $edit);
+      $form += invite_page_form($remaining_invites, $edit);
       break;
     case 'block':
       $form += invite_block_form($remaining_invites);
@@ -644,7 +666,7 @@
  *
  * @param $remaining_invite
  *   Number of remaining invites.
- * @param $edit
+ * @param $edit
  *   Previous values when resending an invite.
  * @return
  *   A form definition.
@@ -804,15 +826,36 @@
 
   return $form;
 }
+
+/**
+ * Implements hook_theme().
+ *
+ * @return unknown
+ */
+function invite_theme() {
+  return array(
+    'invite_form' => array(
+      'arguments' => array('form' => array()),
+    ),
+    'invite_user_overview' => array(
+      'arguments' => array('rows' => array()),
+      'file' => 'invite_admin.inc',
+    ),
+    'invite_token_help' => array(
+      'arguments' => array('type' => '', 'prefix' => '', 'suffix' => ''),
+      'file' => 'invite_token.inc',
+    ),
+  );
+}
 
 /**
  * Theme function for the invite form.
  *
  * @ingroup themeable
  */
-function theme_invite_form($form) {
+function theme_invite_form($form) {
   $output = '';
-  $op = $form['#parameters'][1];
+  $op = $form['#parameters'][2];
 
   if ($op == 'page') {
     // Show form elements.
@@ -835,7 +878,7 @@
 
     // Perform token replacement on message body.
     $types = _invite_token_types(array('data' => array('message' => $message_form)));
-    $output .= token_replace_multiple($body, $types);
+    $output .= token_replace_multiple($body, $types);
 
     $output .= "</div></div>\n";
   }
@@ -852,15 +895,16 @@
  * Filters out e-mails that are already registered or have been invited before.
  * Checks the invite limit of the user and the max. number of invites per turn.
  */
-function invite_form_validate($form_id, &$edit) {
+function invite_form_validate($form, &$form_state) {
   global $user;
 
-  $emails = _invite_get_emails($edit['email']);
+  $emails = _invite_get_emails($form_state['values']['email']);
 
-  if (!$edit['resent']) {
+  if (!$form_state['values']['resent']) {
     if (count($emails) > 0) {
+      $email_placeholder = db_placeholders($emails, 'varchar');
       // Filter out already registered users, but pass validation.
-      $failed_emails = _invite_validate_emails("SELECT mail AS email FROM {users} WHERE mail IN (%s)", $emails);
+      $failed_emails = _invite_validate_emails("SELECT mail AS email FROM {users} WHERE mail IN (". $email_placeholder .")", $emails);
       if (count($failed_emails)) {
         $error = format_plural(count($failed_emails), 'The following recipient is already a member:', 'The following recipients are already members:') .'<br />';
         foreach ($failed_emails as $key => $email) {
@@ -872,7 +916,7 @@
       }
 
       // Filter out already invited users, but pass validation.
-      $failed_emails = _invite_validate_emails("SELECT email FROM {invite} WHERE email IN (%s) AND uid = %d AND canceled = 0", $emails, $user->uid);
+      $failed_emails = _invite_validate_emails("SELECT email FROM {invite} WHERE email IN (". $email_placeholder .") AND uid = %d AND canceled = 0", $emails, $user->uid);
       if (count($failed_emails)) {
         $error = format_plural(count($failed_emails), 'You did already invite the following recipient:', 'You did already invite the following recipients:') .'<br />';
         $error .= implode(', ', array_map('check_plain', $failed_emails));
@@ -887,8 +931,8 @@
       }
 
       // Check invite limit, fail to let the user choose which ones to send.
-      if (isset($edit['remaining_invites']) && count($emails) > $edit['remaining_invites']) {
-        form_set_error('email', format_plural($edit['remaining_invites'], 'You have only 1 invite left.', 'You have only @count invites left.'));
+      if (isset($form_state['values']['remaining_invites']) && count($emails) > $form_state['values']['remaining_invites']) {
+        form_set_error('email', format_plural($form_state['values']['remaining_invites'], 'You have only 1 invite left.', 'You have only @count invites left.'));
         return;
       }
 
@@ -901,7 +945,9 @@
   }
 
   // Save valid emails.
-  form_set_value(array('#parents' => array('valid_emails')), $emails);
+  //form_set_value(array('#parents' => array('valid_emails')), $emails);
+  //form_set_value(array('#parents' => array('valid_emails')), $emails, $form_state);
+  $form_state['values']['valid_emails'] = $emails;
 }
 
 /**
@@ -959,11 +1005,11 @@
  */
 function _invite_validate_emails($sql, &$emails) {
   $failed_emails = array();
-  $args = func_get_args();
-  array_shift($args);
-  array_shift($args);
-  array_unshift($args, "'". implode("','", array_map('db_escape_string', $emails)) ."'");
-  $result = db_query(vsprintf($sql, $args));
+  //$args = func_get_args();
+  //array_shift($args);
+  //array_shift($args);
+  //array_unshift($args, "'". implode("','", array_map('db_escape_string', $emails)) ."'");
+  $result = db_query($sql, $emails);
   while ($row = db_fetch_object($result)) {
     $failed_emails[] = $row->email;
   }
@@ -975,8 +1021,11 @@
 /**
  * Forms API callback; process submitted form data.
  */
-function invite_form_submit($form_id, $edit) {
-  global $user;
+function invite_form_submit($form, &$form_state) {
+  global $user;
+
+  // Set this now, so other things can change it later -
+  $form_state['redirect'] = 'invite';
 
   $failed_emails = array();
   $num_failed = $num_succeeded = 0;
@@ -987,16 +1036,16 @@
     $num_failed = count($failed_emails);
   }
 
-  $subject = isset($edit['subject']) ? trim($edit['subject']) : invite_get_subject();
-  $message = isset($edit['message']) ? trim($edit['message']) : NULL;
+  $subject = isset($form_state['values']['subject']) ? trim($form_state['values']['subject']) : invite_get_subject();
+  $message = isset($form_state['values']['message']) ? trim($form_state['values']['message']) : NULL;
 
-  foreach ($edit['valid_emails'] as $email) {
+  foreach ($form_state['values']['valid_emails'] as $email) {
     // Create the invite object.
-    $code = $edit['reg_code'] ? $edit['reg_code'] : invite_generate_code();
+    $code = $form_state['values']['reg_code'] ? $form_state['values']['reg_code'] : invite_generate_code();
     $invite = _invite_substitutions(array(
       'email' => $email,
       'code'  => $code,
-      'resent'  => $edit['resent'],
+      'resent'  => $form_state['values']['resent'],
       'data'  => array('subject' => $subject, 'message' => $message),
     ));
 
@@ -1009,7 +1058,7 @@
       invite_save($invite);
 
       // Notify other modules.
-      if (!$edit['resent']) {
+      if (!$form_state['values']['resent']) {
         $args = array('inviter' => $invite->inviter, 'email' => $invite->email, 'code' => $invite->code);
         module_invoke_all('invite', 'invite', $args);
       }
@@ -1027,9 +1076,9 @@
   }
 
   if ($num_succeeded) {
-    if (isset($edit['remaining_invites'])) {
+    if (isset($form_state['values']['remaining_invites'])) {
       // Update user property if user is limited.
-      user_save($user, array('invites' => $edit['remaining_invites'] - $num_succeeded));
+      user_save($user, array('invites' => $form_state['values']['remaining_invites'] - $num_succeeded));
     }
     $message = format_plural($num_succeeded, 'Your invitation has been successfully sent. You will be notified when the invitee joins the site.', '@count invitations have been successfully sent. You will be notified when any invitee joins the site.');
     drupal_set_message($message);
@@ -1040,10 +1089,8 @@
   }
   else if (user_access('track invitations') && $user->uid) {
     // Everything went well: redirect to pending invites page.
-    return "user/$user->uid/invites/pending";
+    $form_state['redirect'] = "user/$user->uid/invites/pending";
   }
-
-  return 'invite';
 }
 
 /**
@@ -1122,16 +1169,31 @@
     $headers['Reply-To'] = $reply_to;
   }
 
-  if (!($success = drupal_mail('invite-mail', $recipient, $subject, wordwrap($body, 72), $from, $headers))) {
-    static $error_shown = FALSE;
-    if (!$error_shown) {
-      drupal_set_message(t('Problems occurred while 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' => '<'. $recipient .'>', '@from' => '<'. $from .'>')));
+  $params = array('headers' => $headers, 'body' => $body, 'subject' => $subject);
+  $language = user_preferred_language($user);
+
+  $message = drupal_mail('invite', 'invite-mail', $recipient, $language, $params, $from);
+
+  //drupal_set_message(dprint_r($message, TRUE));
+  //return TRUE; // for testing, we override.
+
+  return $message['result'];
+}
+
+/**
+ * Implements hook_invite().
+ *
+ * @param unknown_type $key
+ * @param unknown_type $message
+ * @param unknown_type $params
+ */
+function invite_mail($key, &$message, $params) {
+  if ($key == 'invite-mail') {
+    $message['subject'] = $subject;
+    $message['body'][] = $params['body'];
+    $message['headers'] = array_merge($message['headers'], $params['headers']);
+
   }
-
-  return $success;
 }
 
 /**
@@ -1194,7 +1256,7 @@
     }
   }
   else {
-    watchdog('invite', t('Detected malicious attempt to delete an invitation.'), WATCHDOG_WARNING, l(t('view'), 'user/'. $user->uid));
+    watchdog('invite', 'Detected malicious attempt to delete an invitation.', array(), WATCHDOG_WARNING, l(t('view'), 'user/'. $user->uid));
     drupal_access_denied();
   }
 
@@ -1204,8 +1266,8 @@
 /**
  * Submit handler to delete an invitation.
  */
-function invite_cancel_submit($form_id, $form_values) {
-  $invite = $form_values['invite'];
+function invite_cancel_submit($form, $form_state) {
+  $invite = $form_state['values']['invite'];
 
   db_query("UPDATE {invite} SET canceled = 1 WHERE reg_code = '%s'", $invite->reg_code);
   drupal_set_message(t('Invitation to %email has been withdrawn.', array('%email' => $invite->email)));
@@ -1254,47 +1316,6 @@
     case 'expired':
       return db_result(db_query("SELECT COUNT(*) FROM {invite} WHERE uid = %d AND joined = 0 AND expiry < %d", $uid, time()));
   }
-}
-
-/**
- * Menu callback; return a list of all users that have invited someone.
- */
-function invite_admin_overview() {
-  require_once drupal_get_path('module', 'invite') .'/invite_admin.inc';
-  return _invite_admin_overview();
-}
-
-/**
- * Menu callback; return a list of invites by a user.
- *
- * @param $uid
- *   A user id.
- */
-function invite_admin_details($uid) {
-  require_once drupal_get_path('module', 'invite') .'/invite_admin.inc';
-  return _invite_admin_details($uid);
-}
-
-/**
- * Menu callback; display invite settings form.
- *
- * @return
- *   A form definition array.
- */
-function invite_settings() {
-  require_once drupal_get_path('module', 'invite') .'/invite_admin.inc';
-  return _invite_settings();
-}
-
-/**
- * Menu callback; display an overview of sent invitations.
- *
- * @param $page
- *   Which invites to list: accepted, pending, or expired.
- */
-function invite_user_overview($page = 'accepted') {
-  require_once drupal_get_path('module', 'invite') .'/invite_admin.inc';
-  return _invite_user_overview($page);
 }
 
 /**
--- invite_admin.inc	Thu Jul 10 12:27:28 2008
+++ invite_admin.inc	Thu Jul 31 12:18:37 2008
@@ -4,10 +4,10 @@
 /**
  * Menu callback; display invite settings form.
  */
-function _invite_settings() {
+function invite_settings() {
   $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 on the <a href="!admin-user-access">Access control page</a>.', array('!admin-user-access' => url('admin/user/access'))));
+    drupal_set_message(t('Please enable the <em>send invitations</em> permission for at least one role. This can be done on the <a href="!admin-user-access">Permissions page</a>.', array('!admin-user-access' => url('admin/user/permissions'))));
   }
   $target_roles = user_roles(1);
 
@@ -40,7 +40,7 @@
   $form['role'] = array(
     '#type' => 'fieldset',
     '#title' => t('Role settings'),
-    '#description' => t('Note: Permission related settings can be found at the <a href="!admin-user-access">Access control page</a>.', array('!admin-user-access' => url('admin/user/access'))),
+    //'#description' => t('Note: Permission related settings can be found at the <a href="!admin-user-access">Permissions page</a>.', array('!admin-user-access' => url('admin/user/permissions'))),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
@@ -165,7 +165,7 @@
 /**
  * Return a list of all users that have invited someone.
  */
-function _invite_admin_overview() {
+function invite_admin_overview() {
   $header = array(
     array('data' => t('Username'), 'field' => 'u1.name', 'sort' => 'asc'),
     array('data' => t('Total'), 'field' => 'invites'),
@@ -175,7 +175,7 @@
     t('Remaining'),
     t('Operations'),
   );
-  
+
   $now = time();
   $filter = $filter_args = $query = NULL;
   $output = drupal_get_form('invite_admin_filter_form');
@@ -190,7 +190,7 @@
   $count_sql  = "SELECT COUNT(DISTINCT i.uid) FROM {invite} i". $filter;
   $result = pager_query($sql, 50, 0, $count_sql, $filter_args);
   $rows = array();
-  
+
   while ($row = db_fetch_object($result)) {
     $cells = array();
     $cells[] = theme('username', $row);
@@ -200,10 +200,10 @@
     $cells[] = invite_count($row->uid, 'expired');
     $remaining = invite_get_remaining_invites($row);
     $cells[] = ($remaining == INVITE_UNLIMITED) ? '&infin;' : $remaining;
-    $cells[] = l(t('details'), "admin/user/invite/details/$row->uid", array(), $query);
+    $cells[] = l(t('details'), "admin/user/invite/details/$row->uid", array('query' => $query));
     $rows[] = $cells;
   }
-  
+
   $output .= theme('table', $header, $rows, array('id' => 'invite'));
   if (!$rows) {
     $output .= t('No inviters found.');
@@ -239,20 +239,21 @@
   return $form;
 }
 
-function invite_admin_filter_form_submit($form_id, $form_values) {
-  if ($form_values['filter']) {
-    $_SESSION[INVITE_ADMIN_SESSION] = $form_values['filter'];
+function invite_admin_filter_form_submit($form, &$form_state) {
+  if ($form_state['values']['filter']) {
+    $_SESSION[INVITE_ADMIN_SESSION] = $form_state['values']['filter'];
   }
 }
 
 /**
  * Return a list of invites by a user.
  *
- * @param $uid
- *   A user id.
+ * @param $account
+ *   A user object.
  */
-function _invite_admin_details($uid) {
+function invite_admin_details($account) {
   $now = time();
+  $uid = $account->uid;
   $status_sort = '';
   if ($_GET['order'] == t('Status')) {
     $sort = db_escape_string($_GET['sort']);
@@ -270,7 +271,7 @@
     array('data' => t('Expires'), 'field' => 'i.expiry'),
     array('data' => t('Status'), 'field' => $status_sort),
   );
-  
+
   $output = '';
   $filter = $filter_args = NULL;
   if (isset($_GET['filter']) && $_GET['filter'] != '') {
@@ -282,7 +283,7 @@
   $sql .= tablesort_sql($header);
   $result = pager_query($sql, 50, 0, NULL, $uid, $filter_args);
   $rows = array();
-  
+
   while ($row = db_fetch_object($result)) {
     $cells = array();
     $cells[] = check_plain($row->email);
@@ -322,7 +323,7 @@
     '#value' => t('Clear'),
     '#prefix' => ' ',
   );
-  return $form;  
+  return $form;
 }
 
 /**
@@ -331,7 +332,7 @@
  * @param $page
  *   Which invites to list: accepted, pending, or expired.
  */
-function _invite_user_overview($page = 'accepted') {
+function invite_user_overview($page = 'accepted') {
   global $user;
 
   $rows = array();
--- invite_cancel_account.info	Sun Jul 13 02:05:38 2008
+++ invite_cancel_account.info	Thu Jul 31 12:16:15 2008
@@ -1,11 +1,7 @@
-; $Id: invite_cancel_account.info,v 1.1.2.1.2.1 2008/07/10 10:27:28 smk Exp $
+; $Id: invite_cancel_account.info,v 1.1.2.1.2.1 2008/07/10 10:27:28 smk Exp $
 name = Cancel User Accounts
 description = "Allows your users to terminate user accounts by withdrawing their invitation. WARNING - This module is put into effect when you enable it."
-dependencies = invite
+dependencies[] = invite
 package = Invite
-
-; Information added by drupal.org packaging script on 2008-07-13
-version = "5.x-2.x-dev"
-project = "invite"
-datestamp = "1215907537"
-
+version = VERSION
+core = 6.x
--- invite_stats.info	Sun Jul 13 02:05:38 2008
+++ invite_stats.info	Thu Jul 31 12:15:54 2008
@@ -1,11 +1,7 @@
-; $Id: invite_stats.info,v 1.1.2.2.2.1 2008/07/10 10:27:28 smk Exp $
+; $Id: invite_stats.info,v 1.1.2.2.2.1 2008/07/10 10:27:28 smk Exp $
 name = Invite Statistics
 description = "Displays some statistics about sent invitations."
-dependencies = invite
+dependencies[] = invite
 package = Invite
-
-; Information added by drupal.org packaging script on 2008-07-13
-version = "5.x-2.x-dev"
-project = "invite"
-datestamp = "1215907537"
-
+version = VERSION
+core = 6.x
--- invite_stats.module	Thu Jul 10 12:27:28 2008
+++ invite_stats.module	Thu Jul 31 12:16:43 2008
@@ -121,7 +121,11 @@
   $user_invite_stats_count = db_result(db_query("SELECT COUNT(*) FROM {invite} WHERE uid = %d AND joined <> 0", $uid));
 
   // Calculate user's rank.
-  $rank = 1 + db_num_rows(db_query("SELECT DISTINCT COUNT(uid) FROM {invite} WHERE joined <> 0 GROUP BY uid HAVING COUNT(uid) > %d", $user_invite_stats_count));
+  $result = db_query("SELECT DISTINCT COUNT(uid) FROM {invite} WHERE joined <> 0 GROUP BY uid HAVING COUNT(uid) > %d", $user_invite_stats_count);
+  $rank = 1;
+  while ($row = db_fetch_array($result)) {
+    $rank++;
+  }
 
   // Fetch users with more invites.
   $i = 0;
@@ -158,6 +162,14 @@
   return theme('invite_stats_ranking', $inviters, $rank);
 }
 
+function invite_stats_theme() {
+  return array(
+    'invite_stats_ranking' => array(
+      'arguments' => array('inviters' => NULL, 'rank' => 1),
+    ),
+  );
+}
+
 /**
  * Theme the Top inviters/user rank block.
  *
--- invite_token.inc	Thu Jul 10 12:28:44 2008
+++ invite_token.inc	Thu Jul 31 12:16:59 2008
@@ -12,7 +12,7 @@
     $values['invite-mail']        = $object->email;
     $values['invite-message']     = check_plain($object->data['message']);
     $values['invite-message-raw'] = $object->data['message'];
-    $values['join-link']          = url('invite/accept/'. $object->code, NULL, NULL, TRUE);
+    $values['join-link']          = url('invite/accept/'. $object->code, array('absolute' => TRUE));
   }
   return $values;
 }
@@ -52,11 +52,11 @@
   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));
+    $rows[] = array(array('data' => drupal_ucfirst($key) .' '. t('tokens'), 'class' => 'region', 'colspan' => 2));
     foreach ($category as $token => $description) {
       $row = array();
       $row[] = $prefix . $token . $suffix;
