| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: filefield_formatter.inc,v 1.21 2010/12/12 23:36:07 quicksketch Exp $ 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 the 'path_plain' formatter. 25 */ 26 function theme_filefield_formatter_path_plain($element) { 27 // Inside a View this function may be called with null data. In that case, 28 // just return. 29 if (empty($element['#item'])) { 30 return ''; 31 } 32 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']; 38 } 39 if (empty($item['filepath']) && !empty($item['fid'])) { 40 $item = array_merge($item, field_file_load($item['fid'])); 41 } 42 return empty($item['filepath']) ? '' : check_plain(file_create_path($item['filepath'])); 43 } 44 45 /** 46 * Theme function for the 'url_plain' formatter. 47 */ 48 function theme_filefield_formatter_url_plain($element) { 49 // Inside a View this function may be called with null data. In that case, 50 // just return. 51 if (empty($element['#item'])) { 52 return ''; 53 } 54 55 $field = content_fields($element['#field_name']); 56 $item = $element['#item']; 57 // If there is no image on the database, use default. 58 if (empty($item['fid']) && $field['use_default_file']) { 59 $item = $field['default_file']; 60 } 61 if (empty($item['filepath']) && !empty($item['fid'])) { 62 $item = array_merge($item, field_file_load($item['fid'])); 63 } 64 65 if (empty($item['filepath'])) { 66 return ''; 67 } 68 69 return file_create_url(field_file_urlencode_path($item['filepath'])); 70 } 71 72 /** 73 * Theme function for any file that is managed by FileField. 74 * 75 * It doesn't really format stuff by itself but rather redirects to other 76 * formatters that are telling us they want to handle the concerned file. 77 * 78 * This function checks if the file may be shown and returns an empty string 79 * if viewing the file is not allowed for any reason. If you need to display it 80 * in any case, please use theme('filefield_file') instead. 81 */ 82 function theme_filefield_item($file, $field) { 83 if (filefield_view_access($field['field_name']) && filefield_file_listed($file, $field)) { 84 return theme('filefield_file', $file); 85 } 86 return ''; 87 } 88 89 /** 90 * Return whether a file should be listed when viewing the node. 91 * 92 * @param $file 93 * A populated FileField item. 94 * @param $field 95 * A CCK field instance array. 96 */ 97 function filefield_file_listed($file, $field) { 98 if (!empty($field['list_field'])) { 99 return !empty($file['list']); 100 } 101 return TRUE; 102 } 103 104 /** 105 * Theme function for the 'generic' single file formatter. 106 */ 107 function theme_filefield_file($file) { 108 // Views may call this function with a NULL value, return an empty string. 109 if (empty($file['fid'])) { 110 return ''; 111 } 112 113 $path = $file['filepath']; 114 $url = file_create_url($path); 115 $icon = theme('filefield_icon', $file); 116 117 // Set options as per anchor format described at 118 // http://microformats.org/wiki/file-format-examples 119 // TODO: Possibly move to until I move to the more complex format described 120 // at http://darrelopry.com/story/microformats-and-media-rfc-if-you-js-or-css 121 $options = array( 122 'attributes' => array( 123 'type' => $file['filemime'] . '; length=' . $file['filesize'], 124 ), 125 ); 126 127 // Use the description as the link text if available. 128 if (empty($file['data']['description'])) { 129 $link_text = $file['filename']; 130 } 131 else { 132 $link_text = $file['data']['description']; 133 $options['attributes']['title'] = $file['filename']; 134 } 135 136 return '<div class="filefield-file">'. $icon . l($link_text, $url, $options) .'</div>'; 137 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |