Project

General

Profile

Download (25.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Media theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * @todo Please document this function.
18
 * @see http://drupal.org/node/1354
19
 */
20
function media_content_type_dir($media_representation, $default = FALSE) {
21
  if ($media_representation->mimeType) {
22
    return substr($media_representation->mimeType, 0, stripos($media_representation->mimeType, '/'));
23
  }
24
  else {
25
    return $default;
26
  }
27
}
28

    
29
/**
30
 * @todo Please document this function.
31
 * @see http://drupal.org/node/1354
32
 */
33
function getimagesize_remote($image_url) {
34
  $response = cdm_http_request($image_url);
35
  $contents = NULL;
36
  if (isset($response->data)) {
37
    $contents = $response->data;
38
  } else {
39
    return FALSE;
40
  }
41

    
42
  $im = @ImageCreateFromString($contents); // Using @ to avoid php warnings.
43
  if (!$im) {
44
    return FALSE;
45
  }
46
  $gis[0] = ImageSX($im);
47
  $gis[1] = ImageSY($im);
48
  // Array member 3 is used below to keep with current getimagesize standards.
49
  $gis[3] = "width={$gis[0]} height={$gis[1]}";
50
  ImageDestroy($im);
51
  return $gis;
52
}
53

    
54
/**
55
 * @todo Please document this function.
56
 * @see http://drupal.org/node/1354
57
 */
58
function theme_cdm_media($variables) {
59
  $descriptionElement = $variables['descriptionElement'];
60
  $mimeTypePreference = $variables['mimeTypePreference'];
61
  $out = '';
62

    
63
  _add_js_thickbox();
64

    
65
  $uuid = $descriptionElement->uuid;
66
  $feature = $descriptionElement->feature;
67
  $medias = $descriptionElement->media;
68

    
69
  foreach ($medias as $media) {
70
    $prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
71
    $mediaRepresentation = array_shift($prefRepresentations);
72
    if ($mediaRepresentation) {
73

    
74
      $contentTypeDirectory = media_content_type_dir($mediaRepresentation);
75

    
76
      $out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
77
      /*
78
      $attributes = array('class'=>'thickbox',
79
      'rel'=>'descriptionElement-'.$uuid, 'title'=>$feature->term);
80
      for($i = 0; $part = $mediaRepresentation->representationParts[$i];
81
      $i++){
82
      if($i == 0){
83
      $image_url = drupal_get_path('module',
84
      'cdm_dataportal').'/images/'.$feature->term.'-media.png';
85
      $media = '<img src="'.$image_url.'" height="14px"
86
      alt="'.$feature->term.'" />';
87
      $out .= l($media, $part->uri, array('attributes' => $attributes,
88
      'absolute' => TRUE, 'html' => TRUE));
89
      } else {
90
      $out .= l('', $part->uri, array('attributes' => $attributes, 'absolute'
91
      => TRUE));
92
      }
93
      }
94
      */
95
    }
96
    else {
97
      // No media available, so display just the type term.
98
      $out .= $feature->representation_L10n;
99
    }
100
  }
101
  return $out;
102
}
103

    
104
/**
105
 * @todo Please document this function.
106
 * @see http://drupal.org/node/1354
107
 */
108
function theme_cdm_mediaTypeTerm($variables) {
109
  $feature = $variables['feature'];
110
  $mediaUrl = $variables['mediaUrl'];
111

    
112
  $provider = '';
113
  // TODO directly use favicon from referred URI and overlay on $icon_image, but
114
  // for now we comment this out.
115
  /*
116
  if(strpos($mediaUrl, 'biodiversitylibrary.org') > 0){
117
    $provider = '-BHL';
118
  }
119
  */
120
  $icon_image = $feature->representation_L10n . '-media' . $provider . '.png';
121
  $icon_url = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/' . $icon_image;
122
  return '<img src="' . $icon_url . '" height="14px" alt="' . $feature->representation_L10n . '" />';
123
}
124

    
125
/**
126
 * @todo Please document this function.
127
 * @see http://drupal.org/node/1354
128
 */
129
function theme_cdm_media_mime_application($variables) {
130
  $mediaRepresentation = $variables['mediaRepresentation'];
131
  $feature = $variables['feature'];
132
  $out = '';
133
  foreach ($mediaRepresentation->parts as $part) {
134
    $attributes = array(
135
      'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
136
      'target' => '_blank',
137
    );
138
    /*
139
    $attributes = array('title'=>$feature->representation_L10n,'target'=>'_blank');
140
    $attributes = array('title'=>'original publication', 'target'=>'_blank');
141
    */
142
    $out .= l(theme('cdm_mediaTypeTerm', array('feature' => $feature, 'mediaUrl' => $part->uri)), $part->uri, array(
143
      'attributes' => $attributes,
144
      'absolute' => TRUE,
145
      'html' => TRUE,
146
    ));
147
  }
148
  return $out;
149
}
150

    
151
/**
152
 * @todo Please document this function.
153
 * @see http://drupal.org/node/1354
154
 */
155
function theme_cdm_media_mime_image($variables) {
156
  $mediaRepresentation = $variables['mediaRepresentation'];
157
  $feature = $variables['feature'];
158
  $out = '';
159
  // TODO thickbox is not used anymore -> delete?
160
  $attributes = array(
161
    'class' => 'thickbox',
162
    'rel' => 'representation-' . $representation->uuid,
163
    'title' => $feature->representation_L10n,
164
  );
165
  for ($i = 0; $part = $representation->representationParts[$i]; $i++) {
166
    if ($i == 0) {
167
      $out .= l(theme('cdm_mediaTypeTerm', array('feature' => $feature, 'mediaUrl' => $part->uri)), $part->uri, array(
168
        'attributes' => $attributes,
169
        'absolute' => TRUE,
170
        'html' => TRUE,
171
      ));
172
    }
173
    else {
174
      // Comment @WA: should this really be an empty link?
175
      $out .= l(t(''), $part->uri, array(
176
        'attributes' => $attributes,
177
        'absolute' => TRUE,
178
      ));
179
    }
180
  }
181
  return $out;
182
}
183

    
184
/**
185
 * @todo Please document this function.
186
 * @see http://drupal.org/node/1354
187
 */
188
function theme_cdm_media_mime_text($variables) {
189
  $representation = $variables['representation'];
190
  $feature = $variables['feature'];
191
  $out = '';
192
  if (!empty($representation->parts)) {
193
    foreach ($representation->parts as $part) {
194
      $attributes = array(
195
        'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
196
        'target' => '_blank',
197
      );
198
      // $attributes = array('title'=>t('original publication'),
199
      // 'target'=>'_blank');
200
      $out .= l(theme('cdm_mediaTypeTerm', array('feature' => $feature, 'mediaUrl' => $part->uri)), $part->uri, array(
201
        'attributes' => $attributes,
202
        'absolute' => TRUE,
203
        'html' => TRUE,
204
      ));
205
    }
206
  }
207
  return $out;
208
}
209

    
210

    
211
/**
212
 * Theme function for captions of media elements. This method is usually called from
213
 * within the theme_cdm_media_gallerie() function or indirectly via AHAH.
214
 *
215
 * @param array $variables
216
 *   an associative array with the following elements:
217
 *   - 'media': the cdm media object to show the captions for
218
 *   - 'elements':
219
 *         an array which defining the caption elements to show up
220
 *         example:
221
 *          Show 'title', 'description', 'file', 'filename' in the caption:
222
 *          array('title', 'description', 'file', 'filename')
223
 *
224
 * @return string
225
 *   the themed html output
226
 */
227
function theme_cdm_media_caption($variables) {
228
  $media = $variables['media'];
229
  $elements = $variables['elements'];
230
  $media_metadata = cdm_read_media_metadata($media);
231

    
232
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
233
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
234
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
235
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
236
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
237

    
238
  $descriptionPrefix = "";
239

    
240
  $out = '<dl class="media-caption">';
241
  // Title.
242
  if ($doTitle) {
243
    if ($media_metadata['title']) {
244
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
245
      $descriptionPrefix = "- ";
246
    }
247
    elseif (!($doDescription && $media_metadata['description'])) {
248
      // Use filename as fallbackoption if no description will be shown.
249
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
250
      $descriptionPrefix = "- ";
251
    }
252
  }
253
  // Description.
254
  if ($media_metadata['description'] && $doDescription) {
255
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
256
  }
257
  // Artist.
258
  if ($media_metadata['artist'] && $doArtist) {
259
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
260
  }
261
  // Location.
262
  if ($doLocation) {
263
    $location = '';
264
    $location .= $media_metadata['location']['sublocation'];
265
    if ($location && $media_metadata['location']['city']) {
266
      $location .= ', ';
267
    }
268
    $location .= $media_metadata['location']['city'];
269
    if ($location && $media_metadata['location']['province']) {
270
      $location .= ', ';
271
    }
272
    $location .= $media_metadata['location']['province'];
273
    if ($location && $media_metadata['location']['country']) {
274
      $location .= ' (' . $media_metadata['location']['country'] . ')';
275
    }
276
    else {
277
      $location .= $media_metadata['location']['country'];
278
    }
279
    if ($location) {
280
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
281
    }
282
  }
283
  // Rights.
284
  if ($doRights) {
285
    $rights = '';
286
    // TODO use cdm_rights_as_dl_groups() to create dl entries
287

    
288
    // Copyrights.
289
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
290
    if ($cnt > 0) {
291
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
292
      for ($i = 0; $i < $cnt; $i++) {
293
        $rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
294
        if ($i + 1 < $cnt) {
295
          $rights .= ' / ';
296
        }
297
      }
298
      $rights .= '</dd>';
299
    }
300
    // License.
301
    $cnt = count($media_metadata['rights']['license']['agentNames']);
302
    if ($cnt > 0) {
303
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
304
      for ($i = 0; $i < $cnt; $i++) {
305
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
306
        if ($i + 1 < $cnt) {
307
          $rights .= ' / ';
308
        }
309
      }
310
      $rights .= '</dd>';
311
    }
312
    if ($rights) {
313
      $out .= $rights . '</dt>';
314
    }
315
  }
316
  // TODO add all other metadata elemenst generically.
317
  $out .= '</dl>';
318
  // Return value,
319
  return $out;
320
}
321

    
322
/**
323
 * Return HTML for a media gallery
324
 *
325
 * @param array $variables
326
 *   An associative array containing:
327
 *   - mediaList: An array of Media entities.
328
 *   - maxExtend
329
 *   - cols
330
 *   - maxRows
331
 *   - showCaption:  boolean value, whether to show captions or not.
332
 *   - captionElements: An array of caption elements to be shown. In case the array
333
 *        is empty of NULL  all available caption elements will be show. In order to
334
 *        supress all captions  set 'showCaption' to FALSE
335
 *        example:
336
 *          1) Show 'title', 'description', 'file', 'filename' in the caption:
337
 *            array('title', 'description', 'file', 'filename'),
338
 *          2) To add an addtional link at the bottom of  the caption:
339
 *            array('titlecache', '#uri'=>t('open Image')) this will cause a link
340
 *            to be rendered with label 'open Image' which will open the accoring
341
 *            media object.
342
 *   - mediaLinkType: Valid values:
343
 *      - "NONE": do not link the images,
344
 *      - "LIGHTBOX": open the link in a light box,
345
 *      - "NORMAL": link to the image page or to the $alternativeMediaUri if
346
 *        it is defined.
347
 *   - alternativeMediaUri: An array of alternative URIs to link the images
348
 *     which will overwrite the URIs of the media parts.
349
 *     The order of URI in this array must correspond with the order of
350
 *     images in $mediaList.
351
 *   - galleryLinkUri: An URI to link the the hint on more images to;
352
 *     if NULL no link is created.
353
 *
354
 * @ingroup: themeable
355
 */
356
function theme_cdm_media_gallerie($variables) {
357

    
358
  $mediaList = $variables['mediaList'];
359

    
360
  // Do not show an empty gallery.
361
  if (count($mediaList) == 0) {
362
    return;
363
  }
364

    
365
  $galleryName = $variables['galleryName'];
366
  $maxExtend = $variables['maxExtend'];
367
  $cols = $variables['cols'];
368
  $maxRows = $variables['maxRows'];
369
  $captionElements = $variables['captionElements'];
370
  $mediaLinkType = $variables['mediaLinkType'];
371
  $alternativeMediaUri = $variables['alternativeMediaUri'];
372
  $galleryLinkUri = $variables['galleryLinkUri'];
373
  $showCaption = $variables['showCaption'];
374

    
375
  $caption_link_uri = '';
376
  if(isset($captionElements['#uri'])){
377
    $caption_link_uri = $captionElements['#uri'];
378
    unset($captionElements['#uri']);
379
  }
380
  if (!is_array($captionElements) || count($captionElements) == 0) {
381
    $captionElements = NULL;
382
  }
383

    
384
  // TODO correctly handle multiple media representation parts
385
  $_SESSION['cdm']['last_gallery'] = current_path();
386
  // Prevent from errors.
387
  if (!isset($mediaList[0])) {
388
   // return;
389
  }
390

    
391
  // --- Duplicate supression: media can be reused but should only be shown
392
  // once.
393
  $tempMediaList = array();
394
  $tempMediaUuids = array();
395
  foreach ($mediaList as $media) {
396
    if (!in_array($media->uuid, $tempMediaUuids)) {
397
      $tempMediaList[] = $media;
398
      $tempMediaUuids[] = $media->uuid;
399
    }
400
  }
401
  $mediaList = $tempMediaList;
402

    
403
  // ---
404
  $galleryID = "media_gallery_" . $galleryName;
405

    
406
  $mediaPartLinkAttributes = array();
407
  $openMediaLinkAttributes = array();
408

    
409
  // Prepare media links.
410
  $doLink = FALSE;
411
  if ($mediaLinkType != 'NONE') {
412
    $doLink = TRUE;
413
  }
414
  if ($mediaLinkType == 'LIGHTBOX') {
415
    $doLink = TRUE;
416
    _add_js_lightbox($galleryID);
417
  }
418

    
419
  // Render the media gallery grid.
420
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
421
  $out .= '<colgroup>';
422
  for ($c = 0; $c < $cols; $c++) {
423
    $out .= '<col width="' . (100 / $cols) . '%">';
424
  }
425
  $out .= '</colgroup>';
426

    
427
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
428
    $captionParts = array();
429
    $mediaIndex = 0;
430
    $out .= '<tr>';
431
    for ($c = 0; $c < $cols; $c++) {
432
      $media = array_shift($mediaList);
433

    
434
      if (isset($media->representations[0]->parts[0])) {
435

    
436
        //
437
        // Find preferred representation.
438
        //
439
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
440
          'image/jpg',
441
          'image/jpeg',
442
          'image/png',
443
          'image/gif',
444
        ), $maxExtend, $maxExtend);
445
        if (count($preferred_media_representations_list) == 0) {
446
          // Fallback to using the first one in the list.
447
          $preferred_media_representations_list = $media->representations;
448
        }
449
        $preferred_media_representation = array_shift($preferred_media_representations_list);
450

    
451
        // $preferred_media_representation->parts[0]->uri =
452
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
453
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
454
        $mediaIndex++;
455

    
456
         $mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
457
            'mediaRepresentationPart' => $preferred_media_representation->parts[0],
458
            'maxExtend' => $maxExtend,
459
            'addPassePartout' => TRUE,
460
         ));
