Project

General

Profile

Download (24.1 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
    else {
79
      // No media available, so display just the type term.
80
      $out .= $feature->representation_L10n;
81
    }
82
  }
83
  return $out;
84
}
85

    
86
/**
87
 * @todo Please document this function.
88
 * @see http://drupal.org/node/1354
89
 */
90
function theme_cdm_media_mime_application($variables) {
91
  $mediaRepresentation = $variables['mediaRepresentation'];
92
  $feature = $variables['feature'];
93
  $out = '';
94
  foreach ($mediaRepresentation->parts as $part) {
95
    $attributes = array(
96
      'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
97
      'target' => '_blank',
98
    );
99
    /*
100
    $attributes = array('title'=>$feature->representation_L10n,'target'=>'_blank');
101
    $attributes = array('title'=>'original publication', 'target'=>'_blank');
102
    */
103
    $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
104
      'attributes' => $attributes,
105
      'absolute' => TRUE,
106
      'html' => TRUE,
107
    ));
108
  }
109
  return $out;
110
}
111

    
112
/**
113
 * @todo Please document this function.
114
 * @see http://drupal.org/node/1354
115
 */
116
function theme_cdm_media_mime_image($variables) {
117
  $mediaRepresentation = $variables['mediaRepresentation'];
118
  $feature = $variables['feature'];
119
  $out = '';
120
  // TODO thickbox is not used anymore -> delete?
121
  $attributes = array(
122
    'class' => 'thickbox',
123
    'rel' => 'representation-' . $representation->uuid,
124
    'title' => $feature->representation_L10n,
125
  );
126
  for ($i = 0; $part = $representation->representationParts[$i]; $i++) {
127
    if ($i == 0) {
128
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
129
        'attributes' => $attributes,
130
        'absolute' => TRUE,
131
        'html' => TRUE,
132
      ));
133
    }
134
    else {
135
      $out .= l('', $part->uri, array(
136
        'attributes' => $attributes,
137
        'absolute' => TRUE,
138
      ));
139
    }
140
  }
141
  return $out;
142
}
143

    
144
/**
145
 * @todo Please document this function.
146
 * @see http://drupal.org/node/1354
147
 */
148
function theme_cdm_media_mime_text($variables) {
149
  $representation = $variables['mediaRepresentation'];
150
  $feature = $variables['feature'];
151
  $out = '';
152
  if (!empty($representation->parts)) {
153
    foreach ($representation->parts as $part) {
154
      $attributes = array(
155
        'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
156
        'target' => '_blank',
157
      );
158
      // $attributes = array('title'=>t('original publication'),
159
      // 'target'=>'_blank');
160
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
161
        'attributes' => $attributes,
162
        'absolute' => TRUE,
163
        'html' => TRUE,
164
      ));
165
    }
166
  }
167
  return $out;
168
}
169

    
170

    
171
/**
172
 * Theme function for captions of media elements. This method is usually called from
173
 * within the theme_cdm_media_gallerie() function or indirectly via AHAH.
174
 *
175
 * @param array $variables
176
 *   an associative array with the following elements:
177
 *   - 'media': the cdm media object to show the captions for
178
 *   - 'elements':
179
 *         an array which defining the caption elements to show up
180
 *         example:
181
 *          Show 'title', 'description', 'file', 'filename' in the caption:
182
 *          array('title', 'description', 'file', 'filename')
183
 *
184
 * @return string
185
 *   the themed html output
186
 */
