This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
forked from ppound/content_model_viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_model_viewer.module
1007 lines (961 loc) · 33.9 KB
/
content_model_viewer.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
995
996
997
998
999
1000
<?php
// $Id$
/**
* @file
*
* Implements hooks and callbacks for this module.
*/
module_load_include('inc', 'content_model_viewer', 'content_model_viewer.db'); // Helper functions/constants for database.
/**
* Constants
* FIXME: These shouldn't be constants, as the permissions should be translatable.
*/
define("PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS", 'View Objects & Datastreams');
define("PERM_CONTENT_MODEL_VIEWER_MODIFY_OBJECT_PROPERTIES", 'Modify Object Properties');
define("PERM_CONTENT_MODEL_VIEWER_PURGE_OBJECTS", 'Purge Objects');
define("PERM_CONTENT_MODEL_VIEWER_ADD_DATASTREAMS", 'Add Datastreams');
define("PERM_CONTENT_MODEL_VIEWER_PURGE_DATASTREAMS", 'Purge Datastreams');
define("PERM_CONTENT_MODEL_VIEWER_DOWNLOAD_DATASTREAMS", 'Download Datastreams');
define("PERM_CONTENT_MODEL_VIEWER_MODIFY_DATASTEAM_PROPERTIES", 'Modify Datastream Properties');
/**
* Implements Menu Hook. Registers Menus.
*/
function content_model_viewer_menu() {
$items['viewer/%'] = array(
'title' => 'Content Model Viewer',
'description' => 'Allows users to view Fedora Objects.',
'page callback' => 'content_model_viewer',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS),
'type' => MENU_NORMAL_ITEM,
);
$items['viewer/%/members'] = array(
'page callback' => 'content_model_viewer_members',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/properties'] = array(
'page callback' => 'content_model_viewer_properties',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_MODIFY_OBJECT_PROPERTIES),
'type' => MENU_CALLBACK,
);
$items['viewer/%/datastreams'] = array(
'page callback' => 'content_model_viewer_datastreams',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/datastreams/%'] = array(
'page callback' => 'content_model_viewer_datastreams',
'page arguments' => array(1, 3),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/overview'] = array(
'page callback' => 'content_model_viewer_overview',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/purge'] = array(
'page callback' => 'content_model_viewer_purge_object',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_PURGE_OBJECTS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/add'] = array(
'page callback' => 'content_model_viewer_add_datastream',
'page arguments' => array(1),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_ADD_DATASTREAMS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/%/purge'] = array(
'page callback' => 'content_model_viewer_purge_datastream',
'page arguments' => array(1, 2),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_PURGE_DATASTREAMS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/%/download'] = array(
'page callback' => 'content_model_viewer_download_datastream',
'page arguments' => array(1, 2),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_DOWNLOAD_DATASTREAMS),
'type' => MENU_CALLBACK,
);
$items['viewer/%/%/view'] = array(
'page callback' => 'content_model_viewer_view_datastream',
'page arguments' => array(1, 2),
'access arguments' => array(PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS),
'type' => MENU_CALLBACK,
);
$items['admin/settings/content_model_viewer'] = array(
'title' => 'Content Model Viewer Settings',
'description' => 'Settings for the Content Model Viewer.',
'page callback' => 'theme',
'page arguments' => array('content_model_viewer_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'content_model_viewer.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/content_model_viewer/%/edit'] = array(
'title' => 'Content Model Viewer Settings',
'description' => 'Settings for the Content Model Viewer.',
'file' => 'content_model_viewer.admin.inc',
'page callback' => 'theme',
'page arguments' => array('content_model_viewer_custom_settings', 3),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
);
$items['admin/settings/content_model_viewer/form/autocomplete/models'] = array(
'page callback' => 'content_model_viewer_autocomplete_models',
'access arguments' => array('administer site configuration'),
'file' => 'content_model_viewer.admin.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_menu_alter().
*
* @param array $items
*/
function content_model_viewer_menu_alter(&$items) {
$items['fedora']['page callback'] = 'content_model_viewer';
$items['fedora/repository']['page callback'] = 'content_model_viewer';
}
/**
* Implements hook_perm. Register permissions.
* FIXME: Translation stuff doesn't like this: content_model_viewer_perm() should have an array of literal string permission names. In content_model_viewer.module. Read more at http://drupal.org/node/323101
* @return array
*/
function content_model_viewer_perm() {
return array(
PERM_CONTENT_MODEL_VIEWER_VIEW_OBJECTS,
PERM_CONTENT_MODEL_VIEWER_MODIFY_OBJECT_PROPERTIES,
PERM_CONTENT_MODEL_VIEWER_PURGE_OBJECTS,
PERM_CONTENT_MODEL_VIEWER_ADD_DATASTREAMS,
PERM_CONTENT_MODEL_VIEWER_PURGE_DATASTREAMS,
PERM_CONTENT_MODEL_VIEWER_DOWNLOAD_DATASTREAMS,
PERM_CONTENT_MODEL_VIEWER_MODIFY_DATASTEAM_PROPERTIES
);
}
/**
* Implements Hook Theme. Registers themes.
*
* @return array
*/
function content_model_viewer_theme() {
return array(
'content_model_viewer' => array(
'arguments' => array('pid' => NULL),
'template' => 'Viewer',
),
'content_model_viewer_metadata_form' => array(
'arguments' => array('pid' => NULL, 'action' => NULL),
'template' => 'Form',
),
'content_model_viewer_settings' => array(
'template' => 'templates/Settings',
),
'content_model_viewer_custom_settings' => array(
'arguments' => array('pid' => NULL),
'template' => 'templates/CustomSettings',
),
'default_content_model_viewer' => array(
'arguments' => array('pid' => NULL),
'file' => 'models/Default.inc',
'template' => 'models/Default',
),
'field_book_content_model_viewer' => array(
'arguments' => array('pid' => NULL),
'template' => 'models/Default',
),
'content_model_viewer_form_table' => array(
'arguments' => array('element' => NULL)
)
);
}
/**
* 'content_model_datastream_viewers' Hook implementation.
*
* Lists all the datastream viewers
*/
function content_model_viewer_content_model_datastream_viewers() {
/**
* @todo make is so that no Classes need to be created and all the information is included
* in this array...
*/
$flexpaper = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'viewers/FlexPaper',
'class' => 'FlexPaperViewer',
);
$xml = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'viewers/XML',
'class' => 'XMLDatastreamViewer',
);
$image_basic = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'viewers/BasicImageViewer',
'class' => 'BasicImageViewer',
);
$image_djatoka = array(// Adore Djatoka is required. Should check the content model for service def or something.
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'viewers/Djatoka',
'class' => 'DjatokaViewer',
);
$text = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'viewers/TextViewer',
'class' => 'TextViewer',
);
return array(
'application/x-shockwave-flash' => $flexpaper,
'application/shockwave-flash' => $flexpaper,
'text/xml' => $xml,
'text/plain' => $text,
'application/rdf+xml' => $xml,
'image/jpeg' => $image_basic,
'image/gif' => $image_basic,
'image/jp2' => $image_basic,
'image/jpeg' => $image_basic,
'image/png' => $image_basic,
'image/raw' => $image_basic,
'image/tiff' => $image_basic,
'image/tif' => $image_basic,
);
}
/**
* Loads all the installed module classes.
*/
function content_model_viewer_include_content_models() {
$include_path = drupal_get_path('module', 'content_model_viewer') . "/models";
$dir = opendir($include_path);
if ($dir !== false) {
while (($file = readdir($dir)) !== false) {
if (preg_match('/\.inc$/', $file)) {
require_once "$include_path/$file";
}
}
}
closedir($dir);
}
/**
* Get the list of installed ContentModelViewer classes.
*/
function content_model_viewer_get_models() {
$models = array();
$classes = get_declared_classes();
foreach ($classes as $class) {
if ($class instanceof ContentModelViewer) {
$models[] = $class;
}
}
return $models;
}
/**
* Loads all the installed viewer classes.
*/
function content_model_viewer_include_viewers() {
$include_path = drupal_get_path('module', 'content_model_viewer') . "/viewers";
$dir = opendir($include_path);
if ($dir !== false) {
while (($file = readdir($dir)) !== false) {
if (preg_match('/\.inc$/', $file)) {
require_once "$include_path/$file";
}
}
}
closedir($dir);
}
/**
* Hook for register_content_models_for_viewer
*
* @return array
*/
function content_model_viewer_register_content_models_for_viewer() {
$models = array();
$models['si:fieldbooks'] = array(
'type' => 'inc',
'module' => 'content_model_viewer',
'file' => 'FieldBooks',
'class' => 'FieldBookModelViewer'
);
return $models;
}
/**
* Gets an instance of a content model viewer.
*
* @param string $pid
*
* @return object
* An instance of the Content Model Viewer if found. Otherwise it returns
* the default content model viewer.
*/
function content_model_viewer_get_registered_content_model_viewer($pid) {
$model_pid = content_model_viewer_get_content_model_pid($pid);
$models = module_invoke_all('register_content_models_for_viewer');
foreach ($models as $key => $model) {
if ($key == $model_pid) {
module_load_include($model['type'], $model['module'], $model['file']);
$class = $model['class'];
return new $class($pid);
}
}
module_load_include('inc', 'content_model_viewer', 'models/Default');
return new DefaultModelViewer($pid);
}
/**
* Checks if there is a registered Content Model Viewer for the given Object.
*
* @param string $pid
* The Fedora Objects pid.
*
* @return boolean
* TRUE if there is a registered Content Model Viewer.
*/
function content_model_viewer_has_registered_content_model_viewer($pid) {
$model_pid = content_model_viewer_get_content_model_pid($pid);
$models = module_invoke_all('register_content_models_for_viewer');
foreach ($models as $key => $model) {
if ($key == $model_pid) {
return TRUE;
}
}
return FALSE;
}
/**
* Get the pid of this objects content model.
*
* @param string $pid
*
* @return string
*/
function content_model_viewer_get_content_model_pid($pid) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
$content_model = ContentModel::loadFromObject($pid);
return $content_model->pid;
}
/**
* Gets the Supported Viewers.
*
* @staticvar array $cache
* @return array
*/
function content_model_viewer_get_supported_viewers() {
static $cache;
if (!isset($cache)) {
$cache = array();
foreach (module_implements('content_model_datastream_viewers') as $module) {
$viewers = module_invoke($module, 'content_model_datastream_viewers');
if (isset($viewers) && is_array($viewers)) {
$cache = array_merge_recursive($cache, $viewers);
}
}
}
return $cache;
}
/**
* Looks for a supported viewer that can view the given MIME type, and gets the viewer properties.
*
* @param string $mime
* A valid MIME Type.
*
* @return array
* The properties of the viewer if found, NULL otherwise. The format of the properties is defined by the
* content_model_datastream_viewers hook.
*/
function content_model_viewer_get_viewer_properties($mime) {
$viewers = content_model_viewer_get_supported_viewers();
foreach ($viewers as $supported_mime_type => $properties) {
if (strcasecmp($supported_mime_type, $mime) === 0) {
return $properties;
}
}
return NULL;
}
/**
* Sets up variables for the template.
*
* @param array $variables
*/
function template_preprocess_content_model_viewer(array &$variables) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$pid = $variables['pid'];
$item = new Fedora_Item($pid);
$variables['label'] = $item->objectProfile->objLabel;
$variables['base_url'] = base_path();
$variables['width'] = variable_get('content_model_viewer_width', 740);
$variables['height'] = variable_get('content_model_viewer_height', 800);
$variables['dsid'] = 'SWF';
$variables['view_function'] = 'loadFlexPlayer';
$variables['paths'] = array(
'object' => array(
'overview' => url("viewer/$pid/overview"),
'properties' => url("viewer/$pid/properties"),
'datastreams' => url("viewer/$pid/datastreams"),
'members' => url("viewer/$pid/members"),
'purge' => url("viewer/$pid/purge")
),
'datastream' => array(
'add' => url("viewer/$pid/add"),
'purge' => url("viewer/$pid/dsid/purge"),
'properties' => url("viewer/$pid/dsid/properties"),
'download' => url("viewer/$pid/dsid/download"),
'view' => url("viewer/$pid/dsid/view")
)
);
//dsm($variables);
}
/**
* Renders the Viewer for a given pid if possible.
*
* @param string $pid
*/
function content_model_viewer($pid = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// Copied from islandora.
if (!fedora_available()) {
drupal_set_message(t('The Fedora repository server is currently unavailable. Please contact the site administrator.'), 'warning', FALSE);
return '';
}
if (function_exists('risearch_available') && !risearch_available()) {
drupal_set_message(t('The Fedora resource index search is currently unavailable. Please contact the site administrator.'), 'warning', FALSE);
return '';
}
if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:root');
}
$item = new fedora_item($pid);
if (!$item->exists()) {
drupal_not_found();
exit();
}
// End of COPY
if (!content_model_viewer_has_registered_content_model_viewer($pid)) {
//Push the call off to Islandora.
$args = func_get_args();
return call_user_func_array('repository_page', $args);
}
// End of redirect to old fedora/repository handler
$pid = isset($pid) ? $pid : variable_get('fedora_repository_pid', 'islandora:root');
// Add Bread Crumbs
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$breadcrumbs = array();
$objectHelper = new ObjectHelper();
$objectHelper->getBreadcrumbs($pid, $breadcrumbs);
drupal_set_breadcrumb(array_reverse($breadcrumbs));
// End Add Bread Crumbs
$path = drupal_get_path('module', 'content_model_viewer');
$js_path = $path . '/js';
if (isset($_POST['action'])) { // Render Metadata Form
$action = $_POST['action'];
drupal_add_js($js_path . '/Form.js');
return theme('content_model_viewer_metadata_form', $pid, $action);
}
else {
/* Load ExtJS */
$ext_path = $path . '/lib/ext';
drupal_add_js($ext_path . '/ext-all.js');
//drupal_add_js($ext_path . '/ext-all-debug-w-comments.js');
drupal_add_css($path . '/css/Clear.css');
drupal_add_css($ext_path . '/resources/css/ext-all-gray.css', 'theme', 'all');
/* Load Panels/Widgets */
drupal_add_js($js_path . '/IncludeFirst.js');
drupal_add_js($js_path . '/SortButton.js');
drupal_add_js($js_path . '/OverviewPanel.js');
drupal_add_js($js_path . '/ViewerPanel.js');
$manage_permissions = array(
PERM_CONTENT_MODEL_VIEWER_MODIFY_OBJECT_PROPERTIES,
PERM_CONTENT_MODEL_VIEWER_PURGE_OBJECTS,
PERM_CONTENT_MODEL_VIEWER_ADD_DATASTREAMS,
PERM_CONTENT_MODEL_VIEWER_PURGE_DATASTREAMS,
PERM_CONTENT_MODEL_VIEWER_MODIFY_DATASTEAM_PROPERTIES
);
$show_manage_panel = false;
foreach ($manage_permissions as $permission) {
if (user_access($permission)) {
$show_manage_panel = true;
}
}
if ($show_manage_panel) {
drupal_add_js($js_path . '/ManagePanel.js');
}
if (content_model_viewer_is_object_collection($pid) || content_model_viewer_object_has_members($pid) || content_model_viewer_object_has_collection_model($pid)) {
drupal_add_js($js_path . '/CollectionPanel.js');
}
drupal_add_js($js_path . '/ContentModelViewer.js');
drupal_add_css($path . '/css/ContentModelViewer.css');
/* Load Viewers */
module_load_include('inc', 'content_model_viewer', 'viewers/AbstractViewer');
module_load_include('inc', 'content_model_viewer', 'models/AbstractModel');
AbstractViewer::LoadRequiredResourcesForAllViewers();
AbstractModel::LoadRequiredResourcesFor($pid);
return theme('content_model_viewer', $pid);
}
}
/**
* Returns the HTML for overview panel in the viewer.
*
* @param string $pid
*
* @return string
*/
function content_model_viewer_overview($pid) {
$viewer = content_model_viewer_get_registered_content_model_viewer($pid);
try {
$data = $viewer->render();
$func = $viewer->getInitializationFunction();
$javascript = drupal_add_js(NULL, NULL, 'header');
$settings = call_user_func_array('array_merge_recursive', $javascript['setting']);
unset($settings['ahah']['']);
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => TRUE, 'data' => $data, 'func' => $func, 'settings' => $settings));
} catch (Exception $e) {
drupal_set_message($e->getMessage());
}
exit();
}
/**
* Gets the members of this collection.
*
* @param string $pid
*/
function content_model_viewer_members($pid) {
module_load_include('inc', 'content_model_viewer', 'Collection');
$collection = new Collection($pid);
list($data, $total) = $collection->getMembers();
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => TRUE, 'data' => $data, 'total' => $total));
exit();
/**
* Expected Data:
*
* 'link' => $base_url . '/viewer/' . 'coccc:1675',
* 'label' => 'Some Colorado College Object',
* 'description' => 'The Colorado College Nugget, formerly the Pikes Peak Nugget from 1900-1941, was issued until 2006-2007. The 1969-1970 Nugget was issued as loose photosheets contained in a box and named the The Colorado College Nugget, formerly the Pikes Peak Nugget from 1900-1941, was issued until 2006-2007. The 1969-1970 Nugget was issued as loose photosheets contained in a box and named the The Colorado College Nugget, formerly the Pikes Peak Nugget from 1900-1941, was issued until 2006-2007. The 1969-1970 Nugget was issued as loose photosheets contained in a box and named the',
* 'owner' => 'fedoraAdmin',
* 'created' => '2011-06-17T15:15:57.214Z',
* 'modified' => '2011-07-15T19:08:16.008Z',
* 'tn' => '/' . $module_path . '/images/collection.png',
*/
}
/**
* Get/Set data stream properties for the given Fedora Object.
*
* @param string $pid
* The PID of the Fedora Object, whose data streams this function will get/set.s
*/
function content_model_viewer_datastreams($pid, $dsid = NULL) {
module_load_include('inc', 'content_model_viewer', 'DatastreamProperties');
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$filter = isset($_GET['filter']) ? $_GET['filter'] : FALSE;
$datastreams = new DatastreamProperties($pid);
list($data, $total) = $datastreams->get($_GET['start'], $_GET['limit'], $filter);
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => TRUE, 'data' => $data, 'total' => $total));
exit();
case 'PUT':
if ($_SERVER['CONTENT_LENGTH'] > 0) {
$stdin = fopen("php://input", "r");
$json = fread($stdin, $_SERVER['CONTENT_LENGTH']);
$data = json_decode($json);
$datastreams = new DatastreamProperties($pid);
$data = $datastreams->setProperties($dsid, $data);
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => TRUE, 'msg' => "Successfully modified $dsid's properties", 'data' => $data));
exit();
}
break;
}
}
/**
* Gets/sets the properties of the object identified by $pid.
*
* @param string $pid
*
* @return string
*/
function content_model_viewer_properties($pid) {
module_load_include('inc', 'content_model_viewer', 'ObjectProperties');
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$object_properties = new ObjectProperties($pid);
$properties = $object_properties->getProperties();
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => TRUE, 'data' => array($properties)));
exit();
case 'POST':
$label = $_POST['label'];
$owner = $_POST['owner'];
$state = $_POST['state'];
$object_properties = new ObjectProperties($pid);
$success = $object_properties->setProperties($label, $owner, $state);
$message = $success ? t('Successfuly modified object properties') : t('Failed to modify object properties');
$properties = $object_properties->getProperties();
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => TRUE, 'msg' => $message, 'data' => $properties));
exit();
}
}
/**
* Purges the object identified by $pid.
*
* The user will be redirected to the sites home page.
*
* @param string $pid
*
* @return string
*/
function content_model_viewer_purge_object($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$success = $item->purge();
$message = $success ? t('Successfuly deleted object') : t('Failed to delete object');
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => $success, 'msg' => $message));
exit();
}
/**
* Adds a datastream to the object identified by $pid.*
*
* @param string $pid
*
* @return string
*/
function content_model_viewer_add_datastream($pid) {
$values = $_POST;
$dsid = $_POST['dsid'];
$label = $_POST['label'];
$control = $_POST['control']; // Manage
$file = array_shift($_FILES);
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$success = false;
if ($file['error'] == UPLOAD_ERR_OK) {
try {
$item = new Fedora_Item($pid);
if (empty($item->datastreams[$dsid])) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
$mimetype_helper = new MimeClass();
$mime = $mimetype_helper->getType($file['name']);
$success = $item->add_datastream_from_file($file['tmp_name'], $dsid, $label, $mime, $control);
}
} catch (Exception $e) {
// log some error...
}
}
$message = $success ? t('Successfully added datastream.') : t('Failed to add datastream.');
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => $success, 'msg' => $message));
exit();
}
/**
* Purges the given datastream ($dsid) from the object identified by $pid.
*
* @param string $pid
* @param string $dsid
*
* @return string
*/
function content_model_viewer_purge_datastream($pid, $dsid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$success = $item->purge_datastream($dsid);
$message = $success ? t('Successfully purged datastream.') : t('Failed to purge datastream.');
if (!headers_sent()) { //Better safe than sorry?
header('Content-type: application/json; charset=utf-8');
}
echo json_encode(array('success' => $success, 'msg' => $message));
exit();
}
/**
* Downloads the given datastream ($dsid) from the object identified by $pid.
*
* @param string $pid
* @param string $dsid
*
* @return string
*/
function content_model_viewer_download_datastream($pid, $dsid) {
module_load_include('inc', 'content_model_viewer', 'Download');
download_datastream($pid, $dsid);
}
/**
* Renders the viewer for the given datastream ($dsid) from the object identified by $pid.
*
* @param string $pid
* @param string $dsid
*
* @return string
*/
function content_model_viewer_view_datastream($pid, $dsid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if (isset($item->datastreams[$dsid])) {
$mime = $item->datastreams[$dsid]['MIMEType'];
$properties = content_model_viewer_get_viewer_properties($mime);
if ($properties) {
module_load_include($properties['type'], $properties['module'], $properties['file']);
$class = $properties['class'];
$viewer = new $class();
echo $viewer->render($pid, $dsid);
exit();
}
}
echo '<div>' . t('No Viewer Avaliable') . '</div>';
exit();
}
/**
* Checks if an object has members.
*
* @param string $pid
*
* @return boolean
*/
function content_model_viewer_object_has_members($pid) {
module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collection = new CollectionClass();
$results = $collection->getRelatedItems($pid);
$results = trim($results);
if ($results != '') {
$document = new DOMDocument();
$document->loadXML($results);
$path = new DOMXPath($document);
$path->registerNamespace('sparql', 'http://www.w3.org/2001/sw/DataAccess/rf1/result');
$results = $path->query('//sparql:result');
$count = $results->length;
return $count > 0;
}
return FALSE;
}
/**
*
* @param <type> $pid
* for this to work an objects cmodel must have a cmodel of islandora:collectionCModel
*/
function content_model_viewer_is_object_collection($pid) {
$itql_query = 'select $object $title $content from <#ri>
where ($object <info:fedora/fedora-system:def/model#label> $title
and $object <fedora-model:hasModel> $content
and ($content <fedora-model:hasModel> <info:fedora/islandora:collectionCModel>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
module_load_include('inc', 'fedora_repository', 'CollectionClass');
$collection = new CollectionClass();
$results = $collection->getRelatedItems(NULL, $itql_query);
$xml = simplexml_load_string($results);
if (!$xml) {
drupal_set_message(t('Error getting list of collection objects'), 'error');
return;
}
foreach ($xml->results->result as $result) {
$a = $result->object->attributes();
$temp = $a['uri'];
$object = substr($temp, strrpos($temp, '/') + 1);
if ($pid === $object) {
return true;
}
}
return FALSE;
}
/**
* Checks to see if the content model of the given object is a collection.
*
* Checks for the presence of a COLLECTION_POLICY datastream.
*
* @param string $pid
* The object pid.
*
* @return bool
* Return TRUE if the object has a collection model.
*/
function content_model_viewer_object_has_collection_model($pid) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if ($item->exists()) {
if (isset($item->datastreams['COLLECTION_POLICY'])) {
return TRUE;
}
}
return FALSE;
}
/**
*
* @param type $pid
*/
function content_model_viewer_edit_metadata_form(array &$form_state, $pid) {
module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$connection_helper = new ConnectionHelper();
$client = $connection_helper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
try {
$edit_form = new EditObjectMetadataForm();
$output = $edit_form->create($pid, $client, $form_state);
$output['action'] = array(
'#type' => 'hidden',
'#value' => 'edit'
);
return $output;
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
return array();
}
}
/**
* Validate Edit Form.
*
* @param array $form
* @param array $form_state
*/
function content_model_viewer_edit_metadata_form_validate(array &$form, array &$form_state) {
if ($form_state['storage']['step'] == 1) {
$form_state['storage']['step']++;
$form_state['rebuild'] = TRUE;
}
else {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
}
}
/**
* Submit Edit Form.
*
* @param array $form
* @param array $form_state
*/
function content_model_viewer_edit_metadata_form_submit(array &$form, array &$form_state) {
module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
try {
$edit_form = new EditObjectMetadataForm();
$edit_form->submit($form, $form_state);
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
$form_state['rebuild'] = TRUE;
}
}
function content_model_viewer_ingest_metadata_form(array &$form_state, $collection_pid) {
if (!user_access('ingest new fedora objects')) {
drupal_set_message(t('You do not have permission to ingest.'), 'error');
return FALSE;
}
module_load_include('inc', 'fedora_repository', 'SecurityClass');
$security_class = new SecurityClass();
if (!$security_class->canIngestHere($collection_pid)) {
// Queries the collection object for a child security datastream and if found parses it
// to determine if this user is allowed to ingest in this collection
// we assume if they are able to modify objects in the collection they can ingest as well.
drupal_set_message(t('You do not have permission to ingest in this collection.'));
return FALSE;
}
if ($collection_pid == NULL) {
drupal_set_message(t('You must specify an collection object pid to ingest an object.'), 'error');
return FALSE;
}
module_load_include('inc', 'islandora_content_model_forms', 'IngestObjectMetadataForm');
try {
$ingest_form = new IngestObjectMetadataForm();
$output = $ingest_form->create($collection_pid, NULL, $form_state);
$output['action'] = array(
'#type' => 'hidden',
'#value' => 'ingest'
);
return $output;
} catch (Exception $e) {
$msg = "File: {$e->getFile()}<br/>Line: {$e->getLine()}<br/>Error: {$e->getMessage()}";
drupal_set_message($msg, 'error');
return array();
}
}
/**
* Validate Ingest Form.
*
* @param array $form
* @param array $form_state
*/
function content_model_viewer_ingest_metadata_form_validate(array &$form, array &$form_state) {
if ($form_state['storage']['step'] == 1) {
$form_state['storage']['step']++;
$form_state['rebuild'] = TRUE;
}
else {
if (!empty($_FILES['files']['name']['ingest-file-location'])) {
$file = file_save_upload('ingest-file-location');
file_move($file->filepath, 0, 'FILE_EXISTS_RENAME');
$form_state['values']['ingest-file-location'] = $file->filepath;
}
if (isset($form_state['values']['ingest-file-location']) && file_exists($form_state['values']['ingest-file-location'])) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
module_load_include('inc', 'fedora_repository', 'MimeClass');
$file = $form_state['values']['ingest-file-location'];
$content_model_pid = ContentModel::getPidFromIdentifier($form_state['values']['models']);
$content_model_pid;
$content_model_dsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']);
if (($content_model = ContentModel::loadFromModel($content_model_pid, $content_model_dsid)) !== FALSE) {
$allowed_mime_types = $content_model->getMimetypes();
$mimetype = new MimeClass();
$format = $mimetype->getType($file);
if (!empty($file)) {
if (!in_array($format, $allowed_mime_types)) {
form_set_error('ingest-file-location', t('The uploaded file\'s mimetype (@format) is not associated with this Content Model. The allowed types are: @types', array(
'@format' => $format,
'@types' => implode(' ', $allowed_mime_types)
)));
file_delete($file);
return;
}
elseif (!$content_model->execIngestRules($file, $format)) {
drupal_set_message(t('Error following Content Model Rules'), 'error');
foreach (ContentModel::$errors as $error) {
drupal_set_message($error, 'error');
}
}
}
}
}
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
}
}
/**
* Submit Ingest Form.
*
* @param array $form
* @param array $form_state
*/