461
        // --- Compose Media Link.
462
        $mediaLinkUri = FALSE;
463
        if ($alternativeMediaUri) {
464
          if (isset($alternativeMediaUri[$mediaIndex])) {
465
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
466
          }
467
          if (is_string($alternativeMediaUri)) {
468
            $mediaLinkUri = $alternativeMediaUri;
469
          }
470
        }
471
        else {
472
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
473
        }
474

    
475
        // media captions will be loaded via AHAH
476
        _add_js_ahah();
477
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
478
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
479
        $ahah_media_caption =  '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
480
          . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
481

    
482
        // preparing the part link (= click on image iteself) which can be handled in two ways
483
        //
484
        //  1. open image in lightbox, the captions in the lighhtbox will be loaded via AHAH
485
        //  2. open the media in a new window with target 'specimen'
486
        if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
487
          $mediaPartLinkAttributes['class'] = array('lightbox');
488
        }
489
        else {
490
          $mediaPartLinkAttributes['target'] = "specimen";
491
          $openMediaLinkAttributes['target'] = "specimen";
492
        }
493
        $mediaPartLinkAttributes['alt'] = $ahah_media_caption;
494

    
495
        // --- preparing the media caption
496

    
497
        /* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
498
         *
499
         * a.kohlbecker 2013-03-14 :
500
         *   It is unclear why no caption elements should be shown, Was it a technical reason?
501
         *   see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
502
         *   If not problems arise with this remove it after some weeks
503
         */
