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