Project

General

Profile

Download (24.6 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 2fe78f3c Andreas Kohlbecker
  $response = cdm_http_request($image_url);
35
  $contents = NULL;
36
  if (isset($response->data)) {
37
    $contents = $response->data;
38
  } else {
39 6657531f Andreas Kohlbecker
    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 275b2642 Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
66 275b2642 Andreas Kohlbecker
function cdm_description_element_media($descriptionElement, $mimeTypePreference) {
67
68 6657531f Andreas Kohlbecker
  $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 275b2642 Andreas Kohlbecker
      // 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 6657531f Andreas Kohlbecker
    }
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 ca7fa7da Andreas Kohlbecker
    $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
112 6657531f Andreas Kohlbecker
      'attributes' => $attributes,
113
      'absolute' => TRUE,
114
      'html' => TRUE,
115
    ));
116
  }
117
  return $out;
118
}
119
120 90fe4c79 Andreas Kohlbecker
121 6657531f Andreas Kohlbecker
/**
122 90fe4c79 Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
131
function theme_cdm_media_mime_image($variables) {
132 90fe4c79 Andreas Kohlbecker
  $media_representation = $variables['mediaRepresentation'];
133 6657531f Andreas Kohlbecker
  $feature = $variables['feature'];
134
  $out = '';
135
  // TODO thickbox is not used anymore -> delete?
136
  $attributes = array(
137
    'class' => 'thickbox',
138 90fe4c79 Andreas Kohlbecker
    'rel' => 'representation-' . $media_representation->uuid,
139 6657531f Andreas Kohlbecker
    'title' => $feature->representation_L10n,
140
  );
141 90fe4c79 Andreas Kohlbecker
  for ($i = 0; $part = $media_representation->parts[$i]; $i++) {
142 6657531f Andreas Kohlbecker
    if ($i == 0) {
143 ca7fa7da Andreas Kohlbecker
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
144 6657531f Andreas Kohlbecker
        'attributes' => $attributes,
145
        'absolute' => TRUE,
146
        'html' => TRUE,
147
      ));
148
    }
149
    else {
150 7cc085da Andreas Kohlbecker
      $out .= l('', $part->uri, array(
151 6657531f Andreas Kohlbecker
        '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 ca7fa7da Andreas Kohlbecker
  $representation = $variables['mediaRepresentation'];
165 6657531f Andreas Kohlbecker
  $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 ca7fa7da Andreas Kohlbecker
      $out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
176 6657531f Andreas Kohlbecker
        'attributes' => $attributes,
177
        'absolute' => TRUE,
178
        'html' => TRUE,
179
      ));
180
    }
181
  }
182
  return $out;
183
}
184
185 7a2a14b3 Andreas Kohlbecker
186 6657531f Andreas Kohlbecker
/**
187 7a2a14b3 Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
202
function theme_cdm_media_caption($variables) {
203
  $media = $variables['media'];
204
  $elements = $variables['elements'];
205 97ff635c Andreas Kohlbecker
  $media_metadata = read_media_metadata($media);
206 6657531f Andreas Kohlbecker
207
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
208
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
209
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
210
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
211
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
212
213
  $descriptionPrefix = "";
214
215
  $out = '<dl class="media-caption">';
216
  // Title.
217
  if ($doTitle) {
218
    if ($media_metadata['title']) {
219
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
220
      $descriptionPrefix = "- ";
221
    }
222
    elseif (!($doDescription && $media_metadata['description'])) {
223 97ff635c Andreas Kohlbecker
      // Use filename as fallback option if no description will be shown.
224 6657531f Andreas Kohlbecker
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
225
      $descriptionPrefix = "- ";
226
    }
227
  }
228
  // Description.
229
  if ($media_metadata['description'] && $doDescription) {
230
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
231
  }
232
  // Artist.
233
  if ($media_metadata['artist'] && $doArtist) {
234
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
235
  }
236
  // Location.
237
  if ($doLocation) {
238
    $location = '';
239
    $location .= $media_metadata['location']['sublocation'];
240
    if ($location && $media_metadata['location']['city']) {
241
      $location .= ', ';
242
    }
243
    $location .= $media_metadata['location']['city'];
244
    if ($location && $media_metadata['location']['province']) {
245
      $location .= ', ';
246
    }
247
    $location .= $media_metadata['location']['province'];
248
    if ($location && $media_metadata['location']['country']) {
249
      $location .= ' (' . $media_metadata['location']['country'] . ')';
250
    }
251
    else {
252
      $location .= $media_metadata['location']['country'];
253
    }
254
    if ($location) {
255
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
256
    }
257
  }
258
  // Rights.
259
  if ($doRights) {
260
    $rights = '';
261 eeb98da8 Andreas Kohlbecker
    // TODO use cdm_rights_as_dl_groups() to create dl entries
262 6657531f Andreas Kohlbecker
263
    // Copyrights.
264
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
265
    if ($cnt > 0) {
266
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
267
      for ($i = 0; $i < $cnt; $i++) {
268
        $rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
269
        if ($i + 1 < $cnt) {
270
          $rights .= ' / ';
271
        }
272
      }
273
      $rights .= '</dd>';
274
    }
275
    // License.
276
    $cnt = count($media_metadata['rights']['license']['agentNames']);
277
    if ($cnt > 0) {
278
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
279
      for ($i = 0; $i < $cnt; $i++) {
280
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
281
        if ($i + 1 < $cnt) {
282
          $rights .= ' / ';
283
        }
284
      }
285
      $rights .= '</dd>';
286
    }
287
    if ($rights) {
288
      $out .= $rights . '</dt>';
289
    }
290
  }
291 97ff635c Andreas Kohlbecker
  // TODO add all other metadata elements generically.
292 6657531f Andreas Kohlbecker
  $out .= '</dl>';
293
  // Return value,
294
  return $out;
295
}
296
297
/**
298
 * Return HTML for a media gallery
299
 *
300
 * @param array $variables
301
 *   An associative array containing:
302
 *   - mediaList: An array of Media entities.
303
 *   - maxExtend
304
 *   - cols
305
 *   - maxRows
306 7a2a14b3 Andreas Kohlbecker
 *   - showCaption:  boolean value, whether to show captions or not.
307
 *   - captionElements: An array of caption elements to be shown. In case the array
308
 *        is empty of NULL  all available caption elements will be show. In order to
309
 *        supress all captions  set 'showCaption' to FALSE
310
 *        example:
311
 *          1) Show 'title', 'description', 'file', 'filename' in the caption:
312
 *            array('title', 'description', 'file', 'filename'),
313
 *          2) To add an addtional link at the bottom of  the caption:
314
 *            array('titlecache', '#uri'=>t('open Image')) this will cause a link
315 b24e7b04 Andreas Kohlbecker
 *            to be rendered with label 'open Image' which will open the according
316 7a2a14b3 Andreas Kohlbecker
 *            media object.
317 6657531f Andreas Kohlbecker
 *   - mediaLinkType: Valid values:
318
 *      - "NONE": do not link the images,
319
 *      - "LIGHTBOX": open the link in a light box,
320
 *      - "NORMAL": link to the image page or to the $alternativeMediaUri if
321
 *        it is defined.
322 7cf177d0 Patrick Plitzner
 *   - alternativeMediaUri: A fix string or an array of alternative URIs to link the images
323 6657531f Andreas Kohlbecker
 *     which will overwrite the URIs of the media parts.
324
 *     The order of URI in this array must correspond with the order of
325
 *     images in $mediaList.
326
 *   - galleryLinkUri: An URI to link the the hint on more images to;
327
 *     if NULL no link is created.
328
 *
329 216abf0b Patric Plitzner
 * @return the image gallery HTML
330 6657531f Andreas Kohlbecker
 * @ingroup: themeable
331
 */
