Project

General

Profile

Download (23.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
  $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
 * Creates the markup for the media associated a DescriptionElement instance.
56
 *
57
 * @param $descriptionElement
58
 *    the DescriptionElement instance
59
 * @param $mimeTypePreference array
60
 *    An array of mime type strings. the order of the mimetpes is the oerder of preference.
61
 *    E.g.: array('application/pdf','image/jpeg')
62
 *
63
 * @return string
64
 *    The markup
65
 */
66
function cdm_description_element_media($descriptionElement, $mimeTypePreference) {
67

    
68
  $out = '';
69

    
70
  _add_js_thickbox();
71

    
72
  $feature = $descriptionElement->feature;
73
  $medias = $descriptionElement->media;
74

    
75
  foreach ($medias as $media) {
76
    $prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
77
    $mediaRepresentation = array_shift($prefRepresentations);
78
    if ($mediaRepresentation) {
79

    
80
      $contentTypeDirectory = media_content_type_dir($mediaRepresentation);
81

    
82
      $out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
83
    }
84
    else {
85
      // Media has empty or corrupt representation
86
      if(user_is_logged_in()){
87
        drupal_set_message('The media entity (' . l($media->uuid, path_to_media($media->uuid)) .') has empty or corrupt representation parts. Maybe the URI is empty.' , 'warning');
88
      }
89
    }
90
  }
91
  return $out;
92
}
93

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

    
120

    
121
/**
122
 * Creates the markup for a CDM Media instance.
123
 *
124
 * (This method is currently only called from within theme_cdm_media())
125
 *
126
 * @param $variables
127
 *    An associative array
128
 * @return string
129
 *    The markup
130
 */
131
function theme_cdm_media_mime_image($variables) {
132
  $media_representation = $variables['mediaRepresentation'];
133
  $feature = $variables['feature'];
134
  $out = '';
135
  // TODO thickbox is not used anymore -> delete?
136
  $attributes = array(
137
    'class' => 'thickbox',
138
    'rel' => 'representation-' . $media_representation->uuid,
139
    'title' => $feature->representation_L10n,
140
  );
141
  for ($i = 0; $part = $media_representation->parts[$i]; $i++) {
142
    if ($i == 0) {
143
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
144
        'attributes' => $attributes,
145
        'absolute' => TRUE,
146
        'html' => TRUE,
147
      ));
148
    }
149
    else {
150
      $out .= l('', $part->uri, array(
151
        'attributes' => $attributes,
152
        'absolute' => TRUE,
153
      ));
154
    }
155
  }
156
  return $out;
157
}
158

    
159
/**
160
 * @todo Please document this function.
161
 * @see http://drupal.org/node/1354
162
 */
163
function theme_cdm_media_mime_text($variables) {
164
  $representation = $variables['mediaRepresentation'];
165
  $feature = $variables['feature'];
166
  $out = '';
167
  if (!empty($representation->parts)) {
168
    foreach ($representation->parts as $part) {
169
      $attributes = array(
170
        'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
171
        'target' => '_blank',
172
      );
173
      // $attributes = array('title'=>t('original publication'),
174
      // 'target'=>'_blank');
175
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
176
        'attributes' => $attributes,
177
        'absolute' => TRUE,
178
        'html' => TRUE,
179
      ));
180
    }
181
  }
182
  return $out;
183
}
184

    
185

    
186
/**
187
 * Theme function for captions of media elements. This method is usually called from
188
 * within the theme_cdm_media_gallerie() function or indirectly via AHAH.
189
 *
190
 * @param array $variables
191
 *   an associative array with the following elements:
192
 *   - 'media': the cdm media object to show the captions for
193
 *   - 'elements':
194
 *         an array which defining the caption elements to show up
195
 *         example:
196
 *          Show 'title', 'description', 'file', 'filename' in the caption:
197
 *          array('title', 'description', 'file', 'filename')
198
 *
199
 * @return string
200
 *   the themed html output
201
 *
202
 * TODO turn into compose method
203
 */
