Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / media.inc @ e249276f

History | View | Annotate | Download (28.6 KB)

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
const MEDIA_GALLERY_ID_PREFIX = 'media-gallery-';
19

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

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

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

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

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

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

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

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

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

    
99
  return $groups;
100

    
101
}
102

    
103

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

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

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

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

    
148

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

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

    
171
  if (!empty($media->description_L10n)) {
172
    $metadata['description'] = $media->description_L10n;
173
  }
174

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

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

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

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

    
207
  /*
208
   // Creation date.
209
   if($media_metadata["Modify Date"])
210
   $metadata['mediacreated'] = $media_metadata["Modify Date"];
211
   else
212
   */
213
  if (!empty($media->mediaCreated)) {
214
    $metadata['mediacreated'] =  timePeriodToString($media->mediaCreated);
215
  }
216

    
217
  return $metadata;
218
}
219

    
220

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

    
259
  $mediaList = $configuration['mediaList'];
260

    
261
  // Do not show an empty gallery.
262
    if (!is_array($mediaList) || count($mediaList) == 0){
263
        return '';
264
    }
265

    
266

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

    
283
  $galleryName = $configuration['galleryName'];
284
  $maxExtend = $configuration['maxExtend'];
285
  $cols = $configuration['cols'];
286
  $maxRows = $configuration['maxRows'];
287
  $captionElements = $configuration['captionElements'];
288
  $mediaLinkType = $configuration['mediaLinkType'];
289
  $alternativeMediaUri = $configuration['alternativeMediaUri'];
290
  $galleryLinkUri = $configuration['galleryLinkUri'];
291
  $showCaption = $configuration['showCaption'];
292

    
293
  $caption_link_uri = '';
294
  if(isset($captionElements['#uri'])){
295
    $caption_link_uri = $captionElements['#uri'];
296
    unset($captionElements['#uri']);
297
  }
298
  if (!is_array($captionElements) || count($captionElements) == 0) {
299
    $captionElements = NULL;
300
  }
301

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

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

    
321
  // ---
322
  $galleryID = "media_gallery_" . $galleryName;
323

    
324
  $mediaPartLinkAttributes = array();
325
  $openMediaLinkAttributes = array();
326

    
327
  // Prepare media links.
328
  $doLink = FALSE;
329
  if ($mediaLinkType != 'NONE') {
330
    $doLink = TRUE;
331
  }
332
  if ($mediaLinkType == 'LIGHTBOX') {
333
    $doLink = TRUE;
334
    _add_js_lightbox($galleryID);
335
  }
336

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

    
345
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
346
    $captionParts = array();
347
    $mediaIndex = 0;
348
    $out .= '<tr class="media-row">';
