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
      // Comment @WA: should this really be an empty link?
136
      $out .= l(t(''), $part->uri, array(
137
        'attributes' => $attributes,
138
        'absolute' => TRUE,
139
      ));
140
    }
141
  }
142
  return $out;
143
}
144

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

    
171

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

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

    
199
  $descriptionPrefix = "";
200

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
457
        // --- preparing the media caption
458

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

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

    
484
        $captionParts[] = $captionPartHtml;
485

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

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

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

    
536
  $out = '';
537

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

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

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

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

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

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

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

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

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

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

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

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

    
672
  _add_js_openlayers();
673

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

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

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

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

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

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

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

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

    
(3-3/9)