Project

General

Profile

Download (22 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities of type SpeciemenOrOccurrences
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
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19
/**
20
 * Returns an array of render array entries for a HTML description list.
21
 *
22
 * @see theme_description_list()
23
 *
24
 * @param array $rights_list
25
 *   array of CDM Rights entities
26
 *
27
 * @return array
28
 *   the render array of the groups for the HTML description list
29
 */
30
function cdm_rights_as_dl_groups($rights_list) {
31
  $copyrights = array();
32

    
33
  $licenses = array();
34
  $access_rights = array();
35
  $unknown = array();
36

    
37
  foreach ($rights_list as $right) {
38
    if (!is_object($right)) {
39
      continue;
40
    }
41
    $type_uuid = isset($right->type->uuid) ? $right->type->uuid : 'UNKNOWN';
42
    switch ($type_uuid) {
43

    
44
      case UUID_RIGHTS_COPYRIGHT:
45
        $text = '';
46
        if (isset($right->text) ){
47
          // sanitize potential '(c)' away
48
          $text  = preg_replace('/^\(c\)/', '', $right->text);
49
        } if (isset($right->agent) ){
50
          $text  .= (strlen($text) > 0 ? ', ' : '') . $right->agent;
51
        }
52

    
53
        $copyrights[] = array('#markup' => '&copy; ' . $text);
54
        break;
55

    
56
      case UUID_RIGHTS_LICENCE:
57
        $license_str = '';
58
        if (isset($right->abbreviatedText)) {
59
          $license_str .= $right->abbreviatedText;
60
        }
61
        if (isset($right->uri)) {
62
          if (strlen($license_str) > 0) {
63
            $license_str = l($license_str, $right->uri);
64
          }
65
          else {
66
            $license_str = l(t('link'), $right->uri);
67
          }
68
        }
69
        if (strlen($license_str) > 0 && isset($right->text)) {
70
          $license_str .= ': ' . $right->text;
71
        }
72
        $licenses[] = array('#markup' => $license_str);
73
        break;
74

    
75
      case UUID_RIGHTS_ACCESS_RIGHTS:
76
        $access_rights[] = array('#markup' => $right->text);
77
        break;
78

    
79
      default:
80
        $unknown_groups[] = array('#markup' => $right->text);
81
    }
82
  }
83

    
84
  $groups = array();
85
  if (count($copyrights) > 0) {
86
    _description_list_group_add($groups, t('Copyright') . ':', $copyrights);
87
  }
88
  if (count($licenses) > 0) {
89
    _description_list_group_add($groups, t('Licenses') . ':', $licenses);
90
  }
91
  if (count($access_rights) > 0) {
92
    _description_list_group_add($groups, t('Access rights') . ':', $access_rights);
93
  }
94
  if (count($unknown) > 0) {
95
    _description_list_group_add($groups, t('Rights') . ':', $unknown);
96
  }
97

    
98
  return $groups;
99

    
100
}
101

    
102

    
103
/**
104
 * Provides the markup for an icon to represent a media which is associated with the given $feature.
105
 *
106
 * @param $feature
107
 *   the cdm Feature term
108
 * @param $media_url
109
 *   Optional, currently unused. May be used in future to display different
110
 *   icons for different media urls, like the fav-icon of the referenced
111
 * @return string
112
 *   The markup for the icon
113
 */
114
function media_feature_icon($feature, $media_url = NULL) {
115
  return font_awesome_icon_markup('fa-book', array('alt' => $feature->representation_L10n));
116
}
117

    
118
/**
119
 * Gets the metadata info such as title or artist and source references of a media file.
120
 *
121
 * The function tries at first to get all the info from the file metadata
122
 * and if it is not available look at the media file info stored at the database.
123
 *
124
 * @param mixed $media
125
 *   The media file object for which to get the metadata.
126
 *
127
 * @return array
128
 *   The array with the available specified metadata info.
129
 */
130
function read_media_metadata($media) {
131

    
132
  $metadata = array(
133
    'title' => '',// Media_metadata and media.
134
    'artist' => '',// Media_metadata and media.
135
    'rights',// Media_metadata and media.
136
    'location',// Media_metadata.
137
    'filename' => '',// Media.
138
    'mediacreated' => '', // Media.
139
    'description' => ''
140
  );
141

    
142
  // Getting the media metadata.
143
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
144
  $media_metadata_aux = (array) $media_metadata;
145

    
146

    
147
  // Filename.
148
  if (!empty($media->representations[0]->parts[0]->uri)) {
149
    $fileUri = $media->representations[0]->parts[0]->uri;
150
    $filename = substr($fileUri, strrpos($fileUri, "/") + 1);
151
    $metadata['filename'] = $filename;
152
  }
153
  else {
154
    $metadata['filename'] = '';
155
  }
156

    
157
  // Title.
158
  if (!empty($media_metadata->ObjectName)) {
159
    $metadata['title'] = $media_metadata->ObjectName;
160
  }
161
  elseif (!empty($media_metadata_aux['Object Name'])) {
162
    $metadata['title'] = $media_metadata_aux['Object Name'];
163
  }
164
  elseif (!empty($media->title_L10n)) {
165
    $metadata['title'] = $media->title_L10n;
166
  }
167
  elseif (!empty($media->titleCache)) {
168
    $metadata['title'] = $media->titleCache;
169
  }
170

    
171
  $metadata['description'] = $media->description_L10n;
172

    
173
  // Artist.
174
  if (!empty($media_metadata->Artist)) {
175
    $metadata['artist'] = '' . $media_metadata->Artist;
176
  }
177
  elseif (!empty($media->artist->titleCache)) {
178
    $metadata['artist'] = $media->artist->titleCache;
179
  }
180

    
181
  // Rights
182
  $metadata['rights'] = array();
183
  if (!empty($media_metadata->Copyright)) {
184
    $rightsObj =  new stdClass();
185
    $rightsObj->type = new stdClass();
186
    $rightsObj->type->uuid = UUID_RIGHTS_COPYRIGHT;
187
    $rightsObj->type->titleCache = 'copyright';
188
    $rightsObj->type->representation_L10n = 'copyright';
189
    $rightsObj->type->text = $media_metadata->Copyright;
190
    $metadata['rights'][] = $rightsObj;
191
  }
192
  if(isset($media->rights) && is_array($media->rights)) {
193
    $metadata['rights'] = array_merge($metadata['rights'], $media->rights);
194
  }
195

    
196
  // Filling the description (though there is no description in the db???).
197
  // $metadata_caption['description'] = $media->description_L10n;
198

    
199
  // Location.
200
  $metadata['location'] = array();
201
  $metadata['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
202
  $metadata['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
203
  $metadata['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
204
  $metadata['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
205

    
206
  /*
207
   // Creation date.
208
   if($media_metadata["Modify Date"])
209
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
210
   else
211
   $metadata_caption['mediacreated'] = $media->created;
212
   */
213

    
214
  return $metadata;
215
}
216

    
217

    
218
/**
219
 * Return HTML for a media gallery
220
 *
221
 * @param array $configuration
222
 *   An associative array containing:
223
 *   - mediaList: An array of Media entities.
224
 *   - maxExtend
225
 *   - cols
226
 *   - maxRows
227
 *   - showCaption:  boolean value, whether to show captions or not.
228
 *   - captionElements: An array of caption elements to be shown. In case the array
229
 *        is empty of NULL  all available caption elements will be show. In order to
230
 *        supress all captions  set 'showCaption' to FALSE
231
 *        example:
232
 *          1) Show 'title', 'description', 'file', 'filename' in the caption:
233
 *            array('title', 'description', 'file', 'filename'),
234
 *          2) To add an addtional link at the bottom of  the caption:
235
 *            array('titlecache', '#uri'=>t('Open Image')) this will cause a link
236
 *            to be rendered with label 'Open image' which will open the according
237
 *            media object.
238
 *   - mediaLinkType: Valid values:
239
 *      - "NONE": do not link the images,
240
 *      - "LIGHTBOX": open the link in a light box,
241
 *      - "NORMAL": link to the image page or to the $alternativeMediaUri if
242
 *        it is defined.
243
 *   - alternativeMediaUri: A fix string or an array of alternative URIs to link the images
244
 *     which will overwrite the URIs of the media parts.
245
 *     The order of URI in this array must correspond with the order of
246
 *     images in $mediaList.
247
 *   - galleryLinkUri: An URI to link the the hint on more images to;
248
 *     if NULL no link is created.
249
 *
250
 * @return array
251
 *   A render array for the image gallery
252
 * @ingroup: compose
253
 */
254
function compose_cdm_media_gallerie($configuration) {
255

    
256
  $mediaList = $configuration['mediaList'];
257

    
258
  // Do not show an empty gallery.
259
  if (count($mediaList) == 0) {
260
    return '';
261
  }
262

    
263
  // merge with default
264
  $configuration = array_merge(
265
    array(
266
      'mediaList' => NULL,
267
      'galleryName' => NULL,
268
      'maxExtend' => 150,
269
      'cols' => 4,
270
      'maxRows' => FALSE,
271
      'captionElements' => array('title'),
272
      'mediaLinkType' => 'LIGHTBOX',
273
      'alternativeMediaUri' => NULL,
274
      'galleryLinkUri' => NULL,
275
      'showCaption' => TRUE,
276
    ),
277
    $configuration);
278

    
279
  $galleryName = $configuration['galleryName'];
280
  $maxExtend = $configuration['maxExtend'];
281
  $cols = $configuration['cols'];
282
  $maxRows = $configuration['maxRows'];
283
  $captionElements = $configuration['captionElements'];
284
  $mediaLinkType = $configuration['mediaLinkType'];
285
  $alternativeMediaUri = $configuration['alternativeMediaUri'];
286
  $galleryLinkUri = $configuration['galleryLinkUri'];
287
  $showCaption = $configuration['showCaption'];
288

    
289
  $caption_link_uri = '';
290
  if(isset($captionElements['#uri'])){
291
    $caption_link_uri = $captionElements['#uri'];
292
    unset($captionElements['#uri']);
293
  }
294
  if (!is_array($captionElements) || count($captionElements) == 0) {
295
    $captionElements = NULL;
296
  }
297

    
298
  // TODO correctly handle multiple media representation parts
299
  $_SESSION['cdm']['last_gallery'] = current_path();
300
  // Prevent from errors.
301
  if (!isset($mediaList[0])) {
302
    // return;
303
  }
304

    
305
  // --- Duplicate supression: media can be reused but should only be shown
306
  // once.
307
  $tempMediaList = array();
308
  $tempMediaUuids = array();
309
  foreach ($mediaList as $media) {
310
    if (!in_array($media->uuid, $tempMediaUuids)) {
311
      $tempMediaList[] = $media;
312
      $tempMediaUuids[] = $media->uuid;
313
    }
314
  }
315
  $mediaList = $tempMediaList;
316

    
317
  // ---
318
  $galleryID = "media_gallery_" . $galleryName;
319

    
320
  $mediaPartLinkAttributes = array();
321
  $openMediaLinkAttributes = array();
322

    
323
  // Prepare media links.
324
  $doLink = FALSE;
325
  if ($mediaLinkType != 'NONE') {
326
    $doLink = TRUE;
327
  }
328
  if ($mediaLinkType == 'LIGHTBOX') {
329
    $doLink = TRUE;
330
    _add_js_lightbox($galleryID);
331
  }
332

    
333
  // Render the media gallery grid.
334
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
335
  $out .= '<colgroup>';
336
  for ($c = 0; $c < $cols; $c++) {
337
    $out .= '<col style="width:' . (100 / $cols) . '%;">';
338
  }
339
  $out .= '</colgroup>';
340

    
341
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
342
    $captionParts = array();
343
    $mediaIndex = 0;
344
    $out .= '<tr>';
345
    for ($c = 0; $c < $cols; $c++) {
346
      $media = array_shift($mediaList);
347

    
348
      if (isset($media->representations[0]->parts[0])) {
349

    
350
        //
351
        // Find preferred representation.
352
        //
353
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
354
          'image/jpg',
355
          'image/jpeg',
356
          'image/png',
357
          'image/gif',
358
        ), $maxExtend, $maxExtend);
359
        if (count($preferred_media_representations_list) == 0) {
360
          // Fallback to using the first one in the list.
361
          $preferred_media_representations_list = $media->representations;
362
        }
363
        $preferred_media_representation = array_shift($preferred_media_representations_list);
364

    
365
        // $preferred_media_representation->parts[0]->uri =
366
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
367
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
368

    
369
        $mediaPartHtml = call_user_func_array(
370
          'cdm_media_gallerie_' . $contentTypeDirectory,
371
          array( $preferred_media_representation->parts[0], $maxExtend, TRUE)
372
        );
373
        // --- Compose Media Link.
374
        $mediaLinkUri = FALSE;
375
        if ($alternativeMediaUri) {
376
          if (isset($alternativeMediaUri[$mediaIndex])) {
377
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
378
          }
379
          if (is_string($alternativeMediaUri)) {
380
            $mediaLinkUri = $alternativeMediaUri;
381
          }
382
        }
383
        else {
384
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
385
        }
386
        $mediaIndex++;
387

    
388
        // media captions will be loaded via AHAH
389
        _add_js_ahah();
390
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
391
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
392
        $ahah_media_caption =  '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
393
          . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
394

    
395
        // preparing the part link (= click on image iteself) which can be handled in two ways
396
        //
397
        //  1. open image in lightbox, the captions in the lightbox will be loaded via AHAH
398
        //  2. open the media in a new window with target 'specimen'
399
        if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
400
          $mediaPartLinkAttributes['class'] = array('lightbox');
401
        }
402
        else {
403
          $mediaPartLinkAttributes['target'] = "specimen";
404
          $openMediaLinkAttributes['target'] = "specimen";
405
        }
406
        $mediaPartLinkAttributes['alt'] = htmlentities($ahah_media_caption);
407

    
408
        // --- preparing the media caption
409

    
410
        /* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
411
         *
412
         * a.kohlbecker 2013-03-14 :
413
         *   It is unclear why no caption elements should be shown, Was it a technical reason?
414
         *   see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
415
         *   If not problems arise with this remove it after some weeks
416
         */
417
        $captionPartHtml = $ahah_media_caption;
418

    
419
        if ($caption_link_uri) {
420
          if ($contentTypeDirectory == 'image') {
421
            // it is an image, so open it in the media page
422
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
423
                'attributes' => array(), 'html' => TRUE,
424
              )) . '</div>';
425
          }
426
          else {
427
            // otherwise open it directly and let the the browser handle the media type
428
            $openMediaLinkAttributes['absolute'] = TRUE;
429
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
430
                'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
431
              )) . '</div>';
432
          }
433
        }
434

    
435
        $captionParts[] = $captionPartHtml;
436

    
437
        // --- Surround imagePart with link, this .
438
        if ($doLink) {
439
          $mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
440
            'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
441
          ));
