Projet

Général

Profil

Paste
Télécharger (5,17 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / file_entity / file_entity.theme.inc @ 2b3c8cc1

1
<?php
2

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

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

    
17
  $url = 'file/' . $file->fid;
18
  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
19

    
20
  // Set options as per anchor format described at
21
  // http://microformats.org/wiki/file-format-examples
22
  $options = array(
23
    'attributes' => array(
24
      'type' => $file->filemime . '; length=' . $file->filesize,
25
    ),
26
  );
27

    
28
  // Use the description as the link text if available.
29
  if (empty($file->description)) {
30
    $link_text = $file->filename;
31
  }
32
  else {
33
    $link_text = $file->description;
34
    $options['attributes']['title'] = check_plain($file->filename);
35
  }
36

    
37
  return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
38
}
39

    
40
/**
41
 * Copy of theme_file_file_link() for linking to the file download URL.
42
 *
43
 * @see theme_file_file_link()
44
 */
45
function theme_file_entity_download_link($variables) {
46
  $file = $variables['file'];
47
  $icon_directory = $variables['icon_directory'];
48

    
49
  $uri = file_entity_download_uri($file);
50
  $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
51

    
52
  // Set options as per anchor format described at
53
  // http://microformats.org/wiki/file-format-examples
54
  $uri['options']['attributes']['type'] = $file->filemime . '; length=' . $file->filesize;
55

    
56
  // Provide the default link text.
57
  if (!isset($variables['text'])) {
58
    $variables['text'] = t('Download [file:name]');
59
  }
60

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

    
65
  $output = '<span class="file">' . $icon . ' ' . l($variables['text'], $uri['path'], $uri['options']);
66
  $output .= ' ' . '<span class="file-size">(' . format_size($file->filesize) . ')</span>';
67
  $output .= '</span>';
68

    
69
  return $output;
70
}
71

    
72
/**
73
 * Returns HTML for displaying an HTML5 <audio> tag.
74
 *
75
 * @param array $variables
76
 *   An associative array containing:
77
 *   - file: Associative array of file data, which must include "uri".
78
 *   - controls: Boolean indicating whether or not controls should be displayed.
79
 *   - autoplay: Boolean indicating whether or not the audio should start
80
 *     playing automatically.
81
 *   - loop: Boolean indicating whether or not the audio should loop.
82
 *
83
 * @ingroup themeable
84
 */
85
function theme_file_entity_file_audio($variables) {
86
  $files = $variables['files'];
87
  $output = '';
88

    
89
  $audio_attributes = array();
90
  if ($variables['controls']) {
91
    $audio_attributes['controls'] = 'controls';
92
  }
93
  if ($variables['autoplay']) {
94
    $audio_attributes['autoplay'] = 'autoplay';
95
  }
96
  if ($variables['loop']) {
97
    $audio_attributes['loop'] = 'loop';
98
  }
99
  if (!empty($variables['preload'])) {
100
    $audio_attributes['preload'] = $variables['preload'];
101
  }
102

    
103
  $output .= '<audio' . drupal_attributes($audio_attributes) . '>';
104
  foreach ($files as $delta => $file) {
105
    $source_attributes = array(
106
      'src' => file_create_url($file['uri']),
107
      'type' => $file['filemime'],
108
    );
109
    $output .= '<source' . drupal_attributes($source_attributes) . ' />';
110
  }
111
  $output .= '</audio>';
112
  return $output;
113
}
114

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

    
135
  $video_attributes = array();
136
  if ($variables['controls']) {
137
    $video_attributes['controls'] = 'controls';
138
  }
139
  if ($variables['autoplay']) {
140
    $video_attributes['autoplay'] = 'autoplay';
141
  }
142
  if ($variables['loop']) {
143
    $video_attributes['loop'] = 'loop';
144
  }
145
  if ($variables['muted']) {
146
    $video_attributes['muted'] = 'muted';
147
  }
148
  if ($variables['width']) {
149
    $video_attributes['width'] = $variables['width'];
150
  }
151
  if ($variables['height']) {
152
    $video_attributes['height'] = $variables['height'];
153
  }
154
  if (!empty($variables['preload'])) {
155
    $video_attributes['preload'] = $variables['preload'];
156
  }
157

    
158
  $output .= '<video' . drupal_attributes($video_attributes) . '>';
159
  foreach ($files as $delta => $file) {
160
    $source_attributes = array(
161
      'src' => file_create_url($file['uri']),
162
      'type' => $file['filemime'],
163
    );
164
    $output .= '<source' . drupal_attributes($source_attributes) . ' />';
165
  }
166
  $output .= '</video>';
167
  return $output;
168
}