-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGettySuggestPlugin.php
More file actions
148 lines (132 loc) · 4.17 KB
/
GettySuggestPlugin.php
File metadata and controls
148 lines (132 loc) · 4.17 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
<?php
/**
* Getty Controlled Vocabulary Suggest
*
* @copyright Copyright 2007-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
/**
* Getty Controlled Vocabulary Suggest plugin.
*
* @package GettySuggest
*/
class GettySuggestPlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'install',
'uninstall',
'initialize',
'define_acl',
'admin_head',
'config',
'config_form'
);
/**
* @var array Filters for the plugin.
*/
protected $_filters = array(
'admin_navigation_main',
);
protected $_options = array(
'gettyLimit'=>'10'
);
/**
* Install the plugin.
*
* @return void
*/
public function hookInstall()
{
$this->_installOptions();
$sql1 = "
CREATE TABLE `{$this->_db->GettySuggest}` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`element_id` int(10) unsigned NOT NULL,
`suggest_endpoint` tinytext COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$this->_db->query($sql1);
}
/**
* Uninstall the plugin.
*
* @return void
*/
public function hookUninstall()
{
$this->_uninstallOptions();
$sql1 = "DROP TABLE IF EXISTS `{$this->_db->GettySuggest}`";
$this->_db->query($sql1);
}
/**
* Initialize the plugin.
*
* @return void
*/
public function hookInitialize()
{
// Register the SelectFilter controller plugin.
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new GettySuggest_Controller_Plugin_Autosuggest);
// Add translation.
add_translation_source(dirname(__FILE__) . '/languages');
}
/**
* Define the plugin's access control list.
*
* @param array $args This array contains a reference to
* the zend ACL under it's 'acl' key.
* @return void
*/
public function hookDefineAcl($args)
{
$args['acl']->addResource('GettySuggest_Index');
}
/**
* Add the GettySuggest link to the admin main navigation.
*
* @param array $nav Array of links for admin nav section
* @return array $nav Updated array of links for admin nav section
*/
public function filterAdminNavigationMain($nav)
{
$nav[] = array(
'label' => __('Getty Suggest'),
'uri' => url('getty-suggest'),
'resource' => 'GettySuggest_Index',
'privilege' => 'index',
);
return $nav;
}
public function markSuggestField($components, $args) {
$components['description'] = $components['description'].'<p class="gett-suggest-notice">(This element has autosuggest activated using the GettySuggest plugin)</p><div class="wait-icon">Querying...</div>';
return($components);
}
public function hookAdminHead() {
queue_css_file('GettySuggest');
$suggests = get_db()->getTable('GettySuggest')->findAll();
foreach($suggests as $suggest) {
$element = get_db()->getTable('Element')->find($suggest->element_id);
add_filter(array('ElementForm', 'Item', $element->getElementSet()->name, $element->name),array($this,'markSuggestField'));
}
}
public function hookConfig() {
set_option('gettyLimit',$_REQUEST['getty-limit']);
}
public function hookConfigForm() {
?>
<div class="field">
<div id="getty-limit-label" class="two columns alpha">
<label for="getty-limit"><?php echo 'Maximum number of terms to return for each Getty vocabulary autosuggest'; ?></label>
</div>
<div class="inputs five columns omega">
<?php echo get_view()->formText('getty-limit',get_option('gettyLimit'),array()); ?>
<p class="explanation"><?php echo __('Higher numbers will give you more options for each term, but will also slow down the response time.'); ?></p>
</div>
</div>
<?php
}
}