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 |
62b804e6
|
Andreas Kohlbecker
|
$last_level = error_reporting (E_ERROR); // suppress warnings from the imagecreatefromstring() method,
|
43 |
|
|
$im = imagecreatefromstring($contents);
|
44 |
|
|
error_reporting($last_level); // reset the error_reporting level
|
45 |
|
|
|
46 |
6657531f
|
Andreas Kohlbecker
|
if (!$im) {
|
47 |
|
|
return FALSE;
|
48 |
|
|
}
|
49 |
|
|
$gis[0] = ImageSX($im);
|
50 |
|
|
$gis[1] = ImageSY($im);
|
51 |
|
|
// Array member 3 is used below to keep with current getimagesize standards.
|
52 |
|
|
$gis[3] = "width={$gis[0]} height={$gis[1]}";
|
53 |
|
|
ImageDestroy($im);
|
54 |
|
|
return $gis;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
275b2642
|
Andreas Kohlbecker
|
* Creates the markup for the media associated a DescriptionElement instance.
|
59 |
|
|
*
|
60 |
|
|
* @param $descriptionElement
|
61 |
|
|
* the DescriptionElement instance
|
62 |
|
|
* @param $mimeTypePreference array
|
63 |
|
|
* An array of mime type strings. the order of the mimetpes is the oerder of preference.
|
64 |
|
|
* E.g.: array('application/pdf','image/jpeg')
|
65 |
|
|
*
|
66 |
|
|
* @return string
|
67 |
|
|
* The markup
|
68 |
f79d32d6
|
Andreas Kohlbecker
|
*
|
69 |
|
|
* FIXME: move to descriptions.inc
|
70 |
6657531f
|
Andreas Kohlbecker
|
*/
|
71 |
275b2642
|
Andreas Kohlbecker
|
function cdm_description_element_media($descriptionElement, $mimeTypePreference) {
|
72 |
|
|
|
73 |
6657531f
|
Andreas Kohlbecker
|
$out = '';
|
74 |
|
|
|
75 |
|
|
_add_js_thickbox();
|
76 |
|
|
|
77 |
|
|
$feature = $descriptionElement->feature;
|
78 |
|
|
$medias = $descriptionElement->media;
|
79 |
|
|
|
80 |
|
|
foreach ($medias as $media) {
|
81 |
|
|
$prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
|
82 |
|
|
$mediaRepresentation = array_shift($prefRepresentations);
|
83 |
|
|
if ($mediaRepresentation) {
|
84 |
|
|
|
85 |
|
|
$contentTypeDirectory = media_content_type_dir($mediaRepresentation);
|
86 |
|
|
|
87 |
|
|
$out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature));
|
88 |
|
|
}
|
89 |
|
|
else {
|
90 |
275b2642
|
Andreas Kohlbecker
|
// Media has empty or corrupt representation
|
91 |
|
|
if(user_is_logged_in()){
|
92 |
|
|
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');
|
93 |
|
|
}
|
94 |
6657531f
|
Andreas Kohlbecker
|
}
|
95 |
|
|
}
|
96 |
|
|
return $out;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* @todo Please document this function.
|
101 |
|
|
* @see http://drupal.org/node/1354
|
102 |
|
|
*/
|
103 |
|
|
function theme_cdm_media_mime_application($variables) {
|
104 |
|
|
$mediaRepresentation = $variables['mediaRepresentation'];
|
105 |
|
|
$feature = $variables['feature'];
|
106 |
|
|
$out = '';
|
107 |
|
|
foreach ($mediaRepresentation->parts as $part) {
|
108 |
|
|
$attributes = array(
|
109 |
|
|
'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
|
110 |
|
|
'target' => '_blank',
|
111 |
|
|
);
|
112 |
|
|
/*
|
113 |
|
|
$attributes = array('title'=>$feature->representation_L10n,'target'=>'_blank');
|
114 |
|
|
$attributes = array('title'=>'original publication', 'target'=>'_blank');
|
115 |
|
|
*/
|
116 |
ca7fa7da
|
Andreas Kohlbecker
|
$out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
|
117 |
6657531f
|
Andreas Kohlbecker
|
'attributes' => $attributes,
|
118 |
|
|
'absolute' => TRUE,
|
119 |
|
|
'html' => TRUE,
|
120 |
|
|
));
|
121 |
|
|
}
|
122 |
|
|
return $out;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
90fe4c79
|
Andreas Kohlbecker
|
|
126 |
6657531f
|
Andreas Kohlbecker
|
/**
|
127 |
90fe4c79
|
Andreas Kohlbecker
|
* Creates the markup for a CDM Media instance.
|
128 |
|
|
*
|
129 |
|
|
* (This method is currently only called from within theme_cdm_media())
|
130 |
|
|
*
|
131 |
|
|
* @param $variables
|
132 |
|
|
* An associative array
|
133 |
|
|
* @return string
|
134 |
|
|
* The markup
|
135 |
6657531f
|
Andreas Kohlbecker
|
*/
|
136 |
|
|
function theme_cdm_media_mime_image($variables) {
|
137 |
90fe4c79
|
Andreas Kohlbecker
|
$media_representation = $variables['mediaRepresentation'];
|
138 |
6657531f
|
Andreas Kohlbecker
|
$feature = $variables['feature'];
|
139 |
|
|
$out = '';
|
140 |
|
|
// TODO thickbox is not used anymore -> delete?
|
141 |
|
|
$attributes = array(
|
142 |
|
|
'class' => 'thickbox',
|
143 |
90fe4c79
|
Andreas Kohlbecker
|
'rel' => 'representation-' . $media_representation->uuid,
|
144 |
6657531f
|
Andreas Kohlbecker
|
'title' => $feature->representation_L10n,
|
145 |
|
|
);
|
146 |
90fe4c79
|
Andreas Kohlbecker
|
for ($i = 0; $part = $media_representation->parts[$i]; $i++) {
|
147 |
6657531f
|
Andreas Kohlbecker
|
if ($i == 0) {
|
148 |
ca7fa7da
|
Andreas Kohlbecker
|
$out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
|
149 |
6657531f
|
Andreas Kohlbecker
|
'attributes' => $attributes,
|
150 |
|
|
'absolute' => TRUE,
|
151 |
|
|
'html' => TRUE,
|
152 |
|
|
));
|
153 |
|
|
}
|
154 |
|
|
else {
|
155 |
7cc085da
|
Andreas Kohlbecker
|
$out .= l('', $part->uri, array(
|
156 |
6657531f
|
Andreas Kohlbecker
|
'attributes' => $attributes,
|
157 |
|
|
'absolute' => TRUE,
|
158 |
|
|
));
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
return $out;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
/**
|
165 |
|
|
* @todo Please document this function.
|
166 |
|
|
* @see http://drupal.org/node/1354
|
167 |
|
|
*/
|
168 |
|
|
function theme_cdm_media_mime_text($variables) {
|
169 |
ca7fa7da
|
Andreas Kohlbecker
|
$representation = $variables['mediaRepresentation'];
|
170 |
6657531f
|
Andreas Kohlbecker
|
$feature = $variables['feature'];
|
171 |
|
|
$out = '';
|
172 |
|
|
if (!empty($representation->parts)) {
|
173 |
|
|
foreach ($representation->parts as $part) {
|
174 |
|
|
$attributes = array(
|
175 |
|
|
'title' => theme('cdm_feature_name', array('feature_name' => $feature->representation_L10n)),
|
176 |
|
|
'target' => '_blank',
|
177 |
|
|
);
|
178 |
|
|
// $attributes = array('title'=>t('original publication'),
|
179 |
|
|
// 'target'=>'_blank');
|
180 |
ca7fa7da
|
Andreas Kohlbecker
|
$out .= l(media_feature_icon($feature, $part->uri), $part->uri, array(
|
181 |
6657531f
|
Andreas Kohlbecker
|
'attributes' => $attributes,
|
182 |
|
|
'absolute' => TRUE,
|
183 |
|
|
'html' => TRUE,
|
184 |
|
|
));
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
return $out;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
7a2a14b3
|
Andreas Kohlbecker
|
|
191 |
6657531f
|
Andreas Kohlbecker
|
/**
|
192 |
7a2a14b3
|
Andreas Kohlbecker
|
* Theme function for captions of media elements. This method is usually called from
|
193 |
|
|
* within the theme_cdm_media_gallerie() function or indirectly via AHAH.
|
194 |
|
|
*
|
195 |
|
|
* @param array $variables
|
196 |
|
|
* an associative array with the following elements:
|
197 |
|
|
* - 'media': the cdm media object to show the captions for
|
198 |
|
|
* - 'elements':
|
199 |
|
|
* an array which defining the caption elements to show up
|
200 |
|
|
* example:
|
201 |
|
|
* Show 'title', 'description', 'file', 'filename' in the caption:
|
202 |
|
|
* array('title', 'description', 'file', 'filename')
|
203 |
|
|
*
|
204 |
|
|
* @return string
|
205 |
|
|
* the themed html output
|
206 |
daef68e9
|
Andreas Kohlbecker
|
*
|
207 |
|
|
* TODO turn into compose method
|
208 |
6657531f
|
Andreas Kohlbecker
|
*/
|
209 |
|
|
function theme_cdm_media_caption($variables) {
|
210 |
0c2b9b9d
|
Andreas Kohlbecker
|
|
211 |
6657531f
|
Andreas Kohlbecker
|
$media = $variables['media'];
|
212 |
|
|
$elements = $variables['elements'];
|
213 |
f79d32d6
|
Andreas Kohlbecker
|
$sources_as_content = $variables['sources_as_content'];
|
214 |
97ff635c
|
Andreas Kohlbecker
|
$media_metadata = read_media_metadata($media);
|
215 |
6657531f
|
Andreas Kohlbecker
|
|
216 |
|
|
$doTitle = !$elements || array_search('title', $elements) !== FALSE;
|
217 |
|
|
$doDescription = !$elements || array_search('description', $elements) !== FALSE;
|
218 |
|
|
$doArtist = !$elements || array_search('artist', $elements) !== FALSE;
|
219 |
e3059327
|
Andreas Kohlbecker
|
$doMediacreated = true; //!$elements || array_search('mediacreated', $elements) !== FALSE;
|
220 |
6657531f
|
Andreas Kohlbecker
|
$doLocation = !$elements || array_search('location', $elements) !== FALSE;
|
221 |
|
|
$doRights = !$elements || array_search('rights', $elements) !== FALSE;
|
222 |
|
|
|
223 |
|
|
$descriptionPrefix = "";
|
224 |
0c2b9b9d
|
Andreas Kohlbecker
|
$footnote_list_key = 'media-' . $media->uuid;
|
225 |
|
|
|
226 |
|
|
// handle sources and annotations
|
227 |
|
|
cdm_lazyload_array_field('media', 'annotations', $media);
|
228 |
|
|
$annotations_and_sources = handle_annotations_and_sources(
|
229 |
|
|
$media,
|
230 |
|
|
array(
|
231 |
f79d32d6
|
Andreas Kohlbecker
|
'sources_as_content' => $sources_as_content,
|
232 |
0c2b9b9d
|
Andreas Kohlbecker
|
'link_to_name_used_in_source' => 1,
|
233 |
|
|
'link_to_reference' => 0,
|
234 |
f79d32d6
|
Andreas Kohlbecker
|
'add_footnote_keys' => $sources_as_content ? 0 : 1
|
235 |
0c2b9b9d
|
Andreas Kohlbecker
|
),
|
236 |
f79d32d6
|
Andreas Kohlbecker
|
NULL,
|
237 |
|
|
$footnote_list_key
|
238 |
0c2b9b9d
|
Andreas Kohlbecker
|
);
|
239 |
|
|
|
240 |
|
|
$out = '';
|
241 |
6657531f
|
Andreas Kohlbecker
|
|
242 |
|
|
// Title.
|
243 |
|
|
if ($doTitle) {
|
244 |
f79d32d6
|
Andreas Kohlbecker
|
$title_string = $media_metadata['title']
|
245 |
|
|
. $annotations_and_sources['foot_note_keys']; // placing the footnote keys here is not optimal, see #6329 A.1.
|
246 |
0c2b9b9d
|
Andreas Kohlbecker
|
$title_string = trim($title_string);
|
247 |
|
|
if (empty($title_string) && !($doDescription && $media_metadata['description'])) {
|
248 |
|
|
// Use filename as fallback option if no description and no source citations are available.
|
249 |
|
|
$title_string = $media_metadata['filename'];
|
250 |
6657531f
|
Andreas Kohlbecker
|
}
|
251 |
0c2b9b9d
|
Andreas Kohlbecker
|
$out .= '<div class="title">' . $title_string . '</div>';
|
252 |
6657531f
|
Andreas Kohlbecker
|
}
|
253 |
0c2b9b9d
|
Andreas Kohlbecker
|
|
254 |
6657531f
|
Andreas Kohlbecker
|
// Description.
|
255 |
|
|
if ($media_metadata['description'] && $doDescription) {
|
256 |
09e628ea
|
Andreas Kohlbecker
|
$out .= '<p class="description">' . $media_metadata['description'] . '</p>';
|
257 |
6657531f
|
Andreas Kohlbecker
|
}
|
258 |
09e628ea
|
Andreas Kohlbecker
|
|
259 |
|
|
$groups = array();
|
260 |
|
|
|
261 |
|
|
$out .= '<dl class="media-caption">';
|
262 |
6657531f
|
Andreas Kohlbecker
|
// Artist.
|
263 |
|
|
if ($media_metadata['artist'] && $doArtist) {
|
264 |
f79d32d6
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Artist') . ':', $media_metadata['artist'] );
|
265 |
6657531f
|
Andreas Kohlbecker
|
}
|
266 |
17993bbd
|
Andreas Kohlbecker
|
// MediaCreated
|
267 |
e3059327
|
Andreas Kohlbecker
|
if ($media_metadata['mediacreated'] && $doMediacreated) {
|
268 |
17993bbd
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Created') . ':', $media_metadata['mediacreated'] );
|
269 |
|
|
}
|
270 |
6657531f
|
Andreas Kohlbecker
|
// Location.
|
271 |
|
|
if ($doLocation) {
|
272 |
|
|
$location = '';
|
273 |
|
|
$location .= $media_metadata['location']['sublocation'];
|
274 |
|
|
if ($location && $media_metadata['location']['city']) {
|
275 |
|
|
$location .= ', ';
|
276 |
|
|
}
|
277 |
|
|
$location .= $media_metadata['location']['city'];
|
278 |
|
|
if ($location && $media_metadata['location']['province']) {
|
279 |
|
|
$location .= ', ';
|
280 |
|
|
}
|
281 |
|
|
$location .= $media_metadata['location']['province'];
|
282 |
|
|
if ($location && $media_metadata['location']['country']) {
|
283 |
|
|
$location .= ' (' . $media_metadata['location']['country'] . ')';
|
284 |
|
|
}
|
285 |
|
|
else {
|
286 |
|
|
$location .= $media_metadata['location']['country'];
|
287 |
|
|
}
|
288 |
|
|
if ($location) {
|
289 |
f79d32d6
|
Andreas Kohlbecker
|
_description_list_group_add($groups, t('Location') . ':', $location );
|
290 |
6657531f
|
Andreas Kohlbecker
|
}
|
291 |
|
|
}
|
292 |
|
|
// Rights.
|
293 |
|
|
if ($doRights) {
|
294 |
f79d32d6
|
Andreas Kohlbecker
|
$groups = array_merge($groups, cdm_rights_as_dl_groups($media_metadata['rights']));
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
if(!empty($annotations_and_sources['source_references'])){
|
298 |
20e02fff
|
Andreas Kohlbecker
|
$sources_label = count($annotations_and_sources['source_references']) > 1 ? t('Sources') : t('Source');
|
299 |
c021779a
|
Andreas Kohlbecker
|
_description_list_group_add($groups, $sources_label . ':', markup_to_render_array(join('; ', $annotations_and_sources['source_references'])) );
|
300 |
6657531f
|
Andreas Kohlbecker
|
}
|
301 |
f79d32d6
|
Andreas Kohlbecker
|
|
302 |
97ff635c
|
Andreas Kohlbecker
|
// TODO add all other metadata elements generically.
|
303 |
f79d32d6
|
Andreas Kohlbecker
|
|
304 |
|
|
$description_list_item = array(
|
305 |
|
|
'#theme' => 'description_list',
|
306 |
|
|
'#groups' => $groups,
|
307 |
|
|
'#attributes' => array('class' => 'media-caption')
|
308 |
|
|
);
|
309 |
|
|
$out .= drupal_render($description_list_item);
|
310 |
0c2b9b9d
|
Andreas Kohlbecker
|
|
311 |
b810c46f
|
Andreas Kohlbecker
|
$out .= cdm_footnotes($footnote_list_key);
|
312 |
0c2b9b9d
|
Andreas Kohlbecker
|
|
313 |
6657531f
|
Andreas Kohlbecker
|
return $out;
|
314 |
|
|
}
|