created)) { $date = (int)$node->created; $values += token_time_date_values($date); } if (isset($node->changed)) { $date = (int)$node->changed; $values += token_time_date_values($date, 'mod'); } break; case 'comment': } return $values; } /** * A helper function to build token values for dates. * Thanks NancyDru, http://drupal.org/node/307520#comment-1073927 * Thanks lomz, http://drupal.org/node/323441#comment-1526090 * * @param $date * The date to be formatted. * @param $prefix * The prefix for the value names. * @return * The array of formatted values. Typically this would be appended * to an existing array ($values += token_date_values($date, 'prefix') */ function token_time_date_values($date, $prefix = NULL) { if ($prefix) { $prefix .= '-'; } $values = array( $prefix .'small' => format_date($date, 'small'), $prefix .'medium' => format_date($date, 'medium'), $prefix .'large' => format_date($date, 'large'), ); $date = (int)$date; $values += array( $prefix . 'g' => date('g', $date), $prefix . 'G' => date('G', $date), $prefix . 'h' => date('h', $date), $prefix . 'H' => date('H', $date), $prefix . 'i' => date('i', $date), $prefix . 's' => date('s', $date), $prefix . 'U' => date('U', $date), ); return $values; } /** * Implementation of hook_token_list(). */ function token_time_token_list($type = 'all') { $tokens = array(); switch($type) { case 'node': case 'all': $tokens['node']['g'] = t("Node creation time (12-hour format, without leading zeros)"); $tokens['node']['G'] = t("Node creation time (24-hour format, without leading zeros)"); $tokens['node']['h'] = t("Node creation time (12-hour format, with leading zeros)"); $tokens['node']['H'] = t("Node creation time (24-hour format, with leading zeros)"); $tokens['node']['i'] = t("Node creation minute (with leading zeros)"); $tokens['node']['s'] = t("Node creation second (with leading zeros)"); $tokens['node']['U'] = t("Node creation time since Epoch (seconds since January 1, 1970)"); break; case 'comment': $tokens['comment']['comment-g'] = t("Comment creation time (12-hour format, without leading zeros)"); $tokens['comment']['comment-G'] = t("Comment creation time (24-hour format, without leading zeros)"); $tokens['comment']['comment-h'] = t("Comment creation time (12-hour format, with leading zeros)"); $tokens['comment']['comment-H'] = t("Comment creation time (24-hour format, with leading zeros)"); $tokens['comment']['comment-i'] = t("Comment creation minute (with leading zeros)"); $tokens['comment']['comment-s'] = t("Comment creation second (with leading zeros)"); $tokens['comment']['comment-U'] = t("Comment creation time since Epoch (seconds since January 1, 1970)"); } return $tokens; }