Project

General

Profile

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

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

    
177

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

    
199
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
200
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
201
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
202
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
203
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
204

    
205
  $descriptionPrefix = "";
206

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

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

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

    
326
  $mediaList = $variables['mediaList'];
327

    
328
  // Do not show an empty gallery.
329
  if (count($mediaList) == 0) {
330
    return;
331
  }
332

    
333
  $galleryName = $variables['galleryName'];
334
  $maxExtend = $variables['maxExtend'];
335
  $cols = $variables['cols'];
336
  $maxRows = $variables['maxRows'];
337
  $captionElements = $variables['captionElements'];
338
  $mediaLinkType = $variables['mediaLinkType'];
339
  $alternativeMediaUri = $variables['alternativeMediaUri'];
340
  $galleryLinkUri = $variables['galleryLinkUri'];
341
  $showCaption = $variables['showCaption'];
342

    
343
  $caption_link_uri = '';
344
  if(isset($captionElements['#uri'])){
345
    $caption_link_uri = $captionElements['#uri'];
346
    unset($captionElements['#uri']);
347
  }
348
  if (!is_array($captionElements) || count($captionElements) == 0) {
349
    $captionElements = NULL;
350
  }
351

    
352
  // TODO correctly handle multiple media representation parts
353
  $_SESSION['cdm']['last_gallery'] = current_path();
354
  // Prevent from errors.
355
  if (!isset($mediaList[0])) {
356
   // return;
357
  }
358

    
359
  // --- Duplicate supression: media can be reused but should only be shown
360
  // once.
361
  $tempMediaList = array();
362
  $tempMediaUuids = array();
363
  foreach ($mediaList as $media) {
364
    if (!in_array($media->uuid, $tempMediaUuids)) {
365
      $tempMediaList[] = $media;
366
      $tempMediaUuids[] = $media->uuid;
367
    }
368
  }
369
  $mediaList = $tempMediaList;
370

    
371
  // ---
372
  $galleryID = "media_gallery_" . $galleryName;
373

    
374
  $mediaPartLinkAttributes = array();
375
  $openMediaLinkAttributes = array();
376

    
377
  // Prepare media links.
378
  $doLink = FALSE;
379
  if ($mediaLinkType != 'NONE') {
380
    $doLink = TRUE;
381
  }
382
  if ($mediaLinkType == 'LIGHTBOX') {
383
    $doLink = TRUE;
384
    _add_js_lightbox($galleryID);
385
  }
386

    
387
  // Render the media gallery grid.
388
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
389
  $out .= '<colgroup>';
390
  for ($c = 0; $c < $cols; $c++) {
391
    $out .= '<col style="width:' . (100 / $cols) . '%;">';
392
  }
393
  $out .= '</colgroup>';
394

    
395
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
396
    $captionParts = array();
397
    $mediaIndex = 0;
398
    $out .= '<tr>';
399
    for ($c = 0; $c < $cols; $c++) {
400
      $media = array_shift($mediaList);
401

    
402
      if (isset($media->representations[0]->parts[0])) {
403

    
404
        //
405
        // Find preferred representation.
406
        //
407
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
408
          'image/jpg',
409
          'image/jpeg',
410
          'image/png',
411
          'image/gif',
412
        ), $maxExtend, $maxExtend);
413
        if (count($preferred_media_representations_list) == 0) {
414
          // Fallback to using the first one in the list.
415
          $preferred_media_representations_list = $media->representations;
416
        }
417
        $preferred_media_representation = array_shift($preferred_media_representations_list);
418

    
419
        // $preferred_media_representation->parts[0]->uri =
420
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
421
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
422

    
423
         $mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
424
            'mediaRepresentationPart' => $preferred_media_representation->parts[0],
425
            'maxExtend' => $maxExtend,
426
            'addPassePartout' => TRUE,
427
         ));
428
        // --- Compose Media Link.
429
        $mediaLinkUri = FALSE;
430
        if ($alternativeMediaUri) {
431
          if (isset($alternativeMediaUri[$mediaIndex])) {
432
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
433
          }
434
          if (is_string($alternativeMediaUri)) {
435
            $mediaLinkUri = $alternativeMediaUri;
436
          }
437
        }
