-
Notifications
You must be signed in to change notification settings - Fork 2
/
islandora_bookviewer.module
156 lines (133 loc) · 5.34 KB
/
islandora_bookviewer.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
<?php
// $Id$
/*
* Created on Aug 10, 2007
*/
/**
* Drupal hook for admin form
* fedora_repository_name is the name of the top level collection this module will query
* fedora_repository_pid is the name of the top level pid.
* Stores this info in the drupal variables table.
* the name and pid can also be passed as url parameters
*/
function islandora_bookviewer_admin() {
return "";
}
function islandora_bookviewer_admin_settings_submit($form, $form_values) {
}
/**
* drupal hook to show help
*/
function islandora_bookviewer_help($path, $arg) {
switch ($path) {
case 'admin/modules#description' :
return t('Grabs a list of items from a collection in Drupal that are presented on the home page.');
case 'node/add#fedora_repository' :
return t('Use this page to grab a list of items from a Fedora collection.');
}
}
function islandora_bookviewer_menu() {
$items['getbookpage/%'] = array(
'page callback' => 'islandora_bookviewer_get_book_page',
'page arguments' => array(1),
'access callback' => TRUE,
//'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['mods2html/%'] = array(
'page callback' => 'islandora_bookviewer_get_mods',
'page arguments' => array(1),
'access callback' => TRUE,
//'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['bookreader/setup'] = array(
'page callback' => 'islandora_bookviewer_setup',
'type' => MENU_CALLBACK,
'access arguments' => array('view fedora collection'),
);
//experimental - do not expose
$items['bookreader/standalone'] = array(
'page callback' => 'bookreader',
'file' => 'standalone.inc',
'type' => MENU_CALLBACK,
// 'access arguments' => array('view fedora collection'),
'access_callback'=>TRUE
);
return $items;
}
function islandora_bookviewer_perm(){
return array('use bookreader');
}
/*
function islandora_bookviewer_get_book_page($page) {
global $base_url;
// the preferred page
$page_path = $base_url .":8080/adore-djatoka/resolver?url_ver=Z39.88-2004&rft_id=". $base_url ."/drupal/fedora/repository/". $page ."/JP2/&svc_id=info:lanl-repo/svc/getRegion&svc_val_fmt=info:ofi/fmt:kev:mtx:jpeg2000&svc.format=image/png&svc.level=4&svc.rotate=0";
// the fallback if the preferred one fails
$page_path = $base_url ."/drupal/fedora/repository/". $page ."/JP2";
return $page_path;
} */
function islandora_bookviewer_get_mods($page) {
global $base_url;
$url = $base_url . ":8080/saxon/SaxonServlet?source=" . $base_url . "/fedora/repository/" . $page . "/MODS&style=" . $base_url . "/" . drupal_get_path('module', 'islandora_bookviewer') . "/mods2html.xsl";
$http = drupal_http_request($url);
//return $http->data;
print $http->data;
return;
}
function islandora_bookviewer_form_islandora_book_admin_settings_alter(&$form, &$form_state) {
$djatoka_path = isset($form_state['values']['islandora_djatoka_path']) ? $form_state['values']['islandora_djatoka_path'] : variable_get('islandora_djatoka_path', 'http://localhost:8080/adore-djatoka');
$djatoka_avail = is_url_valid($djatoka_path);
$confirmation_message = ($djatoka_avail ? '<img src="' . url('misc/watchdog-ok.png') . '"/>'
. t('Djatoka url is valid.') : '<img src="'
. url('misc/watchdog-error.png') . '"/> '
. t('Unable to locate djatoka installtion at !tile_path</p>', array('!tile_path' => $djatoka_path)));
$form['book_ahah_wrapper']['islandora_djatoka_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to Djatoka'),
'#description' => t('Path to Djatoka installation'),
'#default_value' => $djatoka_path,
'#ahah' => array(
'path' => 'islandora/book/ocr',
'wrapper' => 'ibook-url',
'effect' => 'fade',
'event' => 'change'),
);
$form['book_ahah_wrapper']['infobox3'] = array(
'#type' => 'item',
'#value' => $confirmation_message,
);
}
/**
* Provides page information for Bookviewer
* To be invoked with ajax
* @global url $base_url
* @param string $pid
*/
function islandora_bookviewer_setup($pid) {
module_load_include('inc', 'islandora_book', 'book_pack_utils');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $base_url;
$item = new Fedora_Item($pid);
$label = $item->objectProfile->objLabel;
//$djatoka_prefix = "http://localhost:8080/adore-djatoka/resolver?url_ver=Z39.88-2004&rft_id=";
$djatoka_prefix = variable_get('islandora_djatoka_path', 'http://localhost:8080/adore-djatoka') . '/resolver?url_ver=Z39.88-2004&rft_id=';
$islandora_prefix = $base_url . '/fedora/repository/';
$fedora_prefix = variable_get('fedora_base_url', 'http:8080/fedora');
$book_pids = get_sorted_pages($pid);
$filename = $djatoka_prefix . "$fedora_prefix/objects/" . $book_pids[count($book_pids)] . "/datastreams/JP2/content&svc_id=info:lanl-repo/svc/getMetadata";
$pageData = json_decode(file_get_contents($filename));
$configs = array();
$configs['DJATOKA_PREFIX'] = $djatoka_prefix;
$configs['ISLANDORA_PREFIX'] = $islandora_prefix;
$configs['FEDORA_PREFIX'] = $fedora_prefix;
$configs['COMPRESSION'] = 4;
$configs['book_pids'] = $book_pids;
$configs['page_width'] = $pageData->width;
$configs['page_height'] = $pageData->height;
$configs['page_count'] = count($book_pids);
$configs['label'] = $label;
$json = json_encode($configs);
echo $json;
}