-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMiradorPlugin.php
130 lines (120 loc) · 3.81 KB
/
MiradorPlugin.php
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
<?php
/**
*
* Mirador Plugin - integrate Mirador with Omeka
*
* @author Joe Corall <jcorall@kent.edu>
*
* @todo allow setting mirador options in UI/config
* @todo support other image formats than TIFF
* @todo possibly incorporate derivatives using IIIF?
* @todo allow more options than item_id. Right now the only options are "show one item's files" or "show all items' files"
*/
class MiradorPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array(
'install',
'define_routes',
'initialize',
'config_form',
'config',
);
public function hookInstall() {
set_option('mirador_search', '0');
}
public function hookInitialize()
{
// only add the Mirador viewer on the item view page
// to avoid conflicting with file view pages, exhibits, etc.
if (strpos($_SERVER['REQUEST_URI'], '/items/show/') !== FALSE) {
add_file_display_callback(array(
'mimeTypes' => array('image/tiff'),
'fileExtensions' => array('tif', 'tiff'),
), 'MiradorPlugin::viewer', array()
);
}
}
public function hookDefineRoutes($args)
{
// Don't add these routes on the admin side to avoid conflicts.
if (is_admin_theme()) {
return;
}
$args['router']->addRoute(
'mirador_show_page_manifest',
new Zend_Controller_Router_Route(
'manifest.json',
array(
'module' => 'mirador',
'controller' => 'manifest',
'action' => 'show',
'id' => 'mirador_manifest'
)
)
);
$args['router']->addRoute(
'mirador_show_page_search',
new Zend_Controller_Router_Route(
'iiif-search/:id',
array(
'module' => 'mirador',
'controller' => 'search',
'action' => 'show',
'id' => 'mirador_search',
),
array('id' => '\d+')
)
);
$args['router']->addRoute(
'mirador-viewer',
new Zend_Controller_Router_Route(
'mirador-viewer',
array(
'module' => 'mirador',
'controller' => 'viewer',
'action' => 'show',
'id' => 'mirador_viewer',
)
)
);
}
public static function viewer($file, $options)
{
static $items = array();
// only return one file when viewing an item gallery
// the mirador viewer will have all files for the item, so we only need one instance
if (!isset($items[$file->item_id])) {
$query = array('item_id' => $file->item_id);
$items[$file->item_id] = TRUE;
return '<div class="flex-video">
<iframe title="Mirador" src="'.url('mirador-viewer', $query) . '" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
</div>';
}
else {
return '';
}
}
public function hookConfigForm()
{
require_once 'config-form.php';
}
/**
* Save the config form results
*/
public function hookConfig()
{
$options = array(
'mirador_iiif_server_prod',
'mirador_iiif_server_test',
'mirador_search',
);
foreach ($options as $option) {
if (empty($_POST[$option])) {
delete_option($option);
}
else {
set_option($option, $_POST[$option]);
}
}
}
}