Project

General

Profile

Download (9.41 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
 * FIXME: move to descriptions.inc
67
 */
68
function cdm_description_element_media($descriptionElement, $mimeTypePreference) {
69

    
70
  $out = '';
71

    
72
  _add_js_thickbox();
73

    
74
  $feature = $descriptionElement->feature;
75
  $medias = $descriptionElement->media;
76

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

    
82
      $contentTypeDirectory = media_content_type_dir($mediaRepresentation);
83

    
84
      $out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
85
    }
86
    else {
87
      // Media has empty or corrupt representation
88
      if(user_is_logged_in()){
89
        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');
90
      }
91
    }
92
  }
93
  return $out;
94
}
95

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

    
122

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

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

    
187

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

    
208
  $media = $variables['media'];
209
  $elements = $variables['elements'];
210
  $sources_as_content = $variables['sources_as_content'];
211
  $media_metadata = read_media_metadata($media);
212

    
213
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
214
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
215
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
216
  $doMediacreated = true; //!$elements || array_search('mediacreated', $elements) !== FALSE;
217
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
218
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
219

    
220
  $descriptionPrefix = "";
221
  $footnote_list_key = 'media-' . $media->uuid;
222

    
223
  // handle sources and annotations
224
  cdm_lazyload_array_field('media', 'annotations', $media);
225
  $annotations_and_sources = handle_annotations_and_sources(
226
    $media,
227
    array(
228
      'sources_as_content' => $sources_as_content,
229
      'link_to_name_used_in_source' => 1,
230
      'link_to_reference' => 0,
231
      'add_footnote_keys' => $sources_as_content ? 0 : 1
232
    ),
233
     NULL,
234
     $footnote_list_key
235
  );
236

    
237
  $out = '';
238

    
239
  // Title.
240
  if ($doTitle) {
241
    $title_string = $media_metadata['title']
242
      . $annotations_and_sources['foot_note_keys']; // placing the footnote keys here is not optimal, see #6329 A.1.
243
    $title_string = trim($title_string);
244
    if (empty($title_string) && !($doDescription && $media_metadata['description'])) {
245
      // Use filename as fallback option if no description and no source citations are available.
246
      $title_string = $media_metadata['filename'];
247
    }
248
    $out .= '<div class="title">' . $title_string . '</div>';
249
  }
250

    
251
  // Description.
252
  if ($media_metadata['description'] && $doDescription) {
253
    $out .= '<p class="description">' . $media_metadata['description'] . '</p>';
254
  }
255

    
256
  $groups = array();
257

    
258
  $out .= '<dl class="media-caption">';
259
  // Artist.
260
  if ($media_metadata['artist'] && $doArtist) {
261
    _description_list_group_add($groups, t('Artist') . ':', $media_metadata['artist'] );
262
  }
263
  // MediaCreated
264
  if ($media_metadata['mediacreated'] && $doMediacreated) {
265
    _description_list_group_add($groups, t('Created') . ':', $media_metadata['mediacreated'] );
266
  }
267
  // Location.
268
  if ($doLocation) {
269
    $location = '';
270
    $location .= $media_metadata['location']['sublocation'];
271
    if ($location && $media_metadata['location']['city']) {
272
      $location .= ', ';
273
    }
274
    $location .= $media_metadata['location']['city'];
275
    if ($location && $media_metadata['location']['province']) {
276
      $location .= ', ';
277
    }
278
    $location .= $media_metadata['location']['province'];
279
    if ($location && $media_metadata['location']['country']) {
280
      $location .= ' (' . $media_metadata['location']['country'] . ')';
281
    }
282
    else {
283
      $location .= $media_metadata['location']['country'];
284
    }
285
    if ($location) {
286
      _description_list_group_add($groups, t('Location') . ':', $location );
287
    }
288
  }
289
  // Rights.
290
  if ($doRights) {
291
    $groups = array_merge($groups, cdm_rights_as_dl_groups($media_metadata['rights']));
292
  }
293

    
294
  if(!empty($annotations_and_sources['source_references'])){
295
    _description_list_group_add($groups, t('Sources') . ':', join(', ', $annotations_and_sources['source_references']) );
296
  }
297

    
298
  // TODO add all other metadata elements generically.
299

    
300
  $description_list_item = array(
301
    '#theme' => 'description_list',
302
    '#groups' => $groups,
303
    '#attributes' => array('class' => 'media-caption')
304
  );
305
  $out .= drupal_render($description_list_item);
306

    
307
  $out .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key));
308

    
309
  return $out;
310
}
311

    
(3-3/9)