You are here

function api_tokens_page_format_expiration in API Tokens 7

Renders expiration cell.

1 call to api_tokens_page_format_expiration()
api_tokens_page_build_row in includes/api_tokens.admin.inc
Builds token list table row.

File

includes/api_tokens.admin.inc, line 59
Administrative interface for the API Tokens module.

Code

function api_tokens_page_format_expiration($token) {

  // Token is cacheable.
  if (DRUPAL_NO_CACHE != $token['cache']) {
    $expire = $token['cache_expire'];

    // If cache isn't set to CACHE_PERMANENT (0) or CACHE_TEMPORARY (-1)
    if (0 < $expire) {
      if (31536000 <= $expire) {
        $content = t('More then one year');
      }
      else {
        $date = new DateTime('@' . $expire, new DateTimeZone('UTC'));
        $date = array(
          'month' => $date
            ->format('n') - 1,
          'day' => $date
            ->format('j') - 1,
          'hour' => $date
            ->format('G'),
          'minute' => $date
            ->format('i'),
          'second' => $date
            ->format('s'),
        );
        foreach ($date as $key => $value) {
          if (0 < $value) {
            $content = format_plural((int) $value, '1 ' . $key, '@count ' . $key . 's');
            break;
          }
        }
      }
    }
    elseif (CACHE_PERMANENT == $expire) {
      $content = t('Permanent');
    }
    else {
      $content = t('Temporary');
    }
  }
  else {
    $content = '-';
  }
  return $content;
}