438
        else {
439
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
440
        }
441
        $mediaIndex++;
442

    
443
        // media captions will be loaded via AHAH
444
        _add_js_ahah();
445
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
446
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
447
        $ahah_media_caption =  '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
448
          . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
449

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

    
463
        // --- preparing the media caption
464

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

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

    
490
        $captionParts[] = $captionPartHtml;
491

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

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

    
537
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
538
  $maxExtend = $variables['maxExtend'];
539
  $addPassePartout = $variables['addPassePartout'];
540
  $attributes = $variables['attributes'];
541

    
542
  $out = '';
543

    
544
  // TODO merge with theme_cdm_media_mime_image?
545
  if (isset($mediaRepresentationPart)) {
546

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

    
574
    // Turn attributes array into string.
575
    if(!is_array($attributes)){
576
      $attributes = array();
577
    }
578
    if(!isset($attributes['alt'])){
579
      $attributes['alt'] = check_plain($mediaRepresentationPart->uri);
580
    }
581
    $attrStr = ' ';
582
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
583
    if (is_array($attributes)) {
584
      foreach ($attributes as $name => $value) {
585
        $attrStr .= $name . '="' . $value . '" ';
586
      }
587
    }
588

    
589
    if ($addPassePartout) {
590
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
591
    }
592
    else {
593
      // Do not add margins if no pass partout is shown.
594
      $margins = '';
595
    }
596
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
597

    
598
    if ($addPassePartout) {
599
      $out .= '</div>';
600
    }
601
    return $out;
602
  }
603
}
604

    
605
/**
606
 * @todo Please document this function.
607
 * @see http://drupal.org/node/1354
608
 */
609
function theme_cdm_media_gallerie_application($variables) {
610
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
611
  $maxExtend = $variables['maxExtend'];
612
  $addPassePartout = $variables['addPassePartout'];
613
  $attributes = $variables['attributes'];
614
  $out = '';
615
  if (isset($mediaRepresentationPart)) {
616

    
617
    if ($addPassePartout) {
618
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
619
    }
620
    else {
621
      // Do not add margins if no pass partout is shown.
622
      $margins = '';
623
    }
624
    $out .= '<div class="appication">Web Application</div>';
625

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

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

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

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

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

    
678
  _add_js_openlayers();
679

    
680
  // TODO merge code below with code from theme_cdm_media_gallerie_image
681
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
682
  // TODO merge code below with code from theme_cdm_media_gallerie_image
683
  $w = $mediaRepresentationPart->width;
684
  $h = $mediaRepresentationPart->height;
685

    
686
  if ($w == 0 || $h == 0) {
687
    // Take url and replace spaces.
688
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
689
    $imageDimensions = getimagesize_remote($image_uri);
690
    if (!$imageDimensions) {
691
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
692
    }
693
    $w = $imageDimensions[0];
694
    $h = $imageDimensions[1];
695
  }
696

    
697
  // Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
698
  if ($w > $h) {
699
    $lat = 90;
700
    $lon = 90 * ($h / $w);
701
    $maxRes = $w / $maxExtend;
702
  }
703
  else {
704
    $lat = 90 * ($w / $h);
705
    $lon = 90;
706
    $maxRes = $h / $maxExtend;
707
  }
708

    
709
  $maxRes *= 1;
710
  drupal_add_js('
711
 var map;
712

    
713
 var imageLayerOptions={
714
     maxResolution: ' . $maxRes . ',
715
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
716
  };
717
  var mapOptions={
718
      controls:
719
       [
720
         new OpenLayers.Control.PanZoom(),
721
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
722
       ],
723
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
724
  };
725

    
726
 var graphic = new OpenLayers.Layer.Image(
727
          \'Image Title\',
728
          \'' . $mediaRepresentationPart->uri . '\',
729
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
730
          new OpenLayers.Size(' . $w . ', ' . $h . '),
731
          imageLayerOptions
732
          );
733

    
734
 function init() {
735
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
736
   map.addLayers([graphic]);
737
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
738
   map.zoomToMaxExtent();
739
 }
740

    
741
jQuery(document).ready(function(){
742
  init();
743
});', array('type' => 'inline'));
744
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
745
  return $out;
746
}
747

    
(3-3/9)