-
Notifications
You must be signed in to change notification settings - Fork 47
/
islandora_large_image.module
341 lines (321 loc) · 12.5 KB
/
islandora_large_image.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
<?php
/**
* @file
* Hooks and callbacks for this module.
*/
/**
* Implements hook_menu().
*/
function islandora_large_image_menu() {
$items = array();
$items['admin/islandora/solution_pack_config/large_image'] = array(
'title' => 'Large Images',
'description' => 'Define ingest behavior, and select viewer image viewer.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'page arguments' => array('islandora_large_image_admin'),
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_theme().
*
* We supply a pattern so we can overide templates at the theme level if needed.
* we can append a pid to a template and the new template file will be called
* (the pids colon should be replaced with a dash).
*/
function islandora_large_image_theme($existing, $type, $theme, $path) {
return array(
'islandora_large_image' => array(
'template' => 'theme/islandora-large-image',
// We can add pids to the end of this pattern in our preprocess function
// and templates will be able to have have a pid appended to the template
// name to overide a template on a per object basis. An example template
// would be named islandora-basic-image--islandora-27.tpl.phps.
'pattern' => 'islandora_large_image__',
'variables' => array('islandora_object' => NULL),
),
'islandora_large_image_print' => array(
'template' => 'theme/islandora-large-image-print',
'variables' => array('islandora_content' => NULL),
),
);
}
/**
* Implements hook_islandora_view_print_object().
*/
function islandora_large_image_islandora_view_print_object($object) {
$output = array();
if (in_array('islandora:sp_large_image_cmodel', $object->models)) {
$resource_url = url("islandora/object/{$object->id}/datastream/JPG/view");
$params = array(
'title' => $object->label,
'path' => $resource_url,
);
// Theme the image seperatly.
$variables['islandora_img'] = theme('image', $params);
$output = theme('islandora_large_image_print', array(
'islandora_content' => $variables['islandora_img']));
}
return $output;
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_large_image_islandora_required_objects(IslandoraTuque $connection) {
$module_path = drupal_get_path('module', 'islandora_large_image');
// Large Image Content Model.
$large_image_content_model = $connection->repository->constructObject('islandora:sp_large_image_cmodel');
$large_image_content_model->owner = 'fedoraAdmin';
$large_image_content_model->label = 'Islandora Large Image Content Model';
$large_image_content_model->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream.
$datastream = $large_image_content_model->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_large_image_ds_composite_model.xml", FALSE);
$large_image_content_model->ingestDatastream($datastream);
// Large Image Collection.
$large_image_collection = $connection->repository->constructObject('islandora:sp_large_image_collection');
$large_image_collection->owner = 'fedoraAdmin';
$large_image_collection->label = 'Large Image Collection';
$large_image_collection->models = 'islandora:collectionCModel';
$large_image_collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection Policy Datastream.
$datastream = $large_image_collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_large_image_collection_policy.xml", FALSE);
$large_image_collection->ingestDatastream($datastream);
// TN Datastream.
$datastream = $large_image_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromFile("$module_path/images/folder.png", FALSE);
$large_image_collection->ingestDatastream($datastream);
return array(
'islandora_large_image' => array(
'title' => 'Islandora large image',
'objects' => array(
$large_image_content_model,
$large_image_collection,
),
),
);
}
/**
* Implements hook_xml_form_builder_forms().
*/
function islandora_large_image_xml_form_builder_forms() {
$module_path = drupal_get_path('module', 'islandora_large_image');
return array(
'Large image MODS form' => array(
'form_file' => "$module_path/xml/islandora_large_image_form_mods.xml",
),
);
}
/**
* Implements hook_xml_form_builder_form_associations().
*/
function islandora_large_image_xml_form_builder_form_associations() {
return array(
'islandora_large_image_mods_form' => array(
'content_model' => 'islandora:sp_large_image_cmodel',
'form_name' => 'Large image MODS form',
'dsid' => 'MODS',
'title_field' => array('titleInfo', 'title'),
'transform' => 'mods_to_dc.xsl',
'self_transform' => 'islandora_cleanup_mods_extended.xsl',
'template' => FALSE,
),
);
}
/**
* Implements hook_CMODEL_PID_islandora_view_object().
*/
function islandora_large_image_islandora_sp_large_image_cmodel_islandora_view_object($object, $page_number, $page_size) {
$output = theme('islandora_large_image', array('islandora_object' => $object));
return array('' => $output);
}
/**
* Implements template_preprocess_HOOK().
*/
function template_preprocess_islandora_large_image(&$variables) {
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
$islandora_object = $variables['islandora_object'];
$repository = $islandora_object->repository;
module_load_include('inc', 'islandora', 'includes/datastream');
module_load_include('inc', 'islandora', 'includes/utilities');
module_load_include('inc', 'islandora', 'includes/metadata');
// We should eventually remove the DC object and dc_array code as it only
// exists to not break legacy implementations.
if (isset($islandora_object['DC']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) {
try {
$dc = $islandora_object['DC']->content;
$dc_object = DublinCore::importFromXMLString($dc);
}
catch (Exception $e) {
$variables = array(
'@ret' => $e->getMessage(),
'@trace' => $e->getTraceAsString(),
);
watchdog('islandora_large_image', 'Error retrieving object.<br/>Error: @ret<br/>Trace: @trace', $variables, WATCHDOG_ERROR);
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error', FALSE);
}
}
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['dc_array'] = isset($dc_object) ? $dc_object->asArray() : array();
$variables['islandora_object_label'] = $islandora_object->label;
$variables['theme_hook_suggestions'][] = 'islandora_large_image__' . str_replace(':', '_', $islandora_object->id);
$variables['parent_collections'] = islandora_get_parents_from_rels_ext($islandora_object);
$variables['metadata'] = islandora_retrieve_metadata_markup($islandora_object);
$variables['description'] = islandora_retrieve_description_markup($islandora_object);
// Thumbnail.
if (isset($islandora_object['TN']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['TN'])) {
$params = array(
'title' => $islandora_object->label,
'path' => url("islandora/object/{$islandora_object->id}/datastream/TN/view"),
);
$variables['islandora_thumbnail_img'] = theme('image', $params);
}
module_load_include('inc', 'islandora', 'includes/solution_packs');
$params = array();
if (isset($islandora_object['JP2']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['JP2'])) {
// Get token to allow access to XACML protected datastreams.
// Always use token authentication in case there is a global policy.
module_load_include('inc', 'islandora', 'includes/authtokens');
$token = islandora_get_object_token($islandora_object->id, 'JP2', 2);
$jp2_url = url("islandora/object/{$islandora_object->id}/datastream/JP2/view",
array(
'absolute' => TRUE,
'query' => array('token' => $token),
)
);
$params['token'] = $token;
$params['pid'] = $islandora_object->id;
$params['dsid'] = 'JP2';
// Can be removed after 7.x-1.11 is out the door islandora_deprecated.
$params['jp2_url'] = $jp2_url;
}
$viewer = islandora_get_viewer($params, 'islandora_large_image_viewers', $islandora_object);
$variables['islandora_content'] = '';
if ($viewer) {
if (strpos($viewer, 'islandora-openseadragon') !== FALSE) {
if (isset($islandora_object['JP2']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['JP2'])) {
$variables['image_clip'] = theme(
'islandora_openseadragon_clipper',
array('pid' => $islandora_object->id)
);
}
}
$variables['islandora_content'] = $viewer;
}
// If no viewer is configured just show the jpeg.
elseif (isset($islandora_object['JPG']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['JPG'])) {
$params = array(
'title' => $islandora_object->label,
'path' => url("islandora/object/{$islandora_object->id}/datastream/JPG/view"),
);
$variables['islandora_content'] = theme('image', $params);
}
else {
$variables['islandora_content'] = NULL;
}
}
/**
* Implements hook_islandora_ingest_steps().
*/
function islandora_large_image_islandora_sp_large_image_cmodel_islandora_ingest_steps() {
return array(
'islandora_large_image_upload' => array(
'weight' => 10,
'type' => 'form',
'form_id' => 'islandora_large_image_image_upload_form',
'module' => 'islandora_large_image',
'file' => 'includes/image_upload.form.inc',
),
);
}
/**
* Implements hook_process_theme().
*/
function islandora_large_image_preprocess_islandora_object_print(array &$variables) {
$object = $variables['object'];
if (in_array('islandora:sp_large_image_cmodel', $object->models)) {
$url = url("islandora/object/{$object->id}", array('absolute' => TRUE));
$variables['content']['link'] = array(
'#weight' => -10,
'#markup' => t('Persistent link: !link', array("!link" => l($url, $url))),
);
}
}
/**
* Implements hook_process_theme().
*/
function islandora_large_image_process_islandora_object_print(array &$variables) {
$object = $variables['object'];
if (in_array('islandora:sp_large_image_cmodel', $object->models)) {
$clip = isset($variables['clip']) ? $variables['clip'] : NULL;
$variables['content']['buttons'] = array(
'#access' => isset($clip),
'#prefix' => '<div>',
'#suffix' => '</div></br>',
'#weight' => -5,
'print' => array(
'#prefix' => '<strong>',
'#markup' => l(t('Print'), 'javascript:window.print();', array('external' => TRUE)),
'#suffix' => '</strong>',
'#weight' => -5,
),
'0' => array(
'#markup' => ' | ',
'#weight' => -5,
),
'download_clip' => array(
'#prefix' => '<strong>',
'#markup' => l(t('Download Image'), "islandora/object/{$object->id}/download_clip", array(
'query' => array('clip' => $clip))),
'#suffix' => '</strong>',
'#weight' => -5,
),
);
}
}
/**
* Implements hook_CMODEL_islandora_derivative().
*/
function islandora_large_image_islandora_sp_large_image_cmodel_islandora_derivative() {
$mod_path = drupal_get_path('module', 'islandora_large_image');
return array(
array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'TN',
'weight' => 0,
'function' => array(
'islandora_large_image_create_tn_derivative',
),
'file' => "$mod_path/includes/derivatives.inc",
),
array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'JPG',
'weight' => 1,
'function' => array(
'islandora_large_image_create_jpg_derivative',
),
'file' => "$mod_path/includes/derivatives.inc",
),
array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'JP2',
'weight' => 2,
'function' => array(
'islandora_large_image_create_jp2_derivative',
),
'file' => "$mod_path/includes/derivatives.inc",
),
);
}