204
function theme_cdm_media_caption($variables) {
205
  $media = $variables['media'];
206
  $elements = $variables['elements'];
207
  $media_metadata = read_media_metadata($media);
208

    
209
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
210
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
211
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
212
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
213
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
214

    
215
  $descriptionPrefix = "";
216

    
217
  $out = '<dl class="media-caption">';
218
  // Title.
219
  if ($doTitle) {
220
    if ($media_metadata['title']) {
221
      $out .= '<dt class = "title">' . t('Title')  . ':'. '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
222
      $descriptionPrefix = "- ";
223
    }
224
    elseif (!($doDescription && $media_metadata['description'])) {
225
      // Use filename as fallback option if no description will be shown.
226
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
227
      $descriptionPrefix = "- ";
228
    }
229
  }
230
  // Description.
231
  if ($media_metadata['description'] && $doDescription) {
232
    $out .= '<dt class = "description">' . t('Description')  . ':'. '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
233
  }
234
  // Artist.
235
  if ($media_metadata['artist'] && $doArtist) {
236
    $out .= '<dt class = "artist">' . t('Artist')  . ':' . '</dt> <dd class = "artist">' . $media_metadata['artist'] . '</dd>';
237
  }
238
  // Location.
239
  if ($doLocation) {
240
    $location = '';
241
    $location .= $media_metadata['location']['sublocation'];
242
    if ($location && $media_metadata['location']['city']) {
243
      $location .= ', ';
244
    }
245
    $location .= $media_metadata['location']['city'];
246
    if ($location && $media_metadata['location']['province']) {
247
      $location .= ', ';
248
    }
249
    $location .= $media_metadata['location']['province'];
250
    if ($location && $media_metadata['location']['country']) {
251
      $location .= ' (' . $media_metadata['location']['country'] . ')';
252
    }
253
    else {
254
      $location .= $media_metadata['location']['country'];
255
    }
256
    if ($location) {
257
      $out .= '<dt class = "location">' . t('Location') . ':' . '</dt> <dd class = "location">' . $location . '</dd>';
258
    }
259
  }
260
  // Rights.
261
  if ($doRights) {
262
    $rights_render_item = array(
263
      '#theme' => 'description_list',
264
      '#groups' => cdm_rights_as_dl_groups($media_metadata['rights'])
265
    );
266
   $out .= drupal_render($rights_render_item);
267
  }
268
  // TODO add all other metadata elements generically.
269
  $out .= '</dl>';
270
  // Return value,
271
  return $out;
272
}
273

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

    
312
  $mediaList = $variables['mediaList'];
313

    
314
  // Do not show an empty gallery.
315
  if (count($mediaList) == 0) {
316
    return '';
317
  }
318

    
319
  $galleryName = $variables['galleryName'];
320
  $maxExtend = $variables['maxExtend'];
321
  $cols = $variables['cols'];
322
  $maxRows = $variables['maxRows'];
323
  $captionElements = $variables['captionElements'];
324
  $mediaLinkType = $variables['mediaLinkType'];
325
  $alternativeMediaUri = $variables['alternativeMediaUri'];
326
  $galleryLinkUri = $variables['galleryLinkUri'];
327
  $showCaption = $variables['showCaption'];
328

    
329
  $caption_link_uri = '';
330
  if(isset($captionElements['#uri'])){
331
    $caption_link_uri = $captionElements['#uri'];
332
    unset($captionElements['#uri']);
333
  }
334
  if (!is_array($captionElements) || count($captionElements) == 0) {
335
    $captionElements = NULL;
336
  }
337

    
338
  // TODO correctly handle multiple media representation parts
339
  $_SESSION['cdm']['last_gallery'] = current_path();
340
  // Prevent from errors.
341
  if (!isset($mediaList[0])) {
342
   // return;
343
  }
344

    
345
  // --- Duplicate supression: media can be reused but should only be shown
346
  // once.
347
  $tempMediaList = array();
348
  $tempMediaUuids = array();
349
  foreach ($mediaList as $media) {
350
    if (!in_array($media->uuid, $tempMediaUuids)) {
351
      $tempMediaList[] = $media;
352
      $tempMediaUuids[] = $media->uuid;
353
    }
354
  }
355
  $mediaList = $tempMediaList;
356

    
357
  // ---
358
  $galleryID = "media_gallery_" . $galleryName;
359

    
360
  $mediaPartLinkAttributes = array();
361
  $openMediaLinkAttributes = array();
362

    
363
  // Prepare media links.
364
  $doLink = FALSE;
365
  if ($mediaLinkType != 'NONE') {
366
    $doLink = TRUE;
367
  }
368
  if ($mediaLinkType == 'LIGHTBOX') {
369
    $doLink = TRUE;
370
    _add_js_lightbox($galleryID);
371
  }
372

    
373
  // Render the media gallery grid.
374
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
375
  $out .= '<colgroup>';
376
  for ($c = 0; $c < $cols; $c++) {
377
    $out .= '<col style="width:' . (100 / $cols) . '%;">';
378
  }
379
  $out .= '</colgroup>';
380

    
381
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
382
    $captionParts = array();
383
    $mediaIndex = 0;
384
    $out .= '<tr>';
385
    for ($c = 0; $c < $cols; $c++) {
386
      $media = array_shift($mediaList);
387

    
388
      if (isset($media->representations[0]->parts[0])) {
389

    
390
        //
391
        // Find preferred representation.
392
        //
393
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
394
          'image/jpg',
395
          'image/jpeg',
396
          'image/png',
397
          'image/gif',
398
        ), $maxExtend, $maxExtend);
399
        if (count($preferred_media_representations_list) == 0) {
400
          // Fallback to using the first one in the list.
401
          $preferred_media_representations_list = $media->representations;
402
        }
403
        $preferred_media_representation = array_shift($preferred_media_representations_list);
