-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemic_tile.module
112 lines (97 loc) · 3.27 KB
/
emic_tile.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
<?php
function emic_tile_menu() {
$items = array();
$items['load/tile'] = array(
'file' => 'emic_tile.inc',
'page callback' => 'emic_load_tile',
'type' => MENU_CALLBACK,
'access arguments' => array('use TILE'),
);
$items['save/tile'] = array(
'file' => 'emic_tile.inc',
'page callback' => 'emic_save_tile_data',
'type' => MENU_CALLBACK,
'access arguments' => array('use TILE'),
);
$items['emic/getTILE'] = array(
'file' => 'tile_callbacks.inc',
'page callback' => 'load_emic_tile_data',
'type' => MENU_CALLBACK,
'access arguments' => array('use TILE'),
);
return $items;
}
function emic_tile_perm() {
return array(
'use TILE',
'Create TILE',
);
}
function emic_tile_form_book_management_form_alter(&$form, &$form_state) {
if (user_access('Create TILE')) {
module_load_include('inc', 'emic_tile', 'emic_tile');
$form['page_manage']['create_tile_json'] = array(
'#type' => 'checkbox',
'#title' => t('Create data for TILE reader'),
'#weight' => -10,
);
$form['#submit'][] = 'create_emic_tile';
$form['#submit'] = array_reverse($form['#submit']);
}
}
function emic_tile_form_islandora_book_admin_settings_alter(&$form, &$form_state) {
$tile_path = isset($form_state['values']['islandora_tile_path']) ? $form_state['values']['islandora_tile_path'] : variable_get('islandora_tile_path', 'http://localhost/Tile');
$tile_avail = tile_available($tile_path);
$confirmation_message = ($tile_avail ? '<img src="' . url('misc/watchdog-ok.png') . '"/>'
. t('Tile url is valid.') : '<img src="'
. url('misc/watchdog-error.png') . '"/> '
. t('Unable to locate Tile installtion at !tile_path</p>', array('!tile_path' => $tile_path)));
$form['book_ahah_wrapper']['islandora_tile_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to TILE'),
'#description' => t('Path to TILE installation'),
'#default_value' => $tile_path,
'#ahah' => array(
'path' => 'islandora/book/ocr',
'wrapper' => 'ibook-url',
'effect' => 'fade',
'event' => 'change'),
);
$form['book_ahah_wrapper']['infobox2'] = array(
'#type' => 'item',
'#value' => $confirmation_message,
);
}
function tile_available($tile_url) {
$handle = curl_init($tile_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$retval = TRUE;
if ($httpCode % 100 == 4) {
$retval = FALSE;
}
curl_close($handle);
return $retval;
}
function emic_tile_islandora_book_links($pid) {
$tile_host = variable_get('islandora_tile_path', 'http://localhost/Tile/index.php');
$fedora_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora');
$form_string = "
<form method='post' action='$tile_host' target='_blank'>
<input type='hidden' name='PID' value='$pid'>
<input type='submit' value='Tile Image Annotation'>
</form>";
$options = array(
'attributes' => array('target' => '_blank'),
'query' => array(
'PID' => $pid,
),
);
$link = l('TILE image annotation', "$tile_host", $options);
return $link;
}
/**
* <a href="$tile_host"
onClick="document.forms['myform'].submit(); return false;">TILE image annotation</a>
*/