442
        }
443
      }
444
      else {
445
        $mediaPartHtml = '';
446
        $captionParts[] = '';
447
      }
448
      $out .= '<td class="media">' . $mediaPartHtml . '</td>';
449
    }
450
    $out .= '</tr>'; // End of media parts.
451
    if ($showCaption) {
452
      if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
453
        $out .= '<tr>';
454
        // Add caption row.
455
        foreach ($captionParts as $captionPartHtml) {
456
          $out .= '<td class="caption">' . $captionPartHtml . '</td>';
457
        }
458
        $out .= '</tr>';
459
      }
460
    }
461
  }
462

    
463
  if ($galleryLinkUri) {
464
    if (count($mediaList) > 0) {
465
      $moreHtml = count($mediaList) . ' ' . t('more in gallery');
466
    }
467
    else {
468
      $moreHtml = t('open gallery');
469
    }
470
    $moreHtml = l($moreHtml, $galleryLinkUri);
471
    $out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
472
  }
473
  $out .= '</table>';
474

    
475
  return $out;
476
}
477

    
478
/**
479
 * Creates markup for a CDM MediaRepresentation which is referencing an image.
480
 *
481
 * @param $mediaRepresentationPart
482
 * @param $maxExtend
483
 * @param $addPassePartout
484
 * @param $attributes
485
 * @return string
486
 *   The markup for the media representation
487
 */
