2a9958e852b4ff8e6a97057b49d49002181c2ce0
[project/filefield.git] / filefield_meta / filefield_meta.token.inc
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Token integration for FileField Meta.
7 */
8
9 /**
10 * Implementation of hook_token_list().
11 *
12 * Provide a user readable list of FileField Meta tokens.
13 */
14 function filefield_meta_token_list($type = 'all') {
15 if ($type == 'field' || $type == 'all') {
16 $tokens['file']['filefield-width'] = t('File Video width');
17 $tokens['file']['filefield-height'] = t('File Video height');
18 $tokens['file']['filefield-duration'] = t('File Duration');
19 $tokens['file']['filefield-audio-format'] = t('File Audio Format path');
20 $tokens['file']['filefield-audio-sample-rate'] = t('File Audio sample rate');
21 $tokens['file']['filefield-audio-channel-mode'] = t('File Audio channel mode (stereo, mono)');
22 $tokens['file']['filefield-audio-bitrate'] = t('File Audio bitrate');
23 $tokens['file']['filefield-audio-bitrate-mode'] = t('File Audio bitrate mode (cbr, vbr, abr...)');
24
25 // ID3 tags.
26 foreach (filefield_meta_tags() as $tag => $label) {
27 $tokens['file']['filefield-tag-' . $tag] = t('File ID3 @tag tag', array('@tag' => $label));
28 }
29
30 return $tokens;
31 }
32 }
33
34 /**
35 * Implementation of hook_token_values().
36 *
37 * Provide the token values for a given file item.
38 */
39 function filefield_meta_token_values($type, $object = NULL) {
40 $tokens = array();
41 if ($type == 'field' && isset($object[0]['fid'])) {
42 $item = $object[0];
43
44 $tokens['filefield-width'] = $item['data']['width'] ;
45 $tokens['filefield-height'] = $item['data']['height'] ;
46 $tokens['filefield-duration'] = $item['data']['duration'] ;
47 $tokens['filefield-audio-format'] = isset($item['data']['audio_format']) ? check_plain($item['data']['audio_format']) : '';
48 $tokens['filefield-audio-sample-rate'] = isset($item['data']['sample_rate']) ? check_plain($item['data']['sample_rate']) : '';
49 $tokens['filefield-audio-channel-mode'] = isset($item['data']['audio_channel_mode']) ? check_plain($item['data']['audio_channel_mode']) : '';
50 $tokens['filefield-audio-bitrate'] = isset($item['data']['audio_bitrate']) ? check_plain($item['data']['audio_bitrate']) : '';
51 $tokens['filefield-audio-bitrate-mode'] = isset($item['data']['audio_bitrate_mode']) ? check_plain($item['data']['audio_bitrate_mode']) : '';
52
53 // ID3 tags.
54 foreach (filefield_meta_tags() as $tag => $label) {
55 $tokens['filefield-tag-title'] = isset($item['data']['tags'][$tag]) ? check_plain($item['data']['tags'][$tag]) : '';
56 }
57 }
58
59 return $tokens;
60 }