? .DS_Store
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tokenauth/Attic/README.txt,v
retrieving revision 1.3.4.5
diff -u -p -r1.3.4.5 README.txt
--- README.txt	19 Aug 2010 21:19:32 -0000	1.3.4.5
+++ README.txt	29 Jan 2011 10:16:09 -0000
@@ -1,24 +1,25 @@
 # Token Authentication
 
-Enable feed readers and other simple clients to see certain private pages by 
+Enable feed readers and other simple clients to see certain private pages by
 providing an authentication token.
 
 ## Usage
 
-If you put token=x on the querystring and x is a valid token, then an anonymous 
-user will be authenticated as the user who owns the token. You may learn a user's 
-token by clicking on the tab on the user's profile page.
+If you put token=x on the querystring and x is a valid token, then an anonymous
+user will be authenticated as the user who owns the token (for that request
+only). You may learn a user's token by clicking on the tab on the user's profile
+page.
 
 ## Administration
 
-Go to admin/settings/tokenauth to configure this module.
+Go to admin/config/services/tokenauth to configure this module.
 
 ### Security
 
-In configuring Token Authentication, be sure to use it with 'low security' 
-content only. Tokenauth transmits what amounts to a password in the clear via URL, 
-you should assume anyone interested can get ahold of it and use it. Tokenauth 
-should be used for functionality requiring user identification more than user 
+In configuring Token Authentication, be sure to use it with 'low security'
+content only. Tokenauth transmits what amounts to a password in the clear via URL,
+you should assume anyone interested can get ahold of it and use it. Tokenauth
+should be used for functionality requiring user identification more than user
 authentication.
 
 ## Developers
@@ -28,5 +29,14 @@ Use tokenauth_reset_user_form() to get a
 
 ## Todo
 * use the token in other contexts like inbound email (see mailhandler.module)
-  
+
+## D7 todo [dloone]
+* Finish integration of issue #990468 changes. Current implementation always
+  adds token to RSS feed URLs.
+* Finish integration with context.module.
+* Not creating tokens for new users while module is enabled?
+* The token.module token has changed (from "tokenauth-token" to
+  "user:tokenauth-token"). How to handle that in upgrade?
+* Review raw SQL to make sure it's completely friendly to D7's new database API.
+
 $Id: README.txt,v 1.3.4.5 2010/08/19 21:19:32 grayside Exp $