332
function theme_cdm_media_gallerie($variables) {
333
334
  $mediaList = $variables['mediaList'];
335
336
  // Do not show an empty gallery.
337
  if (count($mediaList) == 0) {
338
    return;
339
  }
340
341
  $galleryName = $variables['galleryName'];
342
  $maxExtend = $variables['maxExtend'];
343
  $cols = $variables['cols'];
344
  $maxRows = $variables['maxRows'];
345
  $captionElements = $variables['captionElements'];
346
  $mediaLinkType = $variables['mediaLinkType'];
347
  $alternativeMediaUri = $variables['alternativeMediaUri'];
348
  $galleryLinkUri = $variables['galleryLinkUri'];
349
  $showCaption = $variables['showCaption'];
350 7a2a14b3 Andreas Kohlbecker
351
  $caption_link_uri = '';
352
  if(isset($captionElements['#uri'])){
353
    $caption_link_uri = $captionElements['#uri'];
354
    unset($captionElements['#uri']);
355
  }
356
  if (!is_array($captionElements) || count($captionElements) == 0) {
357
    $captionElements = NULL;
358 6657531f Andreas Kohlbecker
  }
359
360
  // TODO correctly handle multiple media representation parts
361
  $_SESSION['cdm']['last_gallery'] = current_path();
362
  // Prevent from errors.
363
  if (!isset($mediaList[0])) {
364
   // return;
365
  }
366
367
  // --- Duplicate supression: media can be reused but should only be shown
368
  // once.
369
  $tempMediaList = array();
370
  $tempMediaUuids = array();
371
  foreach ($mediaList as $media) {
372
    if (!in_array($media->uuid, $tempMediaUuids)) {
373
      $tempMediaList[] = $media;
374
      $tempMediaUuids[] = $media->uuid;
375
    }
376
  }
377
  $mediaList = $tempMediaList;
378
379
  // ---
380
  $galleryID = "media_gallery_" . $galleryName;
381
382
  $mediaPartLinkAttributes = array();
383
  $openMediaLinkAttributes = array();
384
385
  // Prepare media links.
386
  $doLink = FALSE;
387
  if ($mediaLinkType != 'NONE') {
388
    $doLink = TRUE;
389
  }
390
  if ($mediaLinkType == 'LIGHTBOX') {
391
    $doLink = TRUE;
392
    _add_js_lightbox($galleryID);
393
  }
394
395
  // Render the media gallery grid.
396
  $out = '<table id="' . $galleryID . '" class="media_gallery">';
397
  $out .= '<colgroup>';
398
  for ($c = 0; $c < $cols; $c++) {
399 cbc77aa9 Andreas Kohlbecker
    $out .= '<col style="width:' . (100 / $cols) . '%;">';
400 6657531f Andreas Kohlbecker
  }
401
  $out .= '</colgroup>';
402
403
  for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
404
    $captionParts = array();
405
    $mediaIndex = 0;
406
    $out .= '<tr>';
407
    for ($c = 0; $c < $cols; $c++) {
408
      $media = array_shift($mediaList);
409
410
      if (isset($media->representations[0]->parts[0])) {
411
412
        //
413
        // Find preferred representation.
414
        //
415
        $preferred_media_representations_list = cdm_preferred_media_representations($media, array(
416
          'image/jpg',
417
          'image/jpeg',
418
          'image/png',
419
          'image/gif',
420
        ), $maxExtend, $maxExtend);
421
        if (count($preferred_media_representations_list) == 0) {
422
          // Fallback to using the first one in the list.
423
          $preferred_media_representations_list = $media->representations;
424
        }
425
        $preferred_media_representation = array_shift($preferred_media_representations_list);
426
427
        // $preferred_media_representation->parts[0]->uri =
428
        // "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
429
        $contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
430
431
         $mediaPartHtml = theme('cdm_media_gallerie_' . $contentTypeDirectory, array(
432
            'mediaRepresentationPart' => $preferred_media_representation->parts[0],
433
            'maxExtend' => $maxExtend,
434
            'addPassePartout' => TRUE,
435
         ));
436
        // --- Compose Media Link.
437
        $mediaLinkUri = FALSE;
438
        if ($alternativeMediaUri) {
439
          if (isset($alternativeMediaUri[$mediaIndex])) {
440
            $mediaLinkUri = $alternativeMediaUri[$mediaIndex];
441
          }
442
          if (is_string($alternativeMediaUri)) {
443
            $mediaLinkUri = $alternativeMediaUri;
444
          }
445
        }
446
        else {
447
          $mediaLinkUri = $preferred_media_representation->parts[0]->uri;
448
        }
449 7cf177d0 Patrick Plitzner
        $mediaIndex++;
450 6657531f Andreas Kohlbecker
451 7a2a14b3 Andreas Kohlbecker
        // media captions will be loaded via AHAH
452 6657531f Andreas Kohlbecker
        _add_js_ahah();
453
        $content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
454 7a2a14b3 Andreas Kohlbecker
        $cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
455 b386ae48 Andreas Kohlbecker
        $ahah_media_caption =  '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
456 94550ff9 Andreas Kohlbecker
          . '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
457 6657531f Andreas Kohlbecker
458 7a2a14b3 Andreas Kohlbecker
        // preparing the part link (= click on image iteself) which can be handled in two ways
459
        //
460
        //  1. open image in lightbox, the captions in the lighhtbox will be loaded via AHAH
461
        //  2. open the media in a new window with target 'specimen'
462 6657531f Andreas Kohlbecker
        if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
463
          $mediaPartLinkAttributes['class'] = array('lightbox');
464
        }
465
        else {
466
          $mediaPartLinkAttributes['target'] = "specimen";
467
          $openMediaLinkAttributes['target'] = "specimen";
468
        }
469 cbc77aa9 Andreas Kohlbecker
        $mediaPartLinkAttributes['alt'] = htmlentities($ahah_media_caption);
470 6657531f Andreas Kohlbecker
471 94550ff9 Andreas Kohlbecker
        // --- preparing the media caption
472
473
        /* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
474
         *
475
         * a.kohlbecker 2013-03-14 :
476
         *   It is unclear why no caption elements should be shown, Was it a technical reason?
477
         *   see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
478
         *   If not problems arise with this remove it after some weeks
479
         */
480
        $captionPartHtml = $ahah_media_caption;
481 6657531f Andreas Kohlbecker
482 7a2a14b3 Andreas Kohlbecker
        if ($caption_link_uri) {
483 6657531f Andreas Kohlbecker
          if ($contentTypeDirectory == 'image') {
484 7a2a14b3 Andreas Kohlbecker
          // it is an image, so open it in the media page
485
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
486 6657531f Andreas Kohlbecker
              'attributes' => array(), 'html' => TRUE,
487
            )) . '</div>';
488
          }
489
          else {
490 7a2a14b3 Andreas Kohlbecker
            // otherwise open it directly and let the the browser handle the media type
491 6657531f Andreas Kohlbecker
            $openMediaLinkAttributes['absolute'] = TRUE;
492 7a2a14b3 Andreas Kohlbecker
            $captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
493 6657531f Andreas Kohlbecker
              'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
494
            )) . '</div>';
