-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathNeatlinePlugin.php
265 lines (215 loc) · 6.12 KB
/
NeatlinePlugin.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* @package omeka
* @subpackage neatline
* @copyright 2014 Rector and Board of Visitors, University of Virginia
* @license http://www.apache.org/licenses/LICENSE-2.0.html
*/
class NeatlinePlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array(
'install',
'uninstall',
'upgrade',
'define_acl',
'initialize',
'define_routes',
'after_save_item',
'config_form',
'config'
);
protected $_filters = array(
'public_navigation_main',
'admin_navigation_main',
'neatline_globals',
'neatline_presenters',
'exhibit_layouts',
'search_record_types'
);
// HOOKS
// ------------------------------------------------------------------------
/**
* Create exhibit and record tables.
*/
public function hookInstall()
{
nl_schema260();
}
/**
* Drop exhibit and record tables.
*/
public function hookUninstall()
{
$this->_db->query(<<<SQL
DROP TABLE {$this->_db->prefix}neatline_exhibits
SQL
);
$this->_db->query(<<<SQL
DROP TABLE {$this->_db->prefix}neatline_records
SQL
);
}
/**
* Upgrade the plugin.
*
* @param array $args Contains: `old_version` and `new_version`.
*/
public function hookUpgrade($args)
{
$old = $args['old_version'];
// If trying to upgrade from a pre-2.0 release, throw an error.
if (version_compare($old, '2.0.0', '<')) {
throw new Omeka_Plugin_Installer_Exception(
"Pre-2.0 versions of Neatline can't be upgraded directly to
version 2.2. Upgrade to version 2.0 first!"
);
}
// Otherwise, run 2.x migrations normally.
else {
if (version_compare($old, '2.0.2', '<')) {
new Neatline_Migration_202();
}
if (version_compare($old, '2.1.2', '<')) {
new Neatline_Migration_212();
}
if (version_compare($old, '2.2.0', '<')) {
new Neatline_Migration_220();
}
if (version_compare($old, '2.4.3', '<')) {
new Neatline_Migration_243();
}
if (version_compare($old, '2.5.2', '<')) {
new Neatline_Migration_252();
}
if (version_compare($old, '2.6.0', '<')) {
new Neatline_Migration_260();
}
}
}
/**
* Define the ACL.
*
* @param array $args Contains: `acl` (Zend_Acl).
*/
public function hookDefineAcl($args)
{
nl_defineAcl($args['acl']);
}
/**
* Add translation source.
*/
public function hookInitialize()
{
add_translation_source(dirname(__FILE__).'/languages');
}
/**
* Register routes.
*
* @param array $args Contains: `router` (Zend_Config).
*/
public function hookDefineRoutes($args)
{
$args['router']->addConfig(new Zend_Config_Ini(
NL_DIR.'/routes.ini'
));
}
/**
* Shows plugin configuration page.
*/
public function hookConfigForm($args)
{
$view = $args['view'];
include 'config_form.php';
}
/**
* Saves plugin configuration page.
*
* @param array Options set in the config form.
*/
public function hookConfig($args)
{
set_option('neatline_googlemaps_apikey', $_POST['neatline_googlemaps_apikey']);
set_option('neatline_exhibitblock_height', $_POST['neatline_exhibitblock_height']);
}
/**
* Propagate item updates to Neatline records.
*
* @param array $args Contains: `record` (Item).
*/
public function hookAfterSaveItem($args)
{
$records = $this->_db->getTable('NeatlineRecord');
$records->syncItem($args['record']);
}
// FILTERS
// ------------------------------------------------------------------------
/**
* Add link to main public menu bar.
*
* @param array $tabs Tabs, <LABEL> => <URI> pairs.
* @return array The tab array with the "Neatline" tab.
*/
public function filterPublicNavigationMain($tabs)
{
$tabs[] = array('label' => 'Neatline', 'uri' => url('neatline'));
return $tabs;
}
/**
* Add link to main admin menu bar.
*
* @param array $tabs Tabs, <LABEL> => <URI> pairs.
* @return array The tab array with the "Neatline" tab.
*/
public function filterAdminNavigationMain($tabs)
{
$tabs[] = array('label' => 'Neatline', 'uri' => url('neatline'));
return $tabs;
}
/**
* Register properties on `Neatline.g`.
*
* @param array $globals The array of global properties.
* @param array $args Contains: `exhibit` (NeatlineExhibit).
* @return array The modified array.
*/
public function filterNeatlineGlobals($globals, $args)
{
return array_merge($globals, nl_globals($args['exhibit']));
}
/**
* Register record presenters.
*
* @param array $presenters Presenters, <NAME> => <ID>.
* @return array The array, with None and StaticBubble.
*/
public function filterNeatlinePresenters($presenters)
{
return array_merge($presenters, array(
'None' => 'None',
'Static Bubble' => 'StaticBubble'
));
}
/**
* Register the exhibit layout for Nealtine.
*
* @return void
* @author Eric Rochester <erochest@virginia.edu>
**/
public function filterExhibitLayouts($layouts)
{
$layouts['neatline'] = array(
'name' => __('Neatline'),
'description' => __('Embed a Neatline exhibit.')
);
return $layouts;
}
/**
* Add NeatlineExhibit and NeatlineRecord as searchable types.
*/
public function filterSearchRecordTypes($recordTypes)
{
$recordTypes['NeatlineExhibit'] = __('Neatline Exhibit');
$recordTypes['NeatlineRecord'] = __('Neatline Record');
return $recordTypes;
}
}