forked from discoverygarden/islandora_handle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_handle.module
220 lines (204 loc) · 6.91 KB
/
islandora_handle.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
<?php
/**
* @file
* Module used to house customizations for MIRC@SC.
*/
/**
* Implements hook_menu().
*/
function islandora_handle_menu() {
$items = array();
$items['admin/islandora/islandora-handle'] = array(
'title' => 'Islandora Handle',
'description' => 'Settings for the Islandora Handle module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_handle_server_form'),
'access arguments' => array('administer islandora handle'),
'file' => 'includes/admin.inc',
);
$items['admin/islandora/islandora-handle/server'] = array(
'title' => 'Handle Server',
'description' => 'Settings for the Handle.net server we are interacting with.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_handle_server_form'),
'access arguments' => array('administer islandora handle'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'includes/admin.inc',
'weight' => 0,
);
$items['admin/islandora/islandora-handle/content-models'] = array(
'title' => 'Content Models',
'description' => 'Specific content model configuration for interaction with Handles.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_handle_cmodel_form'),
'access arguments' => array('administer islandora handle'),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/admin.inc',
'weight' => 1,
);
$items['admin/reports/islandora-handle-config-list'] = array(
'title' => 'Islandora Handle Configs',
'description' => 'List the enabled configurations for each content model.',
'page callback' => 'islandora_handle_config_list',
'access arguments' => array('administer islandora handle'),
'file' => 'includes/admin.inc',
);
return $items;
}
/**
* Implements hook_permission().
*/
function islandora_handle_permission() {
return array(
'administer islandora handle' => array(
'title' => 'Administer the Islandora Handle module',
),
);
}
/**
* Implements hook_object_alter().
*/
function islandora_handle_islandora_object_alter(AbstractObject $object, array &$context) {
module_load_include('inc', 'islandora_handle', 'includes/handle');
if ($context['action'] == 'purge') {
// Query cmodels and delete Handles that may be there.
$models = $object->models;
$handle_results = db_select('islandora_handle_apply_handle', 'h')
->fields('h', array('cmodel', 'datastream', 'xsl_location'))
->condition('cmodel', $models)
->execute()
->fetchAll();
if ($handle_results) {
// Go out and attempt to delete the Handle if there is one
// supposed to be created.
$handler_class = islandora_handle_retrieve_selected_handler();
$handler = new $handler_class();
if (!$handler->deleteHandle($object)) {
watchdog('islandora_handle', 'Unable to delete Handle when @pid was purged.', array(
'@pid' => $object->id,
), WATCHDOG_ERROR);
}
}
}
}
/**
* Implements hook_islandora_derivative().
*/
function islandora_handle_islandora_derivative(AbstractObject $object) {
module_load_include('inc', 'islandora_handle', 'includes/handle');
$derivatives = array();
$handle_configs = islandora_handle_retrieve_configurations_by_cmodels($object->models);
foreach ($handle_configs as $config) {
// Object ingested case.
$derivatives[] = array(
'source_dsid' => NULL,
'destination_dsid' => $config->datastream,
'function' => array(
'islandora_handle_append_handle_from_configuration',
),
'file' => drupal_get_path('module', 'islandora_handle') . '/includes/derivatives.inc',
);
$derivatives[] = array(
'source_dsid' => $config->datastream,
'destination_dsid' => 'DC',
'function' => array(
'islandora_handle_add_to_dc_datastream',
),
'file' => drupal_get_path('module', 'islandora_handle') . '/includes/derivatives.inc',
'weight' => 100,
);
// Datastream ingested/modified case.
$derivatives[] = array(
'source_dsid' => $config->datastream,
'destination_dsid' => $config->datastream,
'function' => array(
'islandora_handle_append_handle_from_configuration',
),
'file' => drupal_get_path('module', 'islandora_handle') . '/includes/derivatives.inc',
);
}
$derivatives[] = array(
'source_dsid' => NULL,
'destination_dsid' => NULL,
'function' => array(
'islandora_handle_clean_up_handle',
),
'file' => drupal_get_path('module', 'islandora_handle') . '/includes/derivatives.inc',
'weight' => 100,
);
return $derivatives;
}
/**
* Hook that retrieves the default XSL files that ship with the module.
*
* @return array
* An array containing the list of XSL/XSLT files available.
*/
function islandora_handle_islandora_handle_get_xsl_files() {
$files = file_scan_directory(drupal_get_path('module', 'islandora_handle') . '/transforms/', '/.*\.xslt?$/');
$transform_options = array();
foreach ($files as $file) {
$transform_options[$file->uri] = $file->filename;
}
$handle_uploaded_files = array();
$upload_path = 'public://islandora_handle_xsls';
$uploaded_files = file_scan_directory($upload_path, '/.*\.xslt?$/');
foreach ($uploaded_files as $up_file) {
$handle_uploaded_files[$up_file->uri] = $up_file->filename;
}
foreach ($handle_uploaded_files as $key => $file) {
if (!in_array($file, $transform_options)) {
$transform_options[$key] = $file;
}
}
return $transform_options;
}
/**
* Implements hook islandora_handle_handle_handler().
*/
function islandora_handle_islandora_handle_handle_handler() {
$handlers = array();
$handlers['islandora_handle_debug'] = array(
'label' => t('Debug'),
'class' => 'IslandoraHandleDebugHandler',
);
$handlers['islandora_handle_service'] = array(
'label' => t('Handle Service (Handle 7)'),
'class' => 'IslandoraHandleServiceHandler',
);
$handlers['islandora_handle_rest'] = array(
'label' => t('Handle REST (Handle 8+)'),
'class' => 'IslandoraHandleRestHandler',
);
return $handlers;
}
/**
* Implements hook_token_info()
*/
function islandora_handle_token_info() {
$info['tokens']['fedora']['handle'] = array(
'name' => t('Handle'),
'description' => t('Fedora object handle'),
);
return $info;
}
/**
* Implements hook_tokens()
*/
function islandora_handle_tokens($type, $tokens, array $data = array(), array $options = array()) {
if ($type == 'fedora' & !empty($data['fedora'])) {
$object = $data['fedora'];
$replacements = array();
foreach ($tokens as $name => $original) {
if ($name === 'handle') {
module_load_include('inc', 'islandora_handle', 'includes/handle');
$handler_class = islandora_handle_retrieve_selected_handler();
$handler = new $handler_class();
$handle = $handler->getFullHandle($object);
$replacements[$original] = $handle;
}
}
return $replacements;
}
return array();
}