forked from Islandora/islandora_solution_pack_book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislandora_book.module
640 lines (595 loc) · 20.9 KB
/
islandora_book.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<?php
/**
* @file
* Islandora book solution pack module
*/
/**
* Islandora book menu
* @return array
*/
function islandora_book_menu() {
$items = array();
$items['fedora/book'] = array(
'title' => t('Book view'),
'page callback' => 'islandora_book_create_book_view',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['restore/books'] = array(
'title' => t('Deleted Books'),
'file' => 'management/book_undelete.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('book_undelete_form'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('manage deleted books'),
);
$items['fedora/book_viewer'] = array(
'title' => t('Book viewer'),
'page callback' => 'islandora_book_book_viewer',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
$items['admin/settings/islandora_book'] = array(
'title' => 'Islandora Book Admin',
'description' => 'Configuration Islandora Book Module',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_book_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'islandora_book.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['islandora/book/ocr'] = array(
'page callback' => 'update_ocr_div',
'access arguments' => array('view fedora collection'),
'file' => 'islandora_book.admin.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/updatepage'] = array(
'page callback' => 'page_management_wrapper',
'access arguments' => array('manage book object'),
'file' => 'ObjectManager.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/upload'] = array(
'page callback' => 'upload_pages',
'access arguments' => array('manage book object'),
'file' => 'pageload/upload_frame.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/borndigital'] = array(
'page callback' => 'create_borndigital',
'access arguments' => array('view fedora collection'),
'file' => 'management/born_digital.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/upload_setup'] = array(
'page callback' => 'upload_setup',
'access arguments' => array('manage book object'),
'file' => 'pageload/upload_frame.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/process_file'] = array(
'page callback' => 'process_file',
'access arguments' => array('view fedora collection'),
'file' => 'pageload/upload_frame.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/process_page_directory'] = array(
'page callback' => 'prep_add_form',
'access arguments' => array('view fedora collection'),
'file' => 'pageload/prepare_add_pages_form.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/delete_book_files'] = array(
'page callback' => 'delete_book_page_files',
'access arguments' => array('view fedora collection'),
'file' => 'pageload/upload_frame.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/page/manage'] = array(
'page callback' => 'islandora_book_page_management',
'access arguments' => array('manage page object'),
'file' => 'page_object_manager.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/manage'] = array(
'page callback' => 'islandora_book_display_links',
'access arguments' => array('manage book object'),
'file' => 'management/IslandoraBookDisplayLinks.inc',
'type' => MENU_CALLBACK,
);
$items['islandora/book/management'] = array(
'page callback' => 'book_management_wrapper',
'access arguments' => array('manage book object'),
'file' => 'book_object_manager.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
function islandora_book_perm() {
return array(
'delete pages',
'manage book object',
'manage page object',
'manage deleted books',
);
}
function islandora_book_solution_pack_form() {
module_load_include('inc', 'islandora_book', 'islandora_book.admin');
return islandora_book_admin_settings($form_state);
}
function islandora_book_islandora_tabs($content_models, $pid) {
module_load_include('inc', 'islandora_book', 'page_object_manager');
module_load_include('inc', 'islandora_book', 'book_object_manager');
module_load_include('inc', 'fedora_repository', 'plugins/FedoraObjectDetailedContent');
$tabset = array();
$content_model = $content_models[0]->pid;
if ($content_model == 'islandora:pageCModel' && user_access('manage page object')) {
$return_tabs = get_page_model_management_content($pid);
$return_tabs['fedora_object_details'] = null;
return $return_tabs;
}
if ($content_model == 'islandora:bookCModel' || $content_model == 'islandora:iaBookCModel') {
// $return_tabs = get_book_model_management_content($pid);
$return_tabs['fedora_object_details'] = null;
return $return_tabs;
}
}
/**
* Implementation of hook_init
* (currently disabled)
*/
function disabled_islandora_book_init() {
drupal_add_css(drupal_get_path('module', 'islandora_book') . '/css/islandora_book.css');
}
/**
* Islandora book book viewer
* Allows viewing of book object thorugh embedded player
* @global user $user
* @param string $pid
* @return html
*/
function islandora_book_book_viewer($pid) {
global $user;
$qs = '';
if ($user->uid != 0) {
$qs = '?uid=' . base64_encode($user->name . ':' . $user->pass);
}
$viewer_url = variable_get('fedora_base_url', '') . '/get/' . $pid . '/islandora:viewerSdef/getViewer' . $qs;
$html = '<iframe src="' . $viewer_url . '" frameborder="0" scrolling="no" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>';
$fieldset = array(
'#title' => t('Viewer - ') . $pid,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => $html);
drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme');
return theme('fieldset', $fieldset);
}
/**
* Load an xslt from the main book page uses mods for most of the display.
* @global user $user
* @param string $pid
* @param string $query Default NULL but if supplied then it will execute the query against the book
*/
function islandora_book_create_book_view($pid, $query = NULL) {
global $user;
module_load_include('inc', 'fedora_repository', 'api/ObjectHelper');
$path = drupal_get_path('module', 'islandora_book');
$object_helper = new ObjectHelper;
$xml = $object_helper->getStream($pid, 'MODS');
$dc_xml = $object_helper->getStream($pid, 'DC');
if (!$dc_xml) {
drupal_set_message(t('Object does not exist.'), 'error');
return '';
}
$simpleDCxml = simplexml_load_string($dc_xml);
$types = $simpleDCxml->xpath('//dc:type');
$ingested = 'FALSE';
if (!empty($types)) {
foreach ($types as $type) {
if ($type == 'ingested') {
$ingested = 'TRUE';
}
}
}
if (!isset($pid)) {
drupal_set_message(t('Error getting book view, no identifier specified.'));
return;
}
$proc = NULL;
try {
$proc = new XsltProcessor();
} catch (Exception $e) {
drupal_set_message(t('Error loading Book View XSLT: @e', array('@e' => check_plain($e->getMessage()))));
return;
}
//inject into xsl stylesheet
$params = array(
'USERID' => $user->uid,
'OBJECTSPAGE' => base_path(),
'PID' => $pid,
'INGESTED' => $ingested,
'SOLRFIELD' => variable_get('islandora_book_solr_subject_field', 'mods.subject'),
);
$proc->setParameter("", $params);
$xsl = new DomDocument();
$test = $xsl->load($path . '/xsl/book_view.xsl');
if (!isset($test)) {
drupal_set_message(t('Error loading search results XSLT.'));
return t('Error loading search results XSLT.');
}
$input = new DomDocument();
$didLoadOk = $input->loadXML($xml);
$output = NULL;
if (!isset($didLoadOk)) {
drupal_set_message(t('Error loading Book View XML.'));
return t('Error loading Book View XML.');
}
else {
$xsl = $proc->importStylesheet($xsl);
$output = $proc->transformToXML($input);
}
return $output;
}
/**
* convert query to a page query
* @param type $query
* @param type $pid
* @return string
*/
function convert_query_to_page_query($query, $pid) {
$newQuery = substr($query, 0, strlen($query) - 23);
$pid = str_replace(':', '?', $pid);
$newQuery = $newQuery . " AND PID:$pid* AND dc.type:Text";
return $newQuery;
}
/**
* Custom form element to do our nice images.
* @return boolean
*/
function islandora_book_elements() {
$type['imagebutton'] = array(
'#input' => TRUE,
'#button_type' => 'submit',
'#executes_submit_callback' => TRUE,
'#name' => 'op',
'#process' => array('hook_imagebutton_process' => array()),
);
return $type;
}
/**
* theme imagebutton
* @param type $element
* @return type
*/
function theme_imagebutton($element) {
return '<input style="background:url(\'\'); border:0px; width:10px; padding:0px,0px,0px,0px;" type="image" class="form-' . $element['#button_type'] . '" name="' . $element['#name'] . '" id="' . $element['#id'] . '" value="' . check_plain($element['#default_value']) . '" ' . drupal_attributes($element['#attributes']) . ' src="' . $element['#image'] . '" alt="' . $element['#title'] . '" title="' . $element['#title'] . "\" />\n";
}
/**
* Implementation of hook_theme().
*
* @return type
*/
function islandora_book_theme() {
return array(
'imagebutton' => array(
'arguments' => array('form' => NULL),
),
'islandora_book_book_search_form' => array(
'arguments' => array('form' => NULL),
),
'islandora_book_simple_book_search_form' => array(
'arguments' => array('form' => NULL),
),
'islandora_book_page_table' => array(
'arguments' => array('element' => NULL),
'file' => 'management/IslandoraBookPageTable.inc',
),
'islandora_book_page_reorder_table' => array(
'arguments' => array('element' => NULL),
'file' => 'management/IslandoraPageReorderTable.inc',
),
'islandora_book_undelete_table' => array(
'arguments' => array('element' => NULL),
'file' => 'management/IslandoraBookUndelete.inc',
),
'islandora_file_reorder_table' => array(
'arguments' => array('element' => NULL),
'file' => 'management/IslandoraFileReorderTable.inc',
)
);
}
/**
* _islandora_book_viewer_available
* @return boolean
*/
function _islandora_book_viewer_available() {
$url = parse_url(variable_get('fedora_base_url', 'http://localhost:8080/fedora'));
$fedora_host = ("{$url['scheme']}://{$url['host']}" . (!empty($url['port']) ? ":{$url['port']}/" : '/'));
$response = drupal_http_request("$fedora_host/iiv/images/loading.gif");
return empty($response->error);
}
/**
* Implements hook_fedora_repository_required_fedora_objects
* @return array
*/
function islandora_book_fedora_repository_required_fedora_objects() {
module_load_include('inc', 'fedora_repository', 'fedora_repository.solutionpacks');
// Add the form and associate it to the content model
$module_path = drupal_get_path('module', 'islandora_book');
$form_name = 'Islandora Books MODS Form';
$form_xml = file_get_contents("$module_path/xml/mods_book.xml");
solution_pack_add_form($form_name, $form_xml);
solution_pack_add_form_association('islandora:bookCModel', $form_name);
solution_pack_add_form_association('islandora:iaBookCModel', $form_name);
return array(
'islandora_book' => array(
'module' => 'islandora_book',
'title' => 'Islandora Books',
'objects' => array(
array(
'foxml_file' => "$module_path/xml/islandora_pageCModel.xml",
'pid' => 'islandora:pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_criticalEditionCModelPage.xml",
'pid' => 'islandora:criticalEditionCModelPage',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_bd_pageCModel.xml",
'pid' => 'islandora:bd_pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_iaBookCModel.xml",
'pid' => 'islandora:iaBookCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_bookCModel.xml",
'pid' => 'islandora:bookCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_jp2Sdef.xml",
'pid' => 'islandora:jp2Sdef',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_viewerSdef.xml",
'pid' => 'islandora:viewerSdef',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_viewerSdep-bookCModel.xml",
'pid' => 'islandora:viewerSdep-bookCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_viewerSdep-pageCModel.xml",
'pid' => 'islandora:viewerSdep-pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_tei2htmlSdef.xml",
'pid' => 'islandora:tei2htmlSdef',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_tei2htmlSdep-pageCModel.xml",
'pid' => 'islandora:tei2htmlSdep-pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_book_collection.xml",
'pid' => 'islandora:collection',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_organization-entityCModel.xml",
'pid' => 'islandora:organization-entityCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_place-entityCModel.xml",
'pid' => 'islandora:place-entityCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_person-entityCModel.xml",
'pid' => 'islandora:person-entityCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/islandora_jp2Sdep-pageCModel.xml",
'pid' => 'islandora:jp2Sdep-pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'pid' => 'islandora:bookCollection',
'label' => 'Book Collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:root',
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/book_collection_policy.xml",
),
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
),
),
),
),
);
}
/**
* islandora book purge pages form
* @global string $base_url
* @param array $form_state
* @param string $pid
* @param string $referrer
* @return array
*/
function islandora_book_purge_pages_form(&$form_state, $pid, $referrer = NULL) {
global $base_url;
if (!user_access('purge objects and datastreams')) {
return NULL;
}
if ($pid == NULL) {
return NULL;
}
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
);
if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) {
$form['referrer'] = array(
'#type' => 'hidden',
'#value' => $referrer,
);
}
if (!isset($form_state['storage']['confirm'])) {
// do your normal $form definition here
$form['submit'] = array(
'#type' => 'image_button',
'#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png',
'#value' => t('Purge'),
'#suffix' => 'Purge all pages associated with this book',
);
return $form;
}
else {
// ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form
return confirm_form($form, 'Confirm Purge ALL pages?', $referrer, 'Are you sure you want to delete these objects? This action cannot be undone.', 'Purge Pages', 'Cancel'); //Had better luck leaving off last param 'name'
}
return $form;
}
/**
* islandora book purge pages form submit
* @param array $form
* @param array $form_state
*/
function islandora_book_purge_pages_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/ConnectionHelper');
module_load_include('inc', 'islandora_book', 'book_pack_utils');
$pid = $form_state['values']['pid'];
if (!isset($form_state['storage']['confirm'])) {
$form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form
$form_state['rebuild'] = TRUE; // along with this
}
else {
unset($form_state['storage']['confirm']);
$soapHelper = new ConnectionHelper();
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
$pids_to_delete = get_page_pids($pid);
foreach ($pids_to_delete as $pid_to_delete) {
$params = array(
"pid" => $pid_to_delete,
"logMessage" => "Purged",
"force" => ""
);
try {
$object = $client->__soapCall('purgeObject', array($params));
// unset($form_state['storage']['confirm']);
} catch (exception $e) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to purge object.'), 'error');
}
else {
drupal_set_message(t("@message", check_plain($e->getMessage())), 'error');
}
return;
}
}
$form_state['redirect'] = "fedora/repository/$pid";
}
}
/**
* islandora book help
* implementaion of hook_help()
* @param type $path
* @param type $arg
* @return type
*/
function islandora_book_help($path, $arg) {
switch ($path) {
case 'admin/help#islandora_book':
return t(
'<p>
The Islandora Book Module allows users to create digital representations of books within the Fedora Repository.
A book object is created using !mods data. A collection of associated page objects may then be created created. Page objects
are created by ingesting a zipped folder of TIFF images, each representing a distinct page.
Page TIFFs are used to create a series of Fedora datastreams on ingestion. These streams include derivative images
for display - JPEGS, Thumbnails, and JP2s, and one ore more OCR streams for text display and analysis.
</p>
<p>
<h3>Configuration</h3>
The page datatreams may be created on this server, or on an external processing server with !microservices.<br/>
To process images from TIFFS on this server check <strong>Create derivative images locally?</strong> on the admin page. (Link at the bottom of this page).<br />
TO create OCR streams on this server check <strong>Perform OCR on incoming TIFF images?</strong>. <br /><br />
', array(
'!microservices' => l("Fedora Microservices", 'https://github.com/Islandora/fedora_microservices'),
'!mods' => l('MODS', 'http://www.loc.gov/standards/mods/'),
)
);
}
}
/**
* Implementation of hook_islandora_tabs_alter().
*
* @param &$tabs array
* The array of tabs/tabset to alter.
* @param $params array
* An associative array containing the parameters with which the original
* hook was called.
* @see fedora_repository_get_items()
*/
function islandora_book_islandora_tabs_alter(&$tabs, $params) {
//Turn off object details
$models = array(
'islandora:pageCModel',
'islandora:bookCModel',
'islandora:iaBookCModel'
);
if (in_array($params['content_models'][0]->pid, $models)) {
$tabs['fedora_object_details'] = null;
}
}