349
    for ($c = 0; $c < $cols; $c++) {
350
      $media = array_shift($mediaList);
351
      if(!$media){
352
        continue;
353
      }
354
      $complete_media = cdm_ws_get(CDM_WS_MEDIA, $media->uuid);
355
      if (isset($complete_media->representations[0]->parts[0])) {
356

    
357
          //
358
          // Find preferred representation.
359
          //
360

    
361
          $thumbnail_representations = cdm_preferred_media_representations($complete_media, array(
362
              'image/jpg',
363
              'image/jpeg',
364
              'image/png',
365
              'image/gif',
366
          ),
367
              $maxExtend,
368
              $maxExtend
369
          );
370
          // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
371
          // which only contains the thumbnail representation even if the height and width filters are not set.
372
          // --> #6970
373
          // to get hold of the full resolution images we send a separate request :
374
          // $complete_media = cdm_ws_get(CDM_WS_MEDIA, $media->uuid);
375
          $full_size_representations = cdm_preferred_media_representations($complete_media, array(
376
                  'image/jpg',
377
                  'image/jpeg',
378
                  'image/png',
379
                  'image/gif',
380
              )
381
          );
382
          if (count($thumbnail_representations) == 0) {
383
              // Fallback to using the first one in the list.
384
              $thumbnail_representations = $media->representations;
385
              $full_size_representations = $media->representations;
386
          }
387
          $thumbnail_representation = array_shift($thumbnail_representations);
388
          $full_size_representation = array_shift($full_size_representations);
389

    
390
          // $preferred_media_representation->parts[0]->uri =
391
          // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
392
          $contentTypeDirectory = media_content_type_dir($thumbnail_representation, 'application');
393

    
394
          $mediaPartHtml = call_user_func_array(
395
              'cdm_media_gallerie_' . $contentTypeDirectory,
396
              array($thumbnail_representation->parts[0], $maxExtend, TRUE)
397
          );
398
          // --- Compose Media Link.
399
          $mediaLinkUri = FALSE;
400
          if ($alternativeMediaUri) {
401
              if (isset($alternativeMediaUri[$mediaIndex])) {
402
                  $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
403
              }
404
              if (is_string($alternativeMediaUri)) {
405
                  $mediaLinkUri = $alternativeMediaUri;
406
              }
407
          } else {
408
              $mediaLinkUri = $full_size_representation->parts[0]->uri;
409
          }
410
          $mediaIndex++;
411

    
412
          // media captions will be loaded via AHAH
413
          _add_js_ahah();
414
          $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
415
          //if $captionElements == null, set $captionPartHtml = '' otherwise the loading image is shown but nothing is loaded.
416
          if ($captionElements) {
417

    
418
              $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
419
              $ahah_media_caption = '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
420
                  . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
421

    
422
            // preparing the part link (= click on image itself) which can be handled in two ways
423
            //
424
            //  1. open image in lightbox, the captions in the lightbox will be loaded via AHAH
425
            //  2. open the media in a new window with target 'specimen'
426
            if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
427
              $mediaPartLinkAttributes['class'] = array('lightbox');
428
            } else {
429
              $mediaPartLinkAttributes['target'] = "specimen";
430
              $openMediaLinkAttributes['target'] = "specimen";
431
            }
432
            $mediaPartLinkAttributes['alt'] = htmlentities($ahah_media_caption);
433

    
434
            // --- preparing the media caption
435

    
436
            /* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
437
             *
438
             * a.kohlbecker 2013-03-14 :
439
             *   It is unclear why no caption elements should be shown, Was it a technical reason?
440
             *   see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
441
             *   If not problems arise with this remove it after some weeks
442
             */
443
            $captionPartHtml = $ahah_media_caption;
444
          }else{
445
              $captionPartHtml = '';
446
          }
447
          if ($caption_link_uri) {
448
              if ($contentTypeDirectory == 'image') {
449
                // it is an image, so open it in the media page
450

    
451
                $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
452
                    'attributes' => array(), 'html' => TRUE,
453
                        )) . '</div>';
454

    
455

    
456
              }
457
              else {
458
                // otherwise open it directly and let the the browser handle the media type
459
                $openMediaLinkAttributes['absolute'] = TRUE;
460
                $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
461
                    'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
462
                  )) . '</div>';
463
              }
464
          }
465

    
466
          $captionParts[] = $captionPartHtml;
467

    
468
            // --- Surround imagePart with link, this .
469
          if ($doLink) {
470
            $mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
471
                'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
472
            ));
473
          }
474
      }
475
      else {
476
        $mediaPartHtml = '';
477
        $captionParts[] = '';
478
      }
479
      $out .= '<td class="media">' . $mediaPartHtml . '</td>';
480
    }
481
    $out .= '</tr>'; // End of media parts.
482
    if ($showCaption) {
483
      if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
484
        $out .= '<tr class="caption-row">';
485
        // Add caption row.
486
        foreach ($captionParts as $captionPartHtml) {
487
          $out .= '<td class="caption">' . $captionPartHtml . '</td>';
488
        }
489
        $out .= '</tr>';
490
      }
491
    }
492
  }
