? token_profile.inc Index: token.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v retrieving revision 1.7.4.22 diff -u -p -r1.7.4.22 token.module --- token.module 7 Jun 2010 22:35:56 -0000 1.7.4.22 +++ token.module 8 Jun 2010 04:32:42 -0000 @@ -73,9 +73,8 @@ function token_token_values($type, $obje $values['site-slogan'] = variable_get('site_slogan', ''); $values['site-mission'] = filter_xss_admin(variable_get('site_mission', '')); $values['site-mail'] = variable_get('site_mail', ''); - $time = time(); $tz = variable_get('date_default_timezone', 0); - $values['site-date'] = format_date($time, 'small', '', $tz); - $values += token_get_date_token_values($time, 'site-date-'); + $values += token_get_date_token_values(NULL, 'site-date-'); + $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'] : ''; $values['page-number'] = 1 + (int)(($p = strpos($page, ',')) ? substr($page, 0, $p) : $page); @@ -107,7 +106,6 @@ function token_token_list($type = 'all') $tokens['global']['site-slogan'] = t('The slogan of the current Drupal website.'); $tokens['global']['site-mission'] = t('The mission of the current Drupal website.'); $tokens['global']['site-mail'] = t('The contact email address for the current Drupal website.'); - $tokens['global']['site-date'] = t("The current date on the site's server."); $tokens['global'] += token_get_date_token_info(t('The current'), 'site-date-'); return $tokens; } @@ -386,6 +384,7 @@ function _token_get_id($type = 'global', * @param $description */ function token_get_date_token_info($description, $token_prefix = '') { + $tokens[$token_prefix . 'small'] = t("!description date in 'small' format. (06/07/2010 - 23:28)", array('!description' => $description)); $tokens[$token_prefix . 'yyyy'] = t("!description year (four digit)", array('!description' => $description)); $tokens[$token_prefix . 'yy'] = t("!description year (two digit)", array('!description' => $description)); $tokens[$token_prefix . 'month'] = t("!description month (full word)", array('!description' => $description)); @@ -401,6 +400,7 @@ function token_get_date_token_info($desc $tokens[$token_prefix . 'dd'] = t("!description day (two digits with leading zeros)", array('!description' => $description)); $tokens[$token_prefix . 'd'] = t("!description day (one or two digits without leading zeros)", array('!description' => $description)); $tokens[$token_prefix . 'raw'] = t("!description in UNIX timestamp format (1269441371)", array('!description' => $description)); + $tokens[$token_prefix . 'since'] = t("!description in 'time-since' format. (40 years 3 months)", array('!description' => $description)); return $tokens; } @@ -409,8 +409,12 @@ function token_get_date_token_info($desc * * @param $description */ -function token_get_date_token_values($timestamp, $token_prefix = '') { +function token_get_date_token_values($timestamp = NULL, $token_prefix = '') { $tokens = array(); + $time = time(); + if (!isset($timestamp)) { + $timestamp = $time; + } $timezone = variable_get('date_default_timezone', 0); $formats = array( @@ -431,7 +435,9 @@ function token_get_date_token_values($ti $tokens[$token_prefix . $token] = format_date($timestamp, 'custom', $format, $timezone); } + $tokens[$token_prefix . 'small'] = format_date($timestamp, 'small', '', $timezone); $tokens[$token_prefix . 'raw'] = $timestamp; + $tokens[$token_prefix . 'since'] = format_interval($time - $timestamp); $timestamp += $timezone; if (version_compare(PHP_VERSION, '5.1.0', '>=')) { Index: token.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/token/token.test,v retrieving revision 1.1.2.7 diff -u -p -r1.1.2.7 token.test --- token.test 8 Jun 2010 03:35:57 -0000 1.1.2.7 +++ token.test 8 Jun 2010 04:32:42 -0000 @@ -25,7 +25,7 @@ class TokenTestHelper extends DrupalWebT $values = token_get_values($type, $object, TRUE, $options); $values = array_combine($values->tokens, $values->values); foreach ($tokens as $token => $expected) { - $this->assertIdentical($values[$token], $expected, t("Token value for [@token] was '!actual', expected value '!expected'.", array('@token' => $token, '!actual' => $values[$token], '!expected' => $expected))); + $this->assertIdentical($values[$token], $expected, t("Token value for [@token] was '@actual', expected value '@expected'.", array('@token' => $token, '@actual' => $values[$token], '@expected' => $expected))); } } } @@ -40,13 +40,14 @@ class TokenNodeTestCase extends TokenTes } function testNodeTokens() { + $time = time(); $created = gmmktime(0, 0, 0, 11, 19, 1978); $changed = gmmktime(0, 0, 0, 7, 4, 1984); $node = $this->drupalCreateNode(array( 'type' => 'page', 'language' => 'und', 'created' => $created, - 'log' => '' . $this->randomString() . '', + 'log' => '' . $this->randomName() . '', )); $node->changed = $changed; @@ -55,6 +56,7 @@ class TokenNodeTestCase extends TokenTes 'type' => 'page', 'type-name' => 'Page', 'language' => 'und', + 'small' => '11/19/1978 - 00:00', 'yyyy' => '1978', 'yy' => '78', 'month' => 'November', @@ -68,6 +70,8 @@ class TokenNodeTestCase extends TokenTes 'dd' => '19', 'd' => '19', 'raw' => 280281600, + 'since' => format_interval($time - 280281600), + 'mod-small' => '07/04/1984 - 00:00', 'mod-yyyy' => '1984', 'mod-yy' => '84', 'mod-month' => 'July', @@ -81,6 +85,7 @@ class TokenNodeTestCase extends TokenTes 'mod-dd' => '04', 'mod-d' => '4', 'mod-raw' => 457747200, + 'mod-since' => format_interval($time - 457747200), 'log' => filter_xss($node->log), 'log-raw' => $node->log, ); @@ -126,6 +131,7 @@ class TokenCommentTestCase extends Token } function testCommentTokens() { + $time = time(); $comment = $this->createComment(array( 'timestamp' => gmmktime(0, 0, 0, 7, 4, 1984), )); @@ -146,6 +152,7 @@ class TokenCommentTestCase extends Token 'comment-dd' => '04', 'comment-d' => '4', 'comment-raw' => '457747200', + 'comment-since' => format_interval($time - 457747200), ); $this->assertTokens('comment', $comment, $tokens); Index: token_node.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/token/Attic/token_node.inc,v retrieving revision 1.5.4.24 diff -u -p -r1.5.4.24 token_node.inc --- token_node.inc 8 Jun 2010 03:35:57 -0000 1.5.4.24 +++ token_node.inc 8 Jun 2010 04:32:42 -0000 @@ -197,7 +197,7 @@ function node_token_list($type = 'all') // $tokens['node']['catpath'] = t("Full taxonomy tree for the topmost term"); $tokens['node'] += token_get_date_token_info(t('Node creation')); - $tokens['node']['mod-????'] = t('All tokens for node creation dates can also be used with with the "mod-" prefix; doing so will use the modification date rather than the creation date.'); + $tokens['node'] += token_get_date_token_info(t('Node modification'), 'mod-'); $tokens['node']['menu'] = t("The name of the menu the node belongs to."); $tokens['node']['menu-raw'] = t("The name of the menu the node belongs to."); Index: token_user.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/token/Attic/token_user.inc,v retrieving revision 1.3.4.7 diff -u -p -r1.3.4.7 token_user.inc --- token_user.inc 5 Jun 2010 16:45:58 -0000 1.3.4.7 +++ token_user.inc 8 Jun 2010 04:32:42 -0000 @@ -38,14 +38,19 @@ function user_token_values($type, $objec $values['user-raw'] = $account->name; $values['uid'] = $account->uid; $values['mail'] = $account->uid ? $account->mail : ''; - $values['reg-date'] = $account->uid ? format_date($account->created, 'small') : ''; - $values['reg-since'] = $account->uid ? format_interval(time() - $account->created) : ''; - $values['log-date'] = $account->uid ? format_date($account->access, 'small') : ''; - $values['log-since'] = $account->uid ? format_interval(time() - $account->access) : ''; $values['date-in-tz'] = $account->uid ? format_date(time(), 'small', '', $account->timezone) : ''; $values['account-url'] = $account->uid ? url("user/$account->uid") : ''; $values['account-edit'] = $account->uid ? url("user/$account->uid/edit") : ''; + if ($account->uid) { + $values += token_get_date_token_values($account->created, 'user-created-'); + $values += token_get_date_token_values($account->access, 'user-last-login-'); + $values['reg-date'] = $values['user-created-small']; + $values['reg-since'] = $values['user-created-since']; + $values['log-date'] = $values['user-last-login-small']; + $values['log-since'] = $values['user-last-login-since']; + } + break; } return $values; @@ -62,10 +67,8 @@ function user_token_list($type = 'all') $tokens['user']['uid'] = t("User's ID"); $tokens['user']['mail'] = t("User's email address"); - $tokens['user']['reg-date'] = t("User's registration date"); - $tokens['user']['reg-since'] = t("User's registration date in 'time-since' format. (40 years 2 months)"); - $tokens['user']['log-date'] = t("User's last login date"); - $tokens['user']['log-since'] = t("User's last login date in 'time-since' format. (40 years 2 months)"); + $tokens['user'] += token_get_date_token_info(t("User's registration"), 'user-created-'); + $tokens['user'] += token_get_date_token_info(t("User's last login"), 'user-last-login-'); $tokens['user']['date-in-tz'] = t("The current date in the user's timezone"); $tokens['user']['account-url'] = t("The URL of the user's profile page."); $tokens['user']['account-edit'] = t("The URL the user's account editing page.");