1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/**
|
5
|
* Copyright (C) 2007 EDIT
|
6
|
* European Distributed Institute of Taxonomy
|
7
|
* http://www.e-taxonomy.eu
|
8
|
*
|
9
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
10
|
* See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
|
11
|
*/
|
12
|
|
13
|
function media_content_type_dir($media_representation, $default = false){
|
14
|
|
15
|
if($media_representation->mimeType){
|
16
|
return substr($media_representation->mimeType, 0, stripos($media_representation->mimeType, '/'));
|
17
|
} else {
|
18
|
return $default;
|
19
|
}
|
20
|
}
|
21
|
|
22
|
function getimagesize_remote($image_url) {
|
23
|
|
24
|
$contents = cdm_http_request($image_url);
|
25
|
if(!$contents){
|
26
|
return false;
|
27
|
}
|
28
|
|
29
|
$im = @ImageCreateFromString($contents); // using@ to avoid php user warnings
|
30
|
if (!$im) {
|
31
|
return false;
|
32
|
}
|
33
|
$gis[0] = ImageSX($im);
|
34
|
$gis[1] = ImageSY($im);
|
35
|
// array member 3 is used below to keep with current getimagesize standards
|
36
|
$gis[3] = "width={$gis[0]} height={$gis[1]}";
|
37
|
ImageDestroy($im);
|
38
|
return $gis;
|
39
|
}
|
40
|
|
41
|
|
42
|
|
43
|
function theme_cdm_media($descriptionElement, $mimeTypePreference){
|
44
|
$out = "";
|
45
|
|
46
|
_add_js_thickbox();
|
47
|
|
48
|
$uuid = $descriptionElement->uuid;
|
49
|
$feature = $descriptionElement->feature;
|
50
|
$medias = $descriptionElement->media;
|
51
|
|
52
|
foreach($medias as $media){
|
53
|
$prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
|
54
|
$mediaRepresentation = array_shift($prefRepresentations);
|
55
|
if($mediaRepresentation) {
|
56
|
|
57
|
$contentTypeDirectory = media_content_type_dir($mediaRepresentation);
|
58
|
|
59
|
$out .= theme('cdm_media_mime_' . $contentTypeDirectory, $mediaRepresentation, $feature);
|
60
|
|
61
|
// $attributes = array('class'=>'thickbox', 'rel'=>'descriptionElement-'.$uuid, 'title'=>$feature->term);
|
62
|
// for($i = 0; $part = $mediaRepresentation->representationParts[$i]; $i++){
|
63
|
// if($i == 0){
|
64
|
// $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/'.$feature->term.'-media.png';
|
65
|
// $media = '<img src="'.$image_url.'" height="14px" alt="'.$feature->term.'" />';
|
66
|
// $out .= l($media, $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
|
67
|
// } else {
|
68
|
// $out .= l('', $part->uri, $attributes, NULL, NULL, TRUE);
|
69
|
// }
|
70
|
// }
|
71
|
} else {
|
72
|
// no media available, so display just the type term
|
73
|
$out .= $feature->representation_L10n;
|
74
|
}
|
75
|
}
|
76
|
return $out;
|
77
|
|
78
|
}
|
79
|
|
80
|
function theme_cdm_mediaTypeTerm($feature, $mediaUrl = false){
|
81
|
|
82
|
$provider = '';
|
83
|
//TODO directly use favicon from referred URI and overlay on $icon_image, but for now we comment this out
|
84
|
// if(strpos($mediaUrl, 'biodiversitylibrary.org') > 0){
|
85
|
// $provider = '-BHL';
|
86
|
// }
|
87
|
|
88
|
$icon_image = $feature->representation_L10n.'-media'.$provider.'.png';
|
89
|
$icon_url = drupal_get_path('module', 'cdm_dataportal').'/images/'.$icon_image;
|
90
|
return '<img src="'.$icon_url.'" height="14px" alt="'.$feature->representation_L10n.'" />';
|
91
|
}
|
92
|
|
93
|
function theme_cdm_media_mime_application($mediaRepresentation, $feature){
|
94
|
|
95
|
foreach($mediaRepresentation->parts as $part){
|
96
|
$attributes = array('title'=> theme('cdm_feature_name', $feature->representation_L10n), 'target'=>'_blank');
|
97
|
//$attributes = array('title'=>$feature->representation_L10n, 'target'=>'_blank');
|
98
|
//$attributes = array('title'=>'original publication', 'target'=>'_blank');
|
99
|
$out .= l(theme('cdm_mediaTypeTerm', $feature, $part->uri), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
|
100
|
}
|
101
|
return $out;
|
102
|
}
|
103
|
|
104
|
function theme_cdm_media_mime_image($mediaRepresentation, $feature){
|
105
|
$out = '';
|
106
|
//TODO thickbox is not used anymore -> delete ?
|
107
|
$attributes = array('class'=>'thickbox', 'rel'=>'representation-'.$representation->uuid, 'title'=>$feature->representation_L10n);
|
108
|
for($i = 0; $part = $representation->representationParts[$i]; $i++){
|
109
|
if($i == 0){
|
110
|
$out .= l(theme('cdm_mediaTypeTerm', $feature, $part->uri), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
|
111
|
} else {
|
112
|
$out .= l('', $part->uri, $attributes, NULL, NULL, TRUE);
|
113
|
}
|
114
|
}
|
115
|
return $out;
|
116
|
}
|
117
|
|
118
|
function theme_cdm_media_mime_text($representation, $feature){
|
119
|
|
120
|
foreach($representation->parts as $part){
|
121
|
$attributes = array('title'=> theme('cdm_feature_name', $feature->representation_L10n), 'target'=>'_blank');
|
122
|
//$attributes = array('title'=>t('original publication'), 'target'=>'_blank');
|
123
|
$out .= l(theme('cdm_mediaTypeTerm', $feature, $part->uri), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
|
124
|
}
|
125
|
return $out;
|
126
|
}
|
127
|
|
128
|
|
129
|
function theme_cdm_media_caption($media, $elements = array('title', 'description', 'artist', 'location', 'rights'), $fileUri = null){
|
130
|
|
131
|
$media_metadata = cdm_read_media_metadata($media);
|
132
|
|
133
|
$doTitle= !$elements || array_search('title', $elements)!== false;
|
134
|
$doDescription = !$elements || array_search('description', $elements)!== false;
|
135
|
$doArtist = !$elements || array_search('artist', $elements)!== false;
|
136
|
$doLocation = !$elements || array_search('location', $elements)!== false;
|
137
|
$doRights = !$elements || array_search('rights', $elements)!== false;
|
138
|
|
139
|
$descriptionPrefix = "";
|
140
|
|
141
|
$out = '<dl class="media-caption">';
|
142
|
//title
|
143
|
if($doTitle) {
|
144
|
if($media_metadata['title']){
|
145
|
$out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
|
146
|
$descriptionPrefix = "- ";
|
147
|
} else if(!($doDescription && $media_metadata['description'])) {
|
148
|
// use filename as fallbackoption if no description will be shown
|
149
|
$out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
|
150
|
$descriptionPrefix = "- ";
|
151
|
}
|
152
|
}
|
153
|
//description
|
154
|
if($media_metadata['description'] && $doDescription) {
|
155
|
$out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
|
156
|
}
|
157
|
//artist
|
158
|
if($media_metadata['artist'] && $doArtist) {
|
159
|
$out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
|
160
|
}
|
161
|
//location
|
162
|
if($doLocation){
|
163
|
$location = '';
|
164
|
$location .= $media_metadata['location']['sublocation'];
|
165
|
if ($location && $media_metadata['location']['city']){
|
166
|
$location .= ', ';
|
167
|
}
|
168
|
$location .= $media_metadata['location']['city'];
|
169
|
if ($location && $media_metadata['location']['province']){
|
170
|
$location .= ', ';
|
171
|
}
|
172
|
$location .= $media_metadata['location']['province'];
|
173
|
if ($location && $media_metadata['location']['country']){
|
174
|
$location .= ' (' . $media_metadata['location']['country'] . ')';
|
175
|
} else {
|
176
|
$location .= $media_metadata['location']['country'];
|
177
|
}
|
178
|
if ($location){
|
179
|
$out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
|
180
|
}
|
181
|
}
|
182
|
//rights
|
183
|
if($doRights){
|
184
|
$rights = '';
|
185
|
//copyrights
|
186
|
$cnt = count($media_metadata['rights']['copyright']['agentNames']);
|
187
|
if($cnt > 0){
|
188
|
$rights .= '<dt class="rights">©</dt> <dd class="rights"> ';
|
189
|
for($i = 0; $i < $cnt; $i++){
|
190
|
$rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
|
191
|
if($i+1 < $cnt){
|
192
|
$rights .= ' / ';
|
193
|
}
|
194
|
}
|
195
|
$rights .= '</dd>';
|
196
|
}
|
197
|
//license
|
198
|
$cnt = count($media_metadata['rights']['license']['agentNames']);
|
199
|
if($cnt > 0){
|
200
|
$rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
|
201
|
for($i = 0; $i < $cnt; $i++){
|
202
|
$rights .= $media_metadata['rights']['license']['agentNames'][$i];
|
203
|
if ($i+1 < $cnt){
|
204
|
$rights .= ' / ';
|
205
|
}
|
206
|
}
|
207
|
$rights .= '</dd>';
|
208
|
}
|
209
|
if($rights){
|
210
|
$out .= $rights . '</dt>';
|
211
|
}
|
212
|
}
|
213
|
//TODO add all other metadata elemenst generically
|
214
|
$out .= '</dl>';
|
215
|
//return value
|
216
|
return $out;
|
217
|
}
|
218
|
|
219
|
|
220
|
/**
|
221
|
* @param $mediaList an array of Media entities
|
222
|
* @param $maxExtend
|
223
|
* @param $cols
|
224
|
* @param $maxRows
|
225
|
* @param $captionElements an array possible values are like in the following example: array('title', 'description', 'file', 'filename'),
|
226
|
* to add a link to the caption: array('titlecache', '#uri'=>t('open Image'));
|
227
|
* @param $mediaLinkType valid values:
|
228
|
* "NONE": do not link the images,
|
229
|
* "LIGHTBOX": open the link in a light box,
|
230
|
* "NORMAL": link to the image page or to the $alternativeMediaUri if it is defined
|
231
|
* @param $alternativeMediaUri an array of alternative URIs to link the images wich will overwrite the URIs of the media parts.
|
232
|
* The order of URI in this array must correspond with the order of images in $mediaList
|
233
|
* @param $galleryLinkUri an URI to link the the hint on more images to; if null no link is created
|
234
|
* @return unknown_type
|
235
|
*/
|
236
|
function theme_cdm_media_gallerie(
|
237
|
$mediaList,
|
238
|
$galleryName,
|
239
|
$maxExtend = 150,
|
240
|
$cols = 4,
|
241
|
$maxRows = false,
|
242
|
$captionElements = array('title'),
|
243
|
$mediaLinkType = 'LIGHTBOX',
|
244
|
$alternativeMediaUri = null,
|
245
|
$galleryLinkUri = null,
|
246
|
$showCaption = true){
|
247
|
|
248
|
if(!is_array($captionElements)){
|
249
|
$captionElements = array();
|
250
|
}
|
251
|
//TODO correctly handle multiple media representation parts
|
252
|
$_SESSION['cdm']['last_gallery']= substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'], "?q=")+3);
|
253
|
// prevent from errors
|
254
|
if(!isset($mediaList[0])){
|
255
|
return;
|
256
|
}
|
257
|
|
258
|
// --- duplicate supression: media can be reused but should only be shown once.
|
259
|
$tempMediaList = array();
|
260
|
$tempMediaUuids = array();
|
261
|
foreach ($mediaList as $media) {
|
262
|
if(!in_array($media->uuid, $tempMediaUuids)) {
|
263
|
$tempMediaList[] = $media;
|
264
|
$tempMediaUuids[] = $media->uuid;
|
265
|
}
|
266
|
}
|
267
|
$mediaList = $tempMediaList;
|
268
|
|
269
|
// ---
|
270
|
$galleryID = "media_gallery_".$galleryName;
|
271
|
$mediaPartLinkAttributes = array();
|
272
|
$openMediaLinkAttributes = array();
|
273
|
|
274
|
// prepare media links
|
275
|
$doLink = false;
|
276
|
if($mediaLinkType != 'NONE'){
|
277
|
$doLink = true;
|
278
|
}
|
279
|
if($mediaLinkType == 'LIGHTBOX'){
|
280
|
$doLink = true;
|
281
|
_add_js_lightbox($galleryID);
|
282
|
}
|
283
|
|
284
|
// render the media gallery grid
|
285
|
$out = '<table id="'.$galleryID.'" class="media_gallery">';
|
286
|
$out .= '<colgroup>';
|
287
|
for($c = 0; $c < $cols; $c++){
|
288
|
$out .= '<col width="'.(100 / $cols).'%">';
|
289
|
}
|
290
|
$out .= '</colgroup>';
|
291
|
|
292
|
|
293
|
for($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++){
|
294
|
$captionParts = array();
|
295
|
$out .= '<tr>';
|
296
|
for($c = 0; $c < $cols; $c++){
|
297
|
$media = array_shift($mediaList);
|
298
|
|
299
|
if(isset($media->representations[0]->parts[0])){
|
300
|
|
301
|
//
|
302
|
// find preferred representation
|
303
|
//
|
304
|
$preferred_media_representations_list = cdm_preferred_media_representations(
|
305
|
$media,
|
306
|
array('image/jpg', 'image/jpeg', 'image/png', 'image/gif'),
|
307
|
$maxExtend, $maxExtend);
|
308
|
if(count($preferred_media_representations_list) == 0){
|
309
|
// fallback to using the first one in the list
|
310
|
$preferred_media_representations_list = $media->representations;
|
311
|
}
|
312
|
$preferred_media_representation = array_shift($preferred_media_representations_list);
|
313
|
|
314
|
// $preferred_media_representation->parts[0]->uri = "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
|
315
|
$contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
|
316
|
$mediaIndex++;
|
317
|
$mediaPartHtml = theme('cdm_media_gallerie_'.$contentTypeDirectory, $preferred_media_representation->parts[0], $maxExtend, TRUE);
|
318
|
// --- compose Media Link
|
319
|
$mediaLinkUri = false;
|
320
|
if($alternativeMediaUri){
|
321
|
if(isset($alternativeMediaUri[$mediaIndex])){
|
322
|
$mediaLinkUri = $alternativeMediaUri[$mediaIndex];
|
323
|
}
|
324
|
if(is_string($alternativeMediaUri)){
|
325
|
$mediaLinkUri = $alternativeMediaUri;
|
326
|
}
|
327
|
} else {
|
328
|
$mediaLinkUri = $preferred_media_representation->parts[0]->uri;
|
329
|
}
|
330
|
|
331
|
_add_js_ahah();
|
332
|
$content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
|
333
|
|
334
|
$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/cdm_media_caption/".serialize($captionElements));
|
335
|
$captionPartHtml = '<div class="ahah-content" rel="'.$cdm_proxy_url.'"><span class="loading" style="display: none;">Loading ....</span></div>';
|
336
|
|
337
|
// generate gallery caption
|
338
|
if($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image'){
|
339
|
$mediaPartLinkAttributes['class'] = "lightbox";
|
340
|
} else {
|
341
|
$mediaPartLinkAttributes['target'] = "specimen";
|
342
|
$openMediaLinkAttributes['target'] = "specimen";
|
343
|
}
|
344
|
// generate & add caption to lightbox
|
345
|
$lightBoxCaptionElements = null;
|
346
|
$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/cdm_media_caption"); //.($lightBoxCaptionElements?'/'.join (',',$lightBoxCaptionElements):''));
|
347
|
$mediaPartLinkAttributes['alt'] = '<div class="ahah-content" rel="'.$cdm_proxy_url.'"><span class="loading" style="display: none;">Loading ....</span></div>';
|
348
|
|
349
|
if(isset($captionElements['#uri'])){
|
350
|
if($contentTypeDirectory == 'image'){
|
351
|
$captionPartHtml .= '<div>'.l($captionElements['#uri'], path_to_media($media->uuid), null, null, null, FALSE, TRUE).'</div>';
|
352
|
} else {
|
353
|
$captionPartHtml .= '<div>'.l($captionElements['#uri'], $mediaLinkUri, $openMediaLinkAttributes, null, null, TRUE, TRUE).'</div>';
|
354
|
}
|
355
|
}
|
356
|
$captionParts[] = $captionPartHtml;
|
357
|
|
358
|
// --- surround imagePart with link
|
359
|
if($doLink){
|
360
|
$mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, $mediaPartLinkAttributes, null, null, FALSE, TRUE);
|
361
|
}
|
362
|
|
363
|
} else {
|
364
|
$mediaPartHtml = '';
|
365
|
$captionParts[] = '';
|
366
|
}
|
367
|
$out .= '<td class="media">'.$mediaPartHtml.'</td>';
|
368
|
}
|
369
|
$out .= '</tr>'; // end of media parts
|
370
|
if ($showCaption){
|
371
|
if(count($captionElements) > 0){
|
372
|
$out .= '<tr>';
|
373
|
// add caption row
|
374
|
foreach($captionParts as $captionPartHtml){
|
375
|
$out .= '<td class="caption">'.$captionPartHtml.'</td>';
|
376
|
}
|
377
|
$out .= '</tr>';
|
378
|
}
|
379
|
}
|
380
|
}
|
381
|
if($galleryLinkUri){
|
382
|
if(count($mediaList) > 0){
|
383
|
$moreHtml = count($mediaList).' '.t('more in gallery');
|
384
|
} else {
|
385
|
$moreHtml = t('open gallery');
|
386
|
}
|
387
|
$moreHtml = l($moreHtml, $galleryLinkUri);
|
388
|
$out .= '<tr><td colspan="'.$cols.'">'.$moreHtml.'</td></tr>';
|
389
|
}
|
390
|
$out .= '</table>';
|
391
|
return $out;
|
392
|
}
|
393
|
|
394
|
function theme_cdm_media_gallerie_image($mediaRepresentationPart, $maxExtend, $addPassePartout = FALSE, $attributes = null){
|
395
|
//TODO merge with theme_cdm_media_mime_image?
|
396
|
|
397
|
if(isset($mediaRepresentationPart)){
|
398
|
|
399
|
$h = $mediaRepresentationPart->height;
|
400
|
$w = $mediaRepresentationPart->width;
|
401
|
if($w == 0 || $h == 0){
|
402
|
$image_uri = str_replace(' ','%20',$mediaRepresentationPart->uri); //take url and replace spaces
|
403
|
$imageDimensions = getimagesize_remote($image_uri);
|
404
|
if(!$imageDimensions){
|
405
|
return '<div>'.t('Image unavailable, uri: ').$mediaRepresentationPart->uri.'</div>';
|
406
|
}
|
407
|
$w = $imageDimensions[0];
|
408
|
$h = $imageDimensions[1];
|
409
|
}
|
410
|
$margins = '0 0 0 0';
|
411
|
$ratio = $w / $h;
|
412
|
if($ratio > 1){
|
413
|
$displayHeight = round($maxExtend / $ratio);
|
414
|
$displayWidth = $maxExtend;
|
415
|
$m = round(($maxExtend - $displayHeight) / 2);
|
416
|
$margins = 'margin:'.$m.'px 0 '.$m.'px 0;';
|
417
|
} else {
|
418
|
$displayHeight = $maxExtend;
|
419
|
$displayWidth = round($maxExtend * $ratio);
|
420
|
$m = round(($maxExtend - $displayWidth) / 2);
|
421
|
$margins = 'margin:0 '.$m.'px 0 '.$m.'px;';
|
422
|
}
|
423
|
|
424
|
// turn attributes array into string
|
425
|
$attrStr = ' ';
|
426
|
//$attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
|
427
|
if(is_array($attributes)){
|
428
|
foreach($attributes as $name=>$value){
|
429
|
$attrStr .= $name.'="'.$value.'" ';
|
430
|
}
|
431
|
}
|
432
|
|
433
|
//return '<img src="'."http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/photos/Lapsana_communis_A_01.jpg".'" width="'.$maxExtend.'" height="'.$maxExtend.'" />';
|
434
|
if($addPassePartout){
|
435
|
$out .= '<div class="image-passe-partout" style="width:'.$maxExtend.'px; height:'.$maxExtend.'px;">';
|
436
|
} else {
|
437
|
// do not add margins if no pass partout is shown
|
438
|
$margins = '';
|
439
|
}
|
440
|
$out .= '<img src="'.$mediaRepresentationPart->uri.'" width="'.$displayWidth.'" height="'.$displayHeight.'" style="'.$margins.'"'.$attrStr.' />';
|
441
|
|
442
|
if($addPassePartout){
|
443
|
$out .= '</div>';
|
444
|
}
|
445
|
return $out;
|
446
|
}
|
447
|
|
448
|
}
|
449
|
|
450
|
function theme_cdm_media_gallerie_application($mediaRepresentationPart, $maxExtend, $addPassePartout = FALSE, $attributes = null){
|
451
|
|
452
|
if(isset($mediaRepresentationPart)){
|
453
|
|
454
|
if($addPassePartout){
|
455
|
$out .= '<div class="image-passe-partout" style="width:'.$maxExtend.'px; height:'.$maxExtend.'px;">';
|
456
|
} else {
|
457
|
// do not add margins if no pass partout is shown
|
458
|
$margins = '';
|
459
|
}
|
460
|
$out .= '<div class="appication">Web Application</div>';
|
461
|
|
462
|
if($addPassePartout){
|
463
|
$out .= '</div>';
|
464
|
}
|
465
|
return $out;
|
466
|
}
|
467
|
|
468
|
}
|
469
|
|
470
|
function theme_cdm_media_gallerie_text($mediaRepresentationPart, $maxExtend, $addPassePartout = FALSE, $attributes = null){
|
471
|
|
472
|
if(isset($mediaRepresentationPart)){
|
473
|
|
474
|
if($addPassePartout){
|
475
|
$out .= '<div class="image-passe-partout" style="width:'.$maxExtend.'px; height:'.$maxExtend.'px;">';
|
476
|
} else {
|
477
|
// do not add margins if no pass partout is shown
|
478
|
$margins = '';
|
479
|
}
|
480
|
$out .= '<div class="appication">Web Application</div>';
|
481
|
|
482
|
if($addPassePartout){
|
483
|
$out .= '</div>';
|
484
|
}
|
485
|
return $out;
|
486
|
}
|
487
|
|
488
|
}
|
489
|
|
490
|
function theme_cdm_openlayers_image($mediaRepresentationPart, $maxExtend){
|
491
|
|
492
|
// see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
|
493
|
// and http://trac.openlayers.org/wiki/SettingZoomLevels
|
494
|
|
495
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
|
496
|
|
497
|
//TODO megre code below with code from theme_cdm_media_gallerie_image
|
498
|
//var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
|
499
|
//TODO merge code below with code from theme_cdm_media_gallerie_image
|
500
|
$w = $mediaRepresentationPart->width;
|
501
|
$h = $mediaRepresentationPart->height;
|
502
|
|
503
|
if($w == 0 || $h == 0){
|
504
|
$image_uri = str_replace(' ','%20',$mediaRepresentationPart->uri); //take url and replace spaces
|
505
|
$imageDimensions = getimagesize_remote($image_uri);
|
506
|
if(!$imageDimensions){
|
507
|
return '<div>'.t('Image unavailable, uri:').$mediaRepresentationPart->uri.'</div>';
|
508
|
}
|
509
|
$w = $imageDimensions[0];
|
510
|
$h = $imageDimensions[1];
|
511
|
}
|
512
|
|
513
|
// calculate maxResolution (default is 360 deg / 256 px) and the bounds
|
514
|
if($w > $h){
|
515
|
$lat = 90;
|
516
|
$lon = 90 * ($h / $w);
|
517
|
$maxRes = $w / $maxExtend;
|
518
|
} else {
|
519
|
$lat = 90 * ($w / $h);
|
520
|
$lon = 90;
|
521
|
$maxRes = $h / $maxExtend ;
|
522
|
}
|
523
|
|
524
|
$maxRes *= 1;
|
525
|
drupal_add_js('
|
526
|
var map;
|
527
|
|
528
|
var imageLayerOptions={
|
529
|
maxResolution: '.$maxRes.',
|
530
|
maxExtent: new OpenLayers.Bounds(0, 0, '.$w.', '.$h.')
|
531
|
};
|
532
|
var mapOptions={
|
533
|
controls:
|
534
|
[
|
535
|
new OpenLayers.Control.PanZoom(),
|
536
|
new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
|
537
|
],
|
538
|
restrictedExtent: new OpenLayers.Bounds(0, 0, '.$w.', '.$h.')
|
539
|
};
|
540
|
|
541
|
var graphic = new OpenLayers.Layer.Image(
|
542
|
\'Image Title\',
|
543
|
\''.$mediaRepresentationPart->uri.'\',
|
544
|
new OpenLayers.Bounds(0, 0, '.$w.', '.$h.'),
|
545
|
new OpenLayers.Size('.$w.', '.$h.'),
|
546
|
imageLayerOptions
|
547
|
);
|
548
|
|
549
|
function init() {
|
550
|
map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
|
551
|
map.addLayers([graphic]);
|
552
|
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
|
553
|
map.zoomToMaxExtent();
|
554
|
}
|
555
|
|
556
|
$(document).ready(function(){
|
557
|
init();
|
558
|
|
559
|
});'
|
560
|
, 'inline');
|
561
|
$out = '<div id="openlayers_image" class="image_viewer" style="width: '.$maxExtend.'px; height:'.($maxExtend).'px"></div>';
|
562
|
return $out;
|
563
|
|
564
|
}
|
565
|
|
566
|
|
567
|
function theme_cdm_preferredImage($media, $defaultRepresentationPart, $imageMaxExtend, $parameters = ''){
|
568
|
|
569
|
if(isset($media[0])){
|
570
|
$representationPart = $media[0]->representations[0]->parts[0];
|
571
|
if($parameters){
|
572
|
$representationPart->uri.$parameters;
|
573
|
}
|
574
|
} else {
|
575
|
$representationPart = $defaultRepresentationPart;
|
576
|
}
|
577
|
|
578
|
//$widthAndHeight = ($imageWidth ? ' width="'.$imageWidth : '').($imageHeight ? '" height="'.$imageHeight : '');
|
579
|
// $imageUri = $preferredMedia ? $preferredMedia->representations[0]->parts[0]->uri . $parameters : $defaultImage;
|
580
|
$attributes = array('alt'=>($preferredMedia ? $preferredMedia->representations[0]->parts[0]->uri : "no image available"));
|
581
|
$out .= theme('cdm_media_gallerie_image', $representationPart, $imageMaxExtend, false, $attributes);
|
582
|
// $out = '<img class="left" '.$widthAndHeight.' " src="'.$imageUri.'" alt="'.$altText.'" />';
|
583
|
return $out;
|
584
|
}
|