Index: tokenauth.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tokenauth/Attic/tokenauth.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 tokenauth.inc
--- tokenauth.inc	23 Jan 2011 07:42:42 -0000	1.1.2.2
+++ tokenauth.inc	29 Jan 2011 10:16:10 -0000
@@ -24,9 +24,8 @@ function tokenauth_reset($uid = NULL, $t
     return tokenauth_reset_user($uid, $token, $update);
   }
   else {
-    $sql = 'SELECT uid FROM {users} WHERE uid > 0';
-    $result = db_query($sql);
-    while ($row = db_fetch_object($result)) {
+    $sql = 'SELECT uid FROM {users} WHERE uid > 1';
+    foreach (db_query($sql) as $row) {
       tokenauth_reset_user($row->uid, $token, $update);
     }
     return TRUE;
@@ -55,8 +54,7 @@ function tokenauth_reset_user($uid = NUL
     'token' => isset($token) ? $token : user_password(variable_get('tokenauth_length', 10)),
   );
   if (!$update) {
-    // drupal_write_record mysteriously failing from tokenauth_enable().
-    $return = db_query("INSERT INTO {tokenauth_tokens} (uid,token) VALUES (%d,'%s')", $entry['uid'], $entry['token']);
+    $return = drupal_write_record('tokenauth_tokens', $entry);
   }
   else {
     $return = drupal_write_record('tokenauth_tokens', $entry, 'uid');
@@ -65,33 +63,34 @@ function tokenauth_reset_user($uid = NUL
 }
 
 /**
- * API function to reset a user's token.
+ * API Function to insert a new user token.
  *
  * @param $uid
- *  User ID of the user whose token to reset.
- *
- * @deprecated Use tokenauth_reset_user() instead.
+ *  UID of a specific user for whom to add a token.
+ *  A token must not already exist for this user.
+ * @param $token
+ *  [optional] A specific string to use as the token.
+ *  If not supplied, a token will be generated.
  */
-function tokenauth_user_reset($uid = NULL) {
-  return tokenauth_reset_user($uid);
+function tokenauth_insert($uid, $token = NULL) {
+  return tokenauth_reset($uid, $token, FALSE);
 }
 
 /**
- * API Function to insert new user tokens.
+ * API Function to delete a user token.
  *
  * @param $uid
- *  [optional] UID of a specific user for whom to add a token.
- * @param $token
- *  [optional] A specific string to use as the token.
+ *  UID of the user whose token to delete.
  */
-function tokenauth_insert($uid = NULL, $token = NULL) {
-  return tokenauth_reset($uid, $token, FALSE);
+function tokenauth_delete($uid) {
+  $sql = 'DELETE FROM {tokenauth_tokens} WHERE uid = :uid';
+  db_query($sql, array(":uid" => $uid));
 }
 
 /**
  * API function for retrieving the token for a given user.
  *
- * @param string $uid 
+ * @param string $uid
  *  Assumes current user if no user is provided.
  * @return string
  *  A token, or NULL if user has no token.
@@ -100,7 +99,10 @@ function tokenauth_get_token($uid = NULL
   if (is_null($uid)) {
     $uid = $GLOBALS['user']->uid;
   }
-  return db_result(db_query("SELECT tt.token FROM {tokenauth_tokens} tt WHERE tt.uid = %d", $uid));
+  return db_query("SELECT tt.token FROM {tokenauth_tokens} tt WHERE tt.uid = :uid",
+      array(
+        ':uid'=>$uid
+      ))->fetchField();
 }
 
 /**
@@ -112,8 +114,10 @@ function tokenauth_get_token($uid = NULL
  *  An alphanumeric string.
  */
 function tokenauth_get_user($token) {
-  $sql = "SELECT tt.uid FROM {tokenauth_tokens} tt INNER JOIN {users} u ON tt.uid = u.uid WHERE token = '%s' AND u.status != 0";
-  return db_result(db_query($sql, $token));
+  $sql = "SELECT tt.uid FROM {tokenauth_tokens} tt INNER JOIN {users} u ON tt.uid = u.uid WHERE token = :token AND u.status != 0";
+  return db_query($sql, array(
+      ':token'=>$token
+    ))->fetchField();
 }
 
 /**
@@ -166,26 +170,30 @@ function tokenauth_text_load($account = 
   $tokenauth_text = variable_get('tokenauth_text', array());
 
   if (empty($tokenauth_text)) {
-    $tokenauth_text['body'] =<<<EOT
+    $tokenauth_text['body'] = array();
+    $tokenauth_text['body']['value'] =<<<EOT
 You may use an alphanumeric token to see restricted content using RSS Feed Readers or other simple content viewers. This token authenticates your user account, and as unique to you. If you have reason to believe someone else is misusing your token, please press the <em>Reset token</em> button to get a new one, and update your RSS readers.
 
 Append the string below to the end of URLs approved for use with Token Authentication for temporary authentication.
 EOT;
 
     if (module_exists('token')) {
-      $tokenauth_text['body'] .= "\n\n<strong>Your token:</strong> ?token=<code>[tokenauth-token]</code>";
+      $tokenauth_text['body']['value'] .= "\n\n<strong>Your token:</strong> ?token=<code>[user:tokenauth-token]</code>";
     }
 
-    $tokenauth_text['format'] = FILTER_FORMAT_DEFAULT;
+    $tokenauth_text['body']['format'] = NULL;
   }
   if (!$render) {
-    return $tokenauth_text;
+    $result = $tokenauth_text;
   }
-  if (module_exists('token')) {
-    if (empty($account)) {
-      $account = $GLOBALS['user'];
+  else {
+    if (module_exists('token')) {
+      if (empty($account)) {
+        $account = $GLOBALS['user'];
+      }
+      $tokenauth_text['body']['value'] = token_replace($tokenauth_text['body']['value'], array('user'=>$account));
     }
-    $tokenauth_text['body'] = token_replace($tokenauth_text['body'], 'user', $account);
+    $result = check_markup($tokenauth_text['body']['value'], $tokenauth_text['body']['format']);
   }
-  return check_markup($tokenauth_text['body'], $tokenauth_text['format']);
+  return $result;
 }
Index: tokenauth.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tokenauth/Attic/tokenauth.info,v
retrieving revision 1.3.4.1
diff -u -p -r1.3.4.1 tokenauth.info
--- tokenauth.info	28 May 2008 04:55:54 -0000	1.3.4.1
+++ tokenauth.info	29 Jan 2011 10:16:10 -0000
@@ -1,4 +1,6 @@
 ; $Id: tokenauth.info,v 1.3.4.1 2008/05/28 04:55:54 weitzman Exp $
 name = Token authentication
 description = Enable aggregators, feed readers and other simple clients to see private pages by providing an authentication token.
-core = 6.x
+core = 7.x
+dependencies[] = user
+configure = admin/config/services/tokenauth
Index: tokenauth.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tokenauth/Attic/tokenauth.install,v
retrieving revision 1.3.4.12
diff -u -p -r1.3.4.12 tokenauth.install
--- tokenauth.install	2 Nov 2010 06:14:46 -0000	1.3.4.12
+++ tokenauth.install	29 Jan 2011 10:16:10 -0000
@@ -38,7 +38,6 @@ function tokenauth_schema() {
  * Implementation of hook_install().
  */
 function tokenauth_install() {
-  drupal_install_schema('tokenauth');
   // Tokenauth must authenticate the user before other modules can deny anonymous access.
   db_query("UPDATE {system} SET weight='-1000' WHERE name='tokenauth'");
 }
@@ -47,32 +46,53 @@ function tokenauth_install() {
  * Implementation of hook_enable().
  */
 function tokenauth_enable() {
-  // Assign tokens for each user.
-  $result = db_query("SELECT u.uid FROM {users} u LEFT JOIN {tokenauth_tokens} tt ON u.uid = tt.uid WHERE tt.token IS NULL AND u.uid > 0");
-  while ($row = db_fetch_object($result)) {
+  // Assign tokens for each user who doesn't already have one.
+  $rows = db_query("SELECT u.uid FROM {users} u LEFT JOIN {tokenauth_tokens} tt ON u.uid = tt.uid WHERE tt.token IS NULL AND u.uid > 0");
+  foreach ($rows as $row) {
     tokenauth_insert($row->uid);
   }
-  // Clean up orphaned tokens from users removed while module disabled
-  db_query("DELETE tt.* FROM {tokenauth_tokens} tt WHERE NOT EXISTS (SELECT * FROM {users} u WHERE u.uid=tt.uid)");
+
+  // Clean up orphaned tokens from users removed while module disabled.
+  db_query("DELETE tt.* FROM {tokenauth_tokens} tt WHERE NOT EXISTS (SELECT * FROM {users} u WHERE u.uid = tt.uid)");
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function tokenauth_uninstall() {
-  drupal_uninstall_schema('tokenauth');
+  // Remove variables.
   variable_del('tokenauth_length');
   variable_del('tokenauth_pages');
-  variable_del('tokenauth_reset');
   variable_del('tokenauth_text');
 }
 
 /**
- * Make sure tokenauth has a low module weight.
+ * If the value of the tokenauth_text variable has come from D6,
+ * and it's probably too difficult to reliably convert,
+ * so we delete it and start again from scratch
+ * (but only if it contains D6 data).
+ * This is for the following reasons:
+ * <ul>
+ *    <li>The structure has changed.
+ *      It used to have elements ['body'] and ['format'],
+ *      but now has to have elements ['body']['value'] and ['body']['format'].
+ *    <li>The format specified used to be a numerical index,
+ *      but is now the machine version of the actual format.
+ *    <li>The token.module specifier for the auth token value has changed.
+ * </ul>
  */
-function tokenauth_update_6106() {
-  $ret = array();
-  // Make sure existing tokenauth installations operate at the proper weight.
-  db_query("UPDATE {system} SET weight='-1000' WHERE name='tokenauth'");
-  return $ret;
-}
\ No newline at end of file
+function tokenauth_update_7000(&$sandbox) {
+  $tokenauth_text = variable_get('tokenauth_text', NULL);
+  if (!is_null($tokenauth_text)
+      && array_key_exists('body', $tokenauth_text)
+      && is_string($tokenauth_text['body'])
+      && array_key_exists('format', $tokenauth_text)) {
+    variable_del('tokenauth_text');
+    $result = t('The tokenauth text displayed to the user has been deleted and re-created with its default value. Please <a href="/admin/config/services/tokenauth">review</a> and change if necessary.');
+  }
+  else {
+    $result = NULL;
+  }
+
+  return $result;
+}
Index: tokenauth.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tokenauth/Attic/tokenauth.module,v
retrieving revision 1.11.4.32
diff -u -p -r1.11.4.32 tokenauth.module
--- tokenauth.module	23 Jan 2011 06:56:23 -0000	1.11.4.32
+++ tokenauth.module	29 Jan 2011 10:16:10 -0000
@@ -11,24 +11,34 @@ include_once('tokenauth.inc');
 /**
  * Implementation of hook_perm().
  */
-function tokenauth_perm() {
-  return array('access tokenauth', 'administer tokenauth');
+function tokenauth_permission() {
+  return array(
+      'administer tokenauth'=>array(
+          'title'=>t('Administer tokenauth'),
+          'description'=>t('User can administer site-wide tokenauth settings.')
+      ),
+      'access tokenauth'=>array(
+          'title'=>t('Access tokenauth'),
+          'description'=>t('User can access feeds using auth tokens.')
+      )
+  );
 }
 
 /**
  * Implementation of hook_menu().
  */
 function tokenauth_menu() {
-  $items['admin/settings/tokenauth'] = array(
+  $items['admin/config/services/tokenauth'] = array(
     'title' => t('Token authentication'),
-    'description' => t('Configure token behavior to allow users to authenticate per page-load via URL.'),
+    'description' => t('Configure authorisation token behavior to allow users to authenticate per page-load via URL.'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tokenauth_admin_settings'),
     'access arguments' => array('administer tokenauth'),
     'file' => 'tokenauth.pages.inc',
+    'type' => MENU_NORMAL_ITEM
   );
-  $items['admin/settings/tokenauth/reset'] = array(
-    'title' => t('Reset tokens'),
+  $items['admin/config/services/tokenauth/reset'] = array(
+    'title' => t('Reset authorisation tokens'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tokenauth_reset_confirm'),
     'access arguments' => array('administer tokenauth'),
@@ -45,7 +55,7 @@ function tokenauth_menu() {
     'type' => MENU_LOCAL_TASK,
   );
   $items['user/%user/tokenauth/reset'] = array(
-    'title' => t('Reset token'),
+    'title' => t('Reset authorisation token'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('tokenauth_user_reset_confirm'),
     'access callback' => 'tokenauth_profile_access',
@@ -58,6 +68,19 @@ function tokenauth_menu() {
 }
 
 /**
+ * Implementation of hook_admin_paths().
+ */
+function tokenauth_admin_paths() {
+  $paths = array(
+    'admin/config/services/tokenauth' => TRUE,
+    'admin/config/services/tokenauth/reset' => TRUE,
+    'user/*/tokenauth' => TRUE,
+    'user/*/edit/*' => TRUE,
+  );
+  return $paths;
+}
+
+/**
  * Implementation of hook_help().
  */
 function tokenauth_help($path, $arg) {
@@ -69,10 +92,13 @@ function tokenauth_help($path, $arg) {
 }
 
 /**
- * Access callback for tokenauth view/edit.
+ * Form access callback for tokenauth view/edit.
  */
 function tokenauth_profile_access($account) {
-  return (user_access('administer users') || ($GLOBALS['user']->uid == $account->uid)) && user_access('access tokenauth') && $account->uid > 0;
+  return (user_access('administer users')  // Current user can admin users.
+        || ($GLOBALS['user']->uid == $account->uid)) // Current user is editing own profile.
+      && user_access('access tokenauth')  // Current user can use tokenauth. TODO: Should this be target user rather than current user?
+      && ($account->uid > 1);  // Don't allow anon or admin to use tokenauth under any circumstances.
 }
 
 /**
@@ -80,20 +106,32 @@ function tokenauth_profile_access($accou
  */
 function tokenauth_init() {
   global $user;
-  // Process any provided token and log in user
-  if (user_is_anonymous() && isset($_REQUEST['token']) && tokenauth_allowed_pages($_GET['q'])) {
+  // Process any provided token and log in user.
+  if (user_is_anonymous()
+      && isset($_REQUEST['token'])
+      && tokenauth_allowed_pages($_GET['q'])) {
     if ($uid = tokenauth_get_user($_REQUEST['token'])) {
       $account = user_load($uid);
       if (user_access('access tokenauth', $account)) {
         $user = $account;
-        // Store the fact that this user authenticated via token. Needed for logout.
+        // Store the fact that this user authenticated via token. Needed for tokenauth_exit.
         $_SESSION['tokenauth_auth'] = TRUE;
         if (function_exists('drupal_save_session')) {
           drupal_save_session(FALSE);
         }
-        watchdog('user', 'Page @page loaded for %name via token authentication.', array('@page' => $_GET['q'], '%name' => $account->name));
+        watchdog('user', 'Page @page loaded for %name via token authentication.', array(
+          '@page' => $_GET['q'],
+          '%name' => $account->name
+        ));
+
+        // Warning! Danger!
+        // Kill the static data stored by menu_get_item, which will force it to re-create it
+        // and more importantly, recalculate the access field. This works, but might not be
+        // strictly conformant to the Drupal API.
+        drupal_static_reset('menu_get_item');
       }
     }
+
     // Supplied an invalid token
     if (empty($_SESSION['tokenauth_auth'])) {
       drupal_access_denied();
@@ -102,7 +140,9 @@ function tokenauth_init() {
   }
 
   // Trigger tokenauth context condition.
-  if (module_exists('context') && $plugin = context_get_plugin('condition', 'tokenauth_auth')) {
+  // TODO: [dloone] context integration.
+  if (module_exists('context')
+      && ($plugin = context_get_plugin('condition', 'tokenauth_auth'))) {
     $plugin->execute((int)$_SESSION['tokenauth_auth']);
   }
 }
@@ -128,17 +168,23 @@ function tokenauth_exit() {
  * that also passes tokenauth's allowed pages filter.
  */
 function tokenauth_url_outbound_alter(&$path, &$options, $original_path) {
-  if (isset($_SESSION['tokenauth_auth']) && $_REQUEST['token'] == ($token = tokenauth_get_token())
-    && tokenauth_allowed_pages($original_path)) {
-
-    if (is_array($options['query'])) {
+  if (isset($_SESSION['tokenauth_auth'])
+      && ($_REQUEST['token'] == ($token = tokenauth_get_token()))
+      && tokenauth_allowed_pages($original_path)) {
+    $token = tokenauth_get_token();
+    if ($token != NULL) {
+      // From D6 on, the query element is an array (it previously was a string).
       $options['query']['token'] = $token;
     }
-    elseif (!$options['query']) {
-      $options['query'] = 'token=' . $token;
-    }
-    else {
-      $options['query'] .= '&token=' . $token;
+  }
+  else if (!isset($_SESSION['tokenauth_auth'])
+      && user_access('access tokenauth')
+      && tokenauth_allowed_pages($original_path)) {
+    // We are rendering a link to an RSS file, so append the token.
+    $token = tokenauth_get_token();
+    if ($token != NULL) {
+      // From D6 on, the query element is an array (it previously was a string).
+      $options['query']['token'] = $token;
     }
   }
 }
@@ -157,35 +203,49 @@ function tokenauth_user($op, &$edit, &$a
       tokenauth_insert($account->uid);
       break;
     case 'delete':
-      $sql = 'DELETE FROM {tokenauth_tokens} WHERE uid = %d';
-      db_query($sql, $account->uid);
+      tokenauth_delete($account->uid);
   }
 }
 
+
 /// Token Integration ///
 
 /**
- * Implementation of hook_token_list().
+ * Implementation of hook_token_info().
  */
-function tokenauth_token_list($type = 'user') {
-  if ($type == 'user' || $type == 'all') {
-    $tokens['user']['tokenauth-token'] = t("The user's tokenauth token.");
-    return $tokens;
-  }
+function tokenauth_token_info() {
+  $user_tokens = array();
+  $user_tokens['tokenauth-token'] = array(
+    'name' => t("Auth Token"),
+    'description' => t("The user's tokenauth token."),
+  );
+
+  return array(
+    'tokens' => array('user' => $user_tokens),
+  );
 }
 
 /**
- * Implementation of hook_token_values()
+ * Implementation of hook_tokens().
  */
-function tokenauth_token_values($type, $object = NULL, $options = array()) {
+function tokenauth_tokens($type, $tokens, array $data = array(), array $options = array()) {
+  $replacements = array();
   if ($type == 'user') {
-    $user = $object;
-    $tokens['tokenauth-token'] = tokenauth_get_token($object->uid);
-    return $tokens;
+    foreach ($tokens as $token_name => $token_original) {
+      switch ($token_name) {
+        case 'tokenauth-token': {
+          $replacements[$token_original] = tokenauth_get_token($data['user']->uid);
+          break;
+        }
+      }
+    }
   }
+  return $replacements;
 }
 
+
 /// Context Integration ///
+// TODO: [dloone]
 
 /**
  * Implementation of hook_ctools_plugin_api().
Index: tokenauth.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tokenauth/Attic/tokenauth.pages.inc,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 tokenauth.pages.inc
--- tokenauth.pages.inc	2 Sep 2010 21:10:57 -0000	1.1.2.6
+++ tokenauth.pages.inc	29 Jan 2011 10:16:10 -0000
@@ -15,6 +15,9 @@ function tokenauth_admin_settings() {
   $form['tokenauth_general'] = array(
     '#type' => 'fieldset',
     '#title' => t('Token settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#tree' => TRUE,
   );
   $form['tokenauth_general']['tokenauth_length'] = array(
     '#type' => 'textfield',
@@ -29,7 +32,12 @@ function tokenauth_admin_settings() {
     '#type' => 'textarea',
     '#title' => t('Activate tokens on specific pages'),
     '#default_value' => variable_get('tokenauth_pages', "rss.xml\n*/feed\n*/opml"),
-    '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. Read <a href=\"http://api.drupal.org/api/function/drupal_match_path/6\">drupal_match_path()</a> for the details.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
+    '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. Read <a href=\"http://api.drupal.org/api/function/drupal_match_path/6\">drupal_match_path()</a> for the details.",
+        array(
+          '%blog' => 'blog',
+          '%blog-wildcard' => 'blog/*',
+          '%front' => '<front>'
+    )),
   );
 
   $form['tokenauth_text'] = array(
@@ -37,17 +45,17 @@ function tokenauth_admin_settings() {
     '#title' => t('User text'),
     '#description' => t('This text will be displayed on a tab in each user\'s profile. Use it to explain what functionality Tokenauth provides your site.'),
     '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
+    '#collapsed' => FALSE,
     '#tree' => TRUE,
   );
-  $tokenauth_text = tokenauth_text_load(); 
+  $tokenauth_text = tokenauth_text_load();
   $form['tokenauth_text']['body'] = array(
-    '#type' => 'textarea',
+    '#type' => 'text_format',
     '#title' => t('Body'),
-    '#default_value' => $tokenauth_text['body'],
+    '#default_value' => $tokenauth_text['body']['value'],
     '#rows' => 5,
+    '#format' => $tokenauth_text['body']['format'],
   );
-  $form['tokenauth_text']['format'] = filter_form(FILTER_FORMAT_DEFAULT);
 
   if (module_exists('token')) {
     $form['tokenauth_text']['view']['token_help'] = array(
@@ -55,9 +63,11 @@ function tokenauth_admin_settings() {
       '#type' => 'fieldset',
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
+      '#tree' => TRUE,
     );
     $form['tokenauth_text']['view']['token_help']['help'] = array(
-      '#value' => theme('token_help', array('user', 'global')),
+      '#theme' => 'token_tree',
+      '#token_types' => array('user', 'global'),
     );
   }
 
@@ -65,6 +75,9 @@ function tokenauth_admin_settings() {
     '#type' => 'fieldset',
     '#title' => t('Token actions'),
     '#description' => t('Reset the tokens for all users. If you have changed token length, be sure to save that change before resetting all tokens.'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    '#tree' => TRUE,
   );
   $form['tokenauth_advanced']['tokenauth_reset'] = array(
     '#type' => 'submit',
@@ -79,7 +92,7 @@ function tokenauth_admin_settings() {
  */
 function tokenauth_admin_settings_validate($form, &$form_state) {
   if ($form_state['values']['op'] == t('Reset tokens')) {
-    drupal_goto('admin/settings/tokenauth/reset');
+    drupal_goto('admin/config/services/tokenauth/reset');
   }
   if ($form_state['values']['tokenauth_length'] > 33) {
     form_set_error('tokenauth_length', t('The maximum token length is 32.'));
@@ -89,24 +102,30 @@ function tokenauth_admin_settings_valida
 /**
  * Menu callback: confirm reset tokens.
  */
-function tokenauth_reset_confirm() {
-  return confirm_form(array(), t('Are you sure you want to reset all tokens?'),
-           'admin/settings/tokenauth', t('After the tokens have been reset, all users who use tokenised URLs will have to update them. This action cannot be undone.'), t('Reset tokens'), t('Cancel'));
+function tokenauth_reset_confirm($form, &$form_state) {
+  return confirm_form(
+      array(),
+      t('Are you sure you want to reset all tokens?'),
+      'admin/config/services/tokenauth',
+      t('After the tokens have been reset, all users who use tokenised URLs will have to update them. This action cannot be undone.'),
+      t('Reset tokens'),
+      t('Cancel')
+    );
 }
 
 /**
  * Handler for reset tokens confirmation
  */
-function tokenauth_reset_confirm_submit(&$form_state) {
+function tokenauth_reset_confirm_submit($form, &$form_state) {
   tokenauth_reset();
   drupal_set_message(t('All tokens have been reset.'));
-  $form_state['#redirect']  = 'admin/settings/tokenauth';
+  $form_state['redirect']  = 'admin/config/services/tokenauth';
 }
 
 /**
  * Menu callback: confirm reset users token.
  */
-function tokenauth_user_reset_confirm() {
+function tokenauth_user_reset_confirm($form, &$form_state) {
   if (arg(0) == 'user' && is_numeric(arg(1))) {
     $uid = arg(1);
   }
@@ -132,12 +151,12 @@ function tokenauth_user_reset_confirm_su
 /**
  * Menu callback. Prints the token and instructions.
  */
-function tokenauth_user_profile_form(&$form_state, $account) {
+function tokenauth_user_profile_form($form, &$form_state, $account) {
   drupal_set_title(check_plain($account->name));
   $token = tokenauth_get_token($account->uid);
-  $form['preamble'] = array('#value' => tokenauth_text_load($account, TRUE));
+  $form['#prefix'] = tokenauth_text_load($account, TRUE);
   if (!module_exists('token')) {
-    $form['preamble']['#value'] .= "<p><strong>" . t('Your token:') . "</strong> ?token=<code>$token</code></p>";
+    $form['#prefix'] .= "<p><strong>" . t('Your token:') . "</strong> ?token=<code>$token</code></p>";
   }
   $form = array_merge($form, tokenauth_reset_user_form($account->uid, NULL, $token));
   return $form;
