Projet

Général

Profil

Paste
Télécharger (6,74 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / file_entity / file_entity.theme.inc @ 59ae487e

1
<?php
2

    
3
/**
4
 * @file
5
 * Theme callbacks for the file entity module.
6
 */
7

    
8
/**
9
 * Copy of theme_file_link() for linking to the view file page.
10
 *
11
 * @see theme_file_link()
12
 */
13
function theme_file_entity_file_link($variables) {
14
  $file = $variables['file'];
15
  $uri = entity_uri('file', $file);
16

    
17
  // Human-readable names, for use as text-alternatives to icons.
18
  $mime_name = array(
19
    'application/msword' => t('Microsoft Office document icon'),
20
    'application/vnd.ms-excel' => t('Office spreadsheet icon'),
21
    'application/vnd.ms-powerpoint' => t('Office presentation icon'),
22
    'application/pdf' => t('PDF icon'),
23
    'video/quicktime' => t('Movie icon'),
24
    'audio/mpeg' => t('Audio icon'),
25
    'audio/wav' => t('Audio icon'),
26
    'image/jpeg' => t('Image icon'),
27
    'image/png' => t('Image icon'),
28
    'image/gif' => t('Image icon'),
29
    'application/zip' => t('Package icon'),
30
    'text/html' => t('HTML icon'),
31
    'text/plain' => t('Plain text icon'),
32
    'application/octet-stream' => t('Binary Data'),
33
  );
34

    
35
  $mimetype = file_get_mimetype($file->uri);
36

    
37
  $icon = theme('file_icon', array(
38
    'file' => $file,
39
    'icon_directory' => $variables['icon_directory'],
40
    'alt' => !empty($mime_name[$mimetype]) ? $mime_name[$mimetype] : t('File'),
41
  ));
42

    
43
  // Set options as per anchor format described at
44
  // http://microformats.org/wiki/file-format-examples
45
  $uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;
46

    
47
  // Use the description as the link text if available.
48
  if (empty($file->description)) {
49
    $link_text = $file->filename;
50
  }
51
  else {
52
    $link_text = $file->description;
53
    $options['attributes']['title'] = check_plain($file->filename);
54
  }
55

    
56
  return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
57
}
58

    
59
/**
60
 * Copy of theme_file_link() for linking to the file download URL.
61
 *
62
 * @see theme_file_link()
63
 */
64
function theme_file_entity_download_link($variables) {
65
  $file = $variables['file'];
66
  $uri = file_entity_download_uri($file);
67

    
68
  // Human-readable names, for use as text-alternatives to icons.
69
  $mime_name = array(
70
    'application/msword' => t('Microsoft Office document icon'),
71
    'application/vnd.ms-excel' => t('Office spreadsheet icon'),
72
    'application/vnd.ms-powerpoint' => t('Office presentation icon'),
73
    'application/pdf' => t('PDF icon'),
74
    'video/quicktime' => t('Movie icon'),
75
    'audio/mpeg' => t('Audio icon'),
76
    'audio/wav' => t('Audio icon'),
77
    'image/jpeg' => t('Image icon'),
78
    'image/png' => t('Image icon'),
79
    'image/gif' => t('Image icon'),
80
    'application/zip' => t('Package icon'),
81
    'text/html' => t('HTML icon'),
82
    'text/plain' => t('Plain text icon'),
83
    'application/octet-stream' => t('Binary Data'),
84
  );
85

    
86
  $mimetype = file_get_mimetype($file->uri);
87

    
88
  $icon = theme('file_icon', array(
89
    'file' => $file,
90
    'icon_directory' => $variables['icon_directory'],
91
    'alt' => !empty($mime_name[$mimetype]) ? $mime_name[$mimetype] : t('File'),
92
  ));
93

    
94
  // Set options as per anchor format described at
95
  // http://microformats.org/wiki/file-format-examples
96
  $uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;
97

    
98
  // Provide the default link text.
99
  if (!isset($variables['text'])) {
100
    $variables['text'] = t('Download [file:name]');
101
  }
102

    
103
  // Perform unsanitized token replacement if $uri['options']['html'] is empty
104
  // since then l() will escape the link text.
105
  $variables['text'] = token_replace($variables['text'], array('file' => $file), array('clear' => TRUE, 'sanitize' => !empty($uri['options']['html'])));
106

    
107
  $output = '<span class="file">' . $icon . ' ' . l($variables['text'], $uri['path'], $uri['options']);
108
  $output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
109
  $output .= '</span>';
110

    
111
  return $output;
112
}
113

    
114
/**
115
 * Returns HTML for displaying an HTML5 <audio> tag.
116
 *
117
 * @param array $variables
118
 *   An associative array containing:
119
 *   - file: Associative array of file data, which must include "uri".
120
 *   - controls: Boolean indicating whether or not controls should be displayed.
121
 *   - autoplay: Boolean indicating whether or not the audio should start
122
 *     playing automatically.
123
 *   - loop: Boolean indicating whether or not the audio should loop.
124
 *
125
 * @ingroup themeable
126
 */
127
function theme_file_entity_file_audio($variables) {
128
  $files = $variables['files'];
129
  $output = '';
130

    
131
  $audio_attributes = array();
132
  if ($variables['controls']) {
133
    $audio_attributes['controls'] = 'controls';
134
  }
135
  if ($variables['autoplay']) {
136
    $audio_attributes['autoplay'] = 'autoplay';
137
  }
138
  if ($variables['loop']) {
139
    $audio_attributes['loop'] = 'loop';
140
  }
141
  if (!empty($variables['preload'])) {
142
    $audio_attributes['preload'] = $variables['preload'];
143
  }
144

    
145
  $output .= '<audio' . drupal_attributes($audio_attributes) . '>';
146
  foreach ($files as $delta => $file) {
147
    $source_attributes = array(
148
      'src' => file_create_url($file['uri']),
149
      'type' => $file['filemime'],
150
    );
151
    $output .= '<source' . drupal_attributes($source_attributes) . ' />';
152
  }
153
  $output .= '</audio>';
154
  return $output;
155
}
156

    
157
/**
158
 * Returns HTML for displaying an HTML5 <video> tag.
159
 *
160
 * @param array $variables
161
 *   An associative array containing:
162
 *   - file: Associative array of file data, which must include "uri".
163
 *   - controls: Boolean indicating whether or not controls should be displayed.
164
 *   - autoplay: Boolean indicating whether or not the video should start
165
 *     playing automatically.
166
 *   - loop: Boolean indicating whether or not the video should loop.
167
 *   - muted: Boolean indicating whether or not the sound should be muted.
168
 *   - width: Width, in pixels, of the video player.
169
 *   - height: Height, in pixels, of the video player.
170
 *
171
 * @ingroup themeable
172
 */
173
function theme_file_entity_file_video($variables) {
174
  $files = $variables['files'];
175
  $output = '';
176

    
177
  $video_attributes = array();
178
  if ($variables['controls']) {
179
    $video_attributes['controls'] = 'controls';
180
  }
181
  if ($variables['autoplay']) {
182
    $video_attributes['autoplay'] = 'autoplay';
183
  }
184
  if ($variables['loop']) {
185
    $video_attributes['loop'] = 'loop';
186
  }
187
  if ($variables['muted']) {
188
    $video_attributes['muted'] = 'muted';
189
  }
190
  if ($variables['width']) {
191
    $video_attributes['width'] = $variables['width'];
192
  }
193
  if ($variables['height']) {
194
    $video_attributes['height'] = $variables['height'];
195
  }
196
  if (!empty($variables['preload'])) {
197
    $video_attributes['preload'] = $variables['preload'];
198
  }
199

    
200
  $output .= '<video' . drupal_attributes($video_attributes) . '>';
201
  foreach ($files as $delta => $file) {
202
    $source_attributes = array(
203
      'src' => file_create_url($file['uri']),
204
      'type' => $file['filemime'],
205
    );
206
    $output .= '<source' . drupal_attributes($source_attributes) . ' />';
207
  }
208
  $output .= '</video>';
209
  return $output;
210
}