Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / media.inc @ 6eaec849

History | View | Annotate | Download (23.7 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

    
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->titleCache;
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

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

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

    
147

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

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

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

    
174
  // Artist.
175
  if (!empty($media->artist->titleCache)) {
176
    $metadata['artist'] = $media->artist->titleCache;
177
  } else if (!empty($media_metadata->Artist)) {
178
    $metadata['artist'] = '' . $media_metadata->Artist;
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['mediacreated'] = $media_metadata["Modify Date"];
210
   else
211
   */
212
  if (!empty($media->mediaCreated)) {
213
    $metadata['mediacreated'] =  timePeriodToString($media->mediaCreated);
214
  }
215

    
216
  return $metadata;
217
}
218

    
219

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

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

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

    
265

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
433
            // --- preparing the media caption
434

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

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

    
454

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

    
465
          $captionParts[] = $captionPartHtml;
466

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

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

    
505
  return $out;
506
}
507

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

    
521
  $out = '';
522

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

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

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

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

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

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

    
582
  return $out;
583
}
584

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

    
597
  $out = '';
598

    
599
  if (isset($mediaRepresentationPart)) {
600

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

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

    
611
  return $out;
612
}
613

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

    
626
  $out = '';
627

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

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

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

    
640
  return $out;
641
}
642

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

    
659
  _add_js_openlayers();
660

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

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

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

    
686
  $maxRes *= 1;
687

    
688
  drupal_add_js('
689
 var map;
690

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

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

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

    
719
jQuery(document).ready(function(){
720
  init();
721
});', array('type' => 'inline'));
722
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
723
  return $out;
724
}
Add picture from clipboard (Maximum size: 40 MB)