-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflat_annotation_viewer.module
197 lines (148 loc) · 6.16 KB
/
flat_annotation_viewer.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
<?php
use TLA\EAF\Parser;
use TLA\EAF\Resolver\MediaResolver;
define('FLAT_ANNOTATION_VIEWER_DEFAULT_SHOW_TIMESTAMPS', 1);
define('FLAT_ANNOTATION_VIEWER_DEFAULT_WIDTH', 100);
define('FLAT_ANNOTATION_VIEWER_DEFAULT_HEIGHT', 100);
require_once __DIR__ . '/vendor/autoload.php';
function flat_annotation_viewer_api($object) {
module_load_include('inc', 'flat_annotation_viewer', 'includes/SolrMediaFetcher');
$solr = new SolrMediaFetcher();
$data = $solr->fetch($object->id);
try {
$parser = new Parser($data['annotation'], new MediaResolver($data['locations']));
$eaf = $parser->parse();
return drupal_json_output($eaf);
} catch (Exception $e) {
drupal_add_http_header('Status', 500);
return drupal_json_output();
}
}
/**
* hook_theme implementation
*
* @param array $existing
* @param string $type
* @param string $theme
* @param string $path
*
* @return array
*/
function flat_annotation_viewer_theme($existing, $type, $theme, $path) {
return [
'flat_annotation_viewer' => [
'template' => 'theme/flat-annotation-viewer',
],
];
}
/**
* Implements hook_CMODEL_PID_islandora_view_object().
*/
function flat_annotation_viewer_flat_annotation_islandora_view_object($object, $page_number, $page_size) {
$module_path = drupal_get_path('module', 'flat_annotation_viewer');
drupal_add_css($module_path . '/css/annotation-viewer.css');
drupal_add_js($module_path . '/js/annotation-viewer.js.gz', ['scope' => 'footer']);
return theme('flat_annotation_viewer', flat_annotation_viewer_data($object));
}
/**
* Embeddable version of the annotation viewer
*
* @param AbstractObject $object
* @return string
*/
function flat_annotation_viewer_embed($object) {
$module_path = drupal_get_path('module', 'flat_annotation_viewer');
$template = DRUPAL_ROOT . '/' . $module_path . '/theme/flat-annotation-viewer-embed.tpl.php';
// extracting annotation viewer data into current scope
extract(flat_annotation_viewer_data($object), EXTR_SKIP);
// adding annotation viewer assets
$annotation_viewer_js = base_path() . $module_path . '/js/annotation-viewer.js.gz';
$annotation_viewer_css = base_path() . $module_path . '/css/annotation-viewer.css';
// Start output buffering
ob_start();
// Include the template file
include $template;
// End buffering and return its contents
echo ob_get_clean();
exit;
}
function flat_annotation_viewer_data($object) {
module_load_include('inc', 'flat_annotation_viewer', 'includes/SolrMediaFetcher');
$solr = new SolrMediaFetcher();
$items = $solr->fetch($object->id);
return [
'url' => url('islandora/object/' . $items['pid'] . '/av_api'),
'title' => $object->label,
'width' => variable_get('flat_annotation_viewer_width', FLAT_ANNOTATION_VIEWER_DEFAULT_WIDTH),
'height' => variable_get('flat_annotation_viewer_height', FLAT_ANNOTATION_VIEWER_DEFAULT_HEIGHT),
'accessible' => $items['accessible'],
'show_timestamps' => variable_get('flat_annotation_viewer_show_timestamps', FLAT_ANNOTATION_VIEWER_DEFAULT_SHOW_TIMESTAMPS),
];
}
function flat_annotation_viewer_menu() {
$items = [];
$items['islandora/object/%islandora_object/embed'] = [
'title' => 'FLAT Annotation Viewer embed',
'type' => MENU_CALLBACK,
'page callback' => 'flat_annotation_viewer_embed',
'page arguments' => [2],
'access callback' => 'flat_annotation_viewer_menu_access',
];
$items['islandora/object/%islandora_object/av_api'] = [
'title' => 'FLAT Annotation Viewer',
'type' => MENU_CALLBACK,
'page callback' => 'flat_annotation_viewer_api',
'page arguments' => [2],
'access callback' => 'flat_annotation_viewer_menu_access',
];
$items['admin/config/flat_deposit/flat_annotation_viewer'] = [
'title' => 'Configure FLAT Annotation Viewer',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => ['flat_annotation_viewer_admin_form'],
'access callback' => 'flat_annotation_viewer_menu_access',
'file' => 'includes/admin.inc',
];
return $items;
}
function flat_annotation_viewer_menu_access() {
return true;
}
/**
* Implements hook_islandora_required_objects().
*/
function flat_annotation_viewer_islandora_required_objects(IslandoraTuque $connection) {
$modulePath = drupal_get_path('module', 'flat_annotation_viewer');
// Content Model
$contentModel = $connection->repository->constructObject('flat:annotation');
$contentModel->owner = 'fedoraAdmin';
$contentModel->label = 'FLAT Annotation Content Model';
$contentModel->models = 'fedora-system:ContentModel-3.0';
// DS-COMPOSITE-MODEL Datastream
$datastream = $contentModel->constructDatastream('DS-COMPOSITE-MODEL', 'X');
$datastream->label = 'DS-COMPOSITE-MODEL';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile($modulePath . '/xml/ds_composite_model.xml', false);
$contentModel->ingestDatastream($datastream);
// Collection
$collection = $connection->repository->constructObject('flat:annotation_collection');
$collection->owner = 'fedoraAdmin';
$collection->label = 'FLAT Annotation Collection';
$collection->models = 'islandora:collectionCModel';
$collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// Collection Policy
$datastream = $collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'application/xml';
$datastream->setContentFromFile($modulePath . '/xml/collection_policy.xml', false);
$collection->ingestDatastream($datastream);
return [
'flat_annotation_viewer' => [
'title' => 'FLAT Annotation',
'objects' => [
$contentModel,
$collection,
],
],
];
}