495
          }
496
        }
497 7a2a14b3 Andreas Kohlbecker
498 6657531f Andreas Kohlbecker
        $captionParts[] = $captionPartHtml;
499
500 7a2a14b3 Andreas Kohlbecker
        // --- Surround imagePart with link, this .
501 6657531f Andreas Kohlbecker
        if ($doLink) {
502
          $mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
503
            'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
504
          ));
505
        }
506
      }
507
      else {
508
        $mediaPartHtml = '';
509
        $captionParts[] = '';
510
      }
511
      $out .= '<td class="media">' . $mediaPartHtml . '</td>';
512
    }
513
    $out .= '</tr>'; // End of media parts.
514
    if ($showCaption) {
515 7a2a14b3 Andreas Kohlbecker
      if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
516 6657531f Andreas Kohlbecker
        $out .= '<tr>';
517
        // Add caption row.
518
        foreach ($captionParts as $captionPartHtml) {
519
          $out .= '<td class="caption">' . $captionPartHtml . '</td>';
520
        }
521
        $out .= '</tr>';
522
      }
523
    }
524
  }
525
526
  if ($galleryLinkUri) {
527
    if (count($mediaList) > 0) {
528
      $moreHtml = count($mediaList) . ' ' . t('more in gallery');
529
    }
530
    else {
531
      $moreHtml = t('open gallery');
532
    }
533
    $moreHtml = l($moreHtml, $galleryLinkUri);
534
    $out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
535
  }