404

    
405
        // $preferred_media_representation->parts[0]->uri =
406
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
407
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
408

    
409
         $mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
410
            'mediaRepresentationPart' => $preferred_media_representation->parts[0],
411
            'maxExtend' => $maxExtend,
412
            'addPassePartout' => TRUE,
413
         ));
414
        // --- Compose Media Link.
415
        $mediaLinkUri = FALSE;
416
        if ($alternativeMediaUri) {
417
          if (isset($alternativeMediaUri[$mediaIndex])) {
418
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
419
          }
420
          if (is_string($alternativeMediaUri)) {
421
            $mediaLinkUri = $alternativeMediaUri;
422
          }
423
        }
424
        else {
425
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
426
        }
427
        $mediaIndex++;
428

    
429
        // media captions will be loaded via AHAH
430
        _add_js_ahah();
431
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
432
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
433
        $ahah_media_caption =  '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
434
          . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
435

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

    
449
        // --- preparing the media caption
450

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

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

    
476
        $captionParts[] = $captionPartHtml;
477

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

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

    
523
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
524
  $maxExtend = $variables['maxExtend'];
525
  $addPassePartout = $variables['addPassePartout'];
526
  $attributes = $variables['attributes'];
527

    
528
  $out = '';
529

    
530
  // TODO merge with theme_cdm_media_mime_image?
531
  if (isset($mediaRepresentationPart)) {
532

    
533
    $h = $mediaRepresentationPart->height;
534
    $w = $mediaRepresentationPart->width;
535
    if ($w == 0 || $h == 0) {
536
      // Take url and replace spaces.
537
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
538
      $imageDimensions = getimagesize_remote($image_uri);
539
      if (!$imageDimensions) {
540
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
541
      }
542
      $w = $imageDimensions[0];
543
      $h = $imageDimensions[1];
544
    }
545

    
546
    $ratio = $w / $h;
547
    if ($ratio > 1) {
548
      $displayHeight = round($maxExtend / $ratio);
549
      $displayWidth = $maxExtend;
550
      $m = round(($maxExtend - $displayHeight) / 2);
551
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
552
    }
553
    else {
554
      $displayHeight = $maxExtend;
555
      $displayWidth = round($maxExtend * $ratio);
556
      $m = round(($maxExtend - $displayWidth) / 2);
557
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
558
    }
559

    
560
    // Turn attributes array into string.
561
    if(!is_array($attributes)){
562
      $attributes = array();
563
    }
564
    if(!isset($attributes['alt'])){
565
      $attributes['alt'] = check_plain($mediaRepresentationPart->uri);
566
    }
567
    $attrStr = ' ';
568
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
569
    if (is_array($attributes)) {
570
      foreach ($attributes as $name => $value) {
571
        $attrStr .= $name . '="' . $value . '" ';
572
      }
573
    }
574

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

    
584
    if ($addPassePartout) {
585
      $out .= '</div>';
586
    }
587
  }
588

    
589
  return $out;
590
}
591

    
592
/**
593
 * @todo Please document this function.
594
 * @see http://drupal.org/node/1354
595
 */
596
function theme_cdm_media_gallerie_application($variables) {
597
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
598
  $maxExtend = $variables['maxExtend'];
599
  $addPassePartout = $variables['addPassePartout'];
600
  $attributes = $variables['attributes'];
601
  $out = '';
602

    
603
  if (isset($mediaRepresentationPart)) {
604

    
605
    if ($addPassePartout) {
606
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
607
    }
608
    $out .= '<div class="appication">Web Application</div>';
609

    
610
    if ($addPassePartout) {
611
      $out .= '</div>';
612
    }
613
  }
614

    
615
  return $out;
616
}
617

    
618
/**
619
 * @todo Please document this function.
620
 * @see http://drupal.org/node/1354
621
 */
622
function theme_cdm_media_gallerie_text($variables) {
623
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
624
  $maxExtend = $variables['maxExtend'];
625
  $addPassePartout = $variables['addPassePartout'];
626
  $attributes = $variables['attributes'];
627

    
628
  $out = '';
629

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

    
635
    $out .= '<div class="application">Web Application</div>';
636

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

    
642
  return $out;
643
}
644

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

    
663
  _add_js_openlayers();
664

    
665
  // TODO merge code below with code from theme_cdm_media_gallerie_image
666
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
667
  // TODO merge code below with code from theme_cdm_media_gallerie_image
668
  $w = $mediaRepresentationPart->width;
669
  $h = $mediaRepresentationPart->height;
670

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

    
682
  // Calculate maxResolution
683
  if ($w > $h) {
684
    $maxRes = $w / $maxExtend;
685
  }
686
  else {
687
    $maxRes = $h / $maxExtend;
688
  }
689

    
690
  $maxRes *= 1;
691

    
692
  drupal_add_js('
693
 var map;
694

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

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

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

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

    
(3-3/9)