Projet

Général

Profil

Paste
Télécharger (3,01 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / includes / media.theme.inc @ 74f6bef0

1
<?php
2

    
3
/**
4
 * @file
5
 * Media Theming
6
 *
7
 * Theming functions for the Media module.
8
 */
9

    
10

    
11
/**
12
 * Display a media file list.
13
 *
14
 * @param array $element
15
 *   The form element.
16
 *
17
 * @return string
18
 *   HTML of the file list
19
 */
20
function theme_media_file_list($element) {
21
  // Add the CSS for our display.
22
  return '<div class="media-file-list">' . theme('form_element', $element, $element['#children']) . '</div>';
23
}
24

    
25
/**
26
 * Add messages to the page.
27
 */
28
function template_preprocess_media_dialog_page(&$variables) {
29
  $variables['messages'] = theme('status_messages');
30
}
31

    
32
/**
33
 * Adds a wrapper around a preview of a media file.
34
 */
35
function theme_media_thumbnail($variables) {
36
  $label = '';
37
  $element = $variables['element'];
38

    
39
 // Wrappers to go around the thumbnail.
40
  $attributes = array(
41
    'title' => $element['#name'],
42
    'class' => 'media-item',
43
    'data-fid' => $element['#file']->fid,
44
  );
45
  $prefix = '<div ' . drupal_attributes($attributes) . '><div class="media-thumbnail">';
46
  $suffix = '</div></div>';
47

    
48
  // Arguments for the thumbnail link.
49
  $thumb = $element['#children'];
50
  $target = 'file/' . $element['#file']->fid . '/edit';
51
  $options = array(
52
    'query' => drupal_get_destination(),
53
    'html' => TRUE,
54
    'attributes' => array('title' => t('Click to edit details')),
55
  );
56

    
57
  // Element should be a field renderable array. This should be improved.
58
  if (!empty($element['#show_names']) && $element['#name']) {
59
    $label = '<div class="label-wrapper"><label class="media-filename">' . $element['#name'] . '</label></div>';
60
  }
61

    
62
  $output = $prefix;
63
  if (!empty($element['#add_link'])) {
64
    $output .= l($thumb, $target, $options);
65
  }
66
  else {
67
    $output .= $thumb;
68
  }
69
  $output .= $label . $suffix;
70
  return $output;
71
}
72

    
73
/**
74
 * Preprocess the media thumbnail.
75
 */
76
function template_preprocess_media_thumbnail(&$variables) {
77
  // Set the name for the thumbnail to be the filename.  This is done here so
78
  // that other modules can hijack the name displayed if it should not be the
79
  // filename.
80
  $variables['element']['#name'] = isset($variables['element']['#file']->filename) ? check_plain($variables['element']['#file']->filename) : NULL;
81
}
82

    
83
/**
84
 * Field formatter for displaying a file as a large icon.
85
 */
86
function theme_media_formatter_large_icon($variables) {
87
  $file = $variables['file'];
88
  $icon_dir = variable_get('media__icon_base_directory', 'public://media-icons') . '/' . variable_get('media__icon_set', 'default');
89
  $icon = file_icon_path($file, $icon_dir);
90
  $variables['path'] = $icon;
91

    
92
  // theme_image() requires the 'alt' attribute passed as its own variable.
93
  // @see http://drupal.org/node/999338
94
  if (!isset($variables['alt']) && isset($variables['attributes']['alt'])) {
95
    $variables['alt'] = $variables['attributes']['alt'];
96
  }
97

    
98
  // Add image height and width for the image theme functions.
99
  if ($info = image_get_info($icon)) {
100
    $variables += $info;
101
  }
102

    
103
  if ($variables['style_name']) {
104
    $output = theme('image_style', $variables);
105
  }
106
  else {
107
    $output = theme('image', $variables);
108
  }
109
  return $output;
110
}