-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathislandora_downloadable_datastreams.module
117 lines (106 loc) · 3.83 KB
/
islandora_downloadable_datastreams.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
<?php
/**
* @file
* The main islandora_downloadable_datastreams module file.
*/
/**
* Implements hook_menu().
*/
function islandora_downloadable_datastreams_menu() {
return array(
'admin/islandora/tools/downloadblock' => array(
'title' => 'Islandora Downloadable Datastreams',
'description' => 'Configure Islandora Downloadable Datastreams.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_downloadable_datastreams_admin_form'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/admin.form.inc',
),
);
return $items;
}
/**
* Implements hook_block_info(). Creates blocks.
*/
function islandora_downloadable_datastreams_block_info() {
return array(
'datastream_download' => array(
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'islandora/object/*',
'cache' => DRUPAL_CACHE_PER_PAGE,
'info' => t('Datastream download block'),
),
);
}
/**
* Implements hook_block_view().
*/
function islandora_downloadable_datastreams_block_view($delta) {
// use the utilities.inc file
module_load_include('inc', 'islandora_downloadable_datastreams', 'includes/utilities');
$to_render = array();
// Get object CModel and PID - this may be repeating itself, I'm not sure.
$object = menu_get_object('islandora_object', 2);
if ($object) {
$pid = $object->id;
$ids = array();
$ids['pid'] = $pid;
$ids['cmodel'] = islandora_object_load($pid)->models[0];
$dsid = "none";
// If object is a selected CModel, proceed - otherwise, don't render.
if (islandora_downloadable_datastreams_show_for_cmodel($object)) {
// Choose DSID for large images
if ($ids['cmodel']=='islandora:sp_large_image_cmodel') {
$dsid = variable_get('islandora_downloadable_datastreams_image_dsid', 'JP2');
}
// For newspapers and books, assume PDFs
elseif ($ids['cmodel']=='islandora:newspaperIssueCModel' || $ids['cmodel']=='islandora:bookCModel') {
// If there's no PDF datastream, do nothing. Otherwise, PDF.
if (!$object['PDF']) {
$dsid = "none";
}
else {
$dsid = "PDF";
}
}
// For audio, assume PROXY_MP3 for now. Make this configurable - either OBJ or PROXY_MP3.
elseif ($ids['cmodel'] == 'islandora:sp-audioCModel') {
$dsid = "PROXY_MP3";
}
// For video, assume MP4 datastream until we make it configurable instead.
elseif ($ids['cmodel'] == 'islandora:sp_videoCModel') {
$dsid = variable_get('islandora_downloadable_datastreams_video_dsid', 'MP4');
}
// For binary objects
elseif ($ids['cmodel'] == 'islandora:binaryObjectCModel') {
$dsid = "OBJ";
}
// For PDF, check if viewer is present
elseif ($ids['cmodel'] == 'islandora:sp_pdf') {
$viewer = islandora_downloadable_datastreams_check_viewer($ids);
if ($viewer !== "none") {
$dsid = "OBJ";
}
}
// For Citation and Thesis objects, check if viewer is present.
elseif ($ids['cmodel'] == 'ir:thesisCModel' || $ids['cmodel'] == 'ir:citationCModel') {
$viewer = islandora_downloadable_datastreams_check_viewer($ids);
if ($viewer !== "none") {
$dsid = "PDF";
}
}
// For Documents, we want the OBJ.
elseif ($ids['cmodel'] == 'islandora:sp_document') {
$dsid= "OBJ";
}
// Create the link if a DSID is selected
if ($dsid != "none") {
global $base_url;
$label = variable_get('islandora_downloadable_datastreams_label', 'Download');
$to_render['content'] = '<div class="downloadlink"><a href="' . $base_url . '/islandora/object/' . $pid . '/datastream/' . $dsid . '/download">' . $label . '</a></div>';
}
}
return $to_render;
}
}