493

    
494
  if ($galleryLinkUri) {
495
    if (count($mediaList) > 0) {
496
      $moreHtml = count($mediaList) . ' ' . t('more in gallery');
497
    }
498
    else {
499
      $moreHtml = t('open gallery');
500
    }
501
    $moreHtml = l($moreHtml, $galleryLinkUri);
502
    $out .= '<tr class="more-items-row"><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
503
  }
504
  $out .= '</table>';
505

    
506
  return $out;
507
}
508

    
509
/**
510
 * Creates markup for a CDM MediaRepresentation which is referencing an image.
511
 *
512
 * @param $mediaRepresentationPart
513
 * @param $maxExtend
514
 * @param $addPassePartout
515
 * @param $attributes
516
 *   An array of attributes for the img tag.
517
 * @return string
518
 *   The markup for the media representation
519
 */
520
function cdm_media_gallerie_image($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
521

    
522
  $out = '';
523

    
524
  // TODO merge with theme_cdm_media_mime_image?
525
  if (isset($mediaRepresentationPart)) {
526

    
527
    $h = @$mediaRepresentationPart->height;
528
    $w = @$mediaRepresentationPart->width;
529
    if (!($w && $h)) {
530
      // Take url and replace spaces.
531
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
532
      $imageDimensions = getimagesize_remote($image_uri);
533
      if (!$imageDimensions) {
534
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
535
      }
536
      $w = $imageDimensions[0];
537
      $h = $imageDimensions[1];
538
    }
539

    
540
    $ratio = $w / $h;
541
    if ($ratio > 1) {
542
      $displayHeight = round($maxExtend / $ratio);
543
      $displayWidth = $maxExtend;
544
      $m = round(($maxExtend - $displayHeight) / 2);
545
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
546
    }
547
    else {
548
      $displayHeight = $maxExtend;
549
      $displayWidth = round($maxExtend * $ratio);
550
      $m = round(($maxExtend - $displayWidth) / 2);
551
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
552
    }
553

    
554
    // Turn attributes array into string.
555
    if(!is_array($attributes)){
556
      $attributes = array();
557
    }
558
    if(!isset($attributes['alt'])){
559
      $attributes['alt'] = check_plain($mediaRepresentationPart->uri);
560
    }
561
    $attrStr = ' ';
562
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
563
    if (is_array($attributes)) {
564
      foreach ($attributes as $name => $value) {
565
        $attrStr .= $name . '="' . $value . '" ';
566
      }
567
    }
568

    
569
    if ($addPassePartout) {
570
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
571
    }
572
    else {
573
      // Do not add margins if no pass partout is shown.
574
      $margins = '';
575
    }
576
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
577

    
578
    if ($addPassePartout) {
579
      $out .= '</div>';
580
    }
581
  }
582

    
583
  return $out;
584
}
585

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

    
598
  $out = '';
599

    
600
  if (isset($mediaRepresentationPart)) {
601

    
602
    if ($addPassePartout) {
603
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
604
    }
605
    $out .= '<div class="application">Link to external media resource or web application</div>';
606

    
607
    if ($addPassePartout) {
608
      $out .= '</div>';
609
    }
610
  }
611

    
612
  return $out;
613
}
614

    
615
/**
616
 * Creates markup for a CDM MediaRepresentation which is referencing an web application.
617
 *
618
 * @param $mediaRepresentationPart
619
 * @param $maxExtend
620
 * @param $addPassePartout
621
 * @param $attributes
622
 * @return string
623
 *   The markup for the media representation
624
 */
625
function cdm_media_gallerie_text($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
626

    
627
  $out = '';
628

    
629
  if (isset($mediaRepresentationPart)) {
630
    if ($addPassePartout) {
631
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
632
    }
633

    
634
    $out .= '<div class="application">Web Application</div>';
635

    
636
    if ($addPassePartout) {
637
      $out .= '</div>';
638
    }
639
  }
640

    
641
  return $out;
642
}
643

    
644
/**
645
 * Adds the OpenLayers based image viewer to the page.
646
 *
647
 * The OpenLayers based image viewer allows to zoom and pan the displayed image.
648
 *
649
 * Documentation related to using Openlayers in order to view images is found here:
650
 *  - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
651
 *  - @see http://trac.openlayers.org/wiki/SettingZoomLevels
652
 *
653
 * @param array $variables
654
 *   An associative array of theme variables:
655
 *   - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
656
 *   - maxExtend: The maximum extend of the image viewer view port.
657
 */