504
        $captionPartHtml = $ahah_media_caption;
505

    
506
        if ($caption_link_uri) {
507
          if ($contentTypeDirectory == 'image') {
508
          // it is an image, so open it in the media page
509
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
510
              'attributes' => array(), 'html' => TRUE,
511
            )) . '</div>';
512
          }
513
          else {
514
            // otherwise open it directly and let the the browser handle the media type
515
            $openMediaLinkAttributes['absolute'] = TRUE;
516
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
517
              'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
518
            )) . '</div>';
519
          }
520
        }
521

    
522
        $captionParts[] = $captionPartHtml;
523

    
524
        // --- Surround imagePart with link, this .
525
        if ($doLink) {
526
          $mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
527
            'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
528
          ));
529
        }
530
      }
531
      else {
532
        $mediaPartHtml = '';
533
        $captionParts[] = '';
534
      }
535
      $out .= '<td class="media">' . $mediaPartHtml . '</td>';
536
    }
537
    $out .= '</tr>'; // End of media parts.
538
    if ($showCaption) {
539
      if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
540
        $out .= '<tr>';
541
        // Add caption row.
542
        foreach ($captionParts as $captionPartHtml) {
543
          $out .= '<td class="caption">' . $captionPartHtml . '</td>';
544
        }
545
        $out .= '</tr>';
546
      }
