/
OpenSeadragon2Plugin.php
214 lines (190 loc) · 6.68 KB
/
OpenSeadragon2Plugin.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
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
<?php
/**
* OpenSeadragon2
*
* @copyright Copyright 2015 University of Victoria Library
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
require_once dirname(__FILE__) . '/helpers/OpenSeadragonFunctions.php';
require_once dirname(__FILE__) . '/functions.php';
/**
* The OpenSeadragon2 plugin.
*
* @package Omeka\Plugins\OpenSeadragon2
*/
class OpenSeadragon2Plugin extends Omeka_Plugin_AbstractPlugin
{
const DEFAULT_VIEWER_EMBED = 1;
const DEFAULT_VIEWER_WIDTH = 500;
const DEFAULT_VIEWER_HEIGHT = 600;
const DEFAULT_CSS_OVERRIDE = 1;
protected $_hooks = array(
'install',
'uninstall',
'initialize',
'upgrade',
'config_form',
'config',
'admin_items_show',
'admin_files_show',
'admin_files_form',
'public_items_show',
'public_files_show',
'admin_head',
'public_head',
'define_routes'
);
//add_plugin_hook('append_to_item_form', 'hookAdminFilesEdit');
protected $_options = array(
'openseadragon2_embed_admin' => self::DEFAULT_VIEWER_EMBED,
'openseadragon2_width_admin' => self::DEFAULT_VIEWER_WIDTH,
'openseadragon2_height_admin' => self::DEFAULT_VIEWER_HEIGHT,
'openseadragon2_embed_public' => self::DEFAULT_VIEWER_EMBED,
'openseadragon2_css_override_public' => self::DEFAULT_CSS_OVERRIDE,
'openseadragon2_width_public' => self::DEFAULT_VIEWER_WIDTH,
'openseadragon2_height_public' => self::DEFAULT_VIEWER_HEIGHT,
);
/**
* Install the plugin.
*/
public function hookInstall()
{
annotations_install();
$this->_installOptions();
}
/**
* Unnstall the plugin.
*/
public function hookUninstall()
{
annotations_uninstall();
$this->_uninstallOptions();
}
/**
* Initialize the plugin.
*/
public function hookInitialize()
{
// Add translation.
add_translation_source(dirname(__FILE__) . '/languages');
}
/**
* Upgrade the plugin.
*/
public function hookUpgrade($args)
{
// Version 2.0 introduced image viewer embed flags.
if (version_compare($args['old_version'], '2.0', '<')) {
set_option('openseadragon2_embed_admin', self::DEFAULT_VIEWER_EMBED);
set_option('openseadragon2_embed_public', self::DEFAULT_VIEWER_EMBED);
}
}
/**
* Display the config form.
*/
public function hookConfigForm()
{
echo get_view()->partial('plugins/openseadragon-config-form.php');
}
/**
* Handle the config form.
*/
public function hookConfig()
{
if (!is_numeric($_POST['openseadragon2_width_admin']) ||
!is_numeric($_POST['openseadragon2_height_admin']) ||
!is_numeric($_POST['openseadragon2_width_public']) ||
!is_numeric($_POST['openseadragon2_height_public'])) {
throw new Omeka_Validate_Exception('The width and height must be numeric.');
}
set_option('openseadragon2_embed_admin', (int) (boolean) $_POST['openseadragon2_embed_admin']);
set_option('openseadragon2_width_admin', $_POST['openseadragon2_width_admin']);
set_option('openseadragon2_height_admin', $_POST['openseadragon2_height_admin']);
set_option('openseadragon2_embed_public', (int) (boolean) $_POST['openseadragon2_embed_public']);
set_option('openseadragon2_css_override_public', (int) (boolean) $_POST['openseadragon2_css_override_public']);
set_option('openseadragon2_width_public', $_POST['openseadragon2_width_public']);
set_option('openseadragon2_height_public', $_POST['openseadragon2_height_public']);
}
/**
* Display the image viewer in admin items/show.
*/
public function hookAdminItemsShow($args)
{
// Embed viewer only if configured to do so.
if (!get_option('openseadragon2_embed_admin')) {
return;
}
echo $args['view']->openseadragon($args['item']->Files);
echo $args['view']->partial('annotations/annoViewer.php', array('file' => $args['item']->Files));
}
public function hookAdminFilesShow($args)
{
// Embed viewer only if configured to do so.
if (!get_option('openseadragon2_embed_admin')) {
return;
}
echo $args['view']->partial('annotations/annoViewer.php', array('file' => $args['file']));
}
public function hookAdminFilesForm($args)
{
// Embed viewer only if configured to do so.
if (!get_option('openseadragon2_embed_admin')) {
return;
}
echo $args['view']->partial('annotations/annoViewer.php', array('file' => $args['file']));
}
/**
* Display the image viewer in public items/show.
*/
public function hookPublicItemsShow($args)
{
// Embed viewer only if configured to do so.
if (!get_option('openseadragon2_embed_public')) {
return;
}
echo $args['view']->openseadragon($args['item']->Files);
//$arr = $args['item']->Files;
//echo $args['view']->partial('annotations/add.php', array('file' => $arr[0]));
}
public function hookPublicFilesShow($args)
{
// Embed viewer only if configured to do so.
if (!get_option('openseadragon2_embed_public')) {
return;
}
echo $args['view']->openseadragon($args['item']->Files);
//echo $args['view']->partial('annotations/add.php', array('file' => $args['file']));
}
private function _osd_css($width, $height)
{
return ".openseadragonframe { width: ".$width."px; height: ".$height."px};";
}
public function hookAdminHead($args)
{
queue_js_file('bigscreen.min', 'openseadragon');
queue_css_string($this->_osd_css(get_option('openseadragon2_width_admin'), get_option('openseadragon2_height_admin')));
}
public function hookPublicHead($args)
{
queue_js_file('bigscreen.min', 'openseadragon');
if (!get_option('openseadragon2_css_override_public')) {
queue_css_string($this->_osd_css(get_option('openseadragon2_width_public'), get_option('openseadragon2_height_public')));
}
}
function hookDefineRoutes($args)
{
$router = $args['router'];
$router->addConfig(new Zend_Config_Ini(dirname(__FILE__) . '/routes.ini', 'routes'));
/*$router->addRoute(
'annotations',
new Zend_Controller_Router_Route(
'annotations/:action',
array(
'module' => 'annotations',
'controller' => 'open-seadragon2',
'action' => 'add'
)
)
);*/
}
}