#372993: Remove private function call from theme functions. Better PHPdoc.
[project/filefield.git] / filefield_formatter.inc
1 <?php
2 // $Id$
3 /**
4 * @file
5 * FileField: Defines a CCK file field type.
6 *
7 * Uses content.module to store the fid and field specific metadata,
8 * and Drupal's {files} table to store the actual file data.
9 *
10 * This file contains CCK formatter related functionality.
11 */
12
13 /**
14 * Theme function for the 'default' filefield formatter.
15 */
16 function theme_filefield_formatter_default($element) {
17 $file = $element['#item'];
18 $field = content_fields($element['#field_name']);
19 $output = theme('filefield_item', $file, $field);
20 return $output;
21 }
22
23 /**
24 * Theme function for any file that is managed by filefield.
25 * It doesn't really format stuff by itself but rather redirects to other
26 * formatters that are telling us they want to handle the concerned file.
27 *
28 * This function checks if the file may be shown and returns an empty string
29 * if viewing the file is not allowed for any reason. If you need to display it
30 * in any case, please use theme('filefield') instead.
31 */
32 function theme_filefield_item($file, $field) {
33 if (!filefield_view_access($field['field_name'])) {
34 return '<!-- you do not have access to view this file -->';
35 }
36
37 if (filefield_file_listed($file, $field)) {
38 return theme('filefield_file', $file);
39 }
40 return '';
41 }
42
43 /**
44 * Return whether a file should be listed when viewing the node.
45 *
46 * @param $file
47 * A populated FileField item.
48 * @param $field
49 * A CCK field instance array.
50 */
51 function filefield_file_listed($file, $field) {
52 if ($field['list_field']) {
53 return (bool)$file['list'];
54 }
55 return TRUE;
56 }
57
58 /**
59 * Theme function for the 'generic' single file formatter.
60 */
61 function theme_filefield_file($file) {
62 // Views may call this function with a NULL value, return an empty string.
63 if (empty($file['fid'])) {
64 return '';
65 }
66
67 $path = $file['filepath'];
68 $url = file_create_url($path);
69 $icon = theme('filefield_icon', $file);
70 // set options as per anchor format described on http://microformats.org/wiki/file-format-examples
71 // until I move to the more complex microformat described
72 // @ http://darrelopry.com/story/microformats-and-media-rfc-if-you-js-or-css
73 $options = array('attributes' => array('type' => $file['filemime'], 'length' => $file['filesize']));
74 $options['attributes']['title'] = (isset($file['data']['description'])) ? $file['data']['description'] : $file['filename'];
75 return '<div class="filefield-file clear-block">'. $icon . l($file['filename'], $url, $options) .'</div>';
76 }