547
    }
548
  }
549

    
550
  if ($galleryLinkUri) {
551
    if (count($mediaList) > 0) {
552
      $moreHtml = count($mediaList) . ' ' . t('more in gallery');
553
    }
554
    else {
555
      $moreHtml = t('open gallery');
556
    }
557
    $moreHtml = l($moreHtml, $galleryLinkUri);
558
    $out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
559
  }
560
  $out .= '</table>';
561
  return $out;
562
}
563
/**
564
 * @todo Please document this function.
565
 * @see http://drupal.org/node/1354
566
 */
567
function theme_cdm_media_gallerie_image($variables) {
568

    
569
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
570
  $maxExtend = $variables['maxExtend'];
571
  $addPassePartout = $variables['addPassePartout'];
572
  $attributes = $variables['attributes'];
573

    
574
  $out = '';
575

    
576
  // TODO merge with theme_cdm_media_mime_image?
577
  if (isset($mediaRepresentationPart)) {
578

    
579
    $h = $mediaRepresentationPart->height;
580
    $w = $mediaRepresentationPart->width;
581
    if ($w == 0 || $h == 0) {
582
      // Take url and replace spaces.
583
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
584
      $imageDimensions = getimagesize_remote($image_uri);
585
      if (!$imageDimensions) {
586
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
587
      }
588
      $w = $imageDimensions[0];
589
      $h = $imageDimensions[1];
590
    }
591
    $margins = '0 0 0 0';
592
    $ratio = $w / $h;
593
    if ($ratio > 1) {
594
      $displayHeight = round($maxExtend / $ratio);
595
      $displayWidth = $maxExtend;
596
      $m = round(($maxExtend - $displayHeight) / 2);
597
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
598
    }
599
    else {
600
      $displayHeight = $maxExtend;
601
      $displayWidth = round($maxExtend * $ratio);
602
      $m = round(($maxExtend - $displayWidth) / 2);
603
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
604
    }
605

    
606
    // Turn attributes array into string.
607
    $attrStr = ' ';
608
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
609
    if (is_array($attributes)) {
610
      foreach ($attributes as $name => $value) {
611
        $attrStr .= $name . '="' . $value . '" ';
612
      }
613
    }
614

    
615
    if ($addPassePartout) {
616
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
617
    }
618
    else {
619
      // Do not add margins if no pass partout is shown.
620
      $margins = '';
621
    }
622
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
623

    
624
    if ($addPassePartout) {
625
      $out .= '</div>';
626
    }
627
    return $out;
628
  }
629
}
630

    
631
/**
632
 * @todo Please document this function.
633
 * @see http://drupal.org/node/1354
634
 */
