Project

General

Profile

Download (25.6 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
  $contents = cdm_http_request($image_url);
35
  if (!$contents) {
36
    return FALSE;
37
  }
38

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

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

    
60
  _add_js_thickbox();
61

    
62
  $uuid = $descriptionElement->uuid;
63
  $feature = $descriptionElement->feature;
64
  $medias = $descriptionElement->media;
65

    
66
  foreach ($medias as $media) {
67
    $prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
68
    $mediaRepresentation = array_shift($prefRepresentations);
69
    if ($mediaRepresentation) {
70

    
71
      $contentTypeDirectory = media_content_type_dir($mediaRepresentation);
72

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

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

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

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

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

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

    
208

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

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

    
236
  $descriptionPrefix = "";
237

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

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

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

    
355
  $mediaList = $variables['mediaList'];
356

    
357
  // Do not show an empty gallery.
358
  if (count($mediaList) == 0) {
359
    return;
360
  }
361

    
362
  $galleryName = $variables['galleryName'];
363
  $maxExtend = $variables['maxExtend'];
364
  $cols = $variables['cols'];
365
  $maxRows = $variables['maxRows'];
366
  $captionElements = $variables['captionElements'];
367
  $mediaLinkType = $variables['mediaLinkType'];
368
  $alternativeMediaUri = $variables['alternativeMediaUri'];
369
  $galleryLinkUri = $variables['galleryLinkUri'];
370
  $showCaption = $variables['showCaption'];
371

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

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

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

    
400
  // ---
401
  $galleryID = "media_gallery_" . $galleryName;
402

    
403
  $mediaPartLinkAttributes = array();
404
  $openMediaLinkAttributes = array();
405

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

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

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

    
431
      if (isset($media->representations[0]->parts[0])) {
432

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

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

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

    
472
        // media captions will be loaded via AHAH
473
        _add_js_ahah();
474
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
475
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
476

    
477

    
478
        // preparing the part link (= click on image iteself) which can be handled in two ways
479
        //
480
        //  1. open image in lightbox, the captions in the lighhtbox will be loaded via AHAH
481
        //  2. open the media in a new window with target 'specimen'
482
        if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
483
          $mediaPartLinkAttributes['class'] = array('lightbox');
484
        }
485
        else {
486
          $mediaPartLinkAttributes['target'] = "specimen";
487
          $openMediaLinkAttributes['target'] = "specimen";
488
        }
489
        $mediaPartLinkAttributes['alt'] = '<div class="ahah-content" rel="' . $cdm_proxy_url_caption . '">'
490
          . '<span class="loading" style="display: none;">Loading ....</span></div>';
491

    
492

    
493
        // preparing the media caption - no caption elements to show up here except the $caption_link_uri, if at all
494
        //
495
        $captionPartHtml = '';
496
        if ($caption_link_uri) {
497
          if ($contentTypeDirectory == 'image') {
498
          // it is an image, so open it in the media page
499
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
500
              'attributes' => array(), 'html' => TRUE,
501
            )) . '</div>';
502
          }
503
          else {
504
            // otherwise open it directly and let the the browser handle the media type
505
            $openMediaLinkAttributes['absolute'] = TRUE;
506
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
507
              'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
508
            )) . '</div>';
509
          }
510
        }
511

    
512
        $captionParts[] = $captionPartHtml;
513

    
514
        // --- Surround imagePart with link, this .
515
        if ($doLink) {
516
          $mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
517
            'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
518
          ));
519
        }
520
      }
521
      else {
522
        $mediaPartHtml = '';
523
        $captionParts[] = '';
524
      }
525
      $out .= '<td class="media">' . $mediaPartHtml . '</td>';
526
    }
527
    $out .= '</tr>'; // End of media parts.
528
    if ($showCaption) {
529
      if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
530
        $out .= '<tr>';
531
        // Add caption row.
532
        foreach ($captionParts as $captionPartHtml) {
533
          $out .= '<td class="caption">' . $captionPartHtml . '</td>';
534
        }
535
        $out .= '</tr>';
536
      }
