Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.51
diff -u -p -r1.51 token.module
--- token.module	18 Nov 2010 00:23:29 -0000	1.51
+++ token.module	21 Nov 2010 23:05:16 -0000
@@ -158,6 +158,8 @@ function token_form_alter(&$form, $form_
     // Profile field forms.
     case 'profile_field_form':
     case 'profile_field_delete':
+    // User picture form.
+    case 'user_admin_settings':
       $form += array('#submit' => array());
       array_unshift($form['#submit'], 'token_clear_cache');
       break;
@@ -265,7 +267,7 @@ function token_flush_caches() {
 /**
  * Retrieve, sort, store token info from the cache.
  */
-function token_get_info($token_type = NULL) {
+function token_get_info() {
   global $language;
 
   // Use the advanced drupal_static() pattern, since this is called very often.
@@ -303,12 +305,26 @@ function token_get_info($token_type = NU
     }
   }
 
-  if (empty($token_type)) {
-    return $token_info;
-  }
-  elseif (isset($token_info[$token_type])) {
-    return $token_info[$token_type];
-  }
+  return $token_info;
+}
+
+/**
+ * Retrieve information about a specific token.
+ *
+ * @param $token_type
+ *   The token type.
+ * @param $token
+ *   The token name.
+ *
+ * @return
+ *   The array of information from token_get_info()'s
+ *   $info[$token_type][$token].
+ *
+ * @see token_get_info()
+ */
+function token_get_token_info($token_type, $token) {
+  $token_info = token_get_info();
+  return isset($token_info['tokens'][$token_type][$token]) ? $token_info['tokens'][$token_type][$token] : NULL;
 }
 
 /**
Index: token.tokens.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.tokens.inc,v
retrieving revision 1.33
diff -u -p -r1.33 token.tokens.inc
--- token.tokens.inc	16 Nov 2010 03:12:10 -0000	1.33
+++ token.tokens.inc	21 Nov 2010 23:05:17 -0000
@@ -40,6 +40,7 @@ function token_token_info_alter(&$info) 
       $info['tokens'][$token_type]['path'] = array(
         'name' => t('Path'),
         'description' => t('The URL alias of the @entity.', array('@entity' => drupal_strtolower($entity_info['label']))),
+        'module' => 'token',
       );
     }
   }
@@ -126,6 +127,13 @@ function token_token_info() {
     'description' => t('The URL of the one-time login page for the user account.'),
     'restricted' => TRUE,
   );
+  if (variable_get('user_pictures', 0)) {
+    $info['tokens']['user']['picture'] = array(
+      'name' => t('Picture'),
+      'description' => t('The picture of the user.'),
+      'type' => 'file',
+    );
+  }
 
   // Menu link tokens (work regardless if menu module is enabled or not).
   $info['types']['menu-link'] = array(
@@ -304,6 +312,7 @@ function token_tokens($type, $tokens, ar
     }
   }
 
+  // File tokens.
   if ($type == 'file' && !empty($data['file'])) {
     $file = $data['file'];
 
@@ -317,6 +326,28 @@ function token_tokens($type, $tokens, ar
     }
   }
 
+  // User tokens.
+  if ($type == 'user' && !empty($data['user'])) {
+    $account = $data['user'];
+
+    foreach ($tokens as $name => $original) {
+      switch ($name) {
+        case 'picture':
+          if (variable_get('user_pictures', 0)) {
+            $replacements[$original] = theme('user_picture', array('account' => $account));
+          }
+          break;
+      }
+    }
+
+    // Chained token relationships.
+    if (variable_get('user_pictures', 0) && !empty($account->picture) && ($picture_tokens = token_find_with_prefix($tokens, 'picture'))) {
+      // @todo Remove when core bug http://drupal.org/node/978028 is fixed.
+      $account->picture->description = '';
+      $replacements += token_generate('file', $picture_tokens, array('file' => $account->picture), $options);
+    }
+  }
+
   // Menu link tokens.
   if ($type == 'menu-link' && !empty($data['menu-link'])) {
     $link = (array) $data['menu-link'];
@@ -415,6 +446,12 @@ function token_tokens($type, $tokens, ar
         // @todo Support entity:label
         // @todo Support entity:url
         case 'path':
+          $token_info = token_get_token_info($type, $name);
+          if (empty($token_info['module']) || $token_info['module'] == 'token') {
+            // We must check that this token was added by token.module itself
+            // otherwise we may cause an array to be returned.
+            continue;
+          }
           if ($uri = entity_uri($entity_type, $entity)) {
             $alias = drupal_get_path_alias($uri['path'], $language_code);
             $replacements[$original] = $sanitize ? check_plain($alias) : $alias;
Index: token.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.test,v
retrieving revision 1.27
diff -u -p -r1.27 token.test
--- token.test	16 Nov 2010 03:12:10 -0000	1.27
+++ token.test	21 Nov 2010 23:05:17 -0000
@@ -346,6 +346,52 @@ class TokenTaxonomyTestCase extends Toke
   }
 }
 
+class TokenUserTestCase extends TokenTestHelper {
+  protected $account = NULL;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'User token tests',
+      'description' => 'Test the user tokens.',
+      'group' => 'Token',
+    );
+  }
+
+  function setUp($modules = array()) {
+    parent::setUp($modules);
+
+    // Enable user pictures.
+    variable_set('user_pictures', 1);
+    variable_set('user_picture_file_size', 0);
+
+    // Set up the pictures directory.
+    $picture_path = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');
+    if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
+      $this->fail('Could not create directory ' . $picture_path . '.');
+    }
+
+    $this->account = $this->drupalCreateUser();
+    $this->drupalLogin($this->account);
+  }
+
+  function testUserTokens() {
+    // Add a user picture to the account.
+    $image = current($this->drupalGetTestFiles('image'));
+    $edit = array('files[picture_upload]' => drupal_realpath($image->uri));
+    $this->drupalPost('user/' . $this->account->uid . '/edit', $edit, t('Save'));
+
+    // Load actual user data from database.
+    $this->account = user_load($this->account->uid, TRUE);
+    $this->assertTrue(!empty($this->account->picture->fid), 'User picture uploaded.');
+
+    $user_tokens = array(
+      'picture' => theme('user_picture', array('account' => $this->account)),
+      'picture:fid' => $this->account->picture->fid,
+    );
+    $this->assertTokens('user', $this->account, $user_tokens);
+  }
+}
+
 class TokenEntityTestCase extends TokenTestHelper {
   public static function getInfo() {
     return array(