187
function theme_cdm_media_caption($variables) {
188
  $media = $variables['media'];
189
  $elements = $variables['elements'];
190
  $media_metadata = read_media_metadata($media);
191

    
192
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
193
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
194
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
195
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
196
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
197

    
198
  $descriptionPrefix = "";
199

    
200
  $out = '<dl class="media-caption">';
201
  // Title.
202
  if ($doTitle) {
203
    if ($media_metadata['title']) {
204
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
205
      $descriptionPrefix = "- ";
206
    }
207
    elseif (!($doDescription && $media_metadata['description'])) {
208
      // Use filename as fallback option if no description will be shown.
209
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
210
      $descriptionPrefix = "- ";
211
    }
212
  }
213
  // Description.
214
  if ($media_metadata['description'] && $doDescription) {
215
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
216
  }
217
  // Artist.
218
  if ($media_metadata['artist'] && $doArtist) {
219
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
220
  }
221
  // Location.
222
  if ($doLocation) {
223
    $location = '';
224
    $location .= $media_metadata['location']['sublocation'];
225
    if ($location && $media_metadata['location']['city']) {
226
      $location .= ', ';
227
    }
228
    $location .= $media_metadata['location']['city'];
229
    if ($location && $media_metadata['location']['province']) {
230
      $location .= ', ';
231
    }
232
    $location .= $media_metadata['location']['province'];
233
    if ($location && $media_metadata['location']['country']) {
234
      $location .= ' (' . $media_metadata['location']['country'] . ')';
235
    }
236
    else {
237
      $location .= $media_metadata['location']['country'];
238
    }
239
    if ($location) {
240
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
241
    }
242
  }
243
  // Rights.
244
  if ($doRights) {
245
    $rights = '';
246
    // TODO use cdm_rights_as_dl_groups() to create dl entries
247

    
248
    // Copyrights.
249
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
250
    if ($cnt > 0) {
251
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
252
      for ($i = 0; $i < $cnt; $i++) {
253
        $rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
254
        if ($i + 1 < $cnt) {
255
          $rights .= ' / ';
256
        }
257
      }
258
      $rights .= '</dd>';
259
    }
260
    // License.
261
    $cnt = count($media_metadata['rights']['license']['agentNames']);
262
    if ($cnt > 0) {
263
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
264
      for ($i = 0; $i < $cnt; $i++) {
265
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
266
        if ($i + 1 < $cnt) {
267
          $rights .= ' / ';
268
        }
269
      }
270
      $rights .= '</dd>';
271
    }
272
    if ($rights) {
273
      $out .= $rights . '</dt>';
274
    }
275
  }
276
  // TODO add all other metadata elements generically.
277
  $out .= '</dl>';
278
  // Return value,
279
  return $out;
280
}
281

    
282
/**
283
 * Return HTML for a media gallery
284
 *
285
 * @param array $variables
286
 *   An associative array containing:
287
 *   - mediaList: An array of Media entities.
288
 *   - maxExtend
289
 *   - cols
290
 *   - maxRows
291
 *   - showCaption:  boolean value, whether to show captions or not.
292
 *   - captionElements: An array of caption elements to be shown. In case the array
293
 *        is empty of NULL  all available caption elements will be show. In order to
294
 *        supress all captions  set 'showCaption' to FALSE
295
 *        example:
296
 *          1) Show 'title', 'description', 'file', 'filename' in the caption:
297
 *            array('title', 'description', 'file', 'filename'),
298
 *          2) To add an addtional link at the bottom of  the caption:
299
 *            array('titlecache', '#uri'=>t('open Image')) this will cause a link
300
 *            to be rendered with label 'open Image' which will open the according
301
 *            media object.
302
 *   - mediaLinkType: Valid values:
303
 *      - "NONE": do not link the images,
304
 *      - "LIGHTBOX": open the link in a light box,
305
 *      - "NORMAL": link to the image page or to the $alternativeMediaUri if
306
 *        it is defined.
307
 *   - alternativeMediaUri: A fix string or an array of alternative URIs to link the images
308
 *     which will overwrite the URIs of the media parts.
309
 *     The order of URI in this array must correspond with the order of
310
 *     images in $mediaList.
311
 *   - galleryLinkUri: An URI to link the the hint on more images to;
312
 *     if NULL no link is created.
313
 *
314
 * @return the image gallery HTML
315
 * @ingroup: themeable
316
 */