537
    }
538
  }
539

    
540
  if ($galleryLinkUri) {
541
    if (count($mediaList) > 0) {
542
      $moreHtml = count($mediaList) . ' ' . t('more in gallery');
543
    }
544
    else {
545
      $moreHtml = t('open gallery');
546
    }
547
    $moreHtml = l($moreHtml, $galleryLinkUri);
548
    $out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
549
  }
550
  $out .= '</table>';
551
  return $out;
552
}
553
/**
554
 * @todo Please document this function.
555
 * @see http://drupal.org/node/1354
556
 */
557
function theme_cdm_media_gallerie_image($variables) {
558

    
559
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
560
  $maxExtend = $variables['maxExtend'];
561
  $addPassePartout = $variables['addPassePartout'];
562
  $attributes = $variables['attributes'];
563

    
564
  $out = '';
565

    
566
  // TODO merge with theme_cdm_media_mime_image?
567
  if (isset($mediaRepresentationPart)) {
568

    
569
    $h = $mediaRepresentationPart->height;
570
    $w = $mediaRepresentationPart->width;
571
    if ($w == 0 || $h == 0) {
572
      // Take url and replace spaces.
573
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
574
      $imageDimensions = getimagesize_remote($image_uri);
575
      if (!$imageDimensions) {
576
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
577
      }
578
      $w = $imageDimensions[0];
579
      $h = $imageDimensions[1];
580
    }
581
    $margins = '0 0 0 0';
582
    $ratio = $w / $h;
583
    if ($ratio > 1) {
584
      $displayHeight = round($maxExtend / $ratio);
585
      $displayWidth = $maxExtend;
586
      $m = round(($maxExtend - $displayHeight) / 2);
587
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
588
    }
589
    else {
590
      $displayHeight = $maxExtend;
591
      $displayWidth = round($maxExtend * $ratio);
592
      $m = round(($maxExtend - $displayWidth) / 2);
593
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
594
    }
595

    
596
    // Turn attributes array into string.
597
    $attrStr = ' ';
598
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
599
    if (is_array($attributes)) {
600
      foreach ($attributes as $name => $value) {
601
        $attrStr .= $name . '="' . $value . '" ';
602
      }
603
    }
604

    
605
    if ($addPassePartout) {
606
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
607
    }
608
    else {
609
      // Do not add margins if no pass partout is shown.
610
      $margins = '';
611
    }
612
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
613

    
614
    if ($addPassePartout) {
615
      $out .= '</div>';
616
    }
617
    return $out;
618
  }
619
}
620

    
621
/**
622
 * @todo Please document this function.
623
 * @see http://drupal.org/node/1354
624
 */
625
function theme_cdm_media_gallerie_application($variables) {
626
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
627
  $maxExtend = $variables['maxExtend'];
628
  $addPassePartout = $variables['addPassePartout'];
629
  $attributes = $variables['attributes'];
630
  if (isset($mediaRepresentationPart)) {
631

    
632
    if ($addPassePartout) {
633
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
634
    }
635
    else {
636
      // Do not add margins if no pass partout is shown.
637
      $margins = '';
638
    }
639
    $out .= '<div class="appication">Web Application</div>';
640

    
641
    if ($addPassePartout) {
642
      $out .= '</div>';
643
    }
644
    return $out;
645
  }
646
}
647

    
648
/**
649
 * @todo Please document this function.
650
 * @see http://drupal.org/node/1354
651
 */
652
function theme_cdm_media_gallerie_text($variables) {
653
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
654
  $maxExtend = $variables['maxExtend'];
655
  $addPassePartout = $variables['addPassePartout'];
656
  $attributes = $variables['attributes'];
657
  if (isset($mediaRepresentationPart)) {
658

    
659
    if ($addPassePartout) {
660
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
661
    }
662
    else {
663
      // Do not add margins if no pass partout is shown.
664
      $margins = '';
665
    }
666
    $out .= '<div class="appication">Web Application</div>';
667

    
668
    if ($addPassePartout) {
669
      $out .= '</div>';
670
    }
671
    return $out;
672
  }
673
}
674

    
675
/**
676
 * @todo Please document this function.
677
 * @see http://drupal.org/node/1354
678
 */
