You are here

function getid3_tokens in getID3() 7

Same name and namespace in other branches
  1. 7.2 getid3.tokens.inc \getid3_tokens()

Implements hook_tokens().

File

./getid3.tokens.inc, line 56
Builds placeholder replacement tokens for files.

Code

function getid3_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $language_code = isset($options['language']) ? $options['language']->language : NULL;
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'file' && !empty($data['file'])) {
    $file = $data['file'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'width':
          $replacements[$original] = (int) $file->getid3->width;
          break;
        case 'height':
          $replacements[$original] = (int) $file->getid3->height;
          break;
        case 'duration':
          $replacements[$original] = theme('getid3_duration', array(
            'duration' => $file->getid3->duration,
          ));
          break;
        case 'audio-format':
          $replacements[$original] = $sanitize ? check_plain($file->getid3->audio_format) : $file->getid3->audio_format;
          break;
        case 'audio-sample-rate':
          $replacements[$original] = theme('getid3_sample_rate', array(
            'sample_rate' => $file->getid3->audio_sample_rate,
          ));
          break;
        case 'audio-channel-mode':
          $replacements[$original] = $sanitize ? check_plain($file->getid3->audio_channel_mode) : $file->getid3->audio_channel_mode;
          break;
        case 'audio-bitrate':
          $replacements[$original] = theme('getid3_bitrate', array(
            'bitrate' => $file->getid3->audio_bitrate,
          ));
          break;
        case 'audio-bitrate-mode':
          $replacements[$original] = $sanitize ? check_plain($file->getid3->audio_bitrate_mode) : $file->getid3->audio_bitrate_mode;
          break;
      }
    }
  }

  // TODO: ID3 tags
  return $replacements;
}