536
  $out .= '</table>';
537
  return $out;
538
}
539
/**
540
 * @todo Please document this function.
541
 * @see http://drupal.org/node/1354
542
 */
543
function theme_cdm_media_gallerie_image($variables) {
544
545
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
546
  $maxExtend = $variables['maxExtend'];
547
  $addPassePartout = $variables['addPassePartout'];
548
  $attributes = $variables['attributes'];
549
550
  $out = '';
551
552
  // TODO merge with theme_cdm_media_mime_image?
553
  if (isset($mediaRepresentationPart)) {
554
555
    $h = $mediaRepresentationPart->height;
556
    $w = $mediaRepresentationPart->width;
557
    if ($w == 0 || $h == 0) {
558
      // Take url and replace spaces.
559
      $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
560
      $imageDimensions = getimagesize_remote($image_uri);
561
      if (!$imageDimensions) {
562
        return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
563
      }
564
      $w = $imageDimensions[0];
565
      $h = $imageDimensions[1];
566
    }
567
    $margins = '0 0 0 0';
568
    $ratio = $w / $h;
569
    if ($ratio > 1) {
570
      $displayHeight = round($maxExtend / $ratio);
571
      $displayWidth = $maxExtend;
572
      $m = round(($maxExtend - $displayHeight) / 2);
573
      $margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
574
    }
575
    else {
576
      $displayHeight = $maxExtend;
577
      $displayWidth = round($maxExtend * $ratio);
578
      $m = round(($maxExtend - $displayWidth) / 2);
579
      $margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
580
    }
581
582
    // Turn attributes array into string.
583 c323bdb8 Andreas Kohlbecker
    if(!is_array($attributes)){
584
      $attributes = array();
585
    }
586
    if(!isset($attributes['alt'])){
587
      $attributes['alt'] = check_plain($mediaRepresentationPart->uri);
588
    }
589 6657531f Andreas Kohlbecker
    $attrStr = ' ';
590
    // $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
591
    if (is_array($attributes)) {
592
      foreach ($attributes as $name => $value) {
593
        $attrStr .= $name . '="' . $value . '" ';
594
      }
595
    }
596
597
    if ($addPassePartout) {
598
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
599
    }
600
    else {
601
      // Do not add margins if no pass partout is shown.
602
      $margins = '';
603
    }
604 c323bdb8 Andreas Kohlbecker
    $out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
605 6657531f Andreas Kohlbecker
606
    if ($addPassePartout) {
607
      $out .= '</div>';
608
    }
609
    return $out;
610
  }
611
}
612
613
/**
614
 * @todo Please document this function.
615
 * @see http://drupal.org/node/1354
616
 */
