1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Media theming functions.
|
5
|
*
|
6
|
* @copyright
|
7
|
* (C) 2007-2012 EDIT
|
8
|
* European Distributed Institute of Taxonomy
|
9
|
* http://www.e-taxonomy.eu
|
10
|
*
|
11
|
* The contents of this module are subject to the Mozilla
|
12
|
* Public License Version 1.1.
|
13
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
14
|
*/
|
15
|
|
16
|
/**
|
17
|
* @todo Please document this function.
|
18
|
* @see http://drupal.org/node/1354
|
19
|
*/
|
20
|
function media_content_type_dir($media_representation, $default = FALSE) {
|
21
|
if ($media_representation->mimeType) {
|
22
|
return substr($media_representation->mimeType, 0, stripos($media_representation->mimeType, '/'));
|
23
|
}
|
24
|
else {
|
25
|
return $default;
|
26
|
}
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* @todo Please document this function.
|
31
|
* @see http://drupal.org/node/1354
|
32
|
*/
|
33
|
function getimagesize_remote($image_url) {
|
34
|
$response = cdm_http_request($image_url);
|
35
|
$contents = NULL;
|
36
|
if (isset($response->data)) {
|
37
|
$contents = $response->data;
|
38
|
} else {
|
39
|
return FALSE;
|
40
|
}
|
41
|
|
42
|
$im = @ImageCreateFromString($contents); // Using @ to avoid php warnings.
|
43
|
if (!$im) {
|
44
|
return FALSE;
|
45
|
}
|
46
|
$gis[0] = ImageSX($im);
|
47
|
$gis[1] = ImageSY($im);
|
48
|
// Array member 3 is used below to keep with current getimagesize standards.
|
49
|
$gis[3] = "width={$gis[0]} height={$gis[1]}";
|
50
|
ImageDestroy($im);
|
51
|
return $gis;
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* 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
|
*
|
66
|
* FIXME: move to descriptions.inc
|
67
|
*/
|
68
|
function cdm_description_element_media($descriptionElement, $mimeTypePreference) {
|
69
|
|
70
|
$out = '';
|
71
|
|
72
|
_add_js_thickbox();
|
73
|
|
74
|
$feature = $descriptionElement->feature;
|
75
|
$medias = $descriptionElement->media;
|
76
|
|
77
|
foreach ($medias as $media) {
|
78
|
$prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
|
79
|
$mediaRepresentation = array_shift($prefRepresentations);
|
80
|
if ($mediaRepresentation) {
|
81
|
|
82
|
$contentTypeDirectory = media_content_type_dir($mediaRepresentation);
|
83
|
|
84
|
$out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
|
85
|
}
|
86
|
else {
|
87
|
// Media has empty or corrupt representation
|
88
|
if(user_is_logged_in()){
|
89
|
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');
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
return $out;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* @todo Please document this function.
|
98
|
* @see http://drupal.org/node/1354
|
99
|
*/
|
100
|
function theme_cdm_media_mime_application($variables) {
|
101
|
$mediaRepresentation = $variables['mediaRepresentation'];
|
102
|
$feature = $variables['feature'];
|
103
|
$out = '';
|
104
|
foreach ($mediaRepresentation->parts as $part) {
|
105
|
$attributes = array(
|
106
|
'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
|
107
|
'target' => '_blank',
|
108
|
);
|
109
|
/*
|
110
|
$attributes = array('title'=>$feature->representation_L10n,'target'=>'_blank');
|
111
|
$attributes = array('title'=>'original publication', 'target'=>'_blank');
|
112
|
*/
|
113
|
$out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
|
114
|
'attributes' => $attributes,
|
115
|
'absolute' => TRUE,
|
116
|
'html' => TRUE,
|
117
|
));
|
118
|
}
|
119
|
return $out;
|
120
|
}
|
121
|
|
122
|
|
123
|
/**
|
124
|
* Creates the markup for a CDM Media instance.
|
125
|
*
|
126
|
* (This method is currently only called from within theme_cdm_media())
|
127
|
*
|
128
|
* @param $variables
|
129
|
* An associative array
|
130
|
* @return string
|
131
|
* The markup
|
132
|
*/
|
133
|
function theme_cdm_media_mime_image($variables) {
|
134
|
$media_representation = $variables['mediaRepresentation'];
|
135
|
$feature = $variables['feature'];
|
136
|
$out = '';
|
137
|
// TODO thickbox is not used anymore -> delete?
|
138
|
$attributes = array(
|
139
|
'class' => 'thickbox',
|
140
|
'rel' => 'representation-' . $media_representation->uuid,
|
141
|
'title' => $feature->representation_L10n,
|
142
|
);
|
143
|
for ($i = 0; $part = $media_representation->parts[$i]; $i++) {
|
144
|
if ($i == 0) {
|
145
|
$out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
|
146
|
'attributes' => $attributes,
|
147
|
'absolute' => TRUE,
|
148
|
'html' => TRUE,
|
149
|
));
|
150
|
}
|
151
|
else {
|
152
|
$out .= l('', $part->uri, array(
|
153
|
'attributes' => $attributes,
|
154
|
'absolute' => TRUE,
|
155
|
));
|
156
|
}
|
157
|
}
|
158
|
return $out;
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* @todo Please document this function.
|
163
|
* @see http://drupal.org/node/1354
|
164
|
*/
|
165
|
function theme_cdm_media_mime_text($variables) {
|
166
|
$representation = $variables['mediaRepresentation'];
|
167
|
$feature = $variables['feature'];
|
168
|
$out = '';
|
169
|
if (!empty($representation->parts)) {
|
170
|
foreach ($representation->parts as $part) {
|
171
|
$attributes = array(
|
172
|
'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
|
173
|
'target' => '_blank',
|
174
|
);
|
175
|
// $attributes = array('title'=>t('original publication'),
|
176
|
// 'target'=>'_blank');
|
177
|
$out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
|
178
|
'attributes' => $attributes,
|
179
|
'absolute' => TRUE,
|
180
|
'html' => TRUE,
|
181
|
));
|
182
|
}
|
183
|
}
|
184
|
return $out;
|
185
|
}
|
186
|
|
187
|
|
188
|
/**
|
189
|
* Theme function for captions of media elements. This method is usually called from
|
190
|
* within the theme_cdm_media_gallerie() function or indirectly via AHAH.
|
191
|
*
|
192
|
* @param array $variables
|
193
|
* an associative array with the following elements:
|
194
|
* - 'media': the cdm media object to show the captions for
|
195
|
* - 'elements':
|
196
|
* an array which defining the caption elements to show up
|
197
|
* example:
|
198
|
* Show 'title', 'description', 'file', 'filename' in the caption:
|
199
|
* array('title', 'description', 'file', 'filename')
|
200
|
*
|
201
|
* @return string
|
202
|
* the themed html output
|
203
|
*
|
204
|
* TODO turn into compose method
|
205
|
*/
|
206
|
function theme_cdm_media_caption($variables) {
|
207
|
|
208
|
$media = $variables['media'];
|
209
|
$elements = $variables['elements'];
|
210
|
$sources_as_content = $variables['sources_as_content'];
|
211
|
$media_metadata = read_media_metadata($media);
|
212
|
|
213
|
$doTitle = !$elements || array_search('title', $elements) !== FALSE;
|
214
|
$doDescription = !$elements || array_search('description', $elements) !== FALSE;
|
215
|
$doArtist = !$elements || array_search('artist', $elements) !== FALSE;
|
216
|
$doLocation = !$elements || array_search('location', $elements) !== FALSE;
|
217
|
$doRights = !$elements || array_search('rights', $elements) !== FALSE;
|
218
|
|
219
|
$descriptionPrefix = "";
|
220
|
$footnote_list_key = 'media-' . $media->uuid;
|
221
|
|
222
|
// handle sources and annotations
|
223
|
cdm_lazyload_array_field('media', 'annotations', $media);
|
224
|
$annotations_and_sources = handle_annotations_and_sources(
|
225
|
$media,
|
226
|
array(
|
227
|
'sources_as_content' => $sources_as_content,
|
228
|
'link_to_name_used_in_source' => 1,
|
229
|
'link_to_reference' => 0,
|
230
|
'add_footnote_keys' => $sources_as_content ? 0 : 1
|
231
|
),
|
232
|
NULL,
|
233
|
$footnote_list_key
|
234
|
);
|
235
|
|
236
|
$out = '';
|
237
|
|
238
|
// Title.
|
239
|
if ($doTitle) {
|
240
|
$title_string = $media_metadata['title']
|
241
|
. $annotations_and_sources['foot_note_keys']; // placing the footnote keys here is not optimal, see #6329 A.1.
|
242
|
$title_string = trim($title_string);
|
243
|
if (empty($title_string) && !($doDescription && $media_metadata['description'])) {
|
244
|
// Use filename as fallback option if no description and no source citations are available.
|
245
|
$title_string = $media_metadata['filename'];
|
246
|
}
|
247
|
$out .= '<div class="title">' . $title_string . '</div>';
|
248
|
$descriptionPrefix = "- ";
|
249
|
}
|
250
|
|
251
|
$groups = array();
|
252
|
|
253
|
$out .= '<dl class="media-caption">';
|
254
|
// Description.
|
255
|
if ($media_metadata['description'] && $doDescription) {
|
256
|
_description_list_group_add($groups, t('Description') . ':', $descriptionPrefix . $media_metadata['description'] );
|
257
|
}
|
258
|
// Artist.
|
259
|
if ($media_metadata['artist'] && $doArtist) {
|
260
|
_description_list_group_add($groups, t('Artist') . ':', $media_metadata['artist'] );
|
261
|
}
|
262
|
// Location.
|
263
|
if ($doLocation) {
|
264
|
$location = '';
|
265
|
$location .= $media_metadata['location']['sublocation'];
|
266
|
if ($location && $media_metadata['location']['city']) {
|
267
|
$location .= ', ';
|
268
|
}
|
269
|
$location .= $media_metadata['location']['city'];
|
270
|
if ($location && $media_metadata['location']['province']) {
|
271
|
$location .= ', ';
|
272
|
}
|
273
|
$location .= $media_metadata['location']['province'];
|
274
|
if ($location && $media_metadata['location']['country']) {
|
275
|
$location .= ' (' . $media_metadata['location']['country'] . ')';
|
276
|
}
|
277
|
else {
|
278
|
$location .= $media_metadata['location']['country'];
|
279
|
}
|
280
|
if ($location) {
|
281
|
_description_list_group_add($groups, t('Location') . ':', $location );
|
282
|
}
|
283
|
}
|
284
|
// Rights.
|
285
|
if ($doRights) {
|
286
|
$groups = array_merge($groups, cdm_rights_as_dl_groups($media_metadata['rights']));
|
287
|
}
|
288
|
|
289
|
if(!empty($annotations_and_sources['source_references'])){
|
290
|
_description_list_group_add($groups, t('Sources') . ':', join(', ', $annotations_and_sources['source_references']) );
|
291
|
}
|
292
|
|
293
|
// TODO add all other metadata elements generically.
|
294
|
|
295
|
$description_list_item = array(
|
296
|
'#theme' => 'description_list',
|
297
|
'#groups' => $groups,
|
298
|
'#attributes' => array('class' => 'media-caption')
|
299
|
);
|
300
|
$out .= drupal_render($description_list_item);
|
301
|
|
302
|
$out .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key));
|
303
|
|
304
|
return $out;
|
305
|
}
|
306
|
|