Project

General

Profile

Download (24.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
  $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
 * @todo Please document this function.
210
 * @see http://drupal.org/node/1354
211
 */
212
function theme_cdm_media_caption($variables) {
213
  $media = $variables['media'];
214
  $elements = $variables['elements'];
215
  $fileUri = $variables['fileUri'];
216
  $media_metadata = cdm_read_media_metadata($media);
217

    
218
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
219
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
220
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
221
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
222
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
223

    
224
  $descriptionPrefix = "";
225

    
226
  $out = '<dl class="media-caption">';
227
  // Title.
228
  if ($doTitle) {
229
    if ($media_metadata['title']) {
230
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
231
      $descriptionPrefix = "- ";
232
    }
233
    elseif (!($doDescription && $media_metadata['description'])) {
234
      // Use filename as fallbackoption if no description will be shown.
235
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
236
      $descriptionPrefix = "- ";
237
    }
238
  }
239
  // Description.
240
  if ($media_metadata['description'] && $doDescription) {
241
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
242
  }
243
  // Artist.
244
  if ($media_metadata['artist'] && $doArtist) {
245
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
246
  }
247
  // Location.
248
  if ($doLocation) {
249
    $location = '';
250
    $location .= $media_metadata['location']['sublocation'];
251
    if ($location && $media_metadata['location']['city']) {
252
      $location .= ', ';
253
    }
254
    $location .= $media_metadata['location']['city'];
255
    if ($location && $media_metadata['location']['province']) {
256
      $location .= ', ';
257
    }
258
    $location .= $media_metadata['location']['province'];
259
    if ($location && $media_metadata['location']['country']) {
260
      $location .= ' (' . $media_metadata['location']['country'] . ')';
261
    }
262
    else {
263
      $location .= $media_metadata['location']['country'];
264
    }
265
    if ($location) {
266
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
267
    }
268
  }
269
  // Rights.
270
  if ($doRights) {
271
    $rights = '';
272

    
273
    // Copyrights.
274
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
275
    if ($cnt > 0) {
276
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
277
      for ($i = 0; $i < $cnt; $i++) {
278
        $rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
279
        if ($i + 1 < $cnt) {
280
          $rights .= ' / ';
281
        }
282
      }
283
      $rights .= '</dd>';
284
    }
285
    // License.
286
    $cnt = count($media_metadata['rights']['license']['agentNames']);
287
    if ($cnt > 0) {
288
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
289
      for ($i = 0; $i < $cnt; $i++) {
290
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
291
        if ($i + 1 < $cnt) {
292
          $rights .= ' / ';
293
        }
294
      }
295
      $rights .= '</dd>';
296
    }
297
    if ($rights) {
298
      $out .= $rights . '</dt>';
299
    }
300
  }
301
  // TODO add all other metadata elemenst generically.
302
  $out .= '</dl>';
303
  // Return value,
304
  return $out;
305
}
306

    
307
/**
308
 * Return HTML for a media gallery
309
 *
310
 * @param array $variables
311
 *   An associative array containing:
312
 *   - mediaList: An array of Media entities.
313
 *   - maxExtend
314
 *   - cols
315
 *   - maxRows
316
 *   - captionElements: An array, possible values are like in the following
317
 *     example:
318
 *       array('title', 'description', 'file', 'filename'),
319
 *       //to add a link to the caption:
320
 *       array('titlecache', '#uri'=>t('open Image'));
321
 *   - mediaLinkType: Valid values:
322
 *      - "NONE": do not link the images,
323
 *      - "LIGHTBOX": open the link in a light box,
324
 *      - "NORMAL": link to the image page or to the $alternativeMediaUri if
325
 *        it is defined.
326
 *   - alternativeMediaUri: An array of alternative URIs to link the images
327
 *     which will overwrite the URIs of the media parts.
328
 *     The order of URI in this array must correspond with the order of
329
 *     images in $mediaList.
330
 *   - galleryLinkUri: An URI to link the the hint on more images to;
331
 *     if NULL no link is created.
332
 *
333
 * @ingroup: themeable
334
 */
335
function theme_cdm_media_gallerie($variables) {
336

    
337
  $mediaList = $variables['mediaList'];
338

    
339
  // Do not show an empty gallery.
340
  if (count($mediaList) == 0) {
341
    return;
342
  }
343

    
344
  $galleryName = $variables['galleryName'];
345
  $maxExtend = $variables['maxExtend'];
346
  $cols = $variables['cols'];
347
  $maxRows = $variables['maxRows'];
348
  $captionElements = $variables['captionElements'];
349
  $mediaLinkType = $variables['mediaLinkType'];
350
  $alternativeMediaUri = $variables['alternativeMediaUri'];
351
  $galleryLinkUri = $variables['galleryLinkUri'];
352
  $showCaption = $variables['showCaption'];
353
  if (!is_array($captionElements)) {
354
    $captionElements = array();
355
  }
356

    
357
  // TODO correctly handle multiple media representation parts
358
  // Comment @WA: this does not work when clean_urls is enabled..
359
  // $_SESSION['cdm']['last_gallery'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "?q=") + 3);
360
  // ..this works.
361
  $_SESSION['cdm']['last_gallery'] = current_path();
362
  // Prevent from errors.
363
  if (!isset($mediaList[0])) {
364
   // return;
365
  }
366

    
367
  // --- Duplicate supression: media can be reused but should only be shown
368
  // once.
369
  $tempMediaList = array();
370
  $tempMediaUuids = array();
371
  foreach ($mediaList as $media) {
372
    if (!in_array($media->uuid, $tempMediaUuids)) {
373
      $tempMediaList[] = $media;
374
      $tempMediaUuids[] = $media->uuid;
375
    }
376
  }
377
  $mediaList = $tempMediaList;
378

    
379
  // ---
380
  $galleryID = "media_gallery_" . $galleryName;
381

    
382
  $mediaPartLinkAttributes = array();
383
  $openMediaLinkAttributes = array();
384

    
385
  // Prepare media links.
386
  $doLink = FALSE;
387
  if ($mediaLinkType != 'NONE') {
388
    $doLink = TRUE;
389
  }
390
  if ($mediaLinkType == 'LIGHTBOX') {
391
    $doLink = TRUE;
392
    _add_js_lightbox($galleryID);
393
  }
394

    
395
  // Render the media gallery grid.
396
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
397
  $out .= '<colgroup>';
398
  for ($c = 0; $c < $cols; $c++) {
399
    $out .= '<col width="' . (100 / $cols) . '%">';
400
  }
401
  $out .= '</colgroup>';
402

    
403
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
404
    $captionParts = array();
405
    $mediaIndex = 0;
406
    $out .= '<tr>';
407
    for ($c = 0; $c < $cols; $c++) {
408
      $media = array_shift($mediaList);
409

    
410
      if (isset($media->representations[0]->parts[0])) {
411

    
412
        //
413
        // Find preferred representation.
414
        //
415
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
416
          'image/jpg',
417
          'image/jpeg',
418
          'image/png',
419
          'image/gif',
420
        ), $maxExtend, $maxExtend);
421
        if (count($preferred_media_representations_list) == 0) {
422
          // Fallback to using the first one in the list.
423
          $preferred_media_representations_list = $media->representations;
424
        }
425
        $preferred_media_representation = array_shift($preferred_media_representations_list);
426

    
427
        // $preferred_media_representation->parts[0]->uri =
428
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
429
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
430
        $mediaIndex++;
431

    
432
         $mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
433
            'mediaRepresentationPart' => $preferred_media_representation->parts[0],
434
            'maxExtend' => $maxExtend,
435
            'addPassePartout' => TRUE,
436
         ));
