media.theme.inc
9.16 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
/**
* @file
* Media Theming
*
* Theming functions for the Media module.
*/
/**
* Display the media file browser.
* @TODO this is depreciated I think
* @param array $element
* The form element.
* @return string
*/
function theme_media_file_browser($element) {
// Add the CSS for our display.
$output = '<div class="media browser">' . $element . '</div>';
return $output;
}
/**
* Display a media file list.
* @TODO this is depreciated I think
* @param array $element
* The form element.
* @return string
*/
function theme_media_file_list($element) {
// Add the CSS for our display.
return '<div class="media-file-list">' . theme('form_element', $element, $element['#children']) . '</div>';
}
/**
* Display a browser pane.
* @TODO this is depreciated I think
*
* @param array $form
* The form element.
* @return string
*/
function theme_media_browser_pane($form) {
return;
$output = array();
// render the drawers
$output[] = '<div' . drupal_attributes($form['#attributes']) . '>';
// render the drawer list
$output[] = ' <div class="browser drawers">';
$output[] = drupal_render_form(null, $form['drawers']);
$output[] = ' </div>';
// render the drawer displays
$output[] = drupal_render_form(null, $form);
$output[] = '</div>';
return implode("\n", $output);
}
/**
* Default theming function for creating the browser frame.
* Assumes an array of file objects as $files and an
* array of $parameters
* @param $variables
* array of variables
* @return unknown_type
*/
function theme_media_browser_content_frame($variables) {
// Pull out all the variables into a usable form
extract($variables);
// Did we get any files back?
if (! count($files)) {
// @TODO display no files found
}
$html = array();
// On the first invocation, load javascript and build the browser frame
if ($invoke) {
}
// Render the results limiter
$html[] = theme('media_browser_control_result_limit', array('parameters' => $parameters));
// Render the actual content
$form = drupal_get_form('media_file_listing_form', $files, $parameters);
$html[] = drupal_render($form);
// Make sure to close the wrapping div
if ($invoke) {
$html[] = '</div>';
}
return implode("\n", $html);
}
/**
* Display a item list of files as thumbnails. Implements
* the admin thumbnail theme for now- serves as a wrapper
*
* @param $files
* An array of file objects to display.
* @return
*/
function theme_media_browser_thumbnails($variables) {
$files = $variables['files'];
$style_name = $variables['style_name'];
$thumbnails = array();
foreach ($files as $file) {
$thumbnails[] = theme('media_admin_thumbnail', array('file' => $file, 'style_name' => $style_name));
}
return theme('item_list', array('items' => $thumbnails, 'attributes' => array('class' => 'media_content_navigator results')));
}
/**
* Theme a thumbnail.
* @param $variables
* array items being passed in
*/
function theme_media_admin_thumbnail($variables) {
$path = drupal_get_path('module', 'media');
$file = $variables['file'];
$style_name = $variables['style_name'];
if (isset($file)) {
$file_url = file_create_url($file->uri);
}
else {
return '';
}
$output = '';
if (module_exists('styles')) {
$thumbnail = theme('styles',
array(
'field_type' => 'file',
'style_name' => $style_name,
'uri' => $file->uri,
'description' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
'object' => $variables['file'],
));
}
else {
// Display a thumbnail for images.
if (strstr($file->filemime, 'image')) {
$thumbnail = theme('image_style',
array(
'style_name' => 'thumbnail',
'path' => $file->uri,
'alt' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
)
);
}
// Display the 'unknown' icon for other file types.
else {
$thumbnail = theme('image',
array(
'path' => $path . '/images/file-unknown.png',
'alt' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
'attributes' => array('class' => 'file-unknown'),
));
}
}
$output .= l($thumbnail,
$file_url,
array(
'html' => TRUE,
'attributes' => array('class' => 'media-thumbnail'),
));
return $output;
}
/**
* Theme operations for a thumbnail.
*/
function theme_media_admin_thumbnail_operations($variables) {
$destination = drupal_get_destination();
$file = $variables['file'];
$output = l(t('edit'), 'media/' . $file->fid . '/edit', array('query' => $destination));
return $output;
}
/**
* Add messages to the page.
*/
function template_preprocess_media_dialog_page(&$variables) {
$variables['messages'] = theme('status_messages');
}
/* ******************************************** */
/* Content navigation controls */
/* ******************************************** */
/**
* Theme function to display the results limiting- 10, 30, 50 results
* per page.
*
* @param $variables
* array parameters
* @return unknown
*/
function theme_media_browser_control_result_limit($variables) {
// Pull out all the variables into a usable form
extract($variables);
if (!isset($limits)) {
$limits = array(10, 30, 50);
}
// @NOTE these do not need to be aware of the current
// page because clicking them will reset the
// display to 1 -> $limit
$parameters['page'] = 0;
// save the active limit
$current_limit = $parameters['limit'];
$per_display = array();
foreach ($limits as $limit) {
if ($limit == $current_limit) {
$class = 'active';
}
else {
$class = '';
}
// set the value of this limit parameter to this limit value
$parameters['limit'] = $limit;
$per_display[] = l($limit, $limit, array('query' => $parameters, 'attributes' => array('class' => $class)));
}
return theme('item_list', array('items' => $per_display, 'attributes' => array('class' => 'result_limit')));
}
/**
* Stolen from file.module theme_file_link
*
* @param $variables
* An associative array containing:
* - file: A file object to which the link will be created.
*/
function theme_media_link($variables) {
$file = $variables['file'];
$url = 'media/' . $file->fid;
$icon = theme('file_icon', array('file' => $file));
// 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 = check_plain($file->filename);
}
else {
$link_text = check_plain($file->description);
$options['attributes']['title'] = check_plain($file->filename);
}
return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
}
/**
* Adds a wrapper around a preview of a media file.
* @param unknown_type $element
* @return unknown_type
*/
function theme_media_thumbnail($variables) {
$label = '';
$element = $variables['element'];
$destination = drupal_get_destination();
// Wrappers to go around the thumbnail
$prefix = '<div class="media-item"><div class="media-thumbnail">';
$suffix = '</div></div>';
// Arguments for the thumbnail link
$thumb = $element['#children'];
$target = 'media/' . $element['#file']->fid . '/edit';
$options = array('query' => $destination, 'html' => TRUE, 'attributes' => array('title' => t('Click to edit details')));
// Element should be a field renderable array... This is a little wonky - admitted.
if (!empty($element['#show_names']) && $element['#name']) {
$label = '<div class="label-wrapper"><label class="media-filename">' . $element['#name'] . '</label></div>';
}
// How can I attach CSS here?
//$element['#attached']['css'][] = drupal_get_path('module', 'media') . '/css/media.css';
drupal_add_css(drupal_get_path('module', 'media') . '/css/media.css');
$output = $prefix;
if (!empty($element['#add_link'])) {
$output .= l($thumb, $target, $options);
}
else {
$output .= $thumb;
}
$output .= $label . $suffix;
return $output;
}
function template_preprocess_media_thumbnail(&$variables) {
// Set the name for the thumbnail to be the filename. This is done here so
// that other modules can hijack the name displayed if it should not be the
// filename.
$variables['element']['#name'] = isset($variables['element']['#file']->filename) ? check_plain($variables['element']['#file']->filename) : NULL;
}
/**
* Field formatter for displaying a file as a large icon.
*/
function theme_media_formatter_large_icon($variables) {
$file = $variables['file'];
$icon_dir = media_variable_get('icon_base_directory') . '/' . media_variable_get('icon_set');
$icon = file_icon_path($file, $icon_dir);
$variables['path'] = $icon;
// theme_image() requires the 'alt' attribute passed as its own variable.
// @see http://drupal.org/node/999338
if (!isset($variables['alt']) && isset($variables['attributes']['alt'])) {
$variables['alt'] = $variables['attributes']['alt'];
}
return theme('image', $variables);
}