Issue #1047480: Provide icons for rtf (application/rtf) and pps
[project/filefield.git] / filefield.token.inc
CommitLineData
ae22fefe
DP
1<?php
2
3/**
87d3e491
NH
4 * @file
5 * Token hook implementations. Included if token.module is installed.
6 */
7
8/**
dc273ff9
NH
9 * Implementation of hook_token_list().
10 *
11 * Provide a user readable list of FileField tokens.
ae22fefe
DP
12 */
13function filefield_token_list($type = 'all') {
14 if ($type == 'field' || $type == 'all') {
15 $tokens = array();
ee665c76
NH
16 $tokens['file']['filefield-fid'] = t('File ID');
17 $tokens['file']['filefield-description'] = t('File description');
18 $tokens['file']['filefield-filename'] = t('File name');
19 $tokens['file']['filefield-filepath'] = t('File path');
20 $tokens['file']['filefield-filemime'] = t('File MIME type');
21 $tokens['file']['filefield-filesize'] = t('File size (in bytes)');
22 $tokens['file']['filefield-filesize_formatted'] = t('File size (pretty printed)');
23 $tokens['file']['filefield-view'] = t('Fully formatted HTML file tag');
24 $tokens['file']['filefield-onlyname'] = t('File name without extension');
25 $tokens['file']['filefield-extension'] = t('File extension');
ae22fefe
DP
26 return $tokens;
27 }
28}
29
30/**
dc273ff9
NH
31 * Implementation of hook_token_values().
32 *
33 * Provide the token values for a given file item.
ae22fefe
DP
34 */
35function filefield_token_values($type, $object = NULL) {
7673e58c 36 $tokens = array();
37 if ($type == 'field' && isset($object[0]['fid'])) {
ae22fefe 38 $item = $object[0];
94bdd499 39 $tokens['filefield-fid'] = $item['fid'];
ac4e6d49
NH
40 $tokens['filefield-description'] = isset($item['data']['description']) ? check_plain($item['data']['description']) : '';
41 $tokens['filefield-filename'] = check_plain($item['filename']);
42 $tokens['filefield-filepath'] = check_plain($item['filepath']);
94bdd499
DP
43 $tokens['filefield-filemime'] = $item['filemime'];
44 $tokens['filefield-filesize'] = $item['filesize'];
45 $tokens['filefield-filesize_formatted'] = format_size($item['filesize']);
46 $tokens['filefield-view'] = $item['view'];
45cabd3e
DP
47 $double_extensions = array('tar.gz', 'tar.bz2');
48 foreach ($double_extensions as $ext) {
49 $length = strlen($ext) + 1;
50 $filename = drupal_strtolower($item['filename']);
51 $pos = strrpos($filename, '.'. $ext);
52 if ($pos !== FALSE && strlen($filename) - $pos == $length) {
53 $tokens['filefield-onlyname'] = substr($item['filename'], 0, $pos);
54 $tokens['filefield-extension'] = $ext;
55 break;
56 }
57 }
58 if (!isset($tokens['filefield-extension'])) {
59 $info = pathinfo($item['filename']);
fa7b2393 60 $tokens['filefield-onlyname'] = basename($info['basename'], '.'. $info['extension']);
45cabd3e
DP
61 $tokens['filefield-extension'] = $info['extension'];
62 }
ae22fefe 63 }
7673e58c 64 return $tokens;
ae22fefe 65}