617
function theme_cdm_media_gallerie_application($variables) {
618
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
619
  $maxExtend = $variables['maxExtend'];
620
  $addPassePartout = $variables['addPassePartout'];
621
  $attributes = $variables['attributes'];
622 e9cdb58f Andreas Kohlbecker
  $out = '';
623 6657531f Andreas Kohlbecker
  if (isset($mediaRepresentationPart)) {
624
625
    if ($addPassePartout) {
626
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
627
    }
628
    else {
629
      // Do not add margins if no pass partout is shown.
630
      $margins = '';
631
    }
632
    $out .= '<div class="appication">Web Application</div>';
633
634
    if ($addPassePartout) {
635
      $out .= '</div>';
636
    }
637
    return $out;
638
  }
639
}
640
641
/**
642
 * @todo Please document this function.
643
 * @see http://drupal.org/node/1354
644
 */
645
function theme_cdm_media_gallerie_text($variables) {
646
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
647
  $maxExtend = $variables['maxExtend'];
648
  $addPassePartout = $variables['addPassePartout'];
649
  $attributes = $variables['attributes'];
650
  if (isset($mediaRepresentationPart)) {
651
652
    if ($addPassePartout) {
653
      $out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
654
    }
655
    else {
656
      // Do not add margins if no pass partout is shown.
657
      $margins = '';
658
    }
659 97ff635c Andreas Kohlbecker
    $out .= '<div class="application">Web Application</div>';
660 6657531f Andreas Kohlbecker
661
    if ($addPassePartout) {
662
      $out .= '</div>';
663
    }
664
    return $out;
665
  }
666
}
667
668
/**
669 4830dfc9 Andreas Kohlbecker
 * Adds the OpenLayers based image viewer to the page.
670
 *
671
 * The OpenLayers based image viewer allows to zoom and pan the displayed image.
672
 *
673
 * Documentation related to using Openlayers in order to view images is found here:
674
 *  - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
675
 *  - @see http://trac.openlayers.org/wiki/SettingZoomLevels
676
 *
677
 * @param array $variables
678
 *   An associative array of theme variables:
679
 *   - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
680
 *   - maxExtend: The maximum extend of the image viewer view port.
681 6657531f Andreas Kohlbecker
 */
