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
|
$output = '<span class="file">' . $icon . ' ' . l($link_text, $uri['path'], $uri['options']);
|
57
|
$output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
|
58
|
$output .= '</span>';
|
59
|
return $output;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Copy of theme_file_link() for linking to the file download URL.
|
64
|
*
|
65
|
* @see theme_file_link()
|
66
|
*/
|
67
|
function theme_file_entity_download_link($variables) {
|
68
|
$file = $variables['file'];
|
69
|
$uri = file_entity_download_uri($file);
|
70
|
|
71
|
// Human-readable names, for use as text-alternatives to icons.
|
72
|
$mime_name = array(
|
73
|
'application/msword' => t('Microsoft Office document icon'),
|
74
|
'application/vnd.ms-excel' => t('Office spreadsheet icon'),
|
75
|
'application/vnd.ms-powerpoint' => t('Office presentation icon'),
|
76
|
'application/pdf' => t('PDF icon'),
|
77
|
'video/quicktime' => t('Movie icon'),
|
78
|
'audio/mpeg' => t('Audio icon'),
|
79
|
'audio/wav' => t('Audio icon'),
|
80
|
'image/jpeg' => t('Image icon'),
|
81
|
'image/png' => t('Image icon'),
|
82
|
'image/gif' => t('Image icon'),
|
83
|
'application/zip' => t('Package icon'),
|
84
|
'text/html' => t('HTML icon'),
|
85
|
'text/plain' => t('Plain text icon'),
|
86
|
'application/octet-stream' => t('Binary Data'),
|
87
|
);
|
88
|
|
89
|
$mimetype = file_get_mimetype($file->uri);
|
90
|
|
91
|
$icon = theme('file_icon', array(
|
92
|
'file' => $file,
|
93
|
'icon_directory' => $variables['icon_directory'],
|
94
|
'alt' => !empty($mime_name[$mimetype]) ? $mime_name[$mimetype] : t('File'),
|
95
|
));
|
96
|
|
97
|
// Set options as per anchor format described at
|
98
|
// http://microformats.org/wiki/file-format-examples
|
99
|
$uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;
|
100
|
|
101
|
// Provide the default link text.
|
102
|
if (!isset($variables['text'])) {
|
103
|
$variables['text'] = t('Download [file:name]');
|
104
|
}
|
105
|
|
106
|
// Perform unsanitized token replacement if $uri['options']['html'] is empty
|
107
|
// since then l() will escape the link text.
|
108
|
$variables['text'] = token_replace($variables['text'], array('file' => $file), array('clear' => TRUE, 'sanitize' => !empty($uri['options']['html'])));
|
109
|
|
110
|
$output = '<span class="file">' . $icon . ' ' . l($variables['text'], $uri['path'], $uri['options']);
|
111
|
$output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
|
112
|
$output .= '</span>';
|
113
|
|
114
|
return $output;
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Returns HTML for displaying an HTML5 <audio> tag.
|
119
|
*
|
120
|
* @param array $variables
|
121
|
* An associative array containing:
|
122
|
* - file: Associative array of file data, which must include "uri".
|
123
|
* - controls: Boolean indicating whether or not controls should be displayed.
|
124
|
* - autoplay: Boolean indicating whether or not the audio should start
|
125
|
* playing automatically.
|
126
|
* - loop: Boolean indicating whether or not the audio should loop.
|
127
|
*
|
128
|
* @ingroup themeable
|
129
|
*/
|
130
|
function theme_file_entity_file_audio($variables) {
|
131
|
$files = $variables['files'];
|
132
|
$output = '';
|
133
|
|
134
|
$audio_attributes = array();
|
135
|
if ($variables['controls']) {
|
136
|
$audio_attributes['controls'] = 'controls';
|
137
|
|
138
|
if (!empty($variables['controls_list'])) {
|
139
|
$controls_list = array();
|
140
|
foreach ($variables['controls_list'] as $key => $value) {
|
141
|
if (!$value) {
|
142
|
switch ($key) {
|
143
|
case 'download':
|
144
|
$controls_list[] = 'nodownload';
|
145
|
break;
|
146
|
case 'remote_playback':
|
147
|
$controls_list[] = 'noremoteplayback';
|
148
|
break;
|
149
|
}
|
150
|
}
|
151
|
}
|
152
|
$audio_attributes['controlsList'] = implode(' ', $controls_list);
|
153
|
}
|
154
|
}
|
155
|
if ($variables['autoplay']) {
|
156
|
$audio_attributes['autoplay'] = 'autoplay';
|
157
|
}
|
158
|
if ($variables['loop']) {
|
159
|
$audio_attributes['loop'] = 'loop';
|
160
|
}
|
161
|
if (!empty($variables['preload'])) {
|
162
|
$audio_attributes['preload'] = $variables['preload'];
|
163
|
}
|
164
|
|
165
|
$output .= '<audio' . drupal_attributes($audio_attributes) . '>';
|
166
|
foreach ($files as $delta => $file) {
|
167
|
$source_attributes = array(
|
168
|
'src' => file_create_url($file['uri']),
|
169
|
'type' => $file['filemime'],
|
170
|
);
|
171
|
$output .= '<source' . drupal_attributes($source_attributes) . ' />';
|
172
|
}
|
173
|
$output .= '</audio>';
|
174
|
return $output;
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* Returns HTML for displaying an HTML5 <video> tag.
|
179
|
*
|
180
|
* @param array $variables
|
181
|
* An associative array containing:
|
182
|
* - file: Associative array of file data, which must include "uri".
|
183
|
* - controls: Boolean indicating whether or not controls should be displayed.
|
184
|
* - autoplay: Boolean indicating whether or not the video should start
|
185
|
* playing automatically.
|
186
|
* - loop: Boolean indicating whether or not the video should loop.
|
187
|
* - muted: Boolean indicating whether or not the sound should be muted.
|
188
|
* - width: Width, in pixels, of the video player.
|
189
|
* - height: Height, in pixels, of the video player.
|
190
|
* - playsinline: Boolean indicating if video should automatically play on
|
191
|
* mobile (iOS).
|
192
|
*
|
193
|
* @ingroup themeable
|
194
|
*/
|
195
|
function theme_file_entity_file_video($variables) {
|
196
|
$files = $variables['files'];
|
197
|
$output = '';
|
198
|
|
199
|
$video_attributes = array();
|
200
|
if ($variables['controls']) {
|
201
|
$video_attributes['controls'] = 'controls';
|
202
|
|
203
|
if (!empty($variables['controls_list'])) {
|
204
|
$controls_list = array();
|
205
|
foreach ($variables['controls_list'] as $key => $value) {
|
206
|
if (!$value) {
|
207
|
switch ($key) {
|
208
|
case 'fullscreen':
|
209
|
$controls_list[] = 'nofullscreen';
|
210
|
break;
|
211
|
case 'download':
|
212
|
$controls_list[] = 'nodownload';
|
213
|
break;
|
214
|
case 'remote_playback':
|
215
|
$controls_list[] = 'noremoteplayback';
|
216
|
break;
|
217
|
}
|
218
|
}
|
219
|
}
|
220
|
$video_attributes['controlsList'] = implode(' ', $controls_list);
|
221
|
}
|
222
|
}
|
223
|
if ($variables['autoplay']) {
|
224
|
$video_attributes['autoplay'] = 'autoplay';
|
225
|
}
|
226
|
if ($variables['loop']) {
|
227
|
$video_attributes['loop'] = 'loop';
|
228
|
}
|
229
|
if ($variables['muted']) {
|
230
|
$video_attributes['muted'] = 'muted';
|
231
|
}
|
232
|
if ($variables['width']) {
|
233
|
$video_attributes['width'] = $variables['width'];
|
234
|
}
|
235
|
if ($variables['height']) {
|
236
|
$video_attributes['height'] = $variables['height'];
|
237
|
}
|
238
|
if (!empty($variables['preload'])) {
|
239
|
$video_attributes['preload'] = $variables['preload'];
|
240
|
}
|
241
|
if ($variables['playsinline']) {
|
242
|
$video_attributes['playsinline'] = 'playsinline';
|
243
|
}
|
244
|
|
245
|
$output .= '<video' . drupal_attributes($video_attributes) . '>';
|
246
|
foreach ($files as $delta => $file) {
|
247
|
$source_attributes = array(
|
248
|
'src' => file_create_url($file['uri']),
|
249
|
'type' => $file['filemime'],
|
250
|
);
|
251
|
$output .= '<source' . drupal_attributes($source_attributes) . ' />';
|
252
|
}
|
253
|
$output .= '</video>';
|
254
|
return $output;
|
255
|
}
|