Project

General

Profile

Download (8.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Media theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * @todo Please document this function.
18
 * @see http://drupal.org/node/1354
19
 */
20
function media_content_type_dir($media_representation, $default = FALSE) {
21
  if ($media_representation->mimeType) {
22
    return substr($media_representation->mimeType, 0, stripos($media_representation->mimeType, '/'));
23
  }
24
  else {
25
    return $default;
26
  }
27
}
28

    
29
/**
30
 * @todo Please document this function.
31
 * @see http://drupal.org/node/1354
32
 */
33
function getimagesize_remote($image_url) {
34
  $response = cdm_http_request($image_url);
35
  $contents = NULL;
36
  if (isset($response->data)) {
37
    $contents = $response->data;
38
  } else {
39
    return FALSE;
40
  }
41

    
42
  $im = @ImageCreateFromString($contents); // Using @ to avoid php warnings.
43
  if (!$im) {
44
    return FALSE;
45
  }
46
  $gis[0] = ImageSX($im);
47
  $gis[1] = ImageSY($im);
48
  // Array member 3 is used below to keep with current getimagesize standards.
49
  $gis[3] = "width={$gis[0]} height={$gis[1]}";
50
  ImageDestroy($im);
51
  return $gis;
52
}
53

    
54
/**
55
 * Creates the markup for the media associated a DescriptionElement instance.
56
 *
57
 * @param $descriptionElement
58
 *    the DescriptionElement instance
59
 * @param $mimeTypePreference array
60
 *    An array of mime type strings. the order of the mimetpes is the oerder of preference.
61
 *    E.g.: array('application/pdf','image/jpeg')
62
 *
63
 * @return string
64
 *    The markup
65
 */
66
function cdm_description_element_media($descriptionElement, $mimeTypePreference) {
67

    
68
  $out = '';
69

    
70
  _add_js_thickbox();
71

    
72
  $feature = $descriptionElement->feature;
73
  $medias = $descriptionElement->media;
74

    
75
  foreach ($medias as $media) {
76
    $prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
77
    $mediaRepresentation = array_shift($prefRepresentations);
78
    if ($mediaRepresentation) {
79

    
80
      $contentTypeDirectory = media_content_type_dir($mediaRepresentation);
81

    
82
      $out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
83
    }
84
    else {
85
      // Media has empty or corrupt representation
86
      if(user_is_logged_in()){
87
        drupal_set_message('The media entity (' . l($media->uuid, path_to_media($media->uuid)) .') has empty or corrupt representation parts. Maybe the URI is empty.' , 'warning');
88
      }
89
    }
90
  }
91
  return $out;
92
}
93

    
94
/**
95
 * @todo Please document this function.
96
 * @see http://drupal.org/node/1354
97
 */
98
function theme_cdm_media_mime_application($variables) {
99
  $mediaRepresentation = $variables['mediaRepresentation'];
100
  $feature = $variables['feature'];
101
  $out = '';
102
  foreach ($mediaRepresentation->parts as $part) {
103
    $attributes = array(
104
      'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
105
      'target' => '_blank',
106
    );
107
    /*
108
    $attributes = array('title'=>$feature->representation_L10n,'target'=>'_blank');
109
    $attributes = array('title'=>'original publication', 'target'=>'_blank');
110
    */
111
    $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
112
      'attributes' => $attributes,
113
      'absolute' => TRUE,
114
      'html' => TRUE,
115
    ));
116
  }
117
  return $out;
118
}
119

    
120

    
121
/**
122
 * Creates the markup for a CDM Media instance.
123
 *
124
 * (This method is currently only called from within theme_cdm_media())
125
 *
126
 * @param $variables
127
 *    An associative array
128
 * @return string
129
 *    The markup
130
 */
131
function theme_cdm_media_mime_image($variables) {
132
  $media_representation = $variables['mediaRepresentation'];
133
  $feature = $variables['feature'];
134
  $out = '';
135
  // TODO thickbox is not used anymore -> delete?
136
  $attributes = array(
137
    'class' => 'thickbox',
138
    'rel' => 'representation-' . $media_representation->uuid,
139
    'title' => $feature->representation_L10n,
140
  );
141
  for ($i = 0; $part = $media_representation->parts[$i]; $i++) {
142
    if ($i == 0) {
143
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
144
        'attributes' => $attributes,
145
        'absolute' => TRUE,
146
        'html' => TRUE,
147
      ));
148
    }
