forked from whikloj/manidora
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanidora.module
994 lines (918 loc) · 32.5 KB
/
manidora.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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
<?php
/**
* @file
* Custom University of Manitoba hacks for Islandora.
*/
$module_path = drupal_get_path('module', 'manidora');
@require_once "$module_path/includes/utilities.inc";
@require_once "$module_path/includes/blocks.inc";
/**
* @deprecated No longer used internally and not recommended.
*
* API call to insert a link to a printer friendly version of something.
*
* @param string $path
* path to page we want a printer friendly version of
* @return string
* The link to the printer friendly version of this object.
*/
function manidora_print_insert_link($path) {
return "";
}
/**
* Implements hook_preprocess_print().
*
* Strips out unneccessary content and adds MODS metadata below the object.
*/
function manidora_preprocess_print(&$variables) {
module_load_include('inc', 'manidora', 'includes/metadata');
// Get the DOM.
$content_dom = new DOMDocument();
$content_dom->loadHTML($variables["print"]["content"]);
//
// Get just the content we want.
// We're looking for the 'content' divs.
//
$divs = $content_dom->getElementsByTagName("div");
$found = FALSE;
for ($i = 0; $i < $divs->length && !$found; $i++) {
if ($divs->item($i)->hasAttribute("class") &&
($divs->item($i)->getAttribute("class") == "islandora-basic-image-content" ||
$divs->item($i)->getAttribute("class") == "islandora-large-image-content" ||
$divs->item($i)->getAttribute("class") == "islandora-newspaper-content")
) {
// Replace original content with just the stripped out 'content' div.
$variables["print"]["content"] = $content_dom->saveHTML($divs->item($i));
$found = TRUE;
}
}
//
// Append the MODS metadata to the end of the content.
//
if ($found) {
// Hack out the PID from the URL.
$url = $variables["print"]["url"];
$explode_results = explode("/islandora/object/", $url);
if (count($explode_results) > 1) {
$pid = $explode_results[1];
}
else {
$pid = $explode_results[0];
}
$pid = urldecode($pid);
// Use the PID to get the Islandora object.
$islandora_object = islandora_object_load($pid);
// Append the MODS metadata list to the end of the content to be themed by
// the printer friendly module.
if ($islandora_object['MODS']) {
$metadata = manidora_retrieve_metadata_form($islandora_object);
$variables["print"]["content"] .= "<br/>" . drupal_render($metadata);
}
}
}
/**
* Implements hook_menu().
*/
function manidora_menu() {
$items = array();
$items['islandora/object/%islandora_object/manitoba_metadata'] = array(
'title' => 'Details',
'type' => MENU_LOCAL_TASK,
'page callback' => 'manidora_retrieve_metadata_form',
'page arguments' => array(2),
'access callback' => 'manidora_metadata_access',
'access arguments' => array(2),
'weight' => 1,
'file' => 'includes/metadata.inc',
);
$items['islandora/object/%islandora_object/manitoba_download'] = array(
'title' => 'Download',
'type' => MENU_LOCAL_TASK,
'page callback' => 'manidora_download_table',
'page arguments' => array(2),
'access callback' => 'manidora_download_access',
'access arguments' => array(2),
'weight' => 2,
);
$items['islandora/manitoba/newspaper_search'] = array(
'title' => 'Manitoba Advanced Newspaper Search',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('manidora_newspaper_search_form'),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS),
'file' => 'includes/newspaper_search.inc',
);
$items['admin/islandora/manidora'] = array(
'title' => 'Manidora',
'description' => 'Configure the UofM customization module!',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/islandora/manidora/settings'] = array(
'title' => 'Manidora',
'description' => 'Configure the UofM customization module.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'page arguments' => array('manidora_admin'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/admin_form.inc',
);
$items['admin/islandora/manidora/collections'] = array(
'title' => 'Manidora Collection listing',
'description' => 'Configure the collection listing.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'page arguments' => array('manidora_collection_list_form'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/admin_form.inc',
);
$items['admin/islandora/manidora/collections/%/edit'] = [
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => ['manidora_omit_collections_edit_form', 4],
'access arguments' => ['administer site configuration'],
'file' => 'includes/admin_form.inc',
];
$items['admin/islandora/manidora/collections/%/delete'] = [
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => ['manidora_omit_collections_delete_form', 4],
'access arguments' => ['administer site configuration'],
'file' => 'includes/admin_form.inc',
];
$items['islandora/manitoba/pdf/print'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'manidora_printable_pdf',
'page arguments' => array(4, NULL),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS),
);
$items['islandora/object/%islandora_object/manidora_download_clip'] = array(
'page callback' => 'manidora_download_clip',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/manidora_download_clip_pdf'] = array(
'page callback' => 'manidora_download_clip_pdf',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
'load arguments' => array(2),
'file' => 'includes/pdf.inc',
);
$items['admin/islandora/manidora/homepage'] = array(
'title' => 'Manidora Homepage images',
'description' => 'Configure the selected homepage thumbnails.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'page arguments' => array('manidora_homepage_thumbnail_admin'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/admin_form.inc',
);
$items['admin/islandora/manidora/homepage/%/remove'] = array(
'title' => 'Manidora Homepage images - removal PID path',
'page callback' => 'manidora_homepage_thumbnail_remove',
'page arguments' => array(4),
'type' => MENU_CALLBACK,
'access arguments' => array('administer site configuration'),
'file' => 'includes/admin_form.inc',
);
$items['islandora/manitoba/autocomplete_general_dental_tags'] = array(
'page callback' => 'manidora_autocomplete_general_dental_tags',
'page arguments' => array(3),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['islandora/manidora/collection_autocomplete'] = array(
'page callback' => 'manidora_autocomplete_collections',
'page arguments' => array(3),
'access arguments' => array('administer site configuration'),
'file' => 'includes/admin_form.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_theme().
*/
function manidora_theme() {
return array(
'manidora_whats_new_item' => array(
'template' => 'theme/manidora-whats-new-item',
'variables' => array('item' => NULL),
'file' => 'includes/blocks.inc',
),
);
}
/**
* Implements hook_menu_alter().
*
* Do the ol' switcharooney on the menu entry for the islandora_fits
* module so that UofM can continue their tabish lifestyles.
*/
function manidora_menu_alter(&$items) {
if (module_exists('islandora_fits')) {
$fits_tab = $items['islandora/object/%islandora_object/manage/fits_metadata'];
$items['islandora/object/%islandora_object/fits_metadata'] = $fits_tab;
$items['islandora/object/%islandora_object/fits_metadata']['weight'] = 3;
$items['islandora/object/%islandora_object/fits_metadata']['access callback'] = 'manidora_technical_metadata_access';
unset($items['islandora/object/%islandora_object/manage/fits_metadata']);
}
// Overrides the hook_object_access() call.
$items['islandora/object/%islandora_object/print_object']['access callback'] = 'manidora_print_object_access';
}
/**
* Implements hook_menu_local_tasks_alter().
*
* Adds id="clip" to print_object tab
*/
function manidora_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($root_path == 'islandora/object/%') {
// This makes the print tab use the newspaper clipper if possible.
for ($foo = 0; $foo < count($data['tabs']); $foo += 1) {
for ($bar = 0; $bar < $data['tabs'][$foo]['count']; $bar += 1) {
if (isset($data['tabs'][$foo]['output'][$bar]['#link']['path']) &&
$data['tabs'][$foo]['output'][$bar]['#link']['path'] == 'islandora/object/%/print_object') {
$data['tabs'][$foo]['output'][$bar]['#options']['attributes'] = array('id' => 'clip');
break;
}
}
}
if (module_exists('islandora_compound_object')) {
// This makes a compound only display the parent label.
$object = menu_get_object('islandora_object', 2);
$children = islandora_compound_object_get_parts($object->id);
$pid = (!empty($children)) ? $children[0] : $object->id;
$compound_object = islandora_object_load($pid);
$compound_info = islandora_compound_object_retrieve_compound_info($compound_object);
if ($compound_info) {
drupal_set_title(filter_xss($compound_info['parent_label']));
}
}
}
}
/**
* Implements hook_access().
*/
function manidora_metadata_access(AbstractObject $object) {
// Now show Details tab for Collections
//if (!in_array('islandora:collectionCModel', $object->models)) {
// You get a string if you don't have access to load the object.
if ($object instanceof AbstractObject) {
if (array_intersect(array('islandora:sp_videoCModel', 'islandora:sp-audioCModel'), $object->models)) {
if (isset($object['PBCORE']) || isset($object['MODS'])) {
return TRUE;
}
}
else {
if (isset($object['MODS'])) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Overwrites the islandora_fits_access() function for use in Manidora.
*
* @param IslandoraObject $object
* An instansiated IslandoraObject.
*
* @return bool
* Access or not.
*/
function manidora_technical_metadata_access($object) {
$allowed_models = array(
'islandora:sp_basic_image',
'islandora:sp_large_image_cmodel',
'islandora:sp_videoCModel',
'islandora:sp-audioCModel'
);
if ($object[variable_get('islandora_fits_techmd_dsid', 'TECHMD')] && user_access('view technical metadata') && count(array_intersect($allowed_models, $object->models))) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Implements hook_access().
* @TODO: Expand on the restriction?
*/
function manidora_download_access($object) {
if (!in_array('islandora:collectionCModel', $object->models)) {
return TRUE;
}
return FALSE;
}
/**
* Overrides the default hook_object_access() call.
*
* Call this instead by altering the menu in manidora_menu_alter().
*/
function manidora_print_object_access($op, $object, $user = NULL) {
$dont_print = array(
'islandora:collectionCModel',
'islandora:newspaperCModel',
'islandora:newspaperIssueCModel',
);
if (count(array_intersect($object->models, $dont_print)) > 0) {
return FALSE;
}
return islandora_object_access($op, $object, $user);
}
/**
* Generates a table of all downloadable datastreams for an IslandoraObject.
*
* Used in the "Download" tab.
*
* @param IslandoraObject $islandora_object
* The object whose datastreams you wish to download.
*
* @return array
* Returns a table containing all the datastreams.
*/
function manidora_download_table($islandora_object) {
module_load_include('inc', 'islandora', 'includes/datastream');
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/breadcrumb');
drupal_add_js(drupal_get_path('module', 'manidora') . '/js/ga.js', 'file');
drupal_add_js("var manidora_trackdownload_page = '/" . current_path() . "';", 'inline');
drupal_set_breadcrumb(islandora_get_breadcrumbs($islandora_object));
drupal_set_title($islandora_object->label . " Downloads");
$headers = array(
'ID' => t('ID'),
'label' => t('Label'),
'mime' => t('Mime type'),
'size' => t('Size'),
'download' => t('Download'),
);
foreach ($islandora_object as $ds) {
if ($ds->size > 0) {
$rows[] = array(
'ID' => l($ds->id, islandora_datastream_get_url($ds, 'view'), array('attributes' => array('rel' => 'alternate'))),
'label' => $ds->label,
'mime' => $ds->mimeType,
'size' => islandora_datastream_get_human_readable_size($ds),
'download' => l(t('download'), islandora_datastream_get_url($ds, 'download'), array('attributes' => array(
'onclick' => "manidora_trackDownloadLink('" . $ds->ID . "');",
'rel' => 'alternate',
))),
);
}
}
// We want TIFFS, JPEG and PDFs at the top of the Downloads list.
$top_a = array();
$bottom_a = array();
foreach ($rows as $row) {
if (preg_match('/>(JPG|PDF|TIFF|OBJ)</', $row['ID'])) {
array_push($top_a, array('data' => $row, 'class' => array('important-download')));
}
else {
array_push($bottom_a, array('data' => $row));
}
}
sort($top_a);
sort($bottom_a);
$rows = array_merge($top_a, $bottom_a);
$table = array(
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
);
return $table;
}
/**
* Preprocessor for newspaper_page, removes some controls.
*/
function manidora_preprocess_islandora_newspaper_page_controls(&$variables) {
unset($variables['controls']['jp2_download']);
unset($variables['controls']['view']);
unset($variables['controls']['pdf_download']);
}
/**
* Gets the title of the object for display.
*
* Newspapers have specialized titles.
*
* @param AbstractObject $object
* The object from which to derive the title.
*/
function manidora_get_title(AbstractObject $object) {
$models = $object->models;
$retrieve_title = in_array('islandora:newspaperPageCModel', $models);
return $retrieve_title ? manidora_retrieve_header_text($object->id) : $object->label;
}
/**
* Gets the title to display for the given newspaper page or newspaper.
*/
function manidora_set_title(AbstractObject $object) {
drupal_set_title(manidora_get_title($object));
}
/**
* Implements hook_islandora_view_object().
*/
function manidora_islandora_view_object_alter(AbstractObject $object) {
manidora_set_title($object);
}
/**
* Implements hook_process_theme().
*/
function manidora_process_islandora_object_print(array &$variables) {
module_load_include('inc', 'manidora', 'includes/metadata');
$object = $variables['object'];
if (in_array('islandora:newspaperPageCModel', $object->models)) {
manidora_set_title($object);
$clip = isset($variables['clip']) ? $variables['clip'] : NULL;
$variables['content']['buttons']['1'] = array(
'#markup' => ' | ',
'#weight' => -5,
);
$variables['content']['buttons']['download_pdf'] = array(
'#prefix' => '<strong>',
'#markup' => l(t('Download PDF'), "islandora/object/{$object->id}/manidora_download_clip_pdf", array(
'query' => array('clip' => $clip))),
'#suffix' => '</strong>',
'#weight' => -5,
);
}
$variables['content']['metadata'] = manidora_retrieve_metadata_form($object);
}
/**
* Alter the image upload forms, to allow a flag to be set for OCR.
*/
function manidora_form_alter(&$form, &$form_state, $form_id) {
$forms_to_modify = array(
'islandora_basic_image_image_upload_form',
'islandora_large_image_image_upload_form',
);
if (in_array($form_id, $forms_to_modify) && module_exists('islandora_ocr')) {
// XXX: Weighted form elements would be preferable to slicing... anyway.
$original_form = $form;
$form = array_slice($original_form, 0, -2);
$form += array(
'ocr_checkbox' => array(
'#type' => 'checkbox',
'#title' => t('OCR image'),
'#description' => t('Flag the image to be run through OCR during the ingest process.'),
),
);
$form += array_slice($original_form, -2);
array_unshift($form['next']['#submit'], 'manidora_ocr_flag_submit');
}
}
/**
* Submit handler; add RELS-EXT statement if we should OCR an image.
*/
function manidora_ocr_flag_submit($form, &$form_state) {
if ($form_state['values']['ocr_checkbox']) {
$object = reset($form_state['islandora']['objects']);
$object->relationships->add(ISLANDORA_RELS_EXT_URI, 'doImageOCR', 'true', 1);
}
}
/**
* Implements hook_CMODEL_PID_islandora_object_ingested().
*
* Generates a high-quality jpeg derivative datastream (HQ_JPG) for embedding
* into PDF's.
*/
function manidora_islandora_newspaperPageCModel_islandora_object_ingested($object) {
module_load_include('inc', 'islandora_large_image', 'includes/derivatives');
$base_name = str_replace(':', '-', $object->id);
$uploaded_file = islandora_large_image_get_uploaded_file($object, $base_name);
$args = array();
$args[] = '-quality ' . escapeshellarg('25%');
$derivative_file = islandora_large_image_imagemagick_convert($uploaded_file, "temporary://{$base_name}_HQ_JPG.jpg", $args);
if ($derivative_file === FALSE) {
/* XXX: Used in newspaper batch... drupal_set_message('...', 'error')
causes the batch to stop, due to
http://api.drush.org/api/drush/includes!drush.inc/function/_drush_log_drupal_messages/6.x */
drupal_set_message(t('Failed to create HQ_JPG derivative'), 'warning');
file_unmanaged_delete($uploaded_file);
return FALSE;
}
islandora_large_image_add_datastream($object, 'HQ_JPG', $derivative_file, 'image/jpeg', t('High quality JPEG'));
file_unmanaged_delete($derivative_file);
file_unmanaged_delete($uploaded_file);
return TRUE;
}
/**
* Implements hook_CMODEL_PID_islandora_solr_object_result_alter().
*
* Puts the Solr query terms into the object URL so that viewers can use them
* for highlighting.
*/
function manidora_islandora_sp_large_image_cmodel_islandora_solr_object_result_alter(&$search_results, $query_processor) {
$search_results['object_url_params']['solr'] = array(
'query' => $query_processor->solrQuery,
'params' => $query_processor->solrParams,
);
}
/**
* Implements hook_process_theme().
*/
function manidora_process_islandora_large_image(&$variables) {
// Override the default text for UofM.
$variables['image_clip'] = "";
}
/**
* Retrieves and renders PBCORE metadata.
*
* @param AbstractObject $object
* An AbstractObject representing a Fedora object.
*
* @return string
* The PBCORE metadata markup to be displayed.
*/
function manidora_pbcore_metadata($object) {
$pbcore_metadata = drupal_get_form('PBCORE Display', $object['PBCORE']->content);
return drupal_render($pbcore_metadata);
}
/**
* Implements hook_islandora_xml_form_builder_forms().
*/
function manidora_xml_form_builder_forms() {
$module_path = drupal_get_path('module', 'manidora');
return array(
'PBCORE Display' => array(
'form_file' => "$module_path/xml/forms/pbcore_display.xml",
),
'UofM Basic Image MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_basic_image_mods_form.xml",
),
'UofM Book MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_book_mods_form.xml",
),
'UofM Large Image MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_large_image_mods_form.xml",
),
'UofM Newspaper MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_newspaper_mods_form.xml",
),
'UofM Newspaper Issue MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_newspaper_issue_mods_form.xml",
),
'UofM PDF MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_pdf_mods_form.xml",
),
'UofM Dental MODS form' => array(
'form_file' => "$module_path/xml/forms/uofm_dental_mods_form.xml",
),
);
}
/**
* Implements hook_foo_form_alter().
*
* We don't want the collection search to display on non-collection pages
* as it is unreliable
*/
function manidora_form_islandora_collection_search_form_alter(&$form, &$form_state) {
if (isset($form['simple']) &&
isset($form['simple']['collection_pid']) &&
isset($form['simple']['collection_pid']['value'])) {
$collection_pid = $form['simple']['collection_pid']['#value'];
if ($collection_pid && preg_match('/^\w+:[a-zA-Z0-9]+$/', $collection_pid)) {
try {
$object = islandora_object_load($collection_pid);
$models = $object->relationships->get(FEDORA_MODEL_URI, 'hasModel');
}
catch (Exception $e) {
watchdog('Manidora', 'Failed to load object or models: %s', array('%s' => $e->getMessage()));
}
}
}
if (isset($models)) {
$collection = FALSE;
foreach ($models as $model) {
if ($model['object']['value'] == 'islandora:collectionCModel' || $model['object']['value'] == 'islandora:newspaperCModel') {
$collection = TRUE;
}
}
}
if (isset($collection) && $collection === FALSE) {
$form['simple']['collection_select']['#default_value'] = 0;
$form['simple']['collection_select']['#access'] = 0;
}
}
/**
* Implements hook_element_info_alter().
*/
function manidora_element_info_alter(&$type) {
$type['creative_commons']['#value_callback'] = 'manidora_creative_commons_hack_up_url_value_callback';
}
/**
* Value callback for creative commons element.
*
* @param array $element
* The element.
* @param array $input
* The input of the element.
* @param array $form_state
* The form state.
*
* @return string
* The license URI.
*/
#function manidora_creative_commons_hack_up_url_value_callback(&$element, $input, &$form_state) {
# module_load_include('inc', 'xml_form_elements', 'includes/creative_commons');
# return manidora_creative_commons_hack_up_url(
# xml_form_elements_creative_commons_value_callback($element, $input, $form_state)
# );
#}
/**
* Hacks up the URL to fit with existing manitoba URLs.
*/
function manidora_creative_commons_hack_up_url($url) {
#return str_replace('http://creativecommons.org/licenses/', '', $url);
return $url;
}
/**
* Implements hook_islandora_derivative().
*/
function manidora_islandora_derivative(AbstractObject $object) {
$derivatives = array();
$image_content_models = array(
'islandora:sp_large_image_cmodel',
'islandora:sp_basic_image',
);
if (array_intersect($object->models, $image_content_models)) {
// We are changing an image...
if ($object->relationships->get(ISLANDORA_RELS_EXT_URI, 'generate_ocr', 'true', 1)) {
$base = array(
'source_dsid' => 'OBJ',
'file' => drupal_get_path('module', 'islandora_ocr') . '/includes/derivatives.inc',
);
$derivatives[] = $base + array(
'destination_dsid' => 'OCR',
'function' => array('islandora_ocr_derive_ocr'),
);
$derivatives[] = $base + array(
'destination_dsid' => 'HOCR',
'function' => array('islandora_ocr_derive_hocr'),
);
}
}
$derivatives[] = array(
'source_dsid' => 'OCR',
'destination_dsid' => NULL,
'function' => array('manidora_aggregate_ocr_in_parents'),
'file' => drupal_get_path('module', 'manidora') . '/includes/compound_ocr_aggregation.inc',
);
return $derivatives;
}
/**
* Implements hook_islandora_datastream_purged().
*/
function manidora_islandora_datastream_purged(AbstractObject $object, $dsid) {
if ($dsid == 'OCR') {
module_load_include('inc', 'manidora', 'includes/compound_ocr_aggregation');
manidora_scrub_aggregated_ocr($object->id);
}
}
/**
* Implements hook_islandora_object_purged().
*/
function manidora_islandora_object_purged($pid) {
module_load_include('inc', 'manidora', 'includes/compound_ocr_aggregation');
manidora_scrub_aggregated_ocr($pid);
}
/**
* Implements hook_islandora_compound_object_children_added_to_parent().
*/
function manidora_islandora_compound_object_children_added_to_parent($objects, $parent_pids) {
$parent_objects = array_filter(array_map('islandora_object_load', $parent_pids));
module_load_include('inc', 'manidora', 'includes/compound_ocr_aggregation');
array_map('manidora_aggregate_child_ocr', $parent_objects);
}
/**
* Implements hook_islandora_compound_object_children_removed_from_parent().
*/
function manidora_islandora_compound_object_children_removed_from_parent($objects, $parent_pids) {
$parent_objects = array_filter(array_map('islandora_object_load', $parent_pids));
module_load_include('inc', 'manidora', 'includes/compound_ocr_aggregation');
array_map('manidora_aggregate_child_ocr', $parent_objects);
}
/**
* Implements hook_islandora_xml_form_builder_form_associations().
*/
function manidora_xml_form_builder_form_associations() {
return array(
'uofm_basic_image_mods_form' => array(
'content_model' => 'islandora:sp_basic_image',
'form_name' => 'UofM Basic Image MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
'uofm_book_mods_form' => array(
'content_model' => 'islandora:bookCModel',
'form_name' => 'UofM Book MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
'uofm_large_image_mods_form' => array(
'content_model' => 'islandora:sp_large_image_cmodel',
'form_name' => 'UofM Large Image MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
'uofm_newspaper_mods_form' => array(
'content_model' => 'islandora:newspaperCModel',
'form_name' => 'UofM Newspaper MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
'uofm_newspaper_issue_mods_form' => array(
'content_model' => 'islandora:newspaperIssueCModel',
'form_name' => 'UofM Newspaper Issue MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
'uofm_pdf_mods_form' => array(
'content_model' => 'islandora:sp_pdf',
'form_name' => 'UofM PDF MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
'uofm_dental_mods_form' => array(
'content_model' => 'islandora:sp_large_image_cmodel',
'form_name' => 'UofM Dental MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'self_transform' => 'cleanup_dentist_form_mods.xsl',
'template' => FALSE,
),
);
}
/**
* Autocomplete field for the manidora Dental form General Tags.
*/
function manidora_autocomplete_general_dental_tags($query = '') {
$voc = taxonomy_vocabulary_machine_name_load('manidora_general_dental_tags');
$terms = taxonomy_term_load_multiple(array(), array('vid' => $voc->vid));
$output = array();
foreach ($terms as $term) {
if (substr_compare($term->name, $query, 0, strlen($query), TRUE) == 0) {
$output[$term->name] = $term->name;
}
}
echo drupal_json_output($output);
}
/**
* Allows access to the element based on the value of another form element.
*/
function manidora_dentist_form_process_optional(array $element, array &$form_state) {
$title = isset($form_state['values']['dental']['title']) ? $form_state['values']['dental']['title'] : '';
foreach (element_children($element) as $i) {
$accessible = (strpos($title, $i) !== FALSE);
$child = &$element[$i];
$child['#access'] = $accessible;
foreach (element_children($child) as $j) {
$grand_child = &$child[$j];
$grand_child['#access'] = $accessible;
}
}
return $element;
}
/**
* Add link to description for general tags, when the user can edit the terms.
*/
function manidora_dentist_form_process_general_tags(array &$element) {
$vocabulary = taxonomy_vocabulary_machine_name_load('manidora_general_dental_tags');
if ($vocabulary) {
if (user_access('edit terms in ' . $vocabulary->vid)) {
$element['general']['#description'] = t('Add / Edit available tags <a href="@url">here</a>.', array('@url' => url('admin/structure/taxonomy/manidora_general_dental_tags')));
}
}
return $element;
}
/**
* Makes the empty value of a checkbox, the empty string rather than 0.
*/
function manidora_checkbox_value_callback($element, $input = FALSE, $form_state = array()) {
if ($input === FALSE) {
// Default value comes from the XML.
return isset($element['#default_value']) && $element['#default_value'] == $element['#return_value'];
}
elseif ($input === NULL || empty($input)) {
return '';
}
else {
return $input;
}
}
/**
* The ajax callback responsible for rendering the optional tags.
*/
function manidora_dental_form_tags_ajax_callback(array $form, array &$form_state) {
return $form['dental']['optional'];
}
/**
* Implements hook_xml_form_builder_get_self_transforms().
*/
function manidora_xml_form_builder_get_self_transforms() {
$module_path = drupal_get_path('module', 'manidora');
return array(
'cleanup_dentist_form_mods.xsl' => "$module_path/xsl/cleanup_dentist_form_mods.xsl",
'remove_dental_from_mods.xsl' => "$module_path/xsl/remove_dental_from_mods.xsl",
'manidora_pbcore_cleanup.xsl' => "$module_path/xsl/manidora_pbcore_cleanup.xsl",
'manidora_pbcore_cleanup_remove_cc.xsl' => "$module_path/xsl/manidora_pbcore_cleanup_remove_cc.xsl",
'remove_dental_and_cc_from_mods.xsl' => "$module_path/xsl/remove_dental_and_cc_from_mods.xsl",
);
}
/**
* Because we want the list display, but not the word "default" in the name.
*/
function manidora_islandora_solr_primary_display() {
return array(
'uofm_list' => array(
'name' => t('List'),
'module' => 'islandora_solr',
'file' => 'includes/results.inc',
'class' => "IslandoraSolrResults",
'function' => "displayResults",
'description' => t("A simple output."),
),
);
}
/**
* Implements function hook_cmodel_pid_dsid_islandora_datastream_ingested().
*
* We want our JPG derivatives to have the label of the filename,
* so this changes it from the default 'Medium Sized JPEG'.
*/
function manidora_islandora_sp_large_image_cmodel_JPG_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
if (isset($object['OBJ']) && isset($object['JPG'])) {
$label = $object['OBJ']->label;
$bare_label = substr($label, 0, strrpos($label, '.'));
$object['JPG']->label = $bare_label . '.jpg';
}
}
/**
* Implements hook_islandora_metadata_display_info().
*/
function manidora_islandora_metadata_display_info() {
return array(
'manidora_metadata' => array(
'label' => t('UofM Metadata display'),
'description' => t('Specific MODS display used by the print_object path'),
'metadata callback' => 'manidora_metadata_markup_callback',
'description callback' => 'manidora_description_markup_callback',
),
);
}
/**
* Returns rendered markup for the above metadata callback.
*
* @param AbstractObject $object
* The Islandora object to provide metadata for.
* @param boolean $print
* Whether to print the metadata or not.
* @return string
*
* @see hook_islandora_metadata_display_info()
*/
function manidora_metadata_markup_callback(AbstractObject $object, $print) {
$output = "";
if ($print) {
module_load_include('inc', 'manidora', 'includes/metadata');
$form = manidora_retrieve_metadata_form($object);
$output = drupal_render($form);
}
return $output;
}
/**
* Returns the description for the above description callback.
*
* @param AbstractObject $object
* The Islandora object to provide metadata for.
*
* @see hook_islandora_metadata_display_info()
*/
function manidora_description_markup_callback(AbstractObject $object) {
return manidora_set_title($object);
}
/**
* Implements hook_islandora_oai_get_xsl_files().
*/
function manidora_islandora_oai_get_xsl_files() {
$mod_dir = drupal_get_path('module', 'manidora');
return array(
"{$mod_dir}/xsl/mods_to_mods_oai.xsl" => 'mods_to_mods_oai.xsl',
);
}