forked from nigelgbanks/islandora_openseadragon
-
Notifications
You must be signed in to change notification settings - Fork 39
/
islandora_openseadragon.module
247 lines (220 loc) · 7.75 KB
/
islandora_openseadragon.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
<?php
/**
* @file
* Hooks and callbacks for this module.
*/
define('ISLANDORA_OPENSEADRAGON_REQUIRED_VERSION', '2.3.1');
define('ISLANDORA_OPENSEADRAGON_DEFAULT_TILE_SIZE', 256);
define('ISLANDORA_OPENSEADRAGON_DEFAULT_TILE_OVERLAP', 0);
/**
* Implements hook_menu().
*/
function islandora_openseadragon_menu() {
return array(
'admin/islandora/islandora_viewers/openseadragon' => array(
'title' => 'OpenSeadragon',
'description' => 'Configure the OpenSeadragon viewer.',
'page callback' => 'drupal_get_form',
'access arguments' => array('administer site configuration'),
'page arguments' => array('islandora_openseadragon_admin'),
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
),
'islandora/object/%islandora_object/download_clip' => array(
'page callback' => 'islandora_openseadragon_download_clip',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
'file' => 'includes/download.clip.inc',
'load arguments' => array(2),
),
);
}
/**
* Implements hook_theme().
*/
function islandora_openseadragon_theme() {
return array(
'islandora_openseadragon_viewer' => array(
'variables' => array(
// @deprecated (7.x-1.10):
// 'uri' and 'fedora_object' has been replaced by the use of 'pid' and
// 'tile_sources'.
'uri' => '',
'fedora_object' => NULL,
'pid' => NULL,
'tile_sources' => array(),
),
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-openseadragon',
),
// A link for clipping JP2 datastreams via djatoka.
'islandora_openseadragon_clipper' => array(
'file' => 'theme/theme.inc',
'variables' => array(
'pid' => NULL,
),
),
);
}
/**
* Implements hook_islandora_viewer_info().
*/
function islandora_openseadragon_islandora_viewer_info() {
return array(
// @XXX The element returned has a width:100% but no natural flow width; it
// is completely dependent on it's parent.
'islandora_openseadragon' => array(
'label' => t('OpenSeadragon'),
// Later we'll add DZI too.
'description' => t('OpenSeadragon viewer with djatoka as tilesource.'),
'configuration' => 'admin/islandora/islandora_viewers/openseadragon',
'callback' => 'islandora_openseadragon_callback',
// DZI has xml as mimetype? Not sure how to handle that.
'mimetype' => array('image/jp2'),
),
);
}
/**
* Callback function for the viewer.
*
* @param array $params
* Params required by the theme. We require the keys:
* - pid: The PID of the object.
* - dsid: This DSID being displayed.
* - token: The token we are working with.
* @param AbstractObject $object
* The object that we are viewing.
*
* @return string
* HTML representation of the OpenSeadragon viewer
*/
function islandora_openseadragon_callback(array $params = array(), AbstractObject $object = NULL) {
module_load_include('inc', 'islandora_openseadragon', 'includes/utilities');
if (isset($params['jp2_url']) && !(isset($params['pid']) && isset($params['dsid']) && isset($params['token']))) {
$message = islandora_deprecated('7.x-1.11', t('The jp2_url parameter has been depreciated. Please update your code before the next release.'));
trigger_error(filter_xss($message), E_USER_DEPRECATED);
// Try to mangle the jp2_url into the data we need.
$matches = array();
preg_match('/object\/([^\/]*)\/datastream\/([^\/]*).*token=([^&]*)/', $params['jp2_url'], $matches);
$pid = isset($matches[1]) ? $matches[1] : NULL;
$dsid = isset($matches[2]) ? $matches[2] : NULL;
$token = isset($matches[3]) ? $matches[3] : NULL;
if (!isset($params['pid'])) {
$params['pid'] = urldecode($pid);
}
if (!isset($params['dsid'])) {
$params['dsid'] = urldecode($dsid);
}
if (!isset($params['token'])) {
$params['token'] = urldecode($token);
}
}
if (isset($params['pid']) && isset($params['dsid']) && isset($params['token'])) {
$token_header = variable_get('islandora_openseadragon_tilesource', 'djatoka') == 'iiif'
&& variable_get('islandora_openseadragon_iiif_token_header', FALSE);
return theme('islandora_openseadragon_viewer', array(
'pid' => $params['pid'],
'tile_sources' => islandora_openseadragon_tile_source($params['pid'], $params['dsid'], $params['token']),
'token' => $params['token'],
'token_header' => $token_header,
));
}
}
/**
* Implements hook_process_theme().
*/
function islandora_openseadragon_preprocess_islandora_object_print(array &$variables) {
if (isset($_GET['clip'])) {
module_load_include('inc', 'islandora_openseadragon', 'includes/utilities');
$clip_parts = islandora_openseadragon_construct_clip_url($_GET['clip']);
if ($clip_parts) {
$variables['clip'] = $clip_parts['original_params'];
$variables['content']['clip'] = array(
'#weight' => 0,
'#prefix' => "<div id='clip'>",
'#markup' => theme_image(array(
'path' => $clip_parts['image_url'],
'attributes' => $clip_parts['dimensions'],
)),
'#suffix' => '</div>',
);
}
else {
drupal_set_message(t('Invalid clip parameters passed.'), 'error');
}
}
}
/**
* Implements hook_token_info().
*/
function islandora_openseadragon_token_info() {
$info = array();
$info['types']['islandora_openseadragon'] = array(
'name' => t('Islandora Openseadragon'),
'description' => t('Tokens for building IIIF identifer in Islandora Openseadragon.'),
'needs-data' => 'islandora_openseadragon',
);
$info['tokens']['islandora_openseadragon']['pid'] = array(
'name' => t('PID'),
'description' => t('The objects PID.'),
);
$info['tokens']['islandora_openseadragon']['dsid'] = array(
'name' => t('DSID'),
'description' => t('The objects DSID.'),
);
$info['tokens']['islandora_openseadragon']['url'] = array(
'name' => t('URL'),
'description' => t('The URL to the object in Islandora.'),
);
$info['tokens']['islandora_openseadragon']['url_token'] = array(
'name' => t('URL with Token'),
'description' => t('The URL to the object in Islandora with token in the query string.'),
);
$info['tokens']['islandora_openseadragon']['token'] = array(
'name' => t('Token'),
'description' => t('The token that can be used to access the object in Islandora.'),
);
return $info;
}
/**
* Implements hook_tokens().
*/
function islandora_openseadragon_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type != 'islandora_openseadragon' || !isset($data['islandora_openseadragon'])) {
return $replacements;
}
$pid = $data['islandora_openseadragon']['pid'];
$dsid = $data['islandora_openseadragon']['dsid'];
$token = $data['islandora_openseadragon']['token'];
foreach ($tokens as $name => $original) {
if ($name == 'pid') {
$replacements[$original] = $pid;
}
elseif ($name == 'dsid') {
$replacements[$original] = $dsid;
}
elseif ($name == 'token') {
$replacements[$original] = $token;
}
elseif ($name == 'url' || $name == 'url_token') {
$options = array(
'absolute' => TRUE,
'language' => language_default(),
'https' => (function_exists('drupal_is_https') ?
drupal_is_https() :
(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')
),
);
if ($name == 'url_token') {
$options['query'] = array(
'token' => $token,
);
}
$replacements[$original] = url("islandora/object/{$pid}/datastream/{$dsid}/view", $options);
}
}
return $replacements;
}