-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimelinePlugin.php
More file actions
executable file
·239 lines (201 loc) · 7.42 KB
/
TimelinePlugin.php
File metadata and controls
executable file
·239 lines (201 loc) · 7.42 KB
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
<?php
if (!defined('TIMELINE_PLUGIN_DIR')) {
define('TIMELINE_PLUGIN_DIR', dirname(__FILE__));
}
if (!defined('TIMELINE_HELPERS_DIR')) {
define('TIMELINE_HELPERS_DIR', TIMELINE_PLUGIN_DIR . '/helpers');
}
if (!defined('TIMELINE_FORMS_DIR')) {
define('TIMELINE_FORMS_DIR', TIMELINE_PLUGIN_DIR . '/forms');
}
require_once TIMELINE_PLUGIN_DIR . '/TimelinePlugin.php';
require_once TIMELINE_HELPERS_DIR . '/TimelineFunctions.php';
/**
* Timeline plugin.
*
* @package Omeka\Plugins\Timeline
*/
class TimelinePlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'admin_head',
'public_head',
'install',
'uninstall',
'initialize',
'define_acl',
'define_routes',
'admin_append_to_plugin_uninstall_message',
'item_browse_sql',
);
protected $_filters = array(
'admin_navigation_main',
'public_navigation_main',
'exhibit_layouts'
);
public function hookAdminHead()
{
queue_css_url('https://cdn.knightlab.com/libs/timeline3/latest/css/timeline.css');
queue_js_url('https://cdn.knightlab.com/libs/timeline3/latest/js/timeline.js');
}
public function hookPublicHead()
{
queue_css_url('https://cdn.knightlab.com/libs/timeline3/latest/css/timeline.css');
queue_js_url('https://cdn.knightlab.com/libs/timeline3/latest/js/timeline.js');
}
public function hookInstall()
{
$db = $this->_db;
$sql = "
CREATE TABLE IF NOT EXISTS `$db->Timeline` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`title` TINYTEXT COLLATE utf8_unicode_ci DEFAULT NULL,
`description` TEXT COLLATE utf8_unicode_ci DEFAULT NULL,
`item_date` INT UNSIGNED NOT NULL,
`item_interval` INT UNSIGNED NOT NULL,
`item_title` INT UNSIGNED NOT NULL,
`item_description` INT UNSIGNED NOT NULL,
`query` TEXT COLLATE utf8_unicode_ci DEFAULT NULL,
`creator_id` INT UNSIGNED NOT NULL,
`public` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`featured` TINYINT(1) NOT NULL DEFAULT '0',
`added` timestamp NOT NULL default '2000-01-01 00:00:00',
`modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
";
$db->query($sql);
}
public function hookUninstall()
{
$db = get_db();
$sql = "DROP TABLE IF EXISTS `$db->Timeline`";
$db->query($sql);
delete_option('timeline');
}
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
add_shortcode('timeline', 'timeline_shortcode');
}
public function hookDefineAcl($args)
{
$acl = $args['acl'];
$acl->addResource('Timeline_Timelines');
// Allow everyone access to browse, show, and items.
$acl->allow(null, 'Timeline_Timelines', array('show', 'browse', 'items'));
$acl->allow('researcher', 'Timeline_Timelines', 'showNotPublic');
$acl->allow('contributor', 'Timeline_Timelines', array('add', 'editSelf', 'querySelf', 'itemsSelf', 'deleteSelf', 'showNotPublic'));
$acl->allow(array('super', 'admin', 'contributor', 'researcher'), 'Timeline_Timelines', array('edit', 'query', 'items', 'delete'), new Omeka_Acl_Assert_Ownership);
}
public function hookDefineRoutes($args)
{
$router = $args['router'];
$actionRoute = new Zend_Controller_Router_Route('timeline/:action/:id',
array(
'module' => 'timeline',
'controller' => 'timelines'
),
array('id' => '\d+'));
$router->addRoute('timelinesAction', $actionRoute);
$defaultRoute = new Zend_Controller_Router_Route('timeline/:action',
array(
'module' => 'timeline',
'controller' => 'timelines'
),
);
$router->addRoute('timelinesDefault', $defaultRoute);
$redirectRoute = new Zend_Controller_Router_Route('timeline',
array(
'module' => 'timeline',
'controller' => 'timelines',
'action' => 'browse'
),
);
$router->addRoute('timelinesRedirect', $redirectRoute);
$pageRoute = new Zend_Controller_Router_Route('timeline/:page',
array(
'module' => 'timeline',
'controller' => 'timelines',
'action' => 'browse',
'page' => '1'
),
array('page' => '\d+'));
$router->addRoute('timelinesPagination', $pageRoute);
}
public function hookAdminAppendToPluginUninstallMessage()
{
$string = __('<strong>Warning</strong>: Uninstalling the Timeline plugin
will remove all Timeline records.');
echo '<p>'.$string.'</p>';
}
/**
* Filter the items_browse_sql to return only items that have a non-empty
* value for the chosen date field, when using the timeline-json context.
* Uses the ItemSearch model (models/ItemSearch.php) to add the check for
* a non-empty DC:Date.
*
* @param Omeka_Db_Select $select
*/
public function hookItemBrowseSql()
{
$context = Zend_Controller_Action_HelperBroker::getStaticHelper('ContextSwitch')->getCurrentContext();
if ($context == 'timeline-json') {
$search = new ItemSearch($select);
$newParams[0]['element_id'] = timeline_get_option('item_date');
$newParams[0]['type'] = 'is not empty';
$search->advanced($newParams);
}
}
/**
* Timeline admin_navigation_main filter.
*
* Adds a button to the admin's main navigation.
*
* @param array $nav
* @return array
*/
public function filterAdminNavigationMain($nav)
{
$nav[] = array(
'label' => __('Timeline'),
'uri' => url('timeline'),
'resource' => 'Timeline_Timelines',
'privilege' => 'browse'
);
return $nav;
}
/**
* Timeline public_navigation_main filter.
*
* Adds a button to the public theme's main navigation.
*
* @param array $nav
* @return array
*/
public function filterPublicNavigationMain($nav)
{
$nav[] = array(
'label' => __('Timeline'),
'uri' => url('timeline')
);
return $nav;
}
/**
* Register an exhibit layout for displaying a timeline.
*
* @param array $layouts Exhibit layout specs.
* @return array
*/
public function filterExhibitLayouts($layouts)
{
$layouts['timeline'] = array(
'name' => __('Timeline'),
'description' => __('Embed a Timeline timeline.')
);
return $layouts;
}
}