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