1 |
eeb98da8
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Functions for dealing with CDM entities of type SpeciemenOrOccurrences
|
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 |
|
|
* @author
|
16 |
|
|
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Returns an array of render array entries for a HTML description list.
|
21 |
|
|
*
|
22 |
|
|
* @see theme_description_list()
|
23 |
|
|
*
|
24 |
|
|
* @param array $rights_list
|
25 |
ca7fa7da
|
Andreas Kohlbecker
|
* array of CDM Rights entities
|
26 |
|
|
*
|
27 |
|
|
* @return array
|
28 |
|
|
* the render array of the groups for the HTML description list
|
29 |
eeb98da8
|
Andreas Kohlbecker
|
*/
|
30 |
|
|
function cdm_rights_as_dl_groups($rights_list) {
|
31 |
|
|
$copyrights = array();
|
32 |
daef68e9
|
Andreas Kohlbecker
|
|
33 |
eeb98da8
|
Andreas Kohlbecker
|
$licenses = array();
|
34 |
|
|
$access_rights = array();
|
35 |
|
|
$unknown = array();
|
36 |
|
|
|
37 |
|
|
foreach ($rights_list as $right) {
|
38 |
ca7fa7da
|
Andreas Kohlbecker
|
if (!is_object($right)) {
|
39 |
eeb98da8
|
Andreas Kohlbecker
|
continue;
|
40 |
|
|
}
|
41 |
|
|
$type_uuid = isset($right->type->uuid) ? $right->type->uuid : 'UNKNOWN';
|
42 |
|
|
switch ($type_uuid) {
|
43 |
|
|
|
44 |
|
|
case UUID_RIGHTS_COPYRIGHT:
|
45 |
daef68e9
|
Andreas Kohlbecker
|
$text = '';
|
46 |
|
|
if (isset($right->text) ){
|
47 |
|
|
// sanitize potential '(c)' away
|
48 |
|
|
$text = preg_replace('/^\(c\)/', '', $right->text);
|
49 |
|
|
} if (isset($right->agent) ){
|
50 |
7a7b09d4
|
Andreas Kohlbecker
|
$text .= (strlen($text) > 0 ? ', ' : '') . $right->agent->titleCache;
|
51 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
52 |
daef68e9
|
Andreas Kohlbecker
|
|
53 |
|
|
$copyrights[] = array('#markup' => '© ' . $text);
|
54 |
eeb98da8
|
Andreas Kohlbecker
|
break;
|
55 |
|
|
|
56 |
|
|
case UUID_RIGHTS_LICENCE:
|
57 |
|
|
$license_str = '';
|
58 |
|
|
if (isset($right->abbreviatedText)) {
|
59 |
|
|
$license_str .= $right->abbreviatedText;
|
60 |
|
|
}
|
61 |
|
|
if (isset($right->uri)) {
|
62 |
|
|
if (strlen($license_str) > 0) {
|
63 |
|
|
$license_str = l($license_str, $right->uri);
|
64 |
ca7fa7da
|
Andreas Kohlbecker
|
}
|
65 |
|
|
else {
|
66 |
|
|
$license_str = l(t('link'), $right->uri);
|
67 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
68 |
|
|
}
|
69 |
|
|
if (strlen($license_str) > 0 && isset($right->text)) {
|
70 |
|
|
$license_str .= ': ' . $right->text;
|
71 |
|
|
}
|
72 |
daef68e9
|
Andreas Kohlbecker
|
$licenses[] = array('#markup' => $license_str);
|
73 |
eeb98da8
|
Andreas Kohlbecker
|
break;
|
74 |
|
|
|
75 |
|
|
case UUID_RIGHTS_ACCESS_RIGHTS:
|
76 |
daef68e9
|
Andreas Kohlbecker
|
$access_rights[] = array('#markup' => $right->text);
|
77 |
eeb98da8
|
Andreas Kohlbecker
|
break;
|
78 |
|
|
|
79 |
|
|
default:
|
80 |
daef68e9
|
Andreas Kohlbecker
|
$unknown_groups[] = array('#markup' => $right->text);
|
81 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
$groups = array();
|
85 |
ca7fa7da
|
Andreas Kohlbecker
|
if (count($copyrights) > 0) {
|
86 |
daef68e9
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Copyright') . ':', $copyrights);
|
87 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
88 |
ca7fa7da
|
Andreas Kohlbecker
|
if (count($licenses) > 0) {
|
89 |
daef68e9
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Licenses') . ':', $licenses);
|
90 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
91 |
ca7fa7da
|
Andreas Kohlbecker
|
if (count($access_rights) > 0) {
|
92 |
daef68e9
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Access rights') . ':', $access_rights);
|
93 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
94 |
ca7fa7da
|
Andreas Kohlbecker
|
if (count($unknown) > 0) {
|
95 |
daef68e9
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Rights') . ':', $unknown);
|
96 |
eeb98da8
|
Andreas Kohlbecker
|
}
|
97 |
|
|
|
98 |
|
|
return $groups;
|
99 |
|
|
|
100 |
ca7fa7da
|
Andreas Kohlbecker
|
}
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Provides the markup for an icon to represent a media which is associated with the given $feature.
|
105 |
|
|
*
|
106 |
|
|
* @param $feature
|
107 |
|
|
* the cdm Feature term
|
108 |
|
|
* @param $media_url
|
109 |
|
|
* Optional, currently unused. May be used in future to display different
|
110 |
|
|
* icons for different media urls, like the fav-icon of the referenced
|
111 |
|
|
* @return string
|
112 |
|
|
* The markup for the icon
|
113 |
|
|
*/
|
114 |
|
|
function media_feature_icon($feature, $media_url = NULL) {
|
115 |
|
|
return font_awesome_icon_markup('fa-book', array('alt' => $feature->representation_L10n));
|
116 |
97ff635c
|
Andreas Kohlbecker
|
}
|
117 |
|
|
|
118 |
|
|
/**
|
119 |
0c2b9b9d
|
Andreas Kohlbecker
|
* Gets the metadata info such as title or artist and source references of a media file.
|
120 |
97ff635c
|
Andreas Kohlbecker
|
*
|
121 |
|
|
* The function tries at first to get all the info from the file metadata
|
122 |
|
|
* and if it is not available look at the media file info stored at the database.
|
123 |
|
|
*
|
124 |
|
|
* @param mixed $media
|
125 |
|
|
* The media file object for which to get the metadata.
|
126 |
|
|
*
|
127 |
|
|
* @return array
|
128 |
|
|
* The array with the available specified metadata info.
|
129 |
|
|
*/
|
130 |
|
|
function read_media_metadata($media) {
|
131 |
|
|
|
132 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata = array(
|
133 |
97ff635c
|
Andreas Kohlbecker
|
'title' => '',// Media_metadata and media.
|
134 |
|
|
'artist' => '',// Media_metadata and media.
|
135 |
|
|
'rights',// Media_metadata and media.
|
136 |
|
|
'location',// Media_metadata.
|
137 |
|
|
'filename' => '',// Media.
|
138 |
0c2b9b9d
|
Andreas Kohlbecker
|
'mediacreated' => '', // Media.
|
139 |
|
|
'description' => ''
|
140 |
|
|
);
|
141 |
97ff635c
|
Andreas Kohlbecker
|
|
142 |
|
|
// Getting the media metadata.
|
143 |
|
|
$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
|
144 |
|
|
$media_metadata_aux = (array) $media_metadata;
|
145 |
|
|
|
146 |
0c2b9b9d
|
Andreas Kohlbecker
|
|
147 |
97ff635c
|
Andreas Kohlbecker
|
// Filename.
|
148 |
|
|
if (!empty($media->representations[0]->parts[0]->uri)) {
|
149 |
|
|
$fileUri = $media->representations[0]->parts[0]->uri;
|
150 |
|
|
$filename = substr($fileUri, strrpos($fileUri, "/") + 1);
|
151 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['filename'] = $filename;
|
152 |
97ff635c
|
Andreas Kohlbecker
|
}
|
153 |
|
|
else {
|
154 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['filename'] = '';
|
155 |
97ff635c
|
Andreas Kohlbecker
|
}
|
156 |
|
|
|
157 |
|
|
// Title.
|
158 |
128e8a65
|
Andreas Kohlbecker
|
if (!empty($media->title_L10n)) {
|
159 |
|
|
$metadata['title'] = $media->title_L10n;
|
160 |
|
|
} else if ($media->protectedTitleCache && !empty($media->titleCache)) {
|
161 |
|
|
$metadata['title'] = $media->titleCache;
|
162 |
|
|
} else if (!empty($media_metadata->ObjectName)) {
|
163 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['title'] = $media_metadata->ObjectName;
|
164 |
128e8a65
|
Andreas Kohlbecker
|
} else if (!empty($media_metadata_aux['Object Name'])) {
|
165 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['title'] = $media_metadata_aux['Object Name'];
|
166 |
128e8a65
|
Andreas Kohlbecker
|
} else if (!empty($media->titleCache)) {
|
167 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['title'] = $media->titleCache;
|
168 |
97ff635c
|
Andreas Kohlbecker
|
}
|
169 |
|
|
|
170 |
7a7b09d4
|
Andreas Kohlbecker
|
if(!empty($media->description_L10n)){
|
171 |
|
|
$metadata['description'] = $media->description_L10n;
|
172 |
|
|
}
|
173 |
97ff635c
|
Andreas Kohlbecker
|
|
174 |
|
|
// Artist.
|
175 |
|
|
if (!empty($media_metadata->Artist)) {
|
176 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['artist'] = '' . $media_metadata->Artist;
|
177 |
97ff635c
|
Andreas Kohlbecker
|
}
|
178 |
|
|
elseif (!empty($media->artist->titleCache)) {
|
179 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['artist'] = $media->artist->titleCache;
|
180 |
97ff635c
|
Andreas Kohlbecker
|
}
|
181 |
|
|
|
182 |
daef68e9
|
Andreas Kohlbecker
|
// Rights
|
183 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['rights'] = array();
|
184 |
97ff635c
|
Andreas Kohlbecker
|
if (!empty($media_metadata->Copyright)) {
|
185 |
daef68e9
|
Andreas Kohlbecker
|
$rightsObj = new stdClass();
|
186 |
|
|
$rightsObj->type = new stdClass();
|
187 |
|
|
$rightsObj->type->uuid = UUID_RIGHTS_COPYRIGHT;
|
188 |
|
|
$rightsObj->type->titleCache = 'copyright';
|
189 |
|
|
$rightsObj->type->representation_L10n = 'copyright';
|
190 |
|
|
$rightsObj->type->text = $media_metadata->Copyright;
|
191 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['rights'][] = $rightsObj;
|
192 |
daef68e9
|
Andreas Kohlbecker
|
}
|
193 |
|
|
if(isset($media->rights) && is_array($media->rights)) {
|
194 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['rights'] = array_merge($metadata['rights'], $media->rights);
|
195 |
97ff635c
|
Andreas Kohlbecker
|
}
|
196 |
|
|
|
197 |
|
|
// Filling the description (though there is no description in the db???).
|
198 |
|
|
// $metadata_caption['description'] = $media->description_L10n;
|
199 |
|
|
|
200 |
|
|
// Location.
|
201 |
0c2b9b9d
|
Andreas Kohlbecker
|
$metadata['location'] = array();
|
202 |
|
|
$metadata['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
|
203 |
|
|
$metadata['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
|
204 |
|
|
$metadata['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
|
205 |
|
|
$metadata['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
|
206 |
97ff635c
|
Andreas Kohlbecker
|
|
207 |
|
|
/*
|
208 |
|
|
// Creation date.
|
209 |
|
|
if($media_metadata["Modify Date"])
|
210 |
|
|
$metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
|
211 |
|
|
else
|
212 |
|
|
$metadata_caption['mediacreated'] = $media->created;
|
213 |
|
|
*/
|
214 |
|
|
|
215 |
0c2b9b9d
|
Andreas Kohlbecker
|
return $metadata;
|
216 |
97ff635c
|
Andreas Kohlbecker
|
}
|
217 |
2a3b0c8e
|
Andreas Kohlbecker
|
|
218 |
|
|
|
219 |
|
|
/**
|
220 |
|
|
* Return HTML for a media gallery
|
221 |
|
|
*
|
222 |
|
|
* @param array $configuration
|
223 |
|
|
* An associative array containing:
|
224 |
|
|
* - mediaList: An array of Media entities.
|
225 |
|
|
* - maxExtend
|
226 |
|
|
* - cols
|
227 |
|
|
* - maxRows
|
228 |
|
|
* - showCaption: boolean value, whether to show captions or not.
|
229 |
|
|
* - captionElements: An array of caption elements to be shown. In case the array
|
230 |
|
|
* is empty of NULL all available caption elements will be show. In order to
|
231 |
|
|
* supress all captions set 'showCaption' to FALSE
|
232 |
|
|
* example:
|
233 |
|
|
* 1) Show 'title', 'description', 'file', 'filename' in the caption:
|
234 |
|
|
* array('title', 'description', 'file', 'filename'),
|
235 |
|
|
* 2) To add an addtional link at the bottom of the caption:
|
236 |
|
|
* array('titlecache', '#uri'=>t('Open Image')) this will cause a link
|
237 |
|
|
* to be rendered with label 'Open image' which will open the according
|
238 |
|
|
* media object.
|
239 |
|
|
* - mediaLinkType: Valid values:
|
240 |
|
|
* - "NONE": do not link the images,
|
241 |
|
|
* - "LIGHTBOX": open the link in a light box,
|
242 |
|
|
* - "NORMAL": link to the image page or to the $alternativeMediaUri if
|
243 |
|
|
* it is defined.
|
244 |
|
|
* - alternativeMediaUri: A fix string or an array of alternative URIs to link the images
|
245 |
|
|
* which will overwrite the URIs of the media parts.
|
246 |
|
|
* The order of URI in this array must correspond with the order of
|
247 |
|
|
* images in $mediaList.
|
248 |
|
|
* - galleryLinkUri: An URI to link the the hint on more images to;
|
249 |
|
|
* if NULL no link is created.
|
250 |
|
|
*
|
251 |
|
|
* @return array
|
252 |
|
|
* A render array for the image gallery
|
253 |
|
|
* @ingroup: compose
|
254 |
|
|
*/
|
255 |
|
|
function compose_cdm_media_gallerie($configuration) {
|
256 |
|
|
|
257 |
|
|
$mediaList = $configuration['mediaList'];
|
258 |
|
|
|
259 |
|
|
// Do not show an empty gallery.
|
260 |
|
|
if (count($mediaList) == 0) {
|
261 |
|
|
return '';
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
// merge with default
|
265 |
|
|
$configuration = array_merge(
|
266 |
|
|
array(
|
267 |
|
|
'mediaList' => NULL,
|
268 |
|
|
'galleryName' => NULL,
|
269 |
|
|
'maxExtend' => 150,
|
270 |
|
|
'cols' => 4,
|
271 |
|
|
'maxRows' => FALSE,
|
272 |
|
|
'captionElements' => array('title'),
|
273 |
|
|
'mediaLinkType' => 'LIGHTBOX',
|
274 |
|
|
'alternativeMediaUri' => NULL,
|
275 |
|
|
'galleryLinkUri' => NULL,
|
276 |
|
|
'showCaption' => TRUE,
|
277 |
|
|
),
|
278 |
|
|
$configuration);
|
279 |
|
|
|
280 |
|
|
$galleryName = $configuration['galleryName'];
|
281 |
|
|
$maxExtend = $configuration['maxExtend'];
|
282 |
|
|
$cols = $configuration['cols'];
|
283 |
|
|
$maxRows = $configuration['maxRows'];
|
284 |
|
|
$captionElements = $configuration['captionElements'];
|
285 |
|
|
$mediaLinkType = $configuration['mediaLinkType'];
|
286 |
|
|
$alternativeMediaUri = $configuration['alternativeMediaUri'];
|
287 |
|
|
$galleryLinkUri = $configuration['galleryLinkUri'];
|
288 |
|
|
$showCaption = $configuration['showCaption'];
|
289 |
|
|
|
290 |
|
|
$caption_link_uri = '';
|
291 |
|
|
if(isset($captionElements['#uri'])){
|
292 |
|
|
$caption_link_uri = $captionElements['#uri'];
|
293 |
|
|
unset($captionElements['#uri']);
|
294 |
|
|
}
|
295 |
|
|
if (!is_array($captionElements) || count($captionElements) == 0) {
|
296 |
|
|
$captionElements = NULL;
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
// TODO correctly handle multiple media representation parts
|
300 |
|
|
$_SESSION['cdm']['last_gallery'] = current_path();
|
301 |
|
|
// Prevent from errors.
|
302 |
|
|
if (!isset($mediaList[0])) {
|
303 |
|
|
// return;
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
// --- Duplicate supression: media can be reused but should only be shown
|
307 |
|
|
// once.
|
308 |
|
|
$tempMediaList = array();
|
309 |
|
|
$tempMediaUuids = array();
|
310 |
|
|
foreach ($mediaList as $media) {
|
311 |
|
|
if (!in_array($media->uuid, $tempMediaUuids)) {
|
312 |
|
|
$tempMediaList[] = $media;
|
313 |
|
|
$tempMediaUuids[] = $media->uuid;
|
314 |
|
|
}
|
315 |
|
|
}
|
316 |
|
|
$mediaList = $tempMediaList;
|
317 |
|
|
|
318 |
|
|
// ---
|
319 |
|
|
$galleryID = "media_gallery_" . $galleryName;
|
320 |
|
|
|
321 |
|
|
$mediaPartLinkAttributes = array();
|
322 |
|
|
$openMediaLinkAttributes = array();
|
323 |
|
|
|
324 |
|
|
// Prepare media links.
|
325 |
|
|
$doLink = FALSE;
|
326 |
|
|
if ($mediaLinkType != 'NONE') {
|
327 |
|
|
$doLink = TRUE;
|
328 |
|
|
}
|
329 |
|
|
if ($mediaLinkType == 'LIGHTBOX') {
|
330 |
|
|
$doLink = TRUE;
|
331 |
|
|
_add_js_lightbox($galleryID);
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
// Render the media gallery grid.
|
335 |
|
|
$out = '<table id="' . $galleryID . '" class="media_gallery">';
|
336 |
|
|
$out .= '<colgroup>';
|
337 |
|
|
for ($c = 0; $c < $cols; $c++) {
|
338 |
|
|
$out .= '<col style="width:' . (100 / $cols) . '%;">';
|
339 |
|
|
}
|
340 |
|
|
$out .= '</colgroup>';
|
341 |
|
|
|
342 |
|
|
for ($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++) {
|
343 |
|
|
$captionParts = array();
|
344 |
|
|
$mediaIndex = 0;
|
345 |
|
|
$out .= '<tr>';
|
346 |
|
|
for ($c = 0; $c < $cols; $c++) {
|
347 |
|
|
$media = array_shift($mediaList);
|
348 |
|
|
|
349 |
|
|
if (isset($media->representations[0]->parts[0])) {
|
350 |
|
|
|
351 |
|
|
//
|
352 |
|
|
// Find preferred representation.
|
353 |
|
|
//
|
354 |
|
|
$preferred_media_representations_list = cdm_preferred_media_representations($media, array(
|
355 |
|
|
'image/jpg',
|
356 |
|
|
'image/jpeg',
|
357 |
|
|
'image/png',
|
358 |
|
|
'image/gif',
|
359 |
|
|
), $maxExtend, $maxExtend);
|
360 |
|
|
if (count($preferred_media_representations_list) == 0) {
|
361 |
|
|
// Fallback to using the first one in the list.
|
362 |
|
|
$preferred_media_representations_list = $media->representations;
|
363 |
|
|
}
|
364 |
|
|
$preferred_media_representation = array_shift($preferred_media_representations_list);
|
365 |
|
|
|
366 |
|
|
// $preferred_media_representation->parts[0]->uri =
|
367 |
|
|
// "http://127.0.0.1/images/palmae/palm_tc_14415_1.jpg";
|
368 |
|
|
$contentTypeDirectory = media_content_type_dir($preferred_media_representation, 'application');
|
369 |
|
|
|
370 |
|
|
$mediaPartHtml = call_user_func_array(
|
371 |
|
|
'cdm_media_gallerie_' . $contentTypeDirectory,
|
372 |
|
|
array( $preferred_media_representation->parts[0], $maxExtend, TRUE)
|
373 |
|
|
);
|
374 |
|
|
// --- Compose Media Link.
|
375 |
|
|
$mediaLinkUri = FALSE;
|
376 |
|
|
if ($alternativeMediaUri) {
|
377 |
|
|
if (isset($alternativeMediaUri[$mediaIndex])) {
|
378 |
|
|
$mediaLinkUri = $alternativeMediaUri[$mediaIndex];
|
379 |
|
|
}
|
380 |
|
|
if (is_string($alternativeMediaUri)) {
|
381 |
|
|
$mediaLinkUri = $alternativeMediaUri;
|
382 |
|
|
}
|
383 |
|
|
}
|
384 |
|
|
else {
|
385 |
|
|
$mediaLinkUri = $preferred_media_representation->parts[0]->uri;
|
386 |
|
|
}
|
387 |
|
|
$mediaIndex++;
|
388 |
|
|
|
389 |
|
|
// media captions will be loaded via AHAH
|
390 |
|
|
_add_js_ahah();
|
391 |
|
|
$content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
|
392 |
|
|
$cdm_proxy_url_caption = url('cdm_api/proxy/' . urlencode($content_url) . "/cdm_media_caption/" . serialize($captionElements));
|
393 |
|
|
$ahah_media_caption = '<div class="ahah-content" data-cdm-ahah-url="' . $cdm_proxy_url_caption . '">'
|
394 |
|
|
. '<span class="loading" style="display: none;">' . loading_image_html() . '</span></div>';
|
395 |
|
|
|
396 |
|
|
// preparing the part link (= click on image iteself) which can be handled in two ways
|
397 |
|
|
//
|
398 |
f79d32d6
|
Andreas Kohlbecker
|
// 1. open image in lightbox, the captions in the lightbox will be loaded via AHAH
|
399 |
2a3b0c8e
|
Andreas Kohlbecker
|
// 2. open the media in a new window with target 'specimen'
|
400 |
|
|
if ($mediaLinkType == 'LIGHTBOX' && $contentTypeDirectory == 'image') {
|
401 |
|
|
$mediaPartLinkAttributes['class'] = array('lightbox');
|
402 |
|
|
}
|
403 |
|
|
else {
|
404 |
|
|
$mediaPartLinkAttributes['target'] = "specimen";
|
405 |
|
|
$openMediaLinkAttributes['target'] = "specimen";
|
406 |
|
|
}
|
407 |
|
|
$mediaPartLinkAttributes['alt'] = htmlentities($ahah_media_caption);
|
408 |
|
|
|
409 |
|
|
// --- preparing the media caption
|
410 |
|
|
|
411 |
|
|
/* old comment: "no caption elements to show up here except the $caption_link_uri, if at all"
|
412 |
|
|
*
|
413 |
|
|
* a.kohlbecker 2013-03-14 :
|
414 |
|
|
* It is unclear why no caption elements should be shown, Was it a technical reason?
|
415 |
|
|
* see commit r16723 740177eb-a1d8-4ec3-a630-accd905eb3da
|
416 |
|
|
* If not problems arise with this remove it after some weeks
|
417 |
|
|
*/
|
418 |
|
|
$captionPartHtml = $ahah_media_caption;
|
419 |
|
|
|
420 |
|
|
if ($caption_link_uri) {
|
421 |
|
|
if ($contentTypeDirectory == 'image') {
|
422 |
|
|
// it is an image, so open it in the media page
|
423 |
|
|
$captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, path_to_media($media->uuid), array(
|
424 |
|
|
'attributes' => array(), 'html' => TRUE,
|
425 |
|
|
)) . '</div>';
|
426 |
|
|
}
|
427 |
|
|
else {
|
428 |
|
|
// otherwise open it directly and let the the browser handle the media type
|
429 |
|
|
$openMediaLinkAttributes['absolute'] = TRUE;
|
430 |
|
|
$captionPartHtml .= '<div class="media-caption-link">' . l($caption_link_uri, $mediaLinkUri, array(
|
431 |
|
|
'attributes' => $openMediaLinkAttributes, 'html' => TRUE,
|
432 |
|
|
)) . '</div>';
|
433 |
|
|
}
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
$captionParts[] = $captionPartHtml;
|
437 |
|
|
|
438 |
|
|
// --- Surround imagePart with link, this .
|
439 |
|
|
if ($doLink) {
|
440 |
|
|
$mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, array(
|
441 |
|
|
'attributes' => $mediaPartLinkAttributes, 'html' => TRUE,
|
442 |
|
|
));
|
443 |
|
|
}
|
444 |
|
|
}
|
445 |
|
|
else {
|
446 |
|
|
$mediaPartHtml = '';
|
447 |
|
|
$captionParts[] = '';
|
448 |
|
|
}
|
449 |
|
|
$out .= '<td class="media">' . $mediaPartHtml . '</td>';
|
450 |
|
|
}
|
451 |
|
|
$out .= '</tr>'; // End of media parts.
|
452 |
|
|
if ($showCaption) {
|
453 |
|
|
if ( (is_array($captionElements) && count($captionElements) > 0) || $caption_link_uri) {
|
454 |
|
|
$out .= '<tr>';
|
455 |
|
|
// Add caption row.
|
456 |
|
|
foreach ($captionParts as $captionPartHtml) {
|
457 |
|
|
$out .= '<td class="caption">' . $captionPartHtml . '</td>';
|
458 |
|
|
}
|
459 |
|
|
$out .= '</tr>';
|
460 |
|
|
}
|
461 |
|
|
}
|
462 |
|
|
}
|
463 |
|
|
|
464 |
|
|
if ($galleryLinkUri) {
|
465 |
|
|
if (count($mediaList) > 0) {
|
466 |
|
|
$moreHtml = count($mediaList) . ' ' . t('more in gallery');
|
467 |
|
|
}
|
468 |
|
|
else {
|
469 |
|
|
$moreHtml = t('open gallery');
|
470 |
|
|
}
|
471 |
|
|
$moreHtml = l($moreHtml, $galleryLinkUri);
|
472 |
|
|
$out .= '<tr><td colspan="' . $cols . '">' . $moreHtml . '</td></tr>';
|
473 |
|
|
}
|
474 |
|
|
$out .= '</table>';
|
475 |
f79d32d6
|
Andreas Kohlbecker
|
|
476 |
2a3b0c8e
|
Andreas Kohlbecker
|
return $out;
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
/**
|
480 |
|
|
* Creates markup for a CDM MediaRepresentation which is referencing an image.
|
481 |
|
|
*
|
482 |
|
|
* @param $mediaRepresentationPart
|
483 |
|
|
* @param $maxExtend
|
484 |
|
|
* @param $addPassePartout
|
485 |
|
|
* @param $attributes
|
486 |
|
|
* @return string
|
487 |
|
|
* The markup for the media representation
|
488 |
|
|
*/
|
489 |
|
|
function cdm_media_gallerie_image($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
|
490 |
|
|
|
491 |
|
|
$out = '';
|
492 |
|
|
|
493 |
|
|
// TODO merge with theme_cdm_media_mime_image?
|
494 |
|
|
if (isset($mediaRepresentationPart)) {
|
495 |
|
|
|
496 |
|
|
$h = $mediaRepresentationPart->height;
|
497 |
|
|
$w = $mediaRepresentationPart->width;
|
498 |
|
|
if ($w == 0 || $h == 0) {
|
499 |
|
|
// Take url and replace spaces.
|
500 |
|
|
$image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
|
501 |
|
|
$imageDimensions = getimagesize_remote($image_uri);
|
502 |
|
|
if (!$imageDimensions) {
|
503 |
|
|
return '<div>' . t('Image unavailable, uri: ') . $mediaRepresentationPart->uri . '</div>';
|
504 |
|
|
}
|
505 |
|
|
$w = $imageDimensions[0];
|
506 |
|
|
$h = $imageDimensions[1];
|
507 |
|
|
}
|
508 |
|
|
|
509 |
|
|
$ratio = $w / $h;
|
510 |
|
|
if ($ratio > 1) {
|
511 |
|
|
$displayHeight = round($maxExtend / $ratio);
|
512 |
|
|
$displayWidth = $maxExtend;
|
513 |
|
|
$m = round(($maxExtend - $displayHeight) / 2);
|
514 |
|
|
$margins = 'margin:' . $m . 'px 0 ' . $m . 'px 0;';
|
515 |
|
|
}
|
516 |
|
|
else {
|
517 |
|
|
$displayHeight = $maxExtend;
|
518 |
|
|
$displayWidth = round($maxExtend * $ratio);
|
519 |
|
|
$m = round(($maxExtend - $displayWidth) / 2);
|
520 |
|
|
$margins = 'margin:0 ' . $m . 'px 0 ' . $m . 'px;';
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
// Turn attributes array into string.
|
524 |
|
|
if(!is_array($attributes)){
|
525 |
|
|
$attributes = array();
|
526 |
|
|
}
|
527 |
|
|
if(!isset($attributes['alt'])){
|
528 |
|
|
$attributes['alt'] = check_plain($mediaRepresentationPart->uri);
|
529 |
|
|
}
|
530 |
|
|
$attrStr = ' ';
|
531 |
|
|
// $attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
|
532 |
|
|
if (is_array($attributes)) {
|
533 |
|
|
foreach ($attributes as $name => $value) {
|
534 |
|
|
$attrStr .= $name . '="' . $value . '" ';
|
535 |
|
|
}
|
536 |
|
|
}
|
537 |
|
|
|
538 |
|
|
if ($addPassePartout) {
|
539 |
|
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
540 |
|
|
}
|
541 |
|
|
else {
|
542 |
|
|
// Do not add margins if no pass partout is shown.
|
543 |
|
|
$margins = '';
|
544 |
|
|
}
|
545 |
|
|
$out .= '<img src="' . $mediaRepresentationPart->uri . '" width="' . $displayWidth . '" height="' . $displayHeight . '" style="' . $margins . '"' . $attrStr . ' />';
|
546 |
|
|
|
547 |
|
|
if ($addPassePartout) {
|
548 |
|
|
$out .= '</div>';
|
549 |
|
|
}
|
550 |
|
|
}
|
551 |
|
|
|
552 |
|
|
return $out;
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
/**
|
556 |
|
|
* Creates markup for a CDM MediaRepresentation which is referencing an web application.
|
557 |
|
|
*
|
558 |
|
|
* @param $mediaRepresentationPart
|
559 |
|
|
* @param $maxExtend
|
560 |
|
|
* @param $addPassePartout
|
561 |
|
|
* @param $attributes
|
562 |
|
|
* @return string
|
563 |
|
|
* The markup for the media representation
|
564 |
|
|
*/
|
565 |
|
|
function cdm_media_gallerie_application($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
|
566 |
|
|
|
567 |
|
|
$out = '';
|
568 |
|
|
|
569 |
|
|
if (isset($mediaRepresentationPart)) {
|
570 |
|
|
|
571 |
|
|
if ($addPassePartout) {
|
572 |
|
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
573 |
|
|
}
|
574 |
|
|
$out .= '<div class="application">Web Application</div>';
|
575 |
|
|
|
576 |
|
|
if ($addPassePartout) {
|
577 |
|
|
$out .= '</div>';
|
578 |
|
|
}
|
579 |
|
|
}
|
580 |
|
|
|
581 |
|
|
return $out;
|
582 |
|
|
}
|
583 |
|
|
|
584 |
|
|
/**
|
585 |
|
|
* Creates markup for a CDM MediaRepresentation which is referencing an web application.
|
586 |
|
|
*
|
587 |
|
|
* @param $mediaRepresentationPart
|
588 |
|
|
* @param $maxExtend
|
589 |
|
|
* @param $addPassePartout
|
590 |
|
|
* @param $attributes
|
591 |
|
|
* @return string
|
592 |
|
|
* The markup for the media representation
|
593 |
|
|
*/
|
594 |
|
|
function cdm_media_gallerie_text($mediaRepresentationPart, $maxExtend, $addPassePartout, $attributes = array()) {
|
595 |
|
|
|
596 |
|
|
$out = '';
|
597 |
|
|
|
598 |
|
|
if (isset($mediaRepresentationPart)) {
|
599 |
|
|
if ($addPassePartout) {
|
600 |
|
|
$out .= '<div class="image-passe-partout" style="width:' . $maxExtend . 'px; height:' . $maxExtend . 'px;">';
|
601 |
|
|
}
|
602 |
|
|
|
603 |
|
|
$out .= '<div class="application">Web Application</div>';
|
604 |
|
|
|
605 |
|
|
if ($addPassePartout) {
|
606 |
|
|
$out .= '</div>';
|
607 |
|
|
}
|
608 |
|
|
}
|
609 |
|
|
|
610 |
|
|
return $out;
|
611 |
|
|
}
|
612 |
|
|
|
613 |
|
|
/**
|
614 |
|
|
* Adds the OpenLayers based image viewer to the page.
|
615 |
|
|
*
|
616 |
|
|
* The OpenLayers based image viewer allows to zoom and pan the displayed image.
|
617 |
|
|
*
|
618 |
|
|
* Documentation related to using Openlayers in order to view images is found here:
|
619 |
|
|
* - @see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
|
620 |
|
|
* - @see http://trac.openlayers.org/wiki/SettingZoomLevels
|
621 |
|
|
*
|
622 |
|
|
* @param array $variables
|
623 |
|
|
* An associative array of theme variables:
|
624 |
|
|
* - mediaRepresentationPart: The CDM MediaRepresentationPart instance to be displayed.
|
625 |
|
|
* - maxExtend: The maximum extend of the image viewer view port.
|
626 |
|
|
*/
|
627 |
|
|
function cdm_openlayers_image($mediaRepresentationPart, $maxExtend) {
|
628 |
|
|
|
629 |
|
|
_add_js_openlayers();
|
630 |
|
|
|
631 |
|
|
// TODO merge code below with code from theme_cdm_media_gallerie_image
|
632 |
|
|
// var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
|
633 |
|
|
// TODO merge code below with code from theme_cdm_media_gallerie_image
|
634 |
|
|
$w = $mediaRepresentationPart->width;
|
635 |
|
|
$h = $mediaRepresentationPart->height;
|
636 |
|
|
|
637 |
|
|
if ($w == 0 || $h == 0) {
|
638 |
|
|
// Take url and replace spaces.
|
639 |
|
|
$image_uri = str_replace(' ', '%20', $mediaRepresentationPart->uri);
|
640 |
|
|
$imageDimensions = getimagesize_remote($image_uri);
|
641 |
|
|
if (!$imageDimensions) {
|
642 |
|
|
return '<div>' . t('Image unavailable, uri:') . $mediaRepresentationPart->uri . '</div>';
|
643 |
|
|
}
|
644 |
|
|
$w = $imageDimensions[0];
|
645 |
|
|
$h = $imageDimensions[1];
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
// Calculate maxResolution
|
649 |
|
|
if ($w > $h) {
|
650 |
|
|
$maxRes = $w / $maxExtend;
|
651 |
|
|
}
|
652 |
|
|
else {
|
653 |
|
|
$maxRes = $h / $maxExtend;
|
654 |
|
|
}
|
655 |
|
|
|
656 |
|
|
$maxRes *= 1;
|
657 |
|
|
|
658 |
|
|
drupal_add_js('
|
659 |
|
|
var map;
|
660 |
|
|
|
661 |
|
|
var imageLayerOptions={
|
662 |
|
|
maxResolution: ' . $maxRes . ',
|
663 |
|
|
maxExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
|
664 |
|
|
};
|
665 |
|
|
var mapOptions={
|
666 |
|
|
controls:
|
667 |
|
|
[
|
668 |
|
|
new OpenLayers.Control.PanZoom(),
|
669 |
|
|
new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
|
670 |
|
|
],
|
671 |
|
|
restrictedExtent: new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . ')
|
672 |
|
|
};
|
673 |
|
|
|
674 |
|
|
var graphic = new OpenLayers.Layer.Image(
|
675 |
|
|
\'Image Title\',
|
676 |
|
|
\'' . $mediaRepresentationPart->uri . '\',
|
677 |
|
|
new OpenLayers.Bounds(0, 0, ' . $w . ', ' . $h . '),
|
678 |
|
|
new OpenLayers.Size(' . $w . ', ' . $h . '),
|
679 |
|
|
imageLayerOptions
|
680 |
|
|
);
|
681 |
|
|
|
682 |
|
|
function init() {
|
683 |
|
|
map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
|
684 |
|
|
map.addLayers([graphic]);
|
685 |
|
|
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
|
686 |
|
|
map.zoomToMaxExtent();
|
687 |
|
|
}
|
688 |
|
|
|
689 |
|
|
jQuery(document).ready(function(){
|
690 |
|
|
init();
|
691 |
|
|
});', array('type' => 'inline'));
|
692 |
|
|
$out = '<div id="openlayers_image" class="image_viewer" style="width: ' . $maxExtend . 'px; height:' . ($maxExtend) . 'px"></div>';
|
693 |
|
|
return $out;
|
694 |
|
|
}
|