-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbc_islandora.module
executable file
·400 lines (361 loc) · 13.9 KB
/
bc_islandora.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?php
/**
* @file
* Custom behavior for Barnard Digital Collections.
*/
define('BC_ISLANDORA_SOLR_DATE_HELP_TEXT_DEFAULT', '(Valid formats: YYYY, YYYY/MM, YYYY/MM/DD)');
/**
* Implements hook_init().
*
* Disable caching for the front page only.
*/
function bc_islandora_init() {
if (drupal_is_front_page()) {
drupal_page_is_cacheable(FALSE);
}
}
/**
* Implements hook_permission().
*/
function bc_islandora_permission() {
return [
'administer bc_islandora' => [
'title' => t('Administer Barnard Islandora'),
'description' => t('Perform administrative tasks for Barnard Islandora.'),
],
];
}
/**
* Implements hook_form().
*
* Admin Settings and Configuration.
*/
function bc_islandora_config($form, &$form_state) {
$form['bc_islandora_newspaper_pid'] = [
'#type' => 'textfield',
'#title' => t('Barnard Newspaper Collection PID'),
'#default_value' => variable_get('bc_islandora_newspaper_pid', 'islandora:74'),
'#description' => t('Barnard College Newspaper Collection PID.'),
];
$form['bc_islandora_pubs_pid'] = [
'#type' => 'textfield',
'#title' => t('Student Publications Collection PID'),
'#default_value' => variable_get('bc_islandora_pubs_pid', 'islandora:1022'),
'#description' => t('Barnard College Student Publications Collection PID.'),
];
$form['bc_islandora_manuscripts_pid'] = [
'#type' => 'textfield',
'#title' => t('Manuscripts Collection PID'),
'#default_value' => variable_get('bc_islandora_manuscripts_pid', 'islandora:manuscriptCollection'),
'#description' => t('Barnard College Manuscript Collection PID. Based on ?? (Oral histories?).'),
];
$form['bc_islandora_scrapbook_pid'] = [
'#type' => 'textfield',
'#title' => t('Alumnae Scrapbook Collection PID (BC15)'),
'#default_value' => variable_get('bc_islandora_scrapbook_pid', 'BC15:0'),
'#description' => t('Barnard College Alumnae Scrapbook Collection PID. Barnard Record Group BC15.'),
];
$form['bc_islandora_bookreader_initial_thumbs'] = [
'#type' => 'textfield',
'#title' => t('IIAB: PIDs to initially display as "thumbs".'),
'#default_value' => variable_get('bc_islandora_bookreader_initial_thumbs', 'BC15-02:01, BC15-04:36, BC15-04:1'),
'#description' => t('Coma separated list of namespaces or PIDs to force to thumbs display in Islandora Internet Archive BookReader.'),
];
$form['bc_islandora_bookreader_initial_1up'] = [
'#type' => 'textfield',
'#title' => t('IIAB: PIDs to initially display as "1up".'),
'#default_value' => variable_get('bc_islandora_bookreader_initial_1up', ''),
'#description' => t('Coma separated list of namespaces or PIDs to force to 1up display in Islandora Internet Archive BookReader.<br /><strong>Scrapbooks (rg BC15.x) need not apply!</strong>'),
];
$form['bc_solr_date_facet_format'] = [
'#type' => 'textfield',
'#title' => t('PHP date format that Solr should use for the date facet.'),
'#default_value' => variable_get('bc_solr_date_facet_format', 'Y/m/d'),
'#description' => t('<strong>Only accepts: day, month, and year format characters of d/j m/n Y/y.</strong><br /><a target=_new href="http://php.net/manual/en/function.date.php#refsect1-function.date-parameters">PHP Date Format documentation.</a> <br />Format preview: @format', ['@format' => date(variable_get('bc_solr_date_facet_format', 'Y/m/d'))]),
];
$form['bc_islandora_date_help_text'] = [
'#type' => 'textfield',
'#title' => t('Human readable help text for SOLR date input.'),
'#default_value' => variable_get('bc_islandora_date_help_text', BC_ISLANDORA_SOLR_DATE_HELP_TEXT_DEFAULT),
'#description' => t('Help text for the date format specified.'),
];
$form['bc_islandora_hide_datepicker'] = [
'#type' => 'checkbox',
'#title' => t('Hide date picker?'),
'#default_value' => variable_get('bc_islandora_hide_datepicker', TRUE),
'#description' => t('Whether to hide the date picker when faceting search results by date range.'),
];
return system_settings_form($form);
}
/**
* Implements hook_menu().
*/
function bc_islandora_menu() {
$items = [];
$items['admin/islandora/bc_config'] = [
'title' => 'Configure Barnard Islandora',
'description' => "<strong>Customize Barnard's Islandora Instance</strong>",
'page callback' => 'drupal_get_form',
'page arguments' => ['bc_islandora_config'],
'type' => MENU_NORMAL_ITEM,
'access arguments' => ['administer bc_islandora'],
];
$items['admin/islandora/bc_metadata'] = [
'title' => 'Update Barnard Metadata',
'page callback' => 'drupal_get_form',
'page arguments' => ['bc_islandora_metadata_form'],
'file' => 'metadata.inc',
'file path' => drupal_get_path('module', 'bc_islandora') . '/includes',
'type' => MENU_NORMAL_ITEM,
'access arguments' => ['administer bc_islandora'],
];
$items['islandora/object/%islandora_object/download_transcript'] = [
'page callback' => 'bc_islandora_download_transcript',
'page arguments' => [2],
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access',
'access arguments' => [ISLANDORA_VIEW_OBJECTS, 2],
];
$items['islandora/object/%islandora_object/uc_transcript_edit_form/%islandora_datastream'] = array(
'title' => 'Uncorrected Transcript Edit form',
'description' => 'Edit transcript',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'bc_islandora_oralhistories_uncorrected_transcript_edit_form',
2,
4,
),
'file' => 'forms.inc',
// This access arg is okay but not ideal. Should be Islandora access callback
// and REPLACE_DATASTREAM
'access arguments' => array('administer bc_islandora'),
'file path' => drupal_get_path('module', 'bc_islandora') . '/includes',
'type' => MENU_CALLBACK,
'load arguments' => array(2),
);
return $items;
}
/**
* Implements hook_islandora_edit_datastream_registry().
*/
function bc_islandora_islandora_edit_datastream_registry(AbstractObject $object, AbstractDatastream $datastream) {
if (strtoupper($datastream->id) == 'UNCORRECTED_TRANSCRIPT') {
return array(
array(
'name' => t('Islandora Oralhistories Edit Uncorrected Transcript'),
'url' => "islandora/object/{$object->id}/uc_transcript_edit_form/{$datastream->id}",
),
);
}
}
/**
* Implements hook_block_info().
*/
function bc_islandora_block_info() {
$blocks = [];
$blocks['solr_sort_select'] = [
'info' => t('Barnard Islandora Solr Sort'),
'cache' => DRUPAL_NO_CACHE,
];
return $blocks;
}
/**
* Implements hook_block_view().
*/
function bc_islandora_block_view($delta = '') {
switch($delta) {
case 'solr_sort_select':
require_once drupal_get_path('module', 'bc_islandora') . '/includes/blocks.inc';
$block['content'] = bc_islandora_islandora_solr_sort_select();
break;
}
return $block;
}
/**
* Implements hook_theme().
*/
function bc_islandora_theme($existing, $type, $theme, $path) {
return [
'bc_islandora_newspaper_issue_navigator' => [
'variables' => [
'object' => NULL,
'start_page' => 1,
],
'file' => 'includes/theme.inc',
],
'bc_islandora_newspaper_page_controls' => [
'variables' => [
'object' => NULL,
],
'file' => 'includes/theme.inc',
],
'bc_islandora_breadcrumb' => [
'variables' => [
'breadcrumb' => [],
],
'file' => 'includes/theme.inc',
],
];
}
/*****
* SECTION: OCR and Transcript Handling.
*****/
/**
* Implements hook_form_alter().
*/
function bc_islandora_form_islandora_paged_content_manage_page_edit_ocr_form_alter(&$form, &$form_state, $form_id) {
$form['#submit'][] = '_bc_islandora_update_transcript_cache';
}
/**
* Submit handler for page OCR form.
*/
function _bc_islandora_update_transcript_cache($form, &$form_state) {
module_load_include('inc', 'bc_islandora', 'includes/utilities');
$object = $form_state['object'];
$object_cid = _barnard_islandora_get_transcript_cid($object);
cache_set($object_cid, _barnard_islandora_generate_transcript($object));
}
/**
* Makes a "transcript" (concatenated page OCR) available for download.
*
* @see islandora_download_datastream()
*/
function bc_islandora_download_transcript($islandora_pid) {
module_load_include('inc', 'islandora_paged_content', 'includes/utilities');
module_load_include('inc', 'bc_islandora', 'includes/utilities');
if ($object = islandora_object_load($islandora_pid)) {
$object_cid = _barnard_islandora_get_transcript_cid($object);
// If this object's transcript has been cached, use the cached version.
if ($cached_ocr = cache_get($object_cid)) {
$object_ocr = $cached_ocr->data;
}
// Otherwise, generate a new transcript and cache it.
else {
$object_ocr = _barnard_islandora_generate_transcript($object);
cache_set($object_cid, $object_ocr);
}
// Download the transcript as a text file.
header('Content-type: text/plain');
header("Content-Disposition: attachment; filename=\"{$object_cid}.txt\"");
print $object_ocr;
exit();
}
return drupal_not_found();
}
/**
* SECTION: Solr Modifications.
*/
/**
* Implements hook_form_alter().
*/
function bc_islandora_form_islandora_solr_date_filter_form_alter(&$form, &$form_state) {
// Remove the attached datepicker.js.
if (variable_get('bc_islandora_hide_datepicker', FALSE)) {
unset($form['#attached']);
}
// Retrieve our date facet_format.
$query_params = drupal_get_query_parameters();
!empty($query_params['date_format']) ?
$facet_format = $query_params['date_format'] :
$facet_format = variable_get('bc_solr_date_facet_format', 'Y/m/d');
// Update the format helper text.
$date_help_text = variable_get('bc_islandora_date_help_text', BC_ISLANDORA_SOLR_DATE_HELP_TEXT_DEFAULT);
$form['date_filter']['date_filter']['#markup'] = "<div class='description'>$date_help_text</div>";
// Remove titles and add placeholder text instead.
unset($form['date_filter']['date_filter_from']['#title']);
unset($form['date_filter']['date_filter_to']['#title']);
$form['date_filter']['date_filter_from']['#attributes']['placeholder'] = 'Start';
$form['date_filter']['date_filter_from']['#suffix'] = '<span id="between-dates">to </span>';
$form['date_filter']['date_filter_to']['#attributes']['placeholder'] = 'End';
// Change "Filter" to "Apply".
$form['date_filter']['date_filter_submit']['#value'] = 'Apply';
// Add a handler to modify the date_filter_to to the latest date possible
// based on current input.
array_unshift($form['#submit'], 'bc_islandora_form_islandora_solr_date_filter_form_submit');
// Do not add anything to blank fields. Leave this function.
if (!$form['date_filter']['date_filter_from']['#default_value'] && !$form['date_filter']['date_filter_to']['#default_value']) {
return;
}
// Modify the current form to use our facet_format.
$date_from = new DateTime($form['date_filter']['date_filter_from']['#default_value']);
$date_to = new DateTime($form['date_filter']['date_filter_to']['#default_value']);
$form['date_filter']['date_filter_from']['#default_value'] = $date_from->format($facet_format);
$form['date_filter']['date_filter_to']['#default_value'] = $date_to->format($facet_format);
}
/**
* When using a facet_format, appends the "oldest date" as the date_filter_to.
*/
function bc_islandora_form_islandora_solr_date_filter_form_submit(&$form, &$form_state) {
module_load_include('inc', 'bc_islandora', 'includes/utilities');
global $_islandora_solr_queryclass;
$form_date_from = $form_state['values']['date_filter']['date_filter_from'];
$form_date_to = $form_state['values']['date_filter']['date_filter_to'];
$_islandora_solr_queryclass->internalSolrParams['date_format'] = _barnard_islandora_get_date_format($form_date_from, $form_date_to);
$form_state['values']['date_filter']['date_filter_to'] .= _barnard_islandora_get_latest_possible_date($form_date_to);
}
/**
* Implements hook_form_alter().
*
* Removes title from Islandora Solr's "Simple Search Box"
*
* @see: https://github.com/BarnardArchives/digitalcollections.barnard.edu/issues/15
*/
function bc_islandora_form_islandora_solr_simple_search_form_alter(&$form, &$form_state) {
$form['simple']['islandora_simple_search_query']['#title'] = '<none>';
}
/**
* Solr list display, but without the word "default" in the rendered name.
*
* @SEE https://github.com/uml-digitalinitiatives/manidora/blob/82561d4cb1f552d71c97e871c54fffb63c55a8fb/manidora.module#L903-L917
*/
function bc_islandora_islandora_solr_primary_display() {
return [
'bcislandora_list' => [
'name' => t('List'),
'module' => 'islandora_solr',
'file' => 'includes/results.inc',
'class' => "IslandoraSolrResults",
'function' => "displayResults",
'description' => t("A simple output."),
],
];
}
/**
* SECTION: Meta-data related modifications.
*/
/**
* Implements hook_barnard_islandora_metadata_functions().
*/
function bc_islandora_barnard_islandora_metadata_functions() {
return [
'bc_primary_display_url' => [
'name' => t('Add: Primary Display URL to MODs'),
'module' => 'bc_islandora',
'file' => 'metadata.inc',
'function' => '_bc_islandora_generate_primary_dislpay_url',
'description' => t("Generates mods:location/mods:url[usage='primary display']."),
],
'bc_primary_' => [
'name' => t('Remove: HOCR Doctype.'),
'module' => 'bc_islandora',
'file' => 'metadata.inc',
'function' => '_bc_islandora_remove_HOCR_doctype',
'description' => t("Removes the HOCR HTML Doctype declaration."),
],
];
}
/**
* Implements hook_islandora_datastream_alter().
*
* @see metadata.inc
*/
function bc_islandora_islandora_datastream_alter($object, $datastream, &$context) {
// Target only ingest.
if ($context['action'] !== 'ingest') {
return;
}
if ($object['MODS'] && $datastream->id == 'MODS') {
module_load_include('inc', 'bc_islandora', 'includes/metadata');
_bc_islandora_generate_primary_dislpay_url($object, TRUE);
}
}