forked from md-systems/file_entity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_entity.theme.inc
160 lines (141 loc) · 4.97 KB
/
file_entity.theme.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* @file
* Theme callbacks for the file entity module.
*/
/**
* Copy of theme_file_file_link() for linking to the view file page.
*
* @see theme_file_file_link()
*/
function theme_file_entity_file_link($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
$url = 'file/' . $file->fid;
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
// Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples
$options = array(
'attributes' => array(
'type' => $file->filemime . '; length=' . $file->filesize,
),
);
// Use the description as the link text if available.
if (empty($file->description)) {
$link_text = $file->filename;
}
else {
$link_text = $file->description;
$options['attributes']['title'] = check_plain($file->filename);
}
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}
/**
* Copy of theme_file_file_link() for linking to the file download URL.
*
* @see theme_file_file_link()
*/
function theme_file_entity_download_link($variables) {
$file = $variables['file'];
$icon_directory = $variables['icon_directory'];
$uri = file_entity_download_url($file)->toString();
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
// Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples
$uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;
// Provide the default link text.
if (!isset($variables['text'])) {
$variables['text'] = t('Download [file:name]');
}
// Peform unsanitized token replacement if $uri['options']['html'] is empty
// since then l() will escape the link text.
$variables['text'] = token_replace($variables['text'], array('file' => $file), array('clear' => TRUE, 'sanitize' => empty($uri['options']['html'])));
$output = '<span class="file">' . $icon . ' ' . l($variables['text'], $uri['path'], $uri['options']);
$output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
$output .= '</span>';
return $output;
}
/**
* Returns HTML for displaying an HTML5 <audio> tag.
*
* @param array $variables
* An associative array containing:
* - file: Associative array of file data, which must include "uri".
* - controls: Boolean indicating whether or not controls should be displayed.
* - autoplay: Boolean indicating whether or not the audio should start
* playing automatically.
* - loop: Boolean indicating whether or not the audio should loop.
*
* @ingroup themeable
*/
function theme_file_entity_file_audio($variables) {
$files = $variables['files'];
$output = '';
$audio_attributes = array();
if ($variables['controls']) {
$audio_attributes['controls'] = 'controls';
}
if ($variables['autoplay']) {
$audio_attributes['autoplay'] = 'autoplay';
}
if ($variables['loop']) {
$audio_attributes['loop'] = 'loop';
}
$output .= '<audio' . drupal_attributes($audio_attributes) . '>';
foreach ($files as $delta => $file) {
$source_attributes = array(
'src' => file_create_url($file['uri']),
'type' => $file['filemime'],
);
$output .= '<source' . drupal_attributes($source_attributes) . ' />';
}
$output .= '</audio>';
return $output;
}
/**
* Returns HTML for displaying an HTML5 <video> tag.
*
* @param array $variables
* An associative array containing:
* - file: Associative array of file data, which must include "uri".
* - controls: Boolean indicating whether or not controls should be displayed.
* - autoplay: Boolean indicating whether or not the video should start
* playing automatically.
* - loop: Boolean indicating whether or not the video should loop.
* - muted: Boolean indicating whether or not the sound should be muted.
* - width: Width, in pixels, of the video player.
* - height: Height, in pixels, of the video player.
*
* @ingroup themeable
*/
function theme_file_entity_file_video($variables) {
$files = $variables['files'];
$output = '';
$video_attributes = array();
if ($variables['controls']) {
$video_attributes['controls'] = 'controls';
}
if ($variables['autoplay']) {
$video_attributes['autoplay'] = 'autoplay';
}
if ($variables['loop']) {
$video_attributes['loop'] = 'loop';
}
if ($variables['muted']) {
$video_attributes['muted'] = 'muted';
}
if ($variables['width'] && $variables['height']) {
$video_attributes['width'] = $variables['width'];
$video_attributes['height'] = $variables['height'];
}
$output .= '<video' . drupal_attributes($video_attributes) . '>';
foreach ($files as $delta => $file) {
$source_attributes = array(
'src' => file_create_url($file['uri']),
'type' => $file['filemime'],
);
$output .= '<source' . drupal_attributes($source_attributes) . ' />';
}
$output .= '</video>';
return $output;
}