Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.7.4.30
diff -u -r1.7.4.30 token.module
--- token.module	9 Jul 2010 17:27:48 -0000	1.7.4.30
+++ token.module	17 Jul 2010 09:37:40 -0000
@@ -64,26 +64,30 @@
  * @param object
  *   Optionally, the object to use for building substitution values.
  *   A node, comment, user, etc.
+ * @param options
+ *   Global context variables to get the tokens. Some values will be always set like user, language, langcode
  * @return
  *   A keyed array containing the substitution tokens and the substitution
  *   values for the passed-in type and object.
  */
-function token_token_values($type, $object = NULL) {
-  global $user;
+function token_token_values($type, $object = NULL, $options = array()) {
   global $base_url;
+
   $values = array();
+  $options += array('base_url' => $base_url);
+  $user = $options['user'];
 
   switch ($type) {
     case 'global':
-      $values['user-name']    = $user->uid ? $user->name : variable_get('anonymous', t('Anonymous'));
+      $values['user-name']    = $user->uid ? $user->name : variable_get('anonymous', t('Anonymous', array(), $options['langcode']));
       $values['user-id']      = $user->uid ? $user->uid : 0;
       $values['user-mail']    = $user->uid ? $user->mail : '';
-      $values['site-url']     = $base_url;
+      $values['site-url']     = $options['base_url'];
       $values['site-name']    = variable_get('site_name', t('Drupal'));
       $values['site-slogan']  = variable_get('site_slogan', '');
       $values['site-mission'] = filter_xss_admin(variable_get('site_mission', ''));
       $values['site-mail']    = variable_get('site_mail', '');
-      $values += token_get_date_token_values(NULL, 'site-date-');
+      $values += token_get_date_token_values(NULL, 'site-date-', $options);
       $values['site-date'] = $values['site-date-small'];
       // The page number may or may not be present. If it is, it may be comma separated values in which case grab the first.
       $page = isset($_GET['page']) ? $_GET['page'] : '';
@@ -245,9 +249,16 @@
  *   values for the passed-in type and object.
  */
 function token_get_values($type = 'global', $object = NULL, $flush = FALSE, $options = array()) {
+  global $language;
+  global $user;
   static $tokens;
   static $running;
 
+  // Add default options, that will be current user and language
+  $options += array('language' => $language, 'user' => $user);
+  $options += array('langcode' => $options['language']->language);
+  $options += array('timezone' => variable_get('configurable_timezones', 1) && $options['user']->uid && strlen($options['user']->timezone) ? $user->timezone : variable_get('date_default_timezone', 0));
+  
   // Flush the static token cache. Useful for processes that need to slog through
   // huge numbers of tokens in a single execution cycle. Flushing it will keep
   // them from burning through memory.
@@ -278,21 +289,23 @@
   token_include();
 
   $id = _token_get_id($type, $object);
-  if ($id && isset($tokens[$type][$id])) {
-    $tmp_tokens = $tokens[$type][$id];
+  // By default, tokens will be cached by language, though this can be overriden through options
+  $cache_key = isset($options['cache_key']) ? $options['cache_key'] : $options['langcode'];
+  if ($id && isset($tokens[$cache_key][$type][$id])) {
+    $tmp_tokens = $tokens[$cache_key][$type][$id];
   }
   else {
     $tmp_tokens = module_invoke_all('token_values', $type, $object, $options);
-    $tokens[$type][$id] = $tmp_tokens;
+    $tokens[$cache_key][$type][$id] = $tmp_tokens;
   }
 
   // Special-case global tokens, as we always want to be able to process
   // those substitutions.
-  if (!isset($tokens['global']['default'])) {
-    $tokens['global']['default'] = module_invoke_all('token_values', 'global');
+  if (!isset($tokens[$cache_key]['global']['default'])) {
+    $tokens[$cache_key]['global']['default'] = module_invoke_all('token_values', 'global', NULL, $options);
   }
 
-  $all = _token_array_merge($tokens['global']['default'], $tokens[$type][$id]);
+  $all = _token_array_merge($tokens[$cache_key]['global']['default'], $tokens[$cache_key][$type][$id]);
 
   $result = new stdClass();
   $result->tokens = array_keys($all);
@@ -452,13 +465,13 @@
  *
  * @param $description
  */
-function token_get_date_token_values($timestamp = NULL, $token_prefix = '') {
+function token_get_date_token_values($timestamp = NULL, $token_prefix = '', $options = array()) {
   $tokens = array();
   $time = time();
   if (!isset($timestamp)) {
     $timestamp = $time;
   }
-  $timezone = variable_get('date_default_timezone', 0);
+  $timezone = isset($options['timezone']) ? $options['timezone'] : variable_get('date_default_timezone', 0);
 
   $formats = array(
     'yyyy' => 'Y',