635
function theme_cdm_media_gallerie_application($variables) {
636
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
637
  $maxExtend = $variables['maxExtend'];
638
  $addPassePartout = $variables['addPassePartout'];
639
  $attributes = $variables['attributes'];
640
  $out = '';
641
  if (isset($mediaRepresentationPart)) {
642

    
643
    if ($addPassePartout) {
644
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
645
    }
646
    else {
647
      // Do not add margins if no pass partout is shown.
648
      $margins = '';
649
    }
650
    $out .= '<div class="appication">Web Application</div>';
651

    
652
    if ($addPassePartout) {
653
      $out .= '</div>';
654
    }
655
    return $out;
656
  }
657
}
658

    
659
/**
660
 * @todo Please document this function.
661
 * @see http://drupal.org/node/1354
662
 */
663
function theme_cdm_media_gallerie_text($variables) {
664
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
665
  $maxExtend = $variables['maxExtend'];
666
  $addPassePartout = $variables['addPassePartout'];
667
  $attributes = $variables['attributes'];
668
  if (isset($mediaRepresentationPart)) {
669

    
670
    if ($addPassePartout) {
671
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
672
    }
673
    else {
674
      // Do not add margins if no pass partout is shown.
675
      $margins = '';
676
    }
677
    $out .= '<div class="appication">Web Application</div>';
678

    
679
    if ($addPassePartout) {
680
      $out .= '</div>';
681
    }
682
    return $out;
683
  }
684
}
685

    
686
/**
687
 * Adds the OpenLayers based image viewer to the page.
688
 *
689
 * The OpenLayers based image viewer allows to zoom and pan the displayed image.
690
 *
691
 * Documentation related to using Openlayers in order to view images is found here:
692
 *  - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
693
 *  - @see http://trac.openlayers.org/wiki/SettingZoomLevels
694
 *
695
 * @param array $variables
696
 *   An associative array of theme variables:
697
 *   - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
698
 *   - maxExtend: The maximum extend of the image viewer view port.
699
 */
