1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Media Theming
|
6 |
|
|
*
|
7 |
|
|
* Theming functions for the Media module.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Adds a wrapper around a preview of a media file.
|
12 |
|
|
*/
|
13 |
|
|
function theme_media_thumbnail($variables) {
|
14 |
|
|
$label = '';
|
15 |
|
|
$element = $variables['element'];
|
16 |
|
|
|
17 |
|
|
// Wrappers to go around the thumbnail.
|
18 |
|
|
$attributes = array(
|
19 |
|
|
'title' => $element['#name'],
|
20 |
|
|
'class' => 'media-item',
|
21 |
|
|
'data-fid' => $element['#file']->fid,
|
22 |
|
|
);
|
23 |
|
|
$prefix = '<div ' . drupal_attributes($attributes) . '><div class="media-thumbnail">';
|
24 |
|
|
$suffix = '</div></div>';
|
25 |
|
|
|
26 |
|
|
// Arguments for the thumbnail link.
|
27 |
|
|
$thumb = $element['#children'];
|
28 |
ca0757b9
|
Assos Assos
|
if (file_entity_access('update', $element['#file'])) {
|
29 |
|
|
$target = 'file/' . $element['#file']->fid . '/edit';
|
30 |
|
|
$title = t('Click to edit details');
|
31 |
|
|
}
|
32 |
|
|
else {
|
33 |
|
|
$target = 'file/' . $element['#file']->fid;
|
34 |
|
|
$title = t('Click to view details');
|
35 |
|
|
}
|
36 |
85ad3d82
|
Assos Assos
|
$options = array(
|
37 |
|
|
'query' => drupal_get_destination(),
|
38 |
|
|
'html' => TRUE,
|
39 |
ca0757b9
|
Assos Assos
|
'attributes' => array('title' => $title),
|
40 |
85ad3d82
|
Assos Assos
|
);
|
41 |
|
|
|
42 |
|
|
// Element should be a field renderable array. This should be improved.
|
43 |
|
|
if (!empty($element['#show_names']) && $element['#name']) {
|
44 |
|
|
$label = '<div class="label-wrapper"><label class="media-filename">' . $element['#name'] . '</label></div>';
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
$output = $prefix;
|
48 |
|
|
if (!empty($element['#add_link'])) {
|
49 |
|
|
$output .= l($thumb, $target, $options);
|
50 |
|
|
}
|
51 |
|
|
else {
|
52 |
|
|
$output .= $thumb;
|
53 |
|
|
}
|
54 |
|
|
$output .= $label . $suffix;
|
55 |
|
|
return $output;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
/**
|
59 |
|
|
* Preprocess the media thumbnail.
|
60 |
|
|
*/
|
61 |
|
|
function template_preprocess_media_thumbnail(&$variables) {
|
62 |
|
|
// Set the name for the thumbnail to be the filename. This is done here so
|
63 |
|
|
// that other modules can hijack the name displayed if it should not be the
|
64 |
|
|
// filename.
|
65 |
|
|
$variables['element']['#name'] = isset($variables['element']['#file']->filename) ? check_plain($variables['element']['#file']->filename) : NULL;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Field formatter for displaying a file as a large icon.
|
70 |
|
|
*/
|
71 |
|
|
function theme_media_formatter_large_icon($variables) {
|
72 |
|
|
$file = $variables['file'];
|
73 |
ca0757b9
|
Assos Assos
|
$icon_dir = variable_get('media_icon_base_directory', 'public://media-icons') . '/' . variable_get('media_icon_set', 'default');
|
74 |
85ad3d82
|
Assos Assos
|
$icon = file_icon_path($file, $icon_dir);
|
75 |
|
|
$variables['path'] = $icon;
|
76 |
|
|
|
77 |
|
|
// theme_image() requires the 'alt' attribute passed as its own variable.
|
78 |
|
|
// @see http://drupal.org/node/999338
|
79 |
|
|
if (!isset($variables['alt']) && isset($variables['attributes']['alt'])) {
|
80 |
|
|
$variables['alt'] = $variables['attributes']['alt'];
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
// Add image height and width for the image theme functions.
|
84 |
|
|
if ($info = image_get_info($icon)) {
|
85 |
|
|
$variables += $info;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
if ($variables['style_name']) {
|
89 |
|
|
$output = theme('image_style', $variables);
|
90 |
|
|
}
|
91 |
|
|
else {
|
92 |
|
|
$output = theme('image', $variables);
|
93 |
|
|
}
|
94 |
|
|
return $output;
|
95 |
|
|
}
|
96 |
ca0757b9
|
Assos Assos
|
|
97 |
|
|
/**
|
98 |
|
|
* Add messages to the page.
|
99 |
|
|
*/
|
100 |
|
|
function template_preprocess_media_dialog_page(&$variables) {
|
101 |
|
|
$variables['messages'] = theme('status_messages');
|
102 |
|
|
} |