317
function theme_cdm_media_gallerie($variables) {
318

    
319
  $mediaList = $variables['mediaList'];
320

    
321
  // Do not show an empty gallery.
322
  if (count($mediaList) == 0) {
323
    return;
324
  }
325

    
326
  $galleryName = $variables['galleryName'];
327
  $maxExtend = $variables['maxExtend'];
328
  $cols = $variables['cols'];
329
  $maxRows = $variables['maxRows'];
330
  $captionElements = $variables['captionElements'];
331
  $mediaLinkType = $variables['mediaLinkType'];
332
  $alternativeMediaUri = $variables['alternativeMediaUri'];
333
  $galleryLinkUri = $variables['galleryLinkUri'];
334
  $showCaption = $variables['showCaption'];
335

    
336
  $caption_link_uri = '';
337
  if(isset($captionElements['#uri'])){
338
    $caption_link_uri = $captionElements['#uri'];
339
    unset($captionElements['#uri']);
340
  }
341
  if (!is_array($captionElements) || count($captionElements) == 0) {
342
    $captionElements = NULL;
343
  }
344

    
345
  // TODO correctly handle multiple media representation parts
346
  $_SESSION['cdm']['last_gallery'] = current_path();
347
  // Prevent from errors.
348
  if (!isset($mediaList[0])) {
349
   // return;
350
  }
351

    
352
  // --- Duplicate supression: media can be reused but should only be shown
353
  // once.
354
  $tempMediaList = array();
355
  $tempMediaUuids = array();
356
  foreach ($mediaList as $media) {
357
    if (!in_array($media->uuid, $tempMediaUuids)) {
358
      $tempMediaList[] = $media;
359
      $tempMediaUuids[] = $media->uuid;
360
    }
361
  }
362
  $mediaList = $tempMediaList;
363

    
364
  // ---
365
  $galleryID = "media_gallery_" . $galleryName;
366

    
367
  $mediaPartLinkAttributes = array();
368
  $openMediaLinkAttributes = array();
369

    
370
  // Prepare media links.
371
  $doLink = FALSE;
372
  if ($mediaLinkType != 'NONE') {
373
    $doLink = TRUE;
374
  }
375
  if ($mediaLinkType == 'LIGHTBOX') {
376
    $doLink = TRUE;
377
    _add_js_lightbox($galleryID);
378
  }
379

    
380
  // Render the media gallery grid.
381
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
382
  $out .= '<colgroup>';
383
  for ($c = 0; $c < $cols; $c++) {
384
    $out .= '<col style="width:' . (100 / $cols) . '%;">';
385
  }
386
  $out .= '</colgroup>';
387

    
388
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
389
    $captionParts = array();
390
    $mediaIndex = 0;
391
    $out .= '<tr>';
392
    for ($c = 0; $c < $cols; $c++) {
393
      $media = array_shift($mediaList);
394

    
395
      if (isset($media->representations[0]->parts[0])) {
396

    
397
        //
398
        // Find preferred representation.
399
        //
400
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
401
          'image/jpg',
402
          'image/jpeg',
403
          'image/png',
404
          'image/gif',
405
        ), $maxExtend, $maxExtend);
406
        if (count($preferred_media_representations_list) == 0) {
407
          // Fallback to using the first one in the list.
408
          $preferred_media_representations_list = $media->representations;
409
        }
410
        $preferred_media_representation = array_shift($preferred_media_representations_list);
411

    
412
        // $preferred_media_representation->parts[0]->uri =
413
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
414
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
415

    
416
         $mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
417
            'mediaRepresentationPart' => $preferred_media_representation->parts[0],
418
            'maxExtend' => $maxExtend,
419
            'addPassePartout' => TRUE,
420
         ));
421
        // --- Compose Media Link.
422
        $mediaLinkUri = FALSE;
423
        if ($alternativeMediaUri) {
424
          if (isset($alternativeMediaUri[$mediaIndex])) {
425
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
426
          }
427
          if (is_string($alternativeMediaUri)) {
428
            $mediaLinkUri = $alternativeMediaUri;
429
          }
430
        }
431
        else {
432
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
433
        }
434
        $mediaIndex++;
435

    
436
        // media captions will be loaded via AHAH
437
        _add_js_ahah();
438
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
439
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
440
        $ahah_media_caption =  '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
441
          . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
442

    
443
        // preparing the part link (= click on image iteself) which can be handled in two ways
444
        //
445
        //  1. open image in lightbox, the captions in the lighhtbox will be loaded via AHAH
446
        //  2. open the media in a new window with target 'specimen'
447
        if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
448
          $mediaPartLinkAttributes['class'] = array('lightbox');
449
        }
450
        else {
451
          $mediaPartLinkAttributes['target'] = "specimen";
452
          $openMediaLinkAttributes['target'] = "specimen";
453
        }
454
        $mediaPartLinkAttributes['alt'] = htmlentities($ahah_media_caption);
455

    
456
        // --- preparing the media caption
457

    
458
        /* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
459
         *
460
         * a.kohlbecker 2013-03-14 :
461
         *   It is unclear why no caption elements should be shown, Was it a technical reason?
462
         *   see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
463
         *   If not problems arise with this remove it after some weeks
464
         */
465
        $captionPartHtml = $ahah_media_caption;
466

    
467
        if ($caption_link_uri) {
468
          if ($contentTypeDirectory == 'image') {
469
          // it is an image, so open it in the media page
470
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
471
              'attributes' => array(), 'html' => TRUE,
472
            )) . '</div>';
473
          }
474
          else {
475
            // otherwise open it directly and let the the browser handle the media type
476
            $openMediaLinkAttributes['absolute'] = TRUE;
477
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
478
              'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
479
            )) . '</div>';
480
          }
481
        }
482

    
483
        $captionParts[] = $captionPartHtml;
484

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

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

    
530
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
531
  $maxExtend = $variables['maxExtend'];
532
  $addPassePartout = $variables['addPassePartout'];
533
  $attributes = $variables['attributes'];
534

    
535
  $out = '';
536

    
537
  // TODO merge with theme_cdm_media_mime_image?