437
        // --- Compose Media Link.
438
        $mediaLinkUri = FALSE;
439
        if ($alternativeMediaUri) {
440
          if (isset($alternativeMediaUri[$mediaIndex])) {
441
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
442
          }
443
          if (is_string($alternativeMediaUri)) {
444
            $mediaLinkUri = $alternativeMediaUri;
445
          }
446
        }
447
        else {
448
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
449
        }
450

    
451
        _add_js_ahah();
452
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
453

    
454
        $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
455
        $captionPartHtml = '<div class="ahah-content" rel="' . $cdm_proxy_url . '"><span class="loading" style="display: none;">Loading ....</span></div>';
456

    
457
        // Generate gallery caption.
458
        if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
459
          $mediaPartLinkAttributes['class'] = array('lightbox');
460
        }
461
        else {
462
          $mediaPartLinkAttributes['target'] = "specimen";
463
          $openMediaLinkAttributes['target'] = "specimen";
464
        }
465
        // Generate & add caption to lightbox.
466
        $lightBoxCaptionElements = NULL;
467
        // .($lightBoxCaptionElements?'/'.join(',',$lightBoxCaptionElements):''));
468
        $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption");
469

    
470
        $mediaPartLinkAttributes['alt'] = '<div class="ahah-content" rel="' . $cdm_proxy_url . '"><span class="loading" style="display: none;">Loading ....</span></div>';
