1
|
<?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
|
* array of CDM Rights entities
|
26
|
*
|
27
|
* @return array
|
28
|
* the render array of the groups for the HTML description list
|
29
|
*/
|
30
|
function cdm_rights_as_dl_groups($rights_list) {
|
31
|
|
32
|
$copyrights = array();
|
33
|
$licenses = array();
|
34
|
$access_rights = array();
|
35
|
$unknown = array();
|
36
|
|
37
|
foreach ($rights_list as $right) {
|
38
|
if (!is_object($right)) {
|
39
|
continue;
|
40
|
}
|
41
|
$type_uuid = isset($right->type->uuid) ? $right->type->uuid : 'UNKNOWN';
|
42
|
switch ($type_uuid) {
|
43
|
|
44
|
case UUID_RIGHTS_COPYRIGHT:
|
45
|
if (isset($right->agent[0]) ){
|
46
|
$agent_names = array();
|
47
|
foreach ($right->agent as $agent) {
|
48
|
$agent_names[] = $agent->titleCache;
|
49
|
}
|
50
|
$copyrights[] = implode(', ', $agent_names);
|
51
|
}
|
52
|
break;
|
53
|
|
54
|
case UUID_RIGHTS_LICENCE:
|
55
|
$license_str = '';
|
56
|
if (isset($right->abbreviatedText)) {
|
57
|
$license_str .= $right->abbreviatedText;
|
58
|
}
|
59
|
if (isset($right->uri)) {
|
60
|
if (strlen($license_str) > 0) {
|
61
|
$license_str = l($license_str, $right->uri);
|
62
|
}
|
63
|
else {
|
64
|
$license_str = l(t('link'), $right->uri);
|
65
|
}
|
66
|
}
|
67
|
if (strlen($license_str) > 0 && isset($right->text)) {
|
68
|
$license_str .= ': ' . $right->text;
|
69
|
}
|
70
|
$licenses[] = $license_str;
|
71
|
break;
|
72
|
|
73
|
case UUID_RIGHTS_ACCESS_RIGHTS:
|
74
|
$access_rights[] = $right->text . $right->uuid;
|
75
|
break;
|
76
|
|
77
|
default:
|
78
|
$unknown_groups[] = $right->text . $right->uuid; // TODO !
|
79
|
}
|
80
|
}
|
81
|
|
82
|
$groups = array();
|
83
|
if (count($copyrights) > 0) {
|
84
|
_description_list_group_add($groups, t('Copyright'), $copyrights);
|
85
|
}
|
86
|
if (count($licenses) > 0) {
|
87
|
_description_list_group_add($groups, t('Licenses'), $licenses);
|
88
|
}
|
89
|
if (count($access_rights) > 0) {
|
90
|
_description_list_group_add($groups, t('Access rights'), $access_rights);
|
91
|
}
|
92
|
if (count($unknown) > 0) {
|
93
|
_description_list_group_add($groups, t('Rights (untyped)'), $unknown);
|
94
|
}
|
95
|
|
96
|
return $groups;
|
97
|
|
98
|
}
|
99
|
|
100
|
|
101
|
/**
|
102
|
* Provides the markup for an icon to represent a media which is associated with the given $feature.
|
103
|
*
|
104
|
* @param $feature
|
105
|
* the cdm Feature term
|
106
|
* @param $media_url
|
107
|
* Optional, currently unused. May be used in future to display different
|
108
|
* icons for different media urls, like the fav-icon of the referenced
|
109
|
* @return string
|
110
|
* The markup for the icon
|
111
|
*/
|
112
|
function media_feature_icon($feature, $media_url = NULL) {
|
113
|
return font_awesome_icon_markup('fa-book', array('alt' => $feature->representation_L10n));
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Gets the metadata info such as title or artist of a media file.
|
118
|
*
|
119
|
* The function tries at first to get all the info from the file metadata
|
120
|
* and if it is not available look at the media file info stored at the database.
|
121
|
*
|
122
|
* @param mixed $media
|
123
|
* The media file object for which to get the metadata.
|
124
|
*
|
125
|
* @return array
|
126
|
* The array with the available specified metadata info.
|
127
|
*/
|
128
|
function read_media_metadata($media) {
|
129
|
|
130
|
$metadata_caption = array(
|
131
|
'title' => '',// Media_metadata and media.
|
132
|
'artist' => '',// Media_metadata and media.
|
133
|
'rights',// Media_metadata and media.
|
134
|
'location',// Media_metadata.
|
135
|
'filename' => '',// Media.
|
136
|
'mediacreated' => '',// Media.
|
137
|
'description' => '',
|
138
|
);// Media.
|
139
|
|
140
|
// Getting the media metadata.
|
141
|
$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
|
142
|
$media_metadata_aux = (array) $media_metadata;
|
143
|
|
144
|
// Filename.
|
145
|
if (!empty($media->representations[0]->parts[0]->uri)) {
|
146
|
$fileUri = $media->representations[0]->parts[0]->uri;
|
147
|
$filename = substr($fileUri, strrpos($fileUri, "/") + 1);
|
148
|
$metadata_caption['filename'] = $filename;
|
149
|
}
|
150
|
else {
|
151
|
$metadata_caption['filename'] = '';
|
152
|
}
|
153
|
|
154
|
// Title.
|
155
|
if (!empty($media_metadata->ObjectName)) {
|
156
|
$metadata_caption['title'] = $media_metadata->ObjectName;
|
157
|
}
|
158
|
elseif (!empty($media_metadata_aux['Object Name'])) {
|
159
|
$metadata_caption['title'] = $media_metadata_aux['Object Name'];
|
160
|
}
|
161
|
elseif (!empty($media->title_L10n)) {
|
162
|
$metadata_caption['title'] = $media->title_L10n;
|
163
|
}
|
164
|
elseif (!empty($media->titleCache)) {
|
165
|
$metadata_caption['title'] = $media->titleCache;
|
166
|
}
|
167
|
|
168
|
// Append description to title.
|
169
|
if (!empty($media->description_L10n)) {
|
170
|
$metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
|
171
|
}
|
172
|
|
173
|
// Artist.
|
174
|
if (!empty($media_metadata->Artist)) {
|
175
|
$metadata_caption['artist'] = '' . $media_metadata->Artist;
|
176
|
}
|
177
|
elseif (!empty($media->artist->titleCache)) {
|
178
|
$metadata_caption['artist'] = $media->artist->titleCache;
|
179
|
}
|
180
|
|
181
|
// Copyright.
|
182
|
$metadata_caption['rights'] = array(
|
183
|
'copyright' => array('agentNames' => array()),
|
184
|
'license' => array(
|
185
|
'agentNames' => array(),
|
186
|
'types' => array(),
|
187
|
'abbreviatedTexts' => array(),
|
188
|
'uris' => array(),
|
189
|
),
|
190
|
);
|
191
|
if (!empty($media_metadata->Copyright)) {
|
192
|
$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
|
193
|
}
|
194
|
elseif (isset($media->rights) && is_array($media->rights)) {
|
195
|
foreach ($media->rights as $right) {
|
196
|
if(isset($right->term)){
|
197
|
switch ($right->type->uuid) {
|
198
|
case UUID_RIGHTS_LICENCE:
|
199
|
$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
|
200
|
$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
|
201
|
$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
|
202
|
$metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
|
203
|
break;
|
204
|
case UUID_RIGHTS_COPYRIGHT:
|
205
|
$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
|
206
|
break;
|
207
|
}
|
208
|
}
|
209
|
}
|
210
|
}
|
211
|
else {
|
212
|
$metadata_caption['rights']['agentNames'][] = '';
|
213
|
}
|
214
|
|
215
|
// Filling the description (though there is no description in the db???).
|
216
|
// $metadata_caption['description'] = $media->description_L10n;
|
217
|
|
218
|
// Location.
|
219
|
$metadata_caption['location'] = array();
|
220
|
$metadata_caption['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
|
221
|
$metadata_caption['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
|
222
|
$metadata_caption['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
|
223
|
$metadata_caption['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
|
224
|
|
225
|
/*
|
226
|
// Creation date.
|
227
|
if($media_metadata["Modify Date"])
|
228
|
$metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
|
229
|
else
|
230
|
$metadata_caption['mediacreated'] = $media->created;
|
231
|
*/
|
232
|
|
233
|
// Returned value.
|
234
|
return $metadata_caption;
|
235
|
}
|