658
function cdm_openlayers_image($mediaRepresentationPart, $maxExtend) {
659

    
660
  _add_js_openlayers();
661

    
662
  // TODO merge code below with code from theme_cdm_media_gallerie_image
663
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
664
  // TODO merge code below with code from theme_cdm_media_gallerie_image
665
  $w = @$mediaRepresentationPart->width;
666
  $h = @$mediaRepresentationPart->height;
667

    
668
  if (!($w && $h)) {
669
    // Take url and replace spaces.
670
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
671
    $imageDimensions = getimagesize_remote($image_uri);
672
    if (!$imageDimensions) {
673
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
674
    }
675
    $w = $imageDimensions[0];
676
    $h = $imageDimensions[1];
677
  }
678

    
679
  // Calculate maxResolution
680
  if ($w > $h) {
681
    $maxRes = $w / $maxExtend;
682
  }
683
  else {
684
    $maxRes = $h / $maxExtend;
685
  }
686

    
687
  $maxRes *= 1;
688

    
689
  drupal_add_js('
690
 var map;
691

    
692
 var imageLayerOptions={
693
     maxResolution: ' . $maxRes . ',
694
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
695
  };
696
  var mapOptions={
697
      controls:
698
       [
699
         new OpenLayers.Control.PanZoom(),
700
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
701
       ],
702
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
703
  };
704

    
705
 var graphic = new OpenLayers.Layer.Image(
706
          \'Image Title\',
707
          \'' . $mediaRepresentationPart->uri . '\',
708
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
709
          new OpenLayers.Size(' . $w . ', ' . $h . '),
710
          imageLayerOptions
711
          );
712

    
713
 function init() {
714
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
715
   map.addLayers([graphic]);
716
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
717
   map.zoomToMaxExtent();
718
 }
719

    
720
jQuery(document).ready(function(){
721
  init();
722
});', array('type' => 'inline'));
723
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
724
  return $out;
725
}
726

    
727

    
728
/**
729
 * @param $taxon
730
 * @param $gallery_viewer
731
 * @param $media
732
 *
733
 * @return string
734
 */
735
function render_taxon_media_gallery($taxon, $gallery_viewer, $media) {
736
  $media_gallery = '<div id="' . MEDIA_GALLERY_ID_PREFIX . $gallery_viewer . '">' .
737
    call_user_func_array('taxon_media_gallery_' . $gallery_viewer, [
738
      $taxon,
739
      $media,
740
    ])
741
    . '</div>';
742
  return $media_gallery;
743
}
744

    
745
/**
746
 * Implementation of Hook taxon_image_gallery() using the static image gallery
747
 * based on OpenLayers..
748
 *
749
 * @param object $taxon
750
 * @param object $media
751
 *
752
 * @return string
753
 *  Markup for the static viewer media gallery
754
 *
755
 * @throws Exception
756
 */
757
function taxon_media_gallery_default($taxon, $media) {
758
  $hasImages = isset($media[0]);
759

    
760
  if ($hasImages) {
761

    
762
    $maxExtend = 150;
763
    $cols = 3;
764
    $maxRows = FALSE;
765
    $alternativeMediaUri = NULL;
766
    /* Comment @WA: was in D5:
767
    $captionElements = array(
768
      'title',
769
      'rights',
770
      '#uri' => t('Open Image'),
771
    );
772
    */
773
    $captionElements = array(
774
      'title',
775
      'description',
776
      'artist',
777
      'location',
778
      'rights',
779
      '#uri' => t('Open image'),
780
    );
781
    $gallery_name = $taxon->uuid;
782
    $mediaLinkType = 'LIGHTBOX';
783

    
784
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
785

    
786
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
787

    
788
    $out = '<div class="image-gallerie">';
789
    $out .= compose_cdm_media_gallerie(array(
790
      'mediaList' => $media,
791
      'galleryName' => $gallery_name,
792
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
793
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
794
      'maxRows' => 0, // Ignore maxrows settings.
795
      'captionElements' => $captionElements,
796
      'mediaLinkType' => $mediaLinkType,
797
      'alternativeMediaUri' => NULL,
798
      'galleryLinkUri' => NULL,
799
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
800
    ));
801
    $out .= '</div>';
802
  }
803
  else {
804
    $out = 'No images available.';
805
  }
806
  return $out;
807
}
808

    
809
/**
810
 * Implementation of Hook taxon_image_gallery() which uses the proprietary FSI viewer.
811
 *
812
 * @param object $taxon
813
 * @param object $media
814
 *
815
 * @return string
816
 *  Markup for the FSI viewer media gallery
817
 *
818
 * @throws Exception
819
 */
820
function taxon_media_gallery_fsi($taxon, $media) {
821
  $flashLink = isset($media[0]);
822

    
823
  if ($flashLink) {
824

    
825
    if (module_exists("fsi_gallery")) {
826
      $out = render_fsi_gallery($taxon, $media);
827
    }
828
    else {
829
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
830
      drupal_set_message($message, "error");
831
      $out = '<h3>' . $message . '</h3>';
832
    }
833
  }
834
  else {
835
    $out = 'No images available.';
836
  }
837
  return $out;
838
}
839

    
840

    
841
/**
842
 * Implementation of Hook taxon_image_gallery() which uses the Universalviewer
843
 *
844
 * @param object $taxon
845
 * @param object $media
846
 *
847
 * @return string
848
 *  Markup for the Universalviewer media gallery
849
 *
850
 * @throws Exception
851
 */
852
function taxon_media_gallery_universalviewer($taxon, $media) {
853

    
854
  $media_query_parameters = taxon_media_query_parameters();
855
  $manifest_uri = cdm_compose_url(
856
    CDM_WS_IIIF_TAXON_MANIFEST,
857
    array($taxon->uuid),
858
    queryString($media_query_parameters)
859
    );
860
  _add_js_universalviewer('#uv', $manifest_uri);
861
  $out = '<div id="uv" class="uv" style="width: 680px; height: 680px;"></div>';
862

    
863
  if(variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL)){
864
    $out .= '<div class="additional_media_copyright">' . variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL) . '</div>';
865
  }
