You are here

function token_get_date_token_values in Token 5

Same name and namespace in other branches
  1. 6 token.module \token_get_date_token_values()

Build a list of common date tokens for use in hook_token_values().

Parameters

$description:

5 calls to token_get_date_token_values()
comment_token_values in ./token_comment.inc
Implementation of hook_token_values().
node_token_values in ./token_node.inc
Implementation of hook_token_values().
token_cck.inc in ./token_cck.inc
token_token_values in ./token.module
Sample implementation of hook_token_values().
user_token_values in ./token_user.inc
Implementation of hook_token_values().

File

./token.module, line 471
The Token API module.

Code

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(
    'yyyy' => 'Y',
    'yy' => 'y',
    'month' => 'F',
    'mon' => 'M',
    'mm' => 'm',
    'm' => 'n',
    'ww' => 'W',
    //'date' => 'N', // Provided later since it is PHP 5.1 only.
    'day' => 'l',
    'ddd' => 'D',
    'dd' => 'd',
    'd' => 'j',
  );
  foreach ($formats as $token => $format) {
    $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', '>=')) {
    $tokens[$token_prefix . 'date'] = gmdate('N', $timestamp);
  }
  return $tokens;
}