-
Notifications
You must be signed in to change notification settings - Fork 4
/
ucla_pdf.module
175 lines (159 loc) · 5.97 KB
/
ucla_pdf.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
<?php
/**
* Implements hook_islandora_required_objects().
*/
function ucla_pdf_islandora_required_objects(IslandoraTuque $connection) {
// module path
$module_path = drupal_get_path('module', 'ucla_pdf');
// UCLA PDF Content Model
$ucla_pdf_content_model = $connection->repository->constructObject('ucla:TahrirPdfCModel');
$ucla_pdf_content_model->owner = 'fedoraAdmin';
$ucla_pdf_content_model->label = 'UCLA PDF Content Model';
$ucla_pdf_content_model->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream
$datastream = $ucla_pdf_content_model->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/ucla_pdf_ds_composite_model.xml", FALSE);
$ucla_pdf_content_model->ingestDatastream($datastream);
//UCLA PDF Collection
$ucla_pdf_collection = $connection->repository->constructObject('ucla:tahrir_pdf_collection');
$ucla_pdf_collection->owner = 'fedoraAdmin';
$ucla_pdf_collection->label = 'Tahrir PDF collection';
$ucla_pdf_collection->models = 'islandora:collectionCModel';
$ucla_pdf_collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection Policy Datastream
$datastream = $ucla_pdf_collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/ucla_pdf_collection_policy.xml", FALSE);
$ucla_pdf_collection->ingestDatastream($datastream);
// TN Datastream
$datastream = $ucla_pdf_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromFile("$module_path/images/folder.png", FALSE);
$ucla_pdf_collection->ingestDatastream($datastream);
return array(
'ucla_pdf' => array(
'title' => 'UCLA PDF',
'objects' => array(
$ucla_pdf_content_model,
$ucla_pdf_collection,
)
)
);
}
/**
* Implements hook_islandora_xml_form_builder_form_associations().
*/
function ucla_pdf_islandora_xml_form_builder_form_associations() {
return array(
'ucla_pdf_mods_form' => array(
'content_model' => 'ucla:TahrirPdfCModel',
'form_name' => 'UCLA PDF Mods form',
'dsid' => 'MODS',
'title_field' => array('mainTitleInfo', 'mainTitle'),
'transform' => 'mods_to_dc.xsl',
'template' => FALSE,
),
);
}
/**
* Implements hook_CMODEL_PID_islandora_object_alter().
*
* Add in islandora:sp_pdf, so it gets handled in largely the same way.
*/
function ucla_pdf_ucla_TahrirPdfCModel_islandora_object_alter($obj, $context) {
if ($context['action'] == 'ingest') {
$obj->relationships->add(FEDORA_MODEL_URI, 'hasModel', 'islandora:sp_pdf');
}
}
/**
* Implements hook_menu().
*/
function ucla_pdf_menu() {
return array(
'islandora/object/%islandora_object/view_translation' => array(
'title' => 'Translation (English)',
'page callback' => 'ucla_pdf_view_translation',
'page arguments' => array(2, 'TRANSLATION-EN'),
'access callback' => 'ucla_pdf_access',
'access arguments' => array(2, 'TRANSLATION-EN'),
'type' => MENU_LOCAL_TASK,
),
'islandora/object/%islandora_object/view_transcription' => array(
'title' => 'Transcription',
'page callback' => 'ucla_pdf_view_transcription',
'page arguments' => array(2, 'TRANSCRIPTION'),
'access callback' => 'ucla_pdf_access',
'access arguments' => array(2, 'TRANSCRIPTION'),
'type' => MENU_LOCAL_TASK,
),
//'islandora/object/%islandora_object/view_dc' => array(
// 'title' => 'DC (For testing)',
// 'page callback' => 'ucla_pdf_view_text',
// 'page arguments' => array(2, 'DC'),
// 'access callback' => 'ucla_pdf_access',
// 'access arguments' => array(2, 'DC'),
// 'type' => MENU_LOCAL_TASK,
//),
);
}
/**
* Check that our streams exist, before showing the paths.
*
* @param AbstractObject $object
* Tuque object containing the datastream
* @param string $dsid
* The id of the datastream in the Tuque object
*/
function ucla_pdf_access($object = NULL, $dsid = NULL) {
return in_array('ucla:TahrirPdfCModel', $object->models) && isset($object[$dsid]) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object[$dsid]);
}
/**
* Page callback to view the translation of a pdf.
*
* @param AbstractObject $object
* Tuque object containing the datastream
* @param string $dsid
* The id of the datastream in the Tuque object containing the text
*/
function ucla_pdf_view_translation($object, $dsid) {
// Get the translation text from the datastrem
module_load_include('inc', 'ucla_pdf', 'ucla_pdf');
$out = ucla_pdf_format_datastream_text($object, $dsid);
$out = "<pre>" . $out . "</pre>";
// Add a link to download the text using Islandora's RESTful api.
global $base_url;
$download_url = $base_url . '/islandora/object/' . $object->id . '/datastream/' . $dsid . '/download';
$link_text = t('Download as txt');
$out .= "<br />" . l($link_text, $download_url, array('attributes' => array('class' => array('ucla-pdf-link'))));
return $out;
}
/**
* Page callback to view the transcription of a pdf.
*
* @param AbstractObject $object
* Tuque object containing the datastream
* @param string $dsid
* The id of the datastream in the Tuque object containing the text
*/
function ucla_pdf_view_transcription($object, $dsid) {
module_load_include('inc', 'ucla_pdf', 'ucla_pdf');
return ucla_pdf_format_datastream_text($object, $dsid);
}
/**
* Implements hook_islandora_ingest_steps().
*/
function ucla_pdf_ucla_TahrirPdfCModel_islandora_ingest_steps() {
return array(
'ucla_pdf_file_upload' => array(
'weight' => 10,
'type' => 'form',
'form_id' => 'islandora_pdf_pdf_upload_form',
'module' => 'islandora_pdf',
'file' => 'includes/pdf_upload.form.inc'
)
);
}