? jquery-tree
? jstree
? treeTable
Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.29
diff -u -p -r1.29 token.module
--- token.module	27 Apr 2010 18:52:52 -0000	1.29
+++ token.module	27 Apr 2010 18:56:31 -0000
@@ -88,7 +88,7 @@ function token_entity_info_alter(&$info)
  */
 function token_module_implements_alter(&$implementations, $hook) {
   if ($hook == 'tokens' || $hook == 'token_info') {
-    $modules = array();
+    $modules = array('profile');
     foreach ($modules as $module) {
       if (module_exists($module)) {
         $implementations[$module] = TRUE;
Index: token.tokens.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.tokens.inc,v
retrieving revision 1.2
diff -u -p -r1.2 token.tokens.inc
--- token.tokens.inc	9 Mar 2010 18:57:05 -0000	1.2
+++ token.tokens.inc	27 Apr 2010 18:56:31 -0000
@@ -58,3 +58,71 @@ function token_tokens($type, $tokens, ar
 
   return $replacements;
 }
+
+/**
+ * Implements hook_token_info().
+ */
+function profile_token_info() {
+  $info = array();
+
+  $fields = _profile_token_get_all_fields();
+  foreach ($fields as $field) {
+    $info['tokens']['user'][$field->name] = array(
+      'name' => check_plain($field->title),
+      'description' => t('@category @type field.', array('@category' => drupal_ucfirst($field->category), '@type' => $field->type)),
+    );
+    if ($field->type == 'date') {
+      $info['tokens']['user'][$field->name]['type'] = 'date';
+    }
+  }
+
+  return $info;
+}
+
+/**
+ * Implements hook_tokens().
+ */
+function profile_tokens($type, $tokens, array $data = array(), array $options = array()) {
+  $replacements = array();
+  $sanitize = !empty($options['sanitize']);
+
+  if ($type == 'user' && !empty($data['user'])) {
+    $account = $data['user'];
+    $profile_fields = _profile_token_get_all_fields();
+
+    // Load profile fields if this is the global user account.
+    // @see http://drupal.org/node/361471
+    if ($account->uid == $GLOBALS['user']->uid) {
+      $profile_users = array($account->uid => $account);
+      profile_user_load($profile_users);
+      $account = $profile_users[$account->uid];
+    }
+
+    foreach ($tokens as $name => $original) {
+      if (isset($account->$name) && array_key_exists($name, $profile_fields)) {
+        $replacements[$original] = $sanitize ? check_plain($account->$name) : $account->$name;
+      }
+    }
+
+    // Handle date tokens, which should be chainable.
+    foreach ($profile_fields as $field) {
+      if ($field->type == 'date' && isset($account->{$field->name}) && $field_tokens = token_find_with_prefix($tokens, $field->name)) {
+        $date = $account->{$field->name};
+        $replacements += token_generate('date', $field_tokens, array('date' => mktime(0, 0, 0, $date['month'], $date['day'], $date['year'])), $options);
+      }
+    }
+  }
+
+  return $replacements;
+}
+
+/**
+ * Fetch an array of profile field objects, keyed by profile field name.
+ */
+function _profile_token_get_all_fields() {
+  $fields = &drupal_static(__FUNCTION__);
+  if (!isset($fields)) {
+    $fields = db_query('SELECT * FROM {profile_field}')->fetchAllAssoc('name');
+  }
+  return $fields;
+}
