-
Notifications
You must be signed in to change notification settings - Fork 37
/
islandora_audio.module
253 lines (234 loc) · 8.9 KB
/
islandora_audio.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
/**
* @file
* Handles the creation/display of islandora:sp-audioCModel objects.
*/
/**
* Implements hook_menu().
*/
function islandora_audio_menu() {
return array(
'admin/islandora/solution_pack_config/audio' => array(
'title' => 'Audio Solution Pack',
'description' => 'Configure audio derivatives and select player.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'page arguments' => array('islandora_audio_admin'),
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
),
);
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_audio_islandora_required_objects(IslandoraTuque $connection) {
$module_path = drupal_get_path('module', 'islandora_audio');
// Audio Content Model.
$audio_content_model = $connection->repository->constructObject('islandora:sp-audioCModel');
$audio_content_model->owner = 'fedoraAdmin';
$audio_content_model->label = 'Islandora Audio Content Model';
$audio_content_model->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream.
$datastream = $audio_content_model->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_audio_ds_composite_model.xml", FALSE);
$audio_content_model->ingestDatastream($datastream);
// Audio Collection.
$audio_collection = $connection->repository->constructObject('islandora:audio_collection');
$audio_collection->owner = 'fedoraAdmin';
$audio_collection->label = 'Audio Collection';
$audio_collection->models = 'islandora:collectionCModel';
$audio_collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection Policy Datastream.
$datastream = $audio_collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_audio_collection_policy.xml", FALSE);
$audio_collection->ingestDatastream($datastream);
// TN Datastream.
$datastream = $audio_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromFile("$module_path/images/folder.png", FALSE);
$audio_collection->ingestDatastream($datastream);
return array(
'islandora_audio' => array(
'title' => 'Islandora audio',
'objects' => array(
$audio_content_model,
$audio_collection,
),
),
);
}
/**
* Implements hook_CMODEL_PID_islandora_view_object().
*/
function islandora_audio_islandora_sp_audiocmodel_islandora_view_object($object, $page_number, $page_size) {
$output = theme('islandora_audio', array('islandora_object' => $object));
return array('' => $output);
}
/**
* Implements hook_xml_form_builder_forms().
*/
function islandora_audio_xml_form_builder_forms() {
$module_path = drupal_get_path('module', 'islandora_audio');
return array(
'Audio MODS form' => array(
'form_file' => "$module_path/xml/islandora_audio_form_mods.xml",
),
);
}
/**
* Implements hook_xml_form_builder_form_associations().
*/
function islandora_audio_xml_form_builder_form_associations() {
return array(
'islandora_audio_mods_form' => array(
'content_model' => 'islandora:sp-audioCModel',
'form_name' => 'Audio MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'self_transform' => 'islandora_cleanup_mods_extended.xsl',
'template' => FALSE,
),
);
}
/**
* Implements hook_theme().
*/
function islandora_audio_theme($existing, $type, $theme, $path) {
return array(
'islandora_audio' => array(
'template' => 'theme/islandora-audio',
'pattern' => 'islandora_audio__',
'variables' => array('islandora_object' => NULL),
),
);
}
/**
* Implements template_preprocess_HOOK().
*/
function template_preprocess_islandora_audio(array &$variables) {
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
$islandora_object = $variables['islandora_object'];
$repository = $islandora_object->repository;
module_load_include('inc', 'islandora', 'includes/datastream');
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/metadata');
// We should eventually remove the DC object and dc_array code as it only
// exists to not break legacy implementations.
try {
if (isset($islandora_object['DC']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) {
$dc = $islandora_object['DC']->content;
$dc_object = DublinCore::importFromXmlString($dc);
}
}
catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE);
}
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
$variables['islandora_object_label'] = $islandora_object->label;
$variables['theme_hook_suggestions'][] = 'islandora_audio__' . str_replace(':', '_', $islandora_object->id);
$variables['parent_collections'] = islandora_get_parents_from_rels_ext($islandora_object);
$variables['metadata'] = islandora_retrieve_metadata_markup($islandora_object);
$variables['description'] = islandora_retrieve_description_markup($islandora_object);
// Start getting parameters for the player...
$audio_params = array(
"pid" => $islandora_object->id,
);
// Thumbnail.
if (isset($islandora_object['TN']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['TN'])) {
$tn_url = url("islandora/object/{$islandora_object->id}/datastream/TN/view");
$params = array(
'title' => $islandora_object->label,
'path' => $tn_url,
);
$variables['islandora_thumbnail_img'] = theme('image', $params);
$audio_params += array(
'tn' => $tn_url,
);
}
// Audio player.
// Determine whether to attempt to use the OBJ or PROXY_MP3.
module_load_include('inc', 'islandora_audio', 'includes/utilities');
$dsid = !isset($islandora_object['PROXY_MP3']) &&
variable_get('islandora_audio_obj_fallback', TRUE) &&
isset($islandora_object['OBJ']) &&
islandora_audio_datastream_valid_for_playback($islandora_object['OBJ']) ? 'OBJ' : 'PROXY_MP3';
if (islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object[$dsid])) {
$audio_url = url("islandora/object/{$islandora_object->id}/datastream/$dsid", array('absolute' => TRUE));
$audio_params += array(
"url" => $audio_url,
"mime" => 'audio/mpeg',
);
module_load_include('inc', 'islandora', 'includes/solution_packs');
$viewer = islandora_get_viewer($audio_params, 'islandora_audio_viewers', $islandora_object);
if ($viewer) {
$variables['islandora_content'] = $viewer;
}
elseif (isset($variables['islandora_thumbnail_img'])) {
$variables['islandora_content'] = l($variables['islandora_thumbnail_img'], $audio_url, array('html' => TRUE));
}
else {
$variables['islandora_content'] = l($islandora_object->label, $audio_url);
}
}
}
/**
* Implements hook_islandora_ingest_steps().
*/
function islandora_audio_islandora_sp_audiocmodel_islandora_ingest_steps() {
return array(
'islandora_audio_upload' => array(
'weight' => 10,
'type' => 'form',
'form_id' => 'islandora_audio_audio_upload_form',
'module' => 'islandora_audio',
'file' => 'includes/audio_upload.form.inc',
),
);
}
/**
* Implements hook_CMODEL_PID_islandora_derivative().
*/
function islandora_audio_islandora_sp_audiocmodel_islandora_derivative() {
$derivative_list = array(
array(
'source_dsid' => NULL,
'destination_dsid' => 'TN',
'weight' => 1,
'function' => array(
'islandora_audio_create_thumbnail',
),
'file' => drupal_get_path('module', 'islandora_audio') . '/includes/derivatives.inc',
),
);
if (!variable_get('islandora_audio_defer_derivatives_on_ingest', FALSE)) {
$derivative_list[] = array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'PROXY_MP3',
'weight' => '0',
'function' => array(
'islandora_audio_create_mp3',
),
'file' => drupal_get_path('module', 'islandora_audio') . '/includes/derivatives.inc',
);
}
return $derivative_list;
}
/**
* Implements hook_file_mimetype_mapping_alter().
*/
function islandora_audio_file_mimetype_mapping_alter(&$mapping) {
// Make sure the mapping is sensible for audio/mpeg by removing
// it from array and adding it to end so it has priority.
$code = $mapping['extensions']['mp3'];
unset($mapping['extensions']['mp3']);
$mapping['extensions']['mp3'] = $code;
}