679
function theme_cdm_openlayers_image($variables) {
680
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
681
  $maxExtend = $variables['maxExtend'];
682

    
683
  // @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
684
  // and
685
  // @see http://trac.openlayers.org/wiki/SettingZoomLevels
686
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/OpenLayers/OpenLayers.js', array('type' => 'file', 'weight' => JS_LIBRARY));
687

    
688
  // TODO merge code below with code from theme_cdm_media_gallerie_image
689
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
690
  // TODO merge code below with code from theme_cdm_media_gallerie_image
691
  $w = $mediaRepresentationPart->width;
692
  $h = $mediaRepresentationPart->height;
693

    
694
  if ($w == 0 || $h == 0) {
695
    // Take url and replace spaces.
696
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
697
    $imageDimensions = getimagesize_remote($image_uri);
698
    if (!$imageDimensions) {
699
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
700
    }
701
    $w = $imageDimensions[0];
702
    $h = $imageDimensions[1];
703
  }
704

    
705
  // Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
706
  if ($w > $h) {
707
    $lat = 90;
708
    $lon = 90 * ($h / $w);
709
    $maxRes = $w / $maxExtend;
710
  }
711
  else {
712
    $lat = 90 * ($w / $h);
713
    $lon = 90;
714
    $maxRes = $h / $maxExtend;
715
  }
716

    
717
  $maxRes *= 1;
718
  drupal_add_js('
719
 var map;
720

    
721
 var imageLayerOptions={
722
     maxResolution: ' . $maxRes . ',
723
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
724
  };
725
  var mapOptions={
726
      controls:
727
       [
728
         new OpenLayers.Control.PanZoom(),
729
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
730
       ],
731
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
732
  };
733

    
734
 var graphic = new OpenLayers.Layer.Image(
735
          \'Image Title\',
736
          \'' . $mediaRepresentationPart->uri . '\',
737
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
738
          new OpenLayers.Size(' . $w . ', ' . $h . '),
739
          imageLayerOptions
740
          );
741

    
742
 function init() {
743
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
744
   map.addLayers([graphic]);
745
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
746
   map.zoomToMaxExtent();
747
 }
748

    
749
jQuery(document).ready(function(){
750
  init();
751
});', array('type' => 'inline'));
752
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
753
  return $out;
754
}
755

    
756
/**
757
 * @todo Please document this function.
758
 * @see http://drupal.org/node/1354
759
 */
760
function theme_cdm_preferredImage($variables) {
761

    
762
  $media = $variables['media'];
763
  $defaultRepresentationPart = $variables['defaultRepresentationPart'];
764
  $imageMaxExtend = $variables['imageMaxExtend'];
765
  $parameters = $variables['parameters'];
766

    
767
  $out = '';
768

    
769
  if (isset($media[0])) {
770
    $representationPart = $media[0]->representations[0]->parts[0];
771
    if ($parameters) {
772
      $representationPart->uri . $parameters;
773
    }
774
  }
775
  else {
776
    $representationPart = $defaultRepresentationPart;
777
  }
778

    
779
  $attributes = array(
780
    'alt' => (isset($media->representations[0]->parts[0]->uri) ? $media->representations[0]->parts[0]->uri : "no image available"),
781
  );
782
  $out .= theme('cdm_media_gallerie_image', array(
783
    'mediaRepresentationPart' => $representationPart,
784
    'maxExtend' => $imageMaxExtend,
785
    'addPassePartout' => FALSE,
786
    'attributes' => $attributes,
787
  ));
788

    
789
  return $out;
790
}
(4-4/9)