700
function theme_cdm_openlayers_image($variables) {
701
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
702
  $maxExtend = $variables['maxExtend'];
703

    
704
  _add_js_openlayers();
705

    
706
  // TODO merge code below with code from theme_cdm_media_gallerie_image
707
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
708
  // TODO merge code below with code from theme_cdm_media_gallerie_image
709
  $w = $mediaRepresentationPart->width;
710
  $h = $mediaRepresentationPart->height;
711

    
712
  if ($w == 0 || $h == 0) {
713
    // Take url and replace spaces.
714
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
715
    $imageDimensions = getimagesize_remote($image_uri);
716
    if (!$imageDimensions) {
717
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
718
    }
719
    $w = $imageDimensions[0];
720
    $h = $imageDimensions[1];
721
  }
722

    
723
  // Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
724
  if ($w > $h) {
725
    $lat = 90;
726
    $lon = 90 * ($h / $w);
727
    $maxRes = $w / $maxExtend;
728
  }
729
  else {
730
    $lat = 90 * ($w / $h);
731
    $lon = 90;
732
    $maxRes = $h / $maxExtend;
733
  }
734

    
735
  $maxRes *= 1;
736
  drupal_add_js('
737
 var map;
738

    
739
 var imageLayerOptions={
740
     maxResolution: ' . $maxRes . ',
741
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
742
  };
743
  var mapOptions={
744
      controls:
745
       [
746
         new OpenLayers.Control.PanZoom(),
747
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
748
       ],
749
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
750
  };
751

    
752
 var graphic = new OpenLayers.Layer.Image(
753
          \'Image Title\',
754
          \'' . $mediaRepresentationPart->uri . '\',
755
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
756
          new OpenLayers.Size(' . $w . ', ' . $h . '),
757
          imageLayerOptions
758
          );
759

    
760
 function init() {
761
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
762
   map.addLayers([graphic]);
763
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
764
   map.zoomToMaxExtent();
765
 }
766

    
767
jQuery(document).ready(function(){
768
  init();
769
});', array('type' => 'inline'));
770
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
771
  return $out;
772
}
773

    
(4-4/10)