538
  if (isset($mediaRepresentationPart)) {
539

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

    
567
    // Turn attributes array into string.
568
    if(!is_array($attributes)){
569
      $attributes = array();
570
    }
571
    if(!isset($attributes['alt'])){
572
      $attributes['alt'] = check_plain($mediaRepresentationPart->uri);
573
    }
574
    $attrStr = ' ';
575
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
576
    if (is_array($attributes)) {
577
      foreach ($attributes as $name => $value) {
578
        $attrStr .= $name . '="' . $value . '" ';
579
      }
580
    }
581

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

    
591
    if ($addPassePartout) {
592
      $out .= '</div>';
593
    }
594
    return $out;
595
  }
596
}
597

    
598
/**
599
 * @todo Please document this function.
600
 * @see http://drupal.org/node/1354
601
 */
602
function theme_cdm_media_gallerie_application($variables) {
603
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
604
  $maxExtend = $variables['maxExtend'];
605
  $addPassePartout = $variables['addPassePartout'];
606
  $attributes = $variables['attributes'];
607
  $out = '';
608
  if (isset($mediaRepresentationPart)) {
609

    
610
    if ($addPassePartout) {
611
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
612
    }
613
    else {
614
      // Do not add margins if no pass partout is shown.
615
      $margins = '';
616
    }
617
    $out .= '<div class="appication">Web Application</div>';
618

    
619
    if ($addPassePartout) {
620
      $out .= '</div>';
621
    }
622
    return $out;
623
  }
624
}
625

    
626
/**
627
 * @todo Please document this function.
628
 * @see http://drupal.org/node/1354
629
 */
630
function theme_cdm_media_gallerie_text($variables) {
631
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
632
  $maxExtend = $variables['maxExtend'];
633
  $addPassePartout = $variables['addPassePartout'];
634
  $attributes = $variables['attributes'];
635
  if (isset($mediaRepresentationPart)) {
636

    
637
    if ($addPassePartout) {
638
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
639
    }
640
    else {
641
      // Do not add margins if no pass partout is shown.
642
      $margins = '';
643
    }
644
    $out .= '<div class="application">Web Application</div>';
645

    
646
    if ($addPassePartout) {
647
      $out .= '</div>';
648
    }
649
    return $out;
650
  }
651
}
652

    
653
/**
654
 * Adds the OpenLayers based image viewer to the page.
655
 *
656
 * The OpenLayers based image viewer allows to zoom and pan the displayed image.
657
 *
658
 * Documentation related to using Openlayers in order to view images is found here:
659
 *  - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
660
 *  - @see http://trac.openlayers.org/wiki/SettingZoomLevels
661
 *
662
 * @param array $variables
663
 *   An associative array of theme variables:
664
 *   - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
665
 *   - maxExtend: The maximum extend of the image viewer view port.
666
 */
667
function theme_cdm_openlayers_image($variables) {
668
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
669
  $maxExtend = $variables['maxExtend'];
670

    
671
  _add_js_openlayers();
672

    
673
  // TODO merge code below with code from theme_cdm_media_gallerie_image
674
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
675
  // TODO merge code below with code from theme_cdm_media_gallerie_image
676
  $w = $mediaRepresentationPart->width;
677
  $h = $mediaRepresentationPart->height;
678

    
679
  if ($w == 0 || $h == 0) {
680
    // Take url and replace spaces.
681
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
682
    $imageDimensions = getimagesize_remote($image_uri);
683
    if (!$imageDimensions) {
684
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
685
    }
686
    $w = $imageDimensions[0];
687
    $h = $imageDimensions[1];
688
  }
689

    
690
  // Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
691
  if ($w > $h) {
692
    $lat = 90;
693
    $lon = 90 * ($h / $w);
694
    $maxRes = $w / $maxExtend;
695
  }
696
  else {
697
    $lat = 90 * ($w / $h);
698
    $lon = 90;
699
    $maxRes = $h / $maxExtend;
700
  }
701

    
702
  $maxRes *= 1;
703
  drupal_add_js('
704
 var map;
705

    
706
 var imageLayerOptions={
707
     maxResolution: ' . $maxRes . ',
708
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
709
  };
710
  var mapOptions={
711
      controls:
712
       [
713
         new OpenLayers.Control.PanZoom(),
714
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
715
       ],
716
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
717
  };
718

    
719
 var graphic = new OpenLayers.Layer.Image(
720
          \'Image Title\',
721
          \'' . $mediaRepresentationPart->uri . '\',
722
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
723
          new OpenLayers.Size(' . $w . ', ' . $h . '),
724
          imageLayerOptions
725
          );
726

    
727
 function init() {
728
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
729
   map.addLayers([graphic]);
730
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
731
   map.zoomToMaxExtent();
732
 }
733

    
734
jQuery(document).ready(function(){
735
  init();
736
});', array('type' => 'inline'));
737
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
738
  return $out;
739
}
740

    
(3-3/9)