488
function cdm_media_gallerie_image($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
489

    
490
  $out = '';
491

    
492
  // TODO merge with theme_cdm_media_mime_image?
493
  if (isset($mediaRepresentationPart)) {
494

    
495
    $h = $mediaRepresentationPart->height;
496
    $w = $mediaRepresentationPart->width;
497
    if ($w == 0 || $h == 0) {
498
      // Take url and replace spaces.
499
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
500
      $imageDimensions = getimagesize_remote($image_uri);
501
      if (!$imageDimensions) {
502
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
503
      }
504
      $w = $imageDimensions[0];
505
      $h = $imageDimensions[1];
506
    }
507

    
508
    $ratio = $w / $h;
509
    if ($ratio > 1) {
510
      $displayHeight = round($maxExtend / $ratio);
511
      $displayWidth = $maxExtend;
512
      $m = round(($maxExtend - $displayHeight) / 2);
513
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
514
    }
515
    else {
516
      $displayHeight = $maxExtend;
517
      $displayWidth = round($maxExtend * $ratio);
518
      $m = round(($maxExtend - $displayWidth) / 2);
519
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
520
    }
521

    
522
    // Turn attributes array into string.
523
    if(!is_array($attributes)){
524
      $attributes = array();
525
    }
526
    if(!isset($attributes['alt'])){
527
      $attributes['alt'] = check_plain($mediaRepresentationPart->uri);
528
    }
529
    $attrStr = ' ';
530
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
531
    if (is_array($attributes)) {
532
      foreach ($attributes as $name => $value) {
533
        $attrStr .= $name . '="' . $value . '" ';
534
      }
535
    }
536

    
537
    if ($addPassePartout) {
538
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
539
    }
540
    else {
541
      // Do not add margins if no pass partout is shown.
542
      $margins = '';
543
    }
544
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
545

    
546
    if ($addPassePartout) {
547
      $out .= '</div>';
548
    }
549
  }
550

    
551
  return $out;
552
}
553

    
554
/**
555
 * Creates markup for a CDM MediaRepresentation which is referencing an web application.
556
 *
557
 * @param $mediaRepresentationPart
558
 * @param $maxExtend
559
 * @param $addPassePartout
560
 * @param $attributes
561
 * @return string
562
 *   The markup for the media representation
563
 */