149
    else {
150
      $out .= l('', $part->uri, array(
151
        'attributes' => $attributes,
152
        'absolute' => TRUE,
153
      ));
154
    }
155
  }
156
  return $out;
157
}
158

    
159
/**
160
 * @todo Please document this function.
161
 * @see http://drupal.org/node/1354
162
 */
163
function theme_cdm_media_mime_text($variables) {
164
  $representation = $variables['mediaRepresentation'];
165
  $feature = $variables['feature'];
166
  $out = '';
167
  if (!empty($representation->parts)) {
168
    foreach ($representation->parts as $part) {
169
      $attributes = array(
170
        'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
171
        'target' => '_blank',
172
      );
173
      // $attributes = array('title'=>t('original publication'),
174
      // 'target'=>'_blank');
175
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
176
        'attributes' => $attributes,
177
        'absolute' => TRUE,
178
        'html' => TRUE,
179
      ));
180
    }
181
  }
182
  return $out;
183
}
184

    
185

    
186
/**
187
 * Theme function for captions of media elements. This method is usually called from
188
 * within the theme_cdm_media_gallerie() function or indirectly via AHAH.
189
 *
190
 * @param array $variables
191
 *   an associative array with the following elements:
192
 *   - 'media': the cdm media object to show the captions for
193
 *   - 'elements':
194
 *         an array which defining the caption elements to show up
195
 *         example:
196
 *          Show 'title', 'description', 'file', 'filename' in the caption:
197
 *          array('title', 'description', 'file', 'filename')
198
 *
199
 * @return string
200
 *   the themed html output
201
 *
202
 * TODO turn into compose method
203
 */
204
function theme_cdm_media_caption($variables) {
205
  $media = $variables['media'];
206
  $elements = $variables['elements'];
207
  $media_metadata = read_media_metadata($media);
208

    
209
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
210
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
211
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
212
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
213
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
214

    
215
  $descriptionPrefix = "";
216

    
217
  $out = '<dl class="media-caption">';
218
  // Title.
219
  if ($doTitle) {
220
    if ($media_metadata['title']) {
221
      $out .= '<dt class = "title">' . t('Title')  . ':'. '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
222
      $descriptionPrefix = "- ";
223
    }
224
    elseif (!($doDescription && $media_metadata['description'])) {
225
      // Use filename as fallback option if no description will be shown.
226
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
227
      $descriptionPrefix = "- ";
228
    }
229
  }
230
  // Description.
231
  if ($media_metadata['description'] && $doDescription) {
232
    $out .= '<dt class = "description">' . t('Description')  . ':'. '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
233
  }
234
  // Artist.
235
  if ($media_metadata['artist'] && $doArtist) {
236
    $out .= '<dt class = "artist">' . t('Artist')  . ':' . '</dt> <dd class = "artist">' . $media_metadata['artist'] . '</dd>';
237
  }
238
  // Location.
239
  if ($doLocation) {
240
    $location = '';
241
    $location .= $media_metadata['location']['sublocation'];
242
    if ($location && $media_metadata['location']['city']) {
243
      $location .= ', ';
244
    }
245
    $location .= $media_metadata['location']['city'];
246
    if ($location && $media_metadata['location']['province']) {
247
      $location .= ', ';
248
    }
249
    $location .= $media_metadata['location']['province'];
250
    if ($location && $media_metadata['location']['country']) {
251
      $location .= ' (' . $media_metadata['location']['country'] . ')';
252
    }
253
    else {
254
      $location .= $media_metadata['location']['country'];
255
    }
256
    if ($location) {
257
      $out .= '<dt class = "location">' . t('Location') . ':' . '</dt> <dd class = "location">' . $location . '</dd>';
258
    }
259
  }
260
  // Rights.
261
  if ($doRights) {
262
    $rights_render_item = array(
263
      '#theme' => 'description_list',
264
      '#groups' => cdm_rights_as_dl_groups($media_metadata['rights'])
265
    );
266
   $out .= drupal_render($rights_render_item);
267
  }
268
  // TODO add all other metadata elements generically.
269
  $out .= '</dl>';
270
  // Return value,
271
  return $out;
272
}
273

    
(3-3/9)