471

    
472
        if (isset($captionElements['#uri'])) {
473
          if ($contentTypeDirectory == 'image') {
474
            $captionPartHtml .= '<div class="media-caption-link">' . l($captionElements['#uri'], path_to_media($media->uuid), array(
475
              'attributes' => array(), 'html' => TRUE,
476
            )) . '</div>';
477
          }
478
          else {
479
            $openMediaLinkAttributes['absolute'] = TRUE;
480
            $captionPartHtml .= '<div class="media-caption-link">' . l($captionElements['#uri'], $mediaLinkUri, array(
481
              'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
482
            )) . '</div>';
483
          }
484
        }
485
        $captionParts[] = $captionPartHtml;
486

    
487
        // --- Surround imagePart with link.
488
        if ($doLink) {
489
          $mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
490
            'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
491
          ));
492
        }
493
      }
494
      else {
495
        $mediaPartHtml = '';
496
        $captionParts[] = '';
497
      }
498
      $out .= '<td class="media">' . $mediaPartHtml . '</td>';
499
    }
500
    $out .= '</tr>'; // End of media parts.
501
    if ($showCaption) {
502
      if (count($captionElements) > 0) {
503
        $out .= '<tr>';
504
        // Add caption row.
505
        foreach ($captionParts as $captionPartHtml) {
506
          $out .= '<td class="caption">' . $captionPartHtml . '</td>';
507
        }
508
        $out .= '</tr>';
509
      }
510
    }
511
  }
512

    
513
  if ($galleryLinkUri) {
514
    if (count($mediaList) > 0) {
515
      $moreHtml = count($mediaList) . ' ' . t('more in gallery');
516
    }
517
    else {
518
      $moreHtml = t('open gallery');
519
    }
520
    $moreHtml = l($moreHtml, $galleryLinkUri);
521
    $out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
522
  }
523
  $out .= '</table>';
524
  return $out;
525
}
526
/**
527
 * @todo Please document this function.
528
 * @see http://drupal.org/node/1354
529
 */