564
function cdm_media_gallerie_application($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
565

    
566
  $out = '';
567

    
568
  if (isset($mediaRepresentationPart)) {
569

    
570
    if ($addPassePartout) {
571
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
572
    }
573
    $out .= '<div class="application">Web Application</div>';
574

    
575
    if ($addPassePartout) {
576
      $out .= '</div>';
577
    }
578
  }
579

    
580
  return $out;
581
}
582

    
583
/**
584
 * Creates markup for a CDM MediaRepresentation which is referencing an web application.
585
 *
586
 * @param $mediaRepresentationPart
587
 * @param $maxExtend
588
 * @param $addPassePartout
589
 * @param $attributes
590
 * @return string
591
 *   The markup for the media representation
592
 */
593
function cdm_media_gallerie_text($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
594

    
595
  $out = '';
596

    
597
  if (isset($mediaRepresentationPart)) {
598
    if ($addPassePartout) {
599
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
600
    }
601

    
602
    $out .= '<div class="application">Web Application</div>';
603

    
604
    if ($addPassePartout) {
605
      $out .= '</div>';
606
    }
607
  }
608

    
609
  return $out;
610
}
611

    
612
/**
613
 * Adds the OpenLayers based image viewer to the page.
614
 *
615
 * The OpenLayers based image viewer allows to zoom and pan the displayed image.
616
 *
617
 * Documentation related to using Openlayers in order to view images is found here:
618
 *  - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
619
 *  - @see http://trac.openlayers.org/wiki/SettingZoomLevels
620
 *
621
 * @param array $variables
622
 *   An associative array of theme variables:
623
 *   - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
624
 *   - maxExtend: The maximum extend of the image viewer view port.
625
 */