682
function theme_cdm_openlayers_image($variables) {
683
  $mediaRepresentationPart = $variables['mediaRepresentationPart'];
684
  $maxExtend = $variables['maxExtend'];
685
686 4830dfc9 Andreas Kohlbecker
  _add_js_openlayers();
687 6657531f Andreas Kohlbecker
688
  // TODO merge code below with code from theme_cdm_media_gallerie_image
689
  // var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
690
  // TODO merge code below with code from theme_cdm_media_gallerie_image
691
  $w = $mediaRepresentationPart->width;
692
  $h = $mediaRepresentationPart->height;
693
694
  if ($w == 0 || $h == 0) {
695
    // Take url and replace spaces.
696
    $image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
697
    $imageDimensions = getimagesize_remote($image_uri);
698
    if (!$imageDimensions) {
699
      return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
700
    }
701
    $w = $imageDimensions[0];
702
    $h = $imageDimensions[1];
703
  }
704
705
  // Calculate maxResolution (default is 360 deg / 256 px) and the bounds.
706
  if ($w > $h) {
707
    $lat = 90;
708
    $lon = 90 * ($h / $w);
709
    $maxRes = $w / $maxExtend;
710
  }
711
  else {
712
    $lat = 90 * ($w / $h);
713
    $lon = 90;
714
    $maxRes = $h / $maxExtend;
715
  }
716
717
  $maxRes *= 1;
718
  drupal_add_js('
719
 var map;
720
721
 var imageLayerOptions={
722
     maxResolution: ' . $maxRes . ',
723
     maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
724
  };
725
  var mapOptions={
726
      controls:
727
       [
728
         new OpenLayers.Control.PanZoom(),
729
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
730
       ],
731
     restrictedExtent:  new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
732
  };
733
734
 var graphic = new OpenLayers.Layer.Image(
735
          \'Image Title\',
736
          \'' . $mediaRepresentationPart->uri . '\',
737
          new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
738
          new OpenLayers.Size(' . $w . ', ' . $h . '),
739
          imageLayerOptions
740
          );
741
742
 function init() {
743
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
744
   map.addLayers([graphic]);
745
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
746
   map.zoomToMaxExtent();
747
 }
748
749
jQuery(document).ready(function(){
750
  init();
751
});', array('type' => 'inline'));
752
  $out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
753
  return $out;
754
}