-
Notifications
You must be signed in to change notification settings - Fork 37
/
islandora_internet_archive_bookreader.module
240 lines (217 loc) · 8.41 KB
/
islandora_internet_archive_bookreader.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
<?php
/**
* @file
* Defines all the hooks this module implements.
*/
/**
* Implements hook_menu().
*/
function islandora_internet_archive_bookreader_menu() {
return array(
'admin/islandora/islandora_viewers/internet_archive_bookreader' => array(
'title' => 'Internet Archive BookReader',
'description' => 'Configure the Internet Archive BookReader.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_internet_archive_bookreader_admin_settings_form'),
'access arguments' => array('administer site configuration'),
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
),
'internet_archive_bookreader_dimensions/%islandora_object' => array(
'page callback' => 'islandora_internet_archive_bookreader_dimensions_callback',
'page arguments' => array(1),
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 1),
'file' => 'includes/callback.inc',
'type' => MENU_CALLBACK,
),
'internet_archive_bookreader_text/%islandora_object' => array(
'page callback' => 'islandora_internet_archive_bookreader_text_callback',
'page arguments' => array(1),
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 1),
'file' => 'includes/callback.inc',
'type' => MENU_CALLBACK,
),
'internet_archive_bookreader_search/%' => array(
'page callback' => 'islandora_internet_archive_bookreader_search_callback',
'page arguments' => array(1, 2),
'access callback' => 'user_access',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS),
'file' => 'includes/callback.inc',
'type' => MENU_CALLBACK,
),
'internet_archive_bookreader_get_image_uri/%islandora_object' => array(
'page callback' => 'islandora_internet_archive_bookreader_get_image_uri_callback',
'page arguments' => array(1),
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 1),
'file' => 'includes/callback.inc',
'type' => MENU_CALLBACK,
),
);
}
/**
* Implements hook_theme().
*/
function islandora_internet_archive_bookreader_theme() {
return array(
'islandora_internet_archive_bookreader' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-internet-archive-bookreader',
'variables' => array(
'object' => NULL,
'datastream_id' => 'JP2',
'page_progression' => NULL,
'pages' => array(),
),
),
'islandora_internet_archive_bookreader_book_info' => array(
'file' => 'theme/theme.inc',
'variables' => array('object' => NULL),
),
);
}
/**
* Implements hook_islandora_viewer_info().
*/
function islandora_internet_archive_bookreader_islandora_viewer_info() {
return array(
'islandora_internet_archive_bookreader' => array(
'label' => t('Internet Archive BookReader'),
'description' => t('Internet Archive BookReader.'),
'configuration' => 'admin/islandora/islandora_viewers/internet_archive_bookreader',
'callback' => 'islandora_internet_archive_bookreader_viewer_callback',
'model' => array(
'islandora:bookCModel',
'islandora:newspaperIssueCModel',
'islandora:manuscriptCModel',
),
),
);
}
/**
* Callback function for the viewer.
*
* @param array $params
* The params for the theme function 'islandora_internet_archive_bookreader'.
*
* @return string
* HTML repersentation of the Internet Archive BookReader.
*/
function islandora_internet_archive_bookreader_viewer_callback(array $params) {
return theme('islandora_internet_archive_bookreader', $params);
}
/**
* Implements hook_CMODEL_PID_islandora_solr_object_result_alter().
*
* Replaces the url for the search result to be the book's url, not the page.
* The page is added as a fragment at the end of the book url.
*/
function islandora_internet_archive_bookreader_islandora_pageCModel_islandora_solr_object_result_alter(&$search_results, $query_processor) {
module_load_include('inc', 'islandora', 'includes/solution_packs');
$viewer_id = islandora_get_viewer_id('islandora_book_viewers');
if ($viewer_id != 'islandora_internet_archive_bookreader') {
return;
}
// Grab the names of the appropriate solr fields from the db.
$parent_book_field_name = variable_get('islandora_book_parent_book_solr_field', 'RELS_EXT_isMemberOf_uri_ms');
$page_number_field_name = variable_get('islandora_paged_content_page_number_solr_field', 'RELS_EXT_isSequenceNumber_literal_ms');
// If:
// there's an object url AND
// there's a solr doc AND
// the solr doc contains the parent book AND
// the solr doc contains the page number...
if (isset($search_results['object_url']) &&
isset($search_results['solr_doc']) &&
isset($search_results['solr_doc'][$parent_book_field_name]) &&
count($search_results['solr_doc'][$parent_book_field_name]) &&
isset($search_results['solr_doc'][$page_number_field_name]) &&
count($search_results['solr_doc'][$page_number_field_name])) {
// Replace the result url with that of the parent book and add the page
// number as a fragment.
$book_pid = preg_replace('/info\:fedora\//', '', $search_results['solr_doc'][$parent_book_field_name][0], 1);
$page_number = $search_results['solr_doc'][$page_number_field_name][0];
if (islandora_object_access(ISLANDORA_VIEW_OBJECTS, islandora_object_load($book_pid))) {
$search_results['object_url'] = "islandora/object/$book_pid";
$search_results['object_url_fragment'] = "page/$page_number/mode/1up";
// XXX: Won't handle fielded searches nicely... then again, if our
// highlighting field is not the one being search on, this makes sense?
if ($query_processor->solrDefType == 'dismax' || $query_processor->solrDefType == 'edismax') {
$search_results['object_url_fragment'] .= "/search/" . rawurlencode($query_processor->solrQuery);
}
}
}
}
/**
* Implements hook_token_info().
*/
function islandora_internet_archive_bookreader_token_info() {
$info = array();
$info['types']['islandora_iareader'] = array(
'name' => t('Islandora IA Bookreader'),
'description' => t('Tokens for building IIIF identifer in Islandora IA Bookreader.'),
'needs-data' => 'islandora_iareader',
);
$info['tokens']['islandora_iareader']['pid'] = array(
'name' => t('PID'),
'description' => t('The objects PID.'),
);
$info['tokens']['islandora_iareader']['dsid'] = array(
'name' => t('DSID'),
'description' => t('The objects DSID.'),
);
$info['tokens']['islandora_iareader']['url'] = array(
'name' => t('URL'),
'description' => t('The URL to the object in Islandora.'),
);
$info['tokens']['islandora_iareader']['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_iareader']['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_internet_archive_bookreader_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type != 'islandora_iareader' || !isset($data['islandora_iareader'])) {
return $replacements;
}
$pid = $data['islandora_iareader']['pid'];
$dsid = $data['islandora_iareader']['dsid'];
$token = $data['islandora_iareader']['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;
}