626
function cdm_openlayers_image($mediaRepresentationPart, $maxExtend) {
627

    
628
  _add_js_openlayers();
629

    
630
  // TODO merge code below with code from theme_cdm_media_gallerie_image
631
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
632
  // TODO merge code below with code from theme_cdm_media_gallerie_image
633
  $w = $mediaRepresentationPart->width;
634
  $h = $mediaRepresentationPart->height;
635

    
636
  if ($w == 0 || $h == 0) {
637
    // Take url and replace spaces.
638
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
639
    $imageDimensions = getimagesize_remote($image_uri);
640
    if (!$imageDimensions) {
641
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
642
    }
643
    $w = $imageDimensions[0];
644
    $h = $imageDimensions[1];
645
  }
646

    
647
  // Calculate maxResolution
648
  if ($w > $h) {
649
    $maxRes = $w / $maxExtend;
650
  }
651
  else {
652
    $maxRes = $h / $maxExtend;
653
  }
654

    
655
  $maxRes *= 1;
656

    
657
  drupal_add_js('
658
 var map;
659

    
660
 var imageLayerOptions={
661
     maxResolution: ' . $maxRes . ',
662
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
663
  };
664
  var mapOptions={
665
      controls:
666
       [
667
         new OpenLayers.Control.PanZoom(),
668
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
669
       ],
670
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
671
  };
672

    
673
 var graphic = new OpenLayers.Layer.Image(
674
          \'Image Title\',
675
          \'' . $mediaRepresentationPart->uri . '\',
676
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
677
          new OpenLayers.Size(' . $w . ', ' . $h . '),
678
          imageLayerOptions
679
          );
680

    
681
 function init() {
682
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
683
   map.addLayers([graphic]);
684
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
685
   map.zoomToMaxExtent();
686
 }
687

    
688
jQuery(document).ready(function(){
689
  init();
690
});', array('type' => 'inline'));
691
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
692
  return $out;
693
}
(4-4/10)