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
|
|
274
|
/**
|
275
|
* Return HTML for a media gallery
|
276
|
*
|
277
|
* @param array $variables
|
278
|
* An associative array containing:
|
279
|
* - mediaList: An array of Media entities.
|
280
|
* - maxExtend
|
281
|
* - cols
|
282
|
* - maxRows
|
283
|
* - showCaption: boolean value, whether to show captions or not.
|
284
|
* - captionElements: An array of caption elements to be shown. In case the array
|
285
|
* is empty of NULL all available caption elements will be show. In order to
|
286
|
* supress all captions set 'showCaption' to FALSE
|
287
|
* example:
|
288
|
* 1) Show 'title', 'description', 'file', 'filename' in the caption:
|
289
|
* array('title', 'description', 'file', 'filename'),
|
290
|
* 2) To add an addtional link at the bottom of the caption:
|
291
|
* array('titlecache', '#uri'=>t('Open Image')) this will cause a link
|
292
|
* to be rendered with label 'Open image' which will open the according
|
293
|
* media object.
|
294
|
* - mediaLinkType: Valid values:
|
295
|
* - "NONE": do not link the images,
|
296
|
* - "LIGHTBOX": open the link in a light box,
|
297
|
* - "NORMAL": link to the image page or to the $alternativeMediaUri if
|
298
|
* it is defined.
|
299
|
* - alternativeMediaUri: A fix string or an array of alternative URIs to link the images
|
300
|
* which will overwrite the URIs of the media parts.
|
301
|
* The order of URI in this array must correspond with the order of
|
302
|
* images in $mediaList.
|
303
|
* - galleryLinkUri: An URI to link the the hint on more images to;
|
304
|
* if NULL no link is created.
|
305
|
*
|
306
|
* @return the image gallery HTML
|
307
|
* @ingroup: themeable
|
308
|
*/
|
309
|
function theme_cdm_media_gallerie($variables) {
|
310
|
|
311
|
$mediaList = $variables['mediaList'];
|
312
|
|
313
|
// Do not show an empty gallery.
|
314
|
if (count($mediaList) == 0) {
|
315
|
return;
|
316
|
}
|
317
|
|
318
|
$galleryName = $variables['galleryName'];
|
319
|
$maxExtend = $variables['maxExtend'];
|
320
|
$cols = $variables['cols'];
|
321
|
$maxRows = $variables['maxRows'];
|
322
|
$captionElements = $variables['captionElements'];
|
323
|
$mediaLinkType = $variables['mediaLinkType'];
|
324
|
$alternativeMediaUri = $variables['alternativeMediaUri'];
|
325
|
$galleryLinkUri = $variables['galleryLinkUri'];
|
326
|
$showCaption = $variables['showCaption'];
|
327
|
|
328
|
$caption_link_uri = '';
|
329
|
if(isset($captionElements['#uri'])){
|
330
|
$caption_link_uri = $captionElements['#uri'];
|
331
|
unset($captionElements['#uri']);
|
332
|
}
|
333
|
if (!is_array($captionElements) || count($captionElements) == 0) {
|
334
|
$captionElements = NULL;
|
335
|
}
|
336
|
|
337
|
// TODO correctly handle multiple media representation parts
|
338
|
$_SESSION['cdm']['last_gallery'] = current_path();
|
339
|
// Prevent from errors.
|
340
|
if (!isset($mediaList[0])) {
|
341
|
// return;
|
342
|
}
|
343
|
|
344
|
// --- Duplicate supression: media can be reused but should only be shown
|
345
|
// once.
|
346
|
$tempMediaList = array();
|
347
|
$tempMediaUuids = array();
|
348
|
foreach ($mediaList as $media) {
|
349
|
if (!in_array($media->uuid, $tempMediaUuids)) {
|
350
|
$tempMediaList[] = $media;
|
351
|
$tempMediaUuids[] = $media->uuid;
|
352
|
}
|
353
|
}
|
354
|
$mediaList = $tempMediaList;
|
355
|
|
356
|
// ---
|
357
|
$galleryID = "media_gallery_" . $galleryName;
|
358
|
|
359
|
$mediaPartLinkAttributes = array();
|
360
|
$openMediaLinkAttributes = array();
|
361
|
|
362
|
// Prepare media links.
|
363
|
$doLink = FALSE;
|
364
|
if ($mediaLinkType != 'NONE') {
|
365
|
$doLink = TRUE;
|
366
|
}
|
367
|
if ($mediaLinkType == 'LIGHTBOX') {
|
368
|
$doLink = TRUE;
|
369
|
_add_js_lightbox($galleryID);
|
370
|
}
|
371
|
|
372
|
// Render the media gallery grid.
|
373
|
$out = '<table id="' . $galleryID . '" class="media_gallery">';
|
374
|
$out .= '<colgroup>';
|
375
|
for ($c = 0; $c < $cols; $c++) {
|
376
|
$out .= '<col style="width:' . (100 / $cols) . '%;">';
|
377
|
}
|
378
|
$out .= '</colgroup>';
|
379
|
|
380
|
for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
|
381
|
$captionParts = array();
|
382
|
$mediaIndex = 0;
|
383
|
$out .= '<tr>';
|
384
|
for ($c = 0; $c < $cols; $c++) {
|
385
|
$media = array_shift($mediaList);
|
386
|
|
387
|
if (isset($media->representations[0]->parts[0])) {
|
388
|
|
389
|
//
|
390
|
// Find preferred representation.
|
391
|
//
|
392
|
$preferred_media_representations_list = cdm_preferred_media_representations($media, array(
|
393
|
'image/jpg',
|
394
|
'image/jpeg',
|
395
|
'image/png',
|
396
|
'image/gif',
|
397
|
), $maxExtend, $maxExtend);
|
398
|
if (count($preferred_media_representations_list) == 0) {
|
399
|
// Fallback to using the first one in the list.
|
400
|
$preferred_media_representations_list = $media->representations;
|
401
|
}
|
402
|
$preferred_media_representation = array_shift($preferred_media_representations_list);
|
403
|
|
404
|
// $preferred_media_representation->parts[0]->uri =
|
405
|
// "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
|
406
|
$contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
|
407
|
|
408
|
$mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
|
409
|
'mediaRepresentationPart' => $preferred_media_representation->parts[0],
|
410
|
'maxExtend' => $maxExtend,
|
411
|
'addPassePartout' => TRUE,
|
412
|
));
|
413
|
// --- Compose Media Link.
|
414
|
$mediaLinkUri = FALSE;
|
415
|
if ($alternativeMediaUri) {
|
416
|
if (isset($alternativeMediaUri[$mediaIndex])) {
|
417
|
$mediaLinkUri = $alternativeMediaUri[$mediaIndex];
|
418
|
}
|
419
|
if (is_string($alternativeMediaUri)) {
|
420
|
$mediaLinkUri = $alternativeMediaUri;
|
421
|
}
|
422
|
}
|
423
|
else {
|
424
|
$mediaLinkUri = $preferred_media_representation->parts[0]->uri;
|
425
|
}
|
426
|
$mediaIndex++;
|
427
|
|
428
|
// media captions will be loaded via AHAH
|
429
|
_add_js_ahah();
|
430
|
$content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
|
431
|
$cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
|
432
|
$ahah_media_caption = '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
|
433
|
. '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
|
434
|
|
435
|
// preparing the part link (= click on image iteself) which can be handled in two ways
|
436
|
//
|
437
|
// 1. open image in lightbox, the captions in the lighhtbox will be loaded via AHAH
|
438
|
// 2. open the media in a new window with target 'specimen'
|
439
|
if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
|
440
|
$mediaPartLinkAttributes['class'] = array('lightbox');
|
441
|
}
|
442
|
else {
|
443
|
$mediaPartLinkAttributes['target'] = "specimen";
|
444
|
$openMediaLinkAttributes['target'] = "specimen";
|
445
|
}
|
446
|
$mediaPartLinkAttributes['alt'] = htmlentities($ahah_media_caption);
|
447
|
|
448
|
// --- preparing the media caption
|
449
|
|
450
|
/* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
|
451
|
*
|
452
|
* a.kohlbecker 2013-03-14 :
|
453
|
* It is unclear why no caption elements should be shown, Was it a technical reason?
|
454
|
* see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
|
455
|
* If not problems arise with this remove it after some weeks
|
456
|
*/
|
457
|
$captionPartHtml = $ahah_media_caption;
|
458
|
|
459
|
if ($caption_link_uri) {
|
460
|
if ($contentTypeDirectory == 'image') {
|
461
|
// it is an image, so open it in the media page
|
462
|
$captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
|
463
|
'attributes' => array(), 'html' => TRUE,
|
464
|
)) . '</div>';
|
465
|
}
|
466
|
else {
|
467
|
// otherwise open it directly and let the the browser handle the media type
|
468
|
$openMediaLinkAttributes['absolute'] = TRUE;
|
469
|
$captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
|
470
|
'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
|
471
|
)) . '</div>';
|
472
|
}
|
473
|
}
|
474
|
|
475
|
$captionParts[] = $captionPartHtml;
|
476
|
|
477
|
// --- Surround imagePart with link, this .
|
478
|
if ($doLink) {
|
479
|
$mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
|
480
|
'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
|
481
|
));
|
482
|
}
|
483
|
}
|
484
|
else {
|
485
|
$mediaPartHtml = '';
|
486
|
$captionParts[] = '';
|
487
|
}
|
488
|
$out .= '<td class="media">' . $mediaPartHtml . '</td>';
|
489
|
}
|
490
|
$out .= '</tr>'; // End of media parts.
|
491
|
if ($showCaption) {
|
492
|
if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
|
493
|
$out .= '<tr>';
|
494
|
// Add caption row.
|
495
|
foreach ($captionParts as $captionPartHtml) {
|
496
|
$out .= '<td class="caption">' . $captionPartHtml . '</td>';
|
497
|
}
|
498
|
$out .= '</tr>';
|
499
|
}
|
500
|
}
|
501
|
}
|
502
|
|
503
|
if ($galleryLinkUri) {
|
504
|
if (count($mediaList) > 0) {
|
505
|
$moreHtml = count($mediaList) . ' ' . t('more in gallery');
|
506
|
}
|
507
|
else {
|
508
|
$moreHtml = t('open gallery');
|
509
|
}
|
510
|
$moreHtml = l($moreHtml, $galleryLinkUri);
|
511
|
$out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
|
512
|
}
|
513
|
$out .= '</table>';
|
514
|
return $out;
|
515
|
}
|
516
|
/**
|
517
|
* @todo Please document this function.
|
518
|
* @see http://drupal.org/node/1354
|
519
|
*/
|
520
|
function theme_cdm_media_gallerie_image($variables) {
|
521
|
|
522
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
523
|
$maxExtend = $variables['maxExtend'];
|
524
|
$addPassePartout = $variables['addPassePartout'];
|
525
|
$attributes = $variables['attributes'];
|
526
|
|
527
|
$out = '';
|
528
|
|
529
|
// TODO merge with theme_cdm_media_mime_image?
|
530
|
if (isset($mediaRepresentationPart)) {
|
531
|
|
532
|
$h = $mediaRepresentationPart->height;
|
533
|
$w = $mediaRepresentationPart->width;
|
534
|
if ($w == 0 || $h == 0) {
|
535
|
// Take url and replace spaces.
|
536
|
$image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
|
537
|
$imageDimensions = getimagesize_remote($image_uri);
|
538
|
if (!$imageDimensions) {
|
539
|
return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
|
540
|
}
|
541
|
$w = $imageDimensions[0];
|
542
|
$h = $imageDimensions[1];
|
543
|
}
|
544
|
$margins = '0 0 0 0';
|
545
|
$ratio = $w / $h;
|
546
|
if ($ratio > 1) {
|
547
|
$displayHeight = round($maxExtend / $ratio);
|
548
|
$displayWidth = $maxExtend;
|
549
|
$m = round(($maxExtend - $displayHeight) / 2);
|
550
|
$margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
|
551
|
}
|
552
|
else {
|
553
|
$displayHeight = $maxExtend;
|
554
|
$displayWidth = round($maxExtend * $ratio);
|
555
|
$m = round(($maxExtend - $displayWidth) / 2);
|
556
|
$margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
|
557
|
}
|
558
|
|
559
|
// Turn attributes array into string.
|
560
|
if(!is_array($attributes)){
|
561
|
$attributes = array();
|
562
|
}
|
563
|
if(!isset($attributes['alt'])){
|
564
|
$attributes['alt'] = check_plain($mediaRepresentationPart->uri);
|
565
|
}
|
566
|
$attrStr = ' ';
|
567
|
// $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
|
568
|
if (is_array($attributes)) {
|
569
|
foreach ($attributes as $name => $value) {
|
570
|
$attrStr .= $name . '="' . $value . '" ';
|
571
|
}
|
572
|
}
|
573
|
|
574
|
if ($addPassePartout) {
|
575
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
576
|
}
|
577
|
else {
|
578
|
// Do not add margins if no pass partout is shown.
|
579
|
$margins = '';
|
580
|
}
|
581
|
$out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
|
582
|
|
583
|
if ($addPassePartout) {
|
584
|
$out .= '</div>';
|
585
|
}
|
586
|
return $out;
|
587
|
}
|
588
|
}
|
589
|
|
590
|
/**
|
591
|
* @todo Please document this function.
|
592
|
* @see http://drupal.org/node/1354
|
593
|
*/
|
594
|
function theme_cdm_media_gallerie_application($variables) {
|
595
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
596
|
$maxExtend = $variables['maxExtend'];
|
597
|
$addPassePartout = $variables['addPassePartout'];
|
598
|
$attributes = $variables['attributes'];
|
599
|
$out = '';
|
600
|
if (isset($mediaRepresentationPart)) {
|
601
|
|
602
|
if ($addPassePartout) {
|
603
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
604
|
}
|
605
|
else {
|
606
|
// Do not add margins if no pass partout is shown.
|
607
|
$margins = '';
|
608
|
}
|
609
|
$out .= '<div class="appication">Web Application</div>';
|
610
|
|
611
|
if ($addPassePartout) {
|
612
|
$out .= '</div>';
|
613
|
}
|
614
|
return $out;
|
615
|
}
|
616
|
}
|
617
|
|
618
|
/**
|
619
|
* @todo Please document this function.
|
620
|
* @see http://drupal.org/node/1354
|
621
|
*/
|
622
|
function theme_cdm_media_gallerie_text($variables) {
|
623
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
624
|
$maxExtend = $variables['maxExtend'];
|
625
|
$addPassePartout = $variables['addPassePartout'];
|
626
|
$attributes = $variables['attributes'];
|
627
|
if (isset($mediaRepresentationPart)) {
|
628
|
|
629
|
if ($addPassePartout) {
|
630
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
631
|
}
|
632
|
else {
|
633
|
// Do not add margins if no pass partout is shown.
|
634
|
$margins = '';
|
635
|
}
|
636
|
$out .= '<div class="application">Web Application</div>';
|
637
|
|
638
|
if ($addPassePartout) {
|
639
|
$out .= '</div>';
|
640
|
}
|
641
|
return $out;
|
642
|
}
|
643
|
}
|
644
|
|
645
|
/**
|
646
|
* Adds the OpenLayers based image viewer to the page.
|
647
|
*
|
648
|
* The OpenLayers based image viewer allows to zoom and pan the displayed image.
|
649
|
*
|
650
|
* Documentation related to using Openlayers in order to view images is found here:
|
651
|
* - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
|
652
|
* - @see http://trac.openlayers.org/wiki/SettingZoomLevels
|
653
|
*
|
654
|
* @param array $variables
|
655
|
* An associative array of theme variables:
|
656
|
* - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
|
657
|
* - maxExtend: The maximum extend of the image viewer view port.
|
658
|
*/
|
659
|
function theme_cdm_openlayers_image($variables) {
|
660
|
$mediaRepresentationPart = $variables['mediaRepresentationPart'];
|
661
|
$maxExtend = $variables['maxExtend'];
|
662
|
|
663
|
_add_js_openlayers();
|
664
|
|
665
|
// TODO merge code below with code from theme_cdm_media_gallerie_image
|
666
|
// var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
|
667
|
// TODO merge code below with code from theme_cdm_media_gallerie_image
|
668
|
$w = $mediaRepresentationPart->width;
|
669
|
$h = $mediaRepresentationPart->height;
|
670
|
|
671
|
if ($w == 0 || $h == 0) {
|
672
|
// Take url and replace spaces.
|
673
|
$image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
|
674
|
$imageDimensions = getimagesize_remote($image_uri);
|
675
|
if (!$imageDimensions) {
|
676
|
return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
|
677
|
}
|
678
|
$w = $imageDimensions[0];
|
679
|
$h = $imageDimensions[1];
|
680
|
}
|
681
|
|
682
|
// Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
|
683
|
if ($w > $h) {
|
684
|
$lat = 90;
|
685
|
$lon = 90 * ($h / $w);
|
686
|
$maxRes = $w / $maxExtend;
|
687
|
}
|
688
|
else {
|
689
|
$lat = 90 * ($w / $h);
|
690
|
$lon = 90;
|
691
|
$maxRes = $h / $maxExtend;
|
692
|
}
|
693
|
|
694
|
$maxRes *= 1;
|
695
|
drupal_add_js('
|
696
|
var map;
|
697
|
|
698
|
var imageLayerOptions={
|
699
|
maxResolution: ' . $maxRes . ',
|
700
|
maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
|
701
|
};
|
702
|
var mapOptions={
|
703
|
controls:
|
704
|
[
|
705
|
new OpenLayers.Control.PanZoom(),
|
706
|
new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
|
707
|
],
|
708
|
restrictedExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
|
709
|
};
|
710
|
|
711
|
var graphic = new OpenLayers.Layer.Image(
|
712
|
\'Image Title\',
|
713
|
\'' . $mediaRepresentationPart->uri . '\',
|
714
|
new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
|
715
|
new OpenLayers.Size(' . $w . ', ' . $h . '),
|
716
|
imageLayerOptions
|
717
|
);
|
718
|
|
719
|
function init() {
|
720
|
map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
|
721
|
map.addLayers([graphic]);
|
722
|
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
|
723
|
map.zoomToMaxExtent();
|
724
|
}
|
725
|
|
726
|
jQuery(document).ready(function(){
|
727
|
init();
|
728
|
});', array('type' => 'inline'));
|
729
|
$out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
|
730
|
return $out;
|
731
|
}
|
732
|
|