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
|
$contents = cdm_http_request($image_url);
|
35
|
if (!$contents) {
|
36
|
return FALSE;
|
37
|
}
|
38
|
|
39
|
$im = @ImageCreateFromString($contents); // Using @ to avoid php warnings.
|
40
|
if (!$im) {
|
41
|
return FALSE;
|
42
|
}
|
43
|
$gis[0] = ImageSX($im);
|
44
|
$gis[1] = ImageSY($im);
|
45
|
// Array member 3 is used below to keep with current getimagesize standards.
|
46
|
$gis[3] = "width={$gis[0]} height={$gis[1]}";
|
47
|
ImageDestroy($im);
|
48
|
return $gis;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @todo Please document this function.
|
53
|
* @see http://drupal.org/node/1354
|
54
|
*/
|
55
|
function theme_cdm_media($variables) {
|
56
|
$descriptionElement = $variables['descriptionElement'];
|
57
|
$mimeTypePreference = $variables['mimeTypePreference'];
|
58
|
$out = '';
|
59
|
|
60
|
_add_js_thickbox();
|
61
|
|
62
|
$uuid = $descriptionElement->uuid;
|
63
|
$feature = $descriptionElement->feature;
|
64
|
$medias = $descriptionElement->media;
|
65
|
|
66
|
foreach ($medias as $media) {
|
67
|
$prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
|
68
|
$mediaRepresentation = array_shift($prefRepresentations);
|
69
|
if ($mediaRepresentation) {
|
70
|
|
71
|
$contentTypeDirectory = media_content_type_dir($mediaRepresentation);
|
72
|
|
73
|
$out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
|
74
|
/*
|
75
|
$attributes = array('class'=>'thickbox',
|
76
|
'rel'=>'descriptionElement-'.$uuid, 'title'=>$feature->term);
|
77
|
for($i = 0; $part = $mediaRepresentation->representationParts[$i];
|
78
|
$i++){
|
79
|
if($i == 0){
|
80
|
$image_url = drupal_get_path('module',
|
81
|
'cdm_dataportal').'/images/'.$feature->term.'-media.png';
|
82
|
$media = '<img src="'.$image_url.'" height="14px"
|
83
|
alt="'.$feature->term.'" />';
|
84
|
$out .= l($media, $part->uri, array('attributes' => $attributes,
|
85
|
'absolute' => TRUE, 'html' => TRUE));
|
86
|
} else {
|
87
|
$out .= l('', $part->uri, array('attributes' => $attributes, 'absolute'
|
88
|
=> TRUE));
|
89
|
}
|
90
|
}
|
91
|
*/
|
92
|
}
|
93
|
else {
|
94
|
// No media available, so display just the type term.
|
95
|
$out .= $feature->representation_L10n;
|
96
|
}
|
97
|
}
|
98
|
return $out;
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* @todo Please document this function.
|
103
|
* @see http://drupal.org/node/1354
|
104
|
*/
|
105
|
function theme_cdm_mediaTypeTerm($variables) {
|
106
|
$feature = $variables['feature'];
|
107
|
$mediaUrl = $variables['mediaUrl'];
|
108
|
|
109
|
$provider = '';
|
110
|
// TODO directly use favicon from referred URI and overlay on $icon_image, but
|
111
|
// for now we comment this out.
|
112
|
/*
|
113
|
if(strpos($mediaUrl, 'biodiversitylibrary.org') > 0){
|
114
|
$provider = '-BHL';
|
115
|
}
|
116
|
*/
|
117
|
$icon_image = $feature->representation_L10n . '-media' . $provider . '.png';
|
118
|
$icon_url = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/' . $icon_image;
|
119
|
return '<img src="' . $icon_url . '" height="14px" alt="' . $feature->representation_L10n . '" />';
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* @todo Please document this function.
|
124
|
* @see http://drupal.org/node/1354
|
125
|
*/
|
126
|
function theme_cdm_media_mime_application($variables) {
|
127
|
$mediaRepresentation = $variables['mediaRepresentation'];
|
128
|
$feature = $variables['feature'];
|
129
|
$out = '';
|
130
|
foreach ($mediaRepresentation->parts as $part) {
|
131
|
$attributes = array(
|
132
|
'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
|
133
|
'target' => '_blank',
|
134
|
);
|
135
|
/*
|
136
|
$attributes = array('title'=>$feature->representation_L10n,'target'=>'_blank');
|
137
|
$attributes = array('title'=>'original publication', 'target'=>'_blank');
|
138
|
*/
|
139
|
$out .= l(theme('cdm_mediaTypeTerm', array('feature' => $feature, 'mediaUrl' => $part->uri)), $part->uri, array(
|
140
|
'attributes' => $attributes,
|
141
|
'absolute' => TRUE,
|
142
|
'html' => TRUE,
|
143
|
));
|
144
|
}
|
145
|
return $out;
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* @todo Please document this function.
|
150
|
* @see http://drupal.org/node/1354
|
151
|
*/
|
152
|
function theme_cdm_media_mime_image($variables) {
|
153
|
$mediaRepresentation = $variables['mediaRepresentation'];
|
154
|
$feature = $variables['feature'];
|
155
|
$out = '';
|
156
|
// TODO thickbox is not used anymore -> delete?
|
157
|
$attributes = array(
|
158
|
'class' => 'thickbox',
|
159
|
'rel' => 'representation-' . $representation->uuid,
|
160
|
'title' => $feature->representation_L10n,
|
161
|
);
|
162
|
for ($i = 0; $part = $representation->representationParts[$i]; $i++) {
|
163
|
if ($i == 0) {
|
164
|
$out .= l(theme('cdm_mediaTypeTerm', array('feature' => $feature, 'mediaUrl' => $part->uri)), $part->uri, array(
|
165
|
'attributes' => $attributes,
|
166
|
'absolute' => TRUE,
|
167
|
'html' => TRUE,
|
168
|
));
|
169
|
}
|
170
|
else {
|
171
|
// Comment @WA: should this really be an empty link?
|
172
|
$out .= l(t(''), $part->uri, array(
|
173
|
'attributes' => $attributes,
|
174
|
'absolute' => TRUE,
|
175
|
));
|
176
|
}
|
177
|
}
|
178
|
return $out;
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* @todo Please document this function.
|
183
|
* @see http://drupal.org/node/1354
|
184
|
*/
|
185
|
function theme_cdm_media_mime_text($variables) {
|
186
|
$representation = $variables['representation'];
|
187
|
$feature = $variables['feature'];
|
188
|
$out = '';
|
189
|
if (!empty($representation->parts)) {
|
190
|
foreach ($representation->parts as $part) {
|
191
|
$attributes = array(
|
192
|
'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
|
193
|
'target' => '_blank',
|
194
|
);
|
195
|
// $attributes = array('title'=>t('original publication'),
|
196
|
// 'target'=>'_blank');
|
197
|
$out .= l(theme('cdm_mediaTypeTerm', array('feature' => $feature, 'mediaUrl' => $part->uri)), $part->uri, array(
|
198
|
'attributes' => $attributes,
|
199
|
'absolute' => TRUE,
|
200
|
'html' => TRUE,
|
201
|
));
|
202
|
}
|
203
|
}
|
204
|
return $out;
|
205
|
}
|
206
|
|
207
|
|
208
|
/**
|
209
|
* Theme function for captions of media elements. This method is usually called from
|
210
|
* within the theme_cdm_media_gallerie() function or indirectly via AHAH.
|
211
|
*
|
212
|
* @param array $variables
|
213
|
* an associative array with the following elements:
|
214
|
* - 'media': the cdm media object to show the captions for
|
215
|
* - 'elements':
|
216
|
* an array which defining the caption elements to show up
|
217
|
* example:
|
218
|
* Show 'title', 'description', 'file', 'filename' in the caption:
|
219
|
* array('title', 'description', 'file', 'filename')
|
220
|
*
|
221
|
* @return string
|
222
|
* the themed html output
|
223
|
*/
|
224
|
function theme_cdm_media_caption($variables) {
|
225
|
$media = $variables['media'];
|
226
|
$elements = $variables['elements'];
|
227
|
$media_metadata = cdm_read_media_metadata($media);
|
228
|
|
229
|
$doTitle = !$elements || array_search('title', $elements) !== FALSE;
|
230
|
$doDescription = !$elements || array_search('description', $elements) !== FALSE;
|
231
|
$doArtist = !$elements || array_search('artist', $elements) !== FALSE;
|
232
|
$doLocation = !$elements || array_search('location', $elements) !== FALSE;
|
233
|
$doRights = !$elements || array_search('rights', $elements) !== FALSE;
|
234
|
|
235
|
$descriptionPrefix = "";
|
236
|
|
237
|
$out = '<dl class="media-caption">';
|
238
|
// Title.
|
239
|
if ($doTitle) {
|
240
|
if ($media_metadata['title']) {
|
241
|
$out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
|
242
|
$descriptionPrefix = "- ";
|
243
|
}
|
244
|
elseif (!($doDescription && $media_metadata['description'])) {
|
245
|
// Use filename as fallbackoption if no description will be shown.
|
246
|
$out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
|
247
|
$descriptionPrefix = "- ";
|
248
|
}
|
249
|
}
|
250
|
// Description.
|
251
|
if ($media_metadata['description'] && $doDescription) {
|
252
|
$out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
|
253
|
}
|
254
|
// Artist.
|
255
|
if ($media_metadata['artist'] && $doArtist) {
|
256
|
$out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
|
257
|
}
|
258
|
// Location.
|
259
|
if ($doLocation) {
|
260
|
$location = '';
|
261
|
$location .= $media_metadata['location']['sublocation'];
|
262
|
if ($location && $media_metadata['location']['city']) {
|
263
|
$location .= ', ';
|
264
|
}
|
265
|
$location .= $media_metadata['location']['city'];
|
266
|
if ($location && $media_metadata['location']['province']) {
|
267
|
$location .= ', ';
|
268
|
}
|
269
|
$location .= $media_metadata['location']['province'];
|
270
|
if ($location && $media_metadata['location']['country']) {
|
271
|
$location .= ' (' . $media_metadata['location']['country'] . ')';
|
272
|
}
|
273
|
else {
|
274
|
$location .= $media_metadata['location']['country'];
|
275
|
}
|
276
|
if ($location) {
|
277
|
$out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
|
278
|
}
|
279
|
}
|
280
|
// Rights.
|
281
|
if ($doRights) {
|
282
|
$rights = '';
|
283
|
|
284
|
// Copyrights.
|
285
|
$cnt = count($media_metadata['rights']['copyright']['agentNames']);
|
286
|
if ($cnt > 0) {
|
287
|
$rights .= '<dt class="rights">©</dt> <dd class="rights"> ';
|
288
|
for ($i = 0; $i < $cnt; $i++) {
|
289
|
$rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
|
290
|
if ($i + 1 < $cnt) {
|
291
|
$rights .= ' / ';
|
292
|
}
|
293
|
}
|
294
|
$rights .= '</dd>';
|
295
|
}
|
296
|
// License.
|
297
|
$cnt = count($media_metadata['rights']['license']['agentNames']);
|
298
|
if ($cnt > 0) {
|
299
|
$rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
|
300
|
for ($i = 0; $i < $cnt; $i++) {
|
301
|
$rights .= $media_metadata['rights']['license']['agentNames'][$i];
|
302
|
if ($i + 1 < $cnt) {
|
303
|
$rights .= ' / ';
|
304
|
}
|
305
|
}
|
306
|
$rights .= '</dd>';
|
307
|
}
|
308
|
if ($rights) {
|
309
|
$out .= $rights . '</dt>';
|
310
|
}
|
311
|
}
|
312
|
// TODO add all other metadata elemenst generically.
|
313
|
$out .= '</dl>';
|
314
|
// Return value,
|
315
|
return $out;
|
316
|
}
|
317
|
|
318
|
/**
|
319
|
* Return HTML for a media gallery
|
320
|
*
|
321
|
* @param array $variables
|
322
|
* An associative array containing:
|
323
|
* - mediaList: An array of Media entities.
|
324
|
* - maxExtend
|
325
|
* - cols
|
326
|
* - maxRows
|
327
|
* - showCaption: boolean value, whether to show captions or not.
|
328
|
* - captionElements: An array of caption elements to be shown. In case the array
|
329
|
* is empty of NULL all available caption elements will be show. In order to
|
330
|
* supress all captions set 'showCaption' to FALSE
|
331
|
* example:
|
332
|
* 1) Show 'title', 'description', 'file', 'filename' in the caption:
|
333
|
* array('title', 'description', 'file', 'filename'),
|
334
|
* 2) To add an addtional link at the bottom of the caption:
|
335
|
* array('titlecache', '#uri'=>t('open Image')) this will cause a link
|
336
|
* to be rendered with label 'open Image' which will open the accoring
|
337
|
* media object.
|
338
|
* - mediaLinkType: Valid values:
|
339
|
* - "NONE": do not link the images,
|
340
|
* - "LIGHTBOX": open the link in a light box,
|
341
|
* - "NORMAL": link to the image page or to the $alternativeMediaUri if
|
342
|
* it is defined.
|
343
|
* - alternativeMediaUri: An array of alternative URIs to link the images
|
344
|
* which will overwrite the URIs of the media parts.
|
345
|
* The order of URI in this array must correspond with the order of
|
346
|
* images in $mediaList.
|
347
|
* - galleryLinkUri: An URI to link the the hint on more images to;
|
348
|
* if NULL no link is created.
|
349
|
*
|
350
|
* @ingroup: themeable
|
351
|
*/
|
352
|
function theme_cdm_media_gallerie($variables) {
|
353
|
|
354
|
$mediaList = $variables['mediaList'];
|
355
|
|
356
|
// Do not show an empty gallery.
|
357
|
if (count($mediaList) == 0) {
|
358
|
return;
|
359
|
}
|
360
|
|
361
|
$galleryName = $variables['galleryName'];
|
362
|
$maxExtend = $variables['maxExtend'];
|
363
|
$cols = $variables['cols'];
|
364
|
$maxRows = $variables['maxRows'];
|
365
|
$captionElements = $variables['captionElements'];
|
366
|
$mediaLinkType = $variables['mediaLinkType'];
|
367
|
$alternativeMediaUri = $variables['alternativeMediaUri'];
|
368
|
$galleryLinkUri = $variables['galleryLinkUri'];
|
369
|
$showCaption = $variables['showCaption'];
|
370
|
|
371
|
$caption_link_uri = '';
|
372
|
if(isset($captionElements['#uri'])){
|
373
|
$caption_link_uri = $captionElements['#uri'];
|
374
|
unset($captionElements['#uri']);
|
375
|
}
|
376
|
if (!is_array($captionElements) || count($captionElements) == 0) {
|
377
|
$captionElements = NULL;
|
378
|
}
|
379
|
|
380
|
// TODO correctly handle multiple media representation parts
|
381
|
$_SESSION['cdm']['last_gallery'] = current_path();
|
382
|
// Prevent from errors.
|
383
|
if (!isset($mediaList[0])) {
|
384
|
// return;
|
385
|
}
|
386
|
|
387
|
// --- Duplicate supression: media can be reused but should only be shown
|
388
|
// once.
|
389
|
$tempMediaList = array();
|
390
|
$tempMediaUuids = array();
|
391
|
foreach ($mediaList as $media) {
|
392
|
if (!in_array($media->uuid, $tempMediaUuids)) {
|
393
|
$tempMediaList[] = $media;
|
394
|
$tempMediaUuids[] = $media->uuid;
|
395
|
}
|
396
|
}
|
397
|
$mediaList = $tempMediaList;
|
398
|
|
399
|
// ---
|
400
|
$galleryID = "media_gallery_" . $galleryName;
|
401
|
|
402
|
$mediaPartLinkAttributes = array();
|
403
|
$openMediaLinkAttributes = array();
|
404
|
|
405
|
// Prepare media links.
|
406
|
$doLink = FALSE;
|
407
|
if ($mediaLinkType != 'NONE') {
|
408
|
$doLink = TRUE;
|
409
|
}
|
410
|
if ($mediaLinkType == 'LIGHTBOX') {
|
411
|
$doLink = TRUE;
|
412
|
_add_js_lightbox($galleryID);
|
413
|
}
|
414
|
|
415
|
// Render the media gallery grid.
|
416
|
$out = '<table id="' . $galleryID . '" class="media_gallery">';
|
417
|
$out .= '<colgroup>';
|
418
|
for ($c = 0; $c < $cols; $c++) {
|
419
|
$out .= '<col width="' . (100 / $cols) . '%">';
|
420
|
}
|
421
|
$out .= '</colgroup>';
|
422
|
|
423
|
for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
|
424
|
$captionParts = array();
|
425
|
$mediaIndex = 0;
|
426
|
$out .= '<tr>';
|
427
|
for ($c = 0; $c < $cols; $c++) {
|
428
|
$media = array_shift($mediaList);
|
429
|
|
430
|
if (isset($media->representations[0]->parts[0])) {
|
431
|
|
432
|
//
|
433
|
// Find preferred representation.
|
434
|
//
|
435
|
$preferred_media_representations_list = cdm_preferred_media_representations($media, array(
|
436
|
'image/jpg',
|
437
|
'image/jpeg',
|
438
|
'image/png',
|
439
|
'image/gif',
|
440
|
), $maxExtend, $maxExtend);
|
441
|
if (count($preferred_media_representations_list) == 0) {
|
442
|
// Fallback to using the first one in the list.
|
443
|
$preferred_media_representations_list = $media->representations;
|
444
|
}
|
445
|
$preferred_media_representation = array_shift($preferred_media_representations_list);
|
446
|
|
447
|
// $preferred_media_representation->parts[0]->uri =
|
448
|
// "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
|
449
|
$contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
|
450
|
$mediaIndex++;
|
451
|
|
452
|
$mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
|
453
|
'mediaRepresentationPart' => $preferred_media_representation->parts[0],
|
454
|
'maxExtend' => $maxExtend,
|
455
|
'addPassePartout' => TRUE,
|
456
|
));
|
457
|
// --- Compose Media Link.
|
458
|
$mediaLinkUri = FALSE;
|
459
|
if ($alternativeMediaUri) {
|
460
|
if (isset($alternativeMediaUri[$mediaIndex])) {
|
461
|
$mediaLinkUri = $alternativeMediaUri[$mediaIndex];
|
462
|
}
|
463
|
if (is_string($alternativeMediaUri)) {
|
464
|
$mediaLinkUri = $alternativeMediaUri;
|
465
|
}
|
466
|
}
|
467
|
else {
|
468
|
$mediaLinkUri = $preferred_media_representation->parts[0]->uri;
|
469
|
}
|
470
|
|
471
|
// media captions will be loaded via AHAH
|
472
|
_add_js_ahah();
|
473
|
$content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
|
474
|
$cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
|
475
|
|
476
|
|
477
|
// preparing the part link (= click on image iteself) which can be handled in two ways
|
478
|
//
|
479
|
// 1. open image in lightbox, the captions in the lighhtbox will be loaded via AHAH
|
480
|
// 2. open the media in a new window with target 'specimen'
|
481
|
if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
|
482
|
$mediaPartLinkAttributes['class'] = array('lightbox');
|
483
|
}
|
484
|
else {
|
485
|
$mediaPartLinkAttributes['target'] = "specimen";
|
486
|
$openMediaLinkAttributes['target'] = "specimen";
|
487
|
}
|
488
|
$mediaPartLinkAttributes['alt'] = '<div class="ahah-content" rel="' . $cdm_proxy_url_caption . '">'
|
489
|
. '<span class="loading" style="display: none;">Loading ....</span></div>';
|
490
|
|
491
|
|
492
|
// preparing the media caption - no caption elements to show up here except the $caption_link_uri, if at all
|
493
|
//
|
494
|
$captionPartHtml = '';
|
495
|
if ($caption_link_uri) {
|
496
|
if ($contentTypeDirectory == 'image') {
|
497
|
// it is an image, so open it in the media page
|
498
|
$captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
|
499
|
'attributes' => array(), 'html' => TRUE,
|
500
|
)) . '</div>';
|
501
|
}
|
502
|
else {
|
503
|
// otherwise open it directly and let the the browser handle the media type
|
504
|
$openMediaLinkAttributes['absolute'] = TRUE;
|
505
|
$captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
|
506
|
'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
|
507
|
)) . '</div>';
|
508
|
}
|
509
|
}
|
510
|
|
511
|
$captionParts[] = $captionPartHtml;
|
512
|
|
513
|
// --- Surround imagePart with link, this .
|
514
|
if ($doLink) {
|
515
|
$mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
|
516
|
'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
|
517
|
));
|
518
|
}
|
519
|
}
|
520
|
else {
|
521
|
$mediaPartHtml = '';
|
522
|
$captionParts[] = '';
|
523
|
}
|
524
|
$out .= '<td class="media">' . $mediaPartHtml . '</td>';
|
525
|
}
|
526
|
$out .= '</tr>'; // End of media parts.
|
527
|
if ($showCaption) {
|
528
|
if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
|
529
|
$out .= '<tr>';
|
530
|
// Add caption row.
|
531
|
foreach ($captionParts as $captionPartHtml) {
|
532
|
$out .= '<td class="caption">' . $captionPartHtml . '</td>';
|
533
|
}
|
534
|
$out .= '</tr>';
|
535
|
}
|
536
|
}
|
537
|
}
|
538
|
|
539
|
if ($galleryLinkUri) {
|
540
|
if (count($mediaList) > 0) {
|
541
|
$moreHtml = count($mediaList) . ' ' . t('more in gallery');
|
542
|
}
|
543
|
else {
|
544
|
$moreHtml = t('open gallery');
|
545
|
}
|
546
|
$moreHtml = l($moreHtml, $galleryLinkUri);
|
547
|
$out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
|
548
|
}
|
549
|
$out .= '</table>';
|
550
|
return $out;
|
551
|
}
|
552
|
/**
|
553
|
* @todo Please document this function.
|
554
|
* @see http://drupal.org/node/1354
|
555
|
*/
|
556
|
function theme_cdm_media_gallerie_image($variables) {
|
557
|
|
558
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
559
|
$maxExtend = $variables['maxExtend'];
|
560
|
$addPassePartout = $variables['addPassePartout'];
|
561
|
$attributes = $variables['attributes'];
|
562
|
|
563
|
$out = '';
|
564
|
|
565
|
// TODO merge with theme_cdm_media_mime_image?
|
566
|
if (isset($mediaRepresentationPart)) {
|
567
|
|
568
|
$h = $mediaRepresentationPart->height;
|
569
|
$w = $mediaRepresentationPart->width;
|
570
|
if ($w == 0 || $h == 0) {
|
571
|
// Take url and replace spaces.
|
572
|
$image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
|
573
|
$imageDimensions = getimagesize_remote($image_uri);
|
574
|
if (!$imageDimensions) {
|
575
|
return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
|
576
|
}
|
577
|
$w = $imageDimensions[0];
|
578
|
$h = $imageDimensions[1];
|
579
|
}
|
580
|
$margins = '0 0 0 0';
|
581
|
$ratio = $w / $h;
|
582
|
if ($ratio > 1) {
|
583
|
$displayHeight = round($maxExtend / $ratio);
|
584
|
$displayWidth = $maxExtend;
|
585
|
$m = round(($maxExtend - $displayHeight) / 2);
|
586
|
$margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
|
587
|
}
|
588
|
else {
|
589
|
$displayHeight = $maxExtend;
|
590
|
$displayWidth = round($maxExtend * $ratio);
|
591
|
$m = round(($maxExtend - $displayWidth) / 2);
|
592
|
$margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
|
593
|
}
|
594
|
|
595
|
// Turn attributes array into string.
|
596
|
$attrStr = ' ';
|
597
|
// $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
|
598
|
if (is_array($attributes)) {
|
599
|
foreach ($attributes as $name => $value) {
|
600
|
$attrStr .= $name . '="' . $value . '" ';
|
601
|
}
|
602
|
}
|
603
|
|
604
|
if ($addPassePartout) {
|
605
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
606
|
}
|
607
|
else {
|
608
|
// Do not add margins if no pass partout is shown.
|
609
|
$margins = '';
|
610
|
}
|
611
|
$out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
|
612
|
|
613
|
if ($addPassePartout) {
|
614
|
$out .= '</div>';
|
615
|
}
|
616
|
return $out;
|
617
|
}
|
618
|
}
|
619
|
|
620
|
/**
|
621
|
* @todo Please document this function.
|
622
|
* @see http://drupal.org/node/1354
|
623
|
*/
|
624
|
function theme_cdm_media_gallerie_application($variables) {
|
625
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
626
|
$maxExtend = $variables['maxExtend'];
|
627
|
$addPassePartout = $variables['addPassePartout'];
|
628
|
$attributes = $variables['attributes'];
|
629
|
if (isset($mediaRepresentationPart)) {
|
630
|
|
631
|
if ($addPassePartout) {
|
632
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
633
|
}
|
634
|
else {
|
635
|
// Do not add margins if no pass partout is shown.
|
636
|
$margins = '';
|
637
|
}
|
638
|
$out .= '<div class="appication">Web Application</div>';
|
639
|
|
640
|
if ($addPassePartout) {
|
641
|
$out .= '</div>';
|
642
|
}
|
643
|
return $out;
|
644
|
}
|
645
|
}
|
646
|
|
647
|
/**
|
648
|
* @todo Please document this function.
|
649
|
* @see http://drupal.org/node/1354
|
650
|
*/
|
651
|
function theme_cdm_media_gallerie_text($variables) {
|
652
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
653
|
$maxExtend = $variables['maxExtend'];
|
654
|
$addPassePartout = $variables['addPassePartout'];
|
655
|
$attributes = $variables['attributes'];
|
656
|
if (isset($mediaRepresentationPart)) {
|
657
|
|
658
|
if ($addPassePartout) {
|
659
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
660
|
}
|
661
|
else {
|
662
|
// Do not add margins if no pass partout is shown.
|
663
|
$margins = '';
|
664
|
}
|
665
|
$out .= '<div class="appication">Web Application</div>';
|
666
|
|
667
|
if ($addPassePartout) {
|
668
|
$out .= '</div>';
|
669
|
}
|
670
|
return $out;
|
671
|
}
|
672
|
}
|
673
|
|
674
|
/**
|
675
|
* Adds the OpenLayers based image viewer to the page.
|
676
|
*
|
677
|
* The OpenLayers based image viewer allows to zoom and pan the displayed image.
|
678
|
*
|
679
|
* Documentation related to using Openlayers in order to view images is found here:
|
680
|
* - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
|
681
|
* - @see http://trac.openlayers.org/wiki/SettingZoomLevels
|
682
|
*
|
683
|
* @param array $variables
|
684
|
* An associative array of theme variables:
|
685
|
* - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
|
686
|
* - maxExtend: The maximum extend of the image viewer view port.
|
687
|
*/
|
688
|
function theme_cdm_openlayers_image($variables) {
|
689
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
690
|
$maxExtend = $variables['maxExtend'];
|
691
|
|
692
|
_add_js_openlayers();
|
693
|
|
694
|
// TODO merge code below with code from theme_cdm_media_gallerie_image
|
695
|
// var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
|
696
|
// TODO merge code below with code from theme_cdm_media_gallerie_image
|
697
|
$w = $mediaRepresentationPart->width;
|
698
|
$h = $mediaRepresentationPart->height;
|
699
|
|
700
|
if ($w == 0 || $h == 0) {
|
701
|
// Take url and replace spaces.
|
702
|
$image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
|
703
|
$imageDimensions = getimagesize_remote($image_uri);
|
704
|
if (!$imageDimensions) {
|
705
|
return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
|
706
|
}
|
707
|
$w = $imageDimensions[0];
|
708
|
$h = $imageDimensions[1];
|
709
|
}
|
710
|
|
711
|
// Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
|
712
|
if ($w > $h) {
|
713
|
$lat = 90;
|
714
|
$lon = 90 * ($h / $w);
|
715
|
$maxRes = $w / $maxExtend;
|
716
|
}
|
717
|
else {
|
718
|
$lat = 90 * ($w / $h);
|
719
|
$lon = 90;
|
720
|
$maxRes = $h / $maxExtend;
|
721
|
}
|
722
|
|
723
|
$maxRes *= 1;
|
724
|
drupal_add_js('
|
725
|
var map;
|
726
|
|
727
|
var imageLayerOptions={
|
728
|
maxResolution: ' . $maxRes . ',
|
729
|
maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
|
730
|
};
|
731
|
var mapOptions={
|
732
|
controls:
|
733
|
[
|
734
|
new OpenLayers.Control.PanZoom(),
|
735
|
new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
|
736
|
],
|
737
|
restrictedExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
|
738
|
};
|
739
|
|
740
|
var graphic = new OpenLayers.Layer.Image(
|
741
|
\'Image Title\',
|
742
|
\'' . $mediaRepresentationPart->uri . '\',
|
743
|
new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
|
744
|
new OpenLayers.Size(' . $w . ', ' . $h . '),
|
745
|
imageLayerOptions
|
746
|
);
|
747
|
|
748
|
function init() {
|
749
|
map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
|
750
|
map.addLayers([graphic]);
|
751
|
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
|
752
|
map.zoomToMaxExtent();
|
753
|
}
|
754
|
|
755
|
jQuery(document).ready(function(){
|
756
|
init();
|
757
|
});', array('type' => 'inline'));
|
758
|
$out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
|
759
|
return $out;
|
760
|
}
|
761
|
|
762
|
/**
|
763
|
* @todo Please document this function.
|
764
|
* @see http://drupal.org/node/1354
|
765
|
*/
|
766
|
function theme_cdm_preferredImage($variables) {
|
767
|
|
768
|
$media = $variables['media'];
|
769
|
$defaultRepresentationPart = $variables['defaultRepresentationPart'];
|
770
|
$imageMaxExtend = $variables['imageMaxExtend'];
|
771
|
$parameters = $variables['parameters'];
|
772
|
|
773
|
$out = '';
|
774
|
|
775
|
if (isset($media[0])) {
|
776
|
$representationPart = $media[0]->representations[0]->parts[0];
|
777
|
if ($parameters) {
|
778
|
$representationPart->uri . $parameters;
|
779
|
}
|
780
|
}
|
781
|
else {
|
782
|
$representationPart = $defaultRepresentationPart;
|
783
|
}
|
784
|
|
785
|
$attributes = array(
|
786
|
'alt' => (isset($media->representations[0]->parts[0]->uri) ? $media->representations[0]->parts[0]->uri : "no image available"),
|
787
|
);
|
788
|
$out .= theme('cdm_media_gallerie_image', array(
|
789
|
'mediaRepresentationPart' => $representationPart,
|
790
|
'maxExtend' => $imageMaxExtend,
|
791
|
'addPassePartout' => FALSE,
|
792
|
'attributes' => $attributes,
|
793
|
));
|
794
|
|
795
|
return $out;
|
796
|
}
|