Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.media.theme @ 20e02fff

History | View | Annotate | Download (9.68 KB)

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
  $last_level = error_reporting (E_ERROR); // suppress warnings from the imagecreatefromstring() method,
43
  $im = imagecreatefromstring($contents);
44
  error_reporting($last_level); // reset the error_reporting level
45

    
46
  if (!$im) {
47
    return FALSE;
48
  }
49
  $gis[0] = ImageSX($im);
50
  $gis[1] = ImageSY($im);
51
  // Array member 3 is used below to keep with current getimagesize standards.
52
  $gis[3] = "width={$gis[0]} height={$gis[1]}";
53
  ImageDestroy($im);
54
  return $gis;
55
}
56

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

    
73
  $out = '';
74

    
75
  _add_js_thickbox();
76

    
77
  $feature = $descriptionElement->feature;
78
  $medias = $descriptionElement->media;
79

    
80
  foreach ($medias as $media) {
81
    $prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
82
    $mediaRepresentation = array_shift($prefRepresentations);
83
    if ($mediaRepresentation) {
84

    
85
      $contentTypeDirectory = media_content_type_dir($mediaRepresentation);
86

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

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

    
125

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

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

    
190

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

    
211
  $media = $variables['media'];
212
  $elements = $variables['elements'];
213
  $sources_as_content = $variables['sources_as_content'];
214
  $media_metadata = read_media_metadata($media);
215

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

    
223
  $descriptionPrefix = "";
224
  $footnote_list_key = 'media-' . $media->uuid;
225

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

    
240
  $out = '';
241

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

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

    
259
  $groups = array();
260

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

    
297
  if(!empty($annotations_and_sources['source_references'])){
298
    $sources_label = count($annotations_and_sources['source_references']) > 1 ? t('Sources') : t('Source');
299
    _description_list_group_add($groups, $sources_label . ':', markup_to_render_array(join(', ', $annotations_and_sources['source_references'])) );
300
  }
301

    
302
  // TODO add all other metadata elements generically.
303

    
304
  $description_list_item = array(
305
    '#theme' => 'description_list',
306
    '#groups' => $groups,
307
    '#attributes' => array('class' => 'media-caption')
308
  );
309
  $out .= drupal_render($description_list_item);
310

    
311
  $out .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key));
312

    
313
  return $out;
314
}
315

    
Add picture from clipboard (Maximum size: 40 MB)