530
function theme_cdm_media_gallerie_image($variables) {
531

    
532
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
533
  $maxExtend = $variables['maxExtend'];
534
  $addPassePartout = $variables['addPassePartout'];
535
  $attributes = $variables['attributes'];
536

    
537
  $out = '';
538

    
539
  // TODO merge with theme_cdm_media_mime_image?
540
  if (isset($mediaRepresentationPart)) {
541

    
542
    $h = $mediaRepresentationPart->height;
543
    $w = $mediaRepresentationPart->width;
544
    if ($w == 0 || $h == 0) {
545
      // Take url and replace spaces.
546
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
547
      $imageDimensions = getimagesize_remote($image_uri);
548
      if (!$imageDimensions) {
549
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
550
      }
551
      $w = $imageDimensions[0];
552
      $h = $imageDimensions[1];
553
    }
554
    $margins = '0 0 0 0';
555
    $ratio = $w / $h;
556
    if ($ratio > 1) {
557
      $displayHeight = round($maxExtend / $ratio);
558
      $displayWidth = $maxExtend;
559
      $m = round(($maxExtend - $displayHeight) / 2);
560
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
561
    }
562
    else {
563
      $displayHeight = $maxExtend;
564
      $displayWidth = round($maxExtend * $ratio);
565
      $m = round(($maxExtend - $displayWidth) / 2);
566
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
567
    }
568

    
569
    // Turn attributes array into string.
570
    $attrStr = ' ';
571
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
572
    if (is_array($attributes)) {
573
      foreach ($attributes as $name => $value) {
574
        $attrStr .= $name . '="' . $value . '" ';
575
      }
576
    }
577

    
578
    if ($addPassePartout) {
579
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
580
    }
581
    else {
582
      // Do not add margins if no pass partout is shown.
583
      $margins = '';
584
    }
585
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
586

    
587
    if ($addPassePartout) {
588
      $out .= '</div>';
589
    }
590
    return $out;
591
  }
592
}
593

    
594
/**
595
 * @todo Please document this function.
596
 * @see http://drupal.org/node/1354
597
 */
598
function theme_cdm_media_gallerie_application($variables) {
599
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
600
  $maxExtend = $variables['maxExtend'];
601
  $addPassePartout = $variables['addPassePartout'];
602
  $attributes = $variables['attributes'];
603
  if (isset($mediaRepresentationPart)) {
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 .= '<div class="appication">Web Application</div>';
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_text($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_openlayers_image($variables) {
653
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
654
  $maxExtend = $variables['maxExtend'];
655

    
656
  // @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
657
  // and
658
  // @see http://trac.openlayers.org/wiki/SettingZoomLevels
659
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/OpenLayers/OpenLayers.js', array('type' => 'file', 'weight' => JS_LIBRARY));
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 == 0 || $h == 0) {
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 (default is 360 deg / 256 px) and the bounds.
679
  if ($w > $h) {
680
    $lat = 90;
681
    $lon = 90 * ($h / $w);
682
    $maxRes = $w / $maxExtend;
683
  }
684
  else {
685
    $lat = 90 * ($w / $h);
686
    $lon = 90;
687
    $maxRes = $h / $maxExtend;
688
  }
689

    
690
  $maxRes *= 1;
691
  drupal_add_js('
692
 var map;
693

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

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

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

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

    
729
/**
730
 * @todo Please document this function.
731
 * @see http://drupal.org/node/1354
732
 */
733
function theme_cdm_preferredImage($variables) {
734

    
735
  $media = $variables['media'];
736
  $defaultRepresentationPart = $variables['defaultRepresentationPart'];
737
  $imageMaxExtend = $variables['imageMaxExtend'];
738
  $parameters = $variables['parameters'];
739

    
740
  $out = '';
741

    
742
  if (isset($media[0])) {
743
    $representationPart = $media[0]->representations[0]->parts[0];
744
    if ($parameters) {
745
      $representationPart->uri . $parameters;
746
    }
747
  }
748
  else {
749
    $representationPart = $defaultRepresentationPart;
750
  }
751

    
752
  $attributes = array(
753
    'alt' => (isset($media->representations[0]->parts[0]->uri) ? $media->representations[0]->parts[0]->uri : "no image available"),
754
  );
755
  $out .= theme('cdm_media_gallerie_image', array(
756
    'mediaRepresentationPart' => $representationPart,
757
    'maxExtend' => $imageMaxExtend,
758
    'addPassePartout' => FALSE,
759
    'attributes' => $attributes,
760
  ));
761

    
762
  return $out;
763
}
(4-4/9)