866
  return $out;
867
}
868

    
869
/**
870
 * Prepares from the settings an array of query parameters for the taxon media webservices:
871
 *
872
 * - CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA
873
 * - CDM_WS_PORTAL_TAXON_MEDIA
874
 * - CDM_WS_IIIF_TAXON_MANIFEST
875
 *
876
 * @return array
877
 */
878
function taxon_media_query_parameters() {
879
  $mediaQueryParameters = [
880
    "type" => "ImageFile",
881
  ];
882
  $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
883
  $mediaQueryParameters['relationships'] = implode(',', get_selection($relationship_choice['direct']));
884
  $mediaQueryParameters['relationshipsInvers'] = implode(',', get_selection($relationship_choice['invers']));
885

    
886
  $taxon_media_filter_choice = variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT));
887
  $mediaQueryParameters['includeTaxonDescriptions'] = (boolean) $taxon_media_filter_choice['includeTaxonDescriptions'] != 0;
888
  $mediaQueryParameters['includeOccurrences'] = (boolean) $taxon_media_filter_choice['includeOccurrences'] != 0;
889
  $mediaQueryParameters['includeTaxonNameDescriptions'] = (boolean) $taxon_media_filter_choice['includeTaxonNameDescriptions'] != 0;
890
  $mediaQueryParameters['includeTaxonomicChildren'] = variable_get('cdm_images_include_children', 0) != 0;
891
  return $mediaQueryParameters;
892
}
893

    
894

    
Add picture from clipboard (Maximum size: 40 MB)