-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSimpleVocabPlugin.php
118 lines (106 loc) · 2.97 KB
/
SimpleVocabPlugin.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
<?php
/**
* Simple Vocab
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
/**
* The Simple Vocab plugin.
*
* @package Omeka\Plugins\SimpleVocab
*/
class SimpleVocabPlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* @var array This plugin's hooks.
*/
protected $_hooks = array(
'install', 'uninstall', 'initialize', 'upgrade',
'define_acl', 'config_form', 'config',
);
/**
* @var array This plugin's filters.
*/
protected $_filters = array('admin_navigation_main');
protected $_options = array(
'simple_vocab_files' => 0,
);
/**
* Install this plugin.
*/
public function hookInstall()
{
$db = get_db();
$sql = "
CREATE TABLE `{$db->SimpleVocabTerm}` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`element_id` int(10) unsigned NOT NULL,
`terms` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `element_id` (`element_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$db->query($sql);
$this->_installOptions();
}
/**
* Uninstall this plugin.
*/
public function hookUninstall()
{
$db = get_db();
$sql = "DROP TABLE IF EXISTS `{$db->SimpleVocabTerm}`;";
$db->query($sql);
$this->_uninstallOptions();
}
public function hookUpgrade($args)
{
if (version_compare($args['old_version'], '2.0.1', '<=')) {
set_option('simple_vocab_files', $this->_options['simple_vocab_files']);
}
}
/**
* Initialize this plugin.
*/
public function hookInitialize()
{
// Register the select filter controller plugin.
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new SimpleVocab_Controller_Plugin_SelectFilter);
// Add translation.
add_translation_source(dirname(__FILE__) . '/languages');
}
public function hookConfigForm()
{
$view = get_view();
include 'config_form.php';
}
public function hookConfig($args)
{
$files = 0;
if (isset($args['post']['simple_vocab_files'])) {
$files = (int) $args['post']['simple_vocab_files'];
}
set_option('simple_vocab_files', $files);
}
/**
* Define this plugin's ACL.
*/
public function hookDefineAcl($args)
{
// Restrict access to super and admin users.
$args['acl']->addResource('SimpleVocab_Index');
}
/**
* Add the Simple Vocab navigation link.
*/
public function filterAdminNavigationMain($nav)
{
$nav[] = array(
'label' => __('Simple Vocab'),
'uri' => url('simple-vocab'),
'resource' => 'SimpleVocab_Index'
);
return $nav;
}
}