Projet

Général

Profil

Paste
Télécharger (7,97 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / file_entity / file_entity.theme.inc @ 66c11afc

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
 *
191
 * @ingroup themeable
192
 */
193
function theme_file_entity_file_video($variables) {
194
  $files = $variables['files'];
195
  $output = '';
196

    
197
  $video_attributes = array();
198
  if ($variables['controls']) {
199
    $video_attributes['controls'] = 'controls';
200

    
201
    if (!empty($variables['controls_list'])) {
202
      $controls_list = array();
203
      foreach ($variables['controls_list'] as $key => $value) {
204
        if (!$value) {
205
          switch ($key) {
206
            case 'fullscreen':
207
              $controls_list[] = 'nofullscreen';
208
              break;
209
            case 'download':
210
              $controls_list[] = 'nodownload';
211
              break;
212
            case 'remote_playback':
213
              $controls_list[] = 'noremoteplayback';
214
              break;
215
          }
216
        }
217
      }
218
      $video_attributes['controlsList'] = implode(' ', $controls_list);
219
    }
220
  }
221
  if ($variables['autoplay']) {
222
    $video_attributes['autoplay'] = 'autoplay';
223
  }
224
  if ($variables['loop']) {
225
    $video_attributes['loop'] = 'loop';
226
  }
227
  if ($variables['muted']) {
228
    $video_attributes['muted'] = 'muted';
229
  }
230
  if ($variables['width']) {
231
    $video_attributes['width'] = $variables['width'];
232
  }
233
  if ($variables['height']) {
234
    $video_attributes['height'] = $variables['height'];
235
  }
236
  if (!empty($variables['preload'])) {
237
    $video_attributes['preload'] = $variables['preload'];
238
  }
239

    
240
  $output .= '<video' . drupal_attributes($video_attributes) . '>';
241
  foreach ($files as $delta => $file) {
242
    $source_attributes = array(
243
      'src' => file_create_url($file['uri']),
244
      'type' => $file['filemime'],
245
    );
246
    $output .= '<source' . drupal_attributes($source_attributes) . ' />';
247
  }
248
  $output .= '</video>';
249
  return $output;
250
}