2
// $Id: filefield_formatter.inc,v 1.13 2009/04/09 16:12:49 quicksketch Exp $
5
* FileField: Defines a CCK file field type.
7
* Uses content.module to store the fid and field specific metadata,
8
* and Drupal's {files} table to store the actual file data.
10
* This file contains CCK formatter related functionality.
14
* Theme function for the 'default' filefield formatter.
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);
24
* Theme function for the 'path_plain' formatter.
26
function theme_filefield_formatter_path_plain($element) {
27
// Inside a View this function may be called with null data. In that case,
29
if (empty($element['#item'])) {
33
$field = content_fields($element['#field_name']);
34
$item = $element['#item'];
35
// If there is no image on the database, use default.
36
if (empty($item['fid']) && $field['use_default_file']) {
37
$item = $field['default_file'];
39
if (empty($item['filepath']) && !empty($item['fid'])) {
40
$item = array_merge($item, field_file_load($item['fid']));
43
return empty($item['filepath']) ? '' : file_create_path($item['filepath']);
47
* Theme function for the 'url_plain' formatter.
49
function theme_filefield_formatter_url_plain($element) {
50
// Inside a View this function may be called with null data. In that case,
52
if (empty($element['#item'])) {
56
$field = content_fields($element['#field_name']);
57
$item = $element['#item'];
58
// If there is no image on the database, use default.
59
if (empty($item['fid']) && $field['use_default_file']) {
60
$item = $field['default_file'];
62
if (empty($item['filepath']) && !empty($item['fid'])) {
63
$item = array_merge($item, field_file_load($item['fid']));
66
return empty($item['filepath']) ? '' : file_create_url($item['filepath']);
70
* Theme function for any file that is managed by FileField.
72
* It doesn't really format stuff by itself but rather redirects to other
73
* formatters that are telling us they want to handle the concerned file.
75
* This function checks if the file may be shown and returns an empty string
76
* if viewing the file is not allowed for any reason. If you need to display it
77
* in any case, please use theme('filefield') instead.
79
function theme_filefield_item($file, $field) {
80
if (filefield_view_access($field['field_name']) && filefield_file_listed($file, $field)) {
81
return theme('filefield_file', $file);
87
* Return whether a file should be listed when viewing the node.
90
* A populated FileField item.
92
* A CCK field instance array.
94
function filefield_file_listed($file, $field) {
95
if ($field['list_field']) {
96
return (bool)$file['list'];
102
* Theme function for the 'generic' single file formatter.
104
function theme_filefield_file($file) {
105
// Views may call this function with a NULL value, return an empty string.
106
if (empty($file['fid'])) {
110
$path = $file['filepath'];
111
$url = file_create_url($path);
112
$icon = theme('filefield_icon', $file);
114
// Set options as per anchor format described at
115
// http://microformats.org/wiki/file-format-examples
116
// TODO: Possibly move to until I move to the more complex format described
117
// at http://darrelopry.com/story/microformats-and-media-rfc-if-you-js-or-css
119
'attributes' => array(
120
'type' => $file['filemime'] . '; length=' . $file['filesize'],
124
// Use the description as the link text if available.
125
if (empty($file['data']['description'])) {
126
$link_text = $file['filename'];
129
$link_text = $file['data']['description'];
130
$options['attributes']['title'] = $file['filename'];
133
return '<div class="filefield-file clear-block">'. $icon . l($link_text, $url, $options) .'</div>';