-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmailUsersPlugin.php
145 lines (131 loc) · 3.89 KB
/
EmailUsersPlugin.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
<?php
/**
* Email Users
*
* @copyright Copyright 2021 Daniele Binaghi
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
/**
* Email Users plugin.
*/
class EmailUsersPlugin extends Omeka_Plugin_AbstractPlugin
{
/**
* @var array Hooks for the plugin.
*/
protected $_hooks = array(
'install',
'uninstall',
'initialize',
'define_acl',
'config',
'config_form'
);
/**
* @var array Filters for the plugin.
*/
protected $_filters = array('admin_navigation_main');
/**
* Install the plugin.
*/
public function hookInstall()
{
$db = $this->_db;
$sql = "
CREATE TABLE IF NOT EXISTS {$db->EmailUsersMessage} (
`id` INT NOT NULL AUTO_INCREMENT,
`sender_id` INT NOT NULL,
`subject` VARCHAR(255) NOT NULL,
`text` BLOB NOT NULL,
`html` TINYINT(1),
`priority` TINYINT(1),
`created` DATETIME NOT NULL,
`sent` DATETIME,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
";
$db->query($sql);
$sql = "
CREATE TABLE IF NOT EXISTS {$db->EmailUsersRecipient} (
`message_id` INT NOT NULL,
`user_id` INT NOT NULL,
`role` VARCHAR(50) NOT NULL,
PRIMARY KEY (`message_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
";
$db->query($sql);
set_option('email_users_composition_subject_prefix', '');
set_option('email_users_composition_header', '');
set_option('email_users_composition_footer', '');
set_option('email_users_composition_use_html', '1');
set_option('email_users_recipient_count_verbose', '0');
}
/**
* Uninstall the plugin.
*/
public function hookUninstall()
{
$db = $this->_db;
$db->query("DROP TABLE IF EXISTS {$db->EmailUsersMessage}");
$db->query("DROP TABLE IF EXISTS {$db->EmailUsersRecipient}");
delete_option('email_users_composition_subject_prefix');
delete_option('email_users_composition_header');
delete_option('email_users_composition_footer');
delete_option('email_users_composition_use_html');
delete_option('email_users_recipient_count_verbose');
}
/**
* Add the translations.
*/
public function hookInitialize()
{
add_translation_source(dirname(__FILE__) . '/languages');
}
/**
* Define the ACL.
*
* @param Omeka_Acl
*/
public function hookDefineAcl($args)
{
$acl = $args['acl'];
$indexResource = new Zend_Acl_Resource('EmailUsers_Index');
$acl->add($indexResource);
$acl->allow(array('super', 'admin'), array('EmailUsers_Index'));
}
/**
* Shows plugin configuration page.
*/
public function hookConfigForm()
{
include 'config_form.php';
}
/**
* Handle the config form.
*/
public function hookConfig($args)
{
$post = $args['post'];
set_option('email_users_composition_subject_prefix', $post['email_users_composition_subject_prefix']);
set_option('email_users_composition_header', $post['email_users_composition_header']);
set_option('email_users_composition_footer', $post['email_users_composition_footer']);
set_option('email_users_composition_use_html', $post['email_users_composition_use_html']);
set_option('email_users_recipient_count_verbose', $post['email_users_recipient_count_verbose']);
}
/**
* Add the Email Users link to the admin main navigation.
*
* @param array Navigation array.
* @return array Filtered navigation array.
*/
public function filterAdminNavigationMain($nav)
{
$nav[] = array(
'label' => __('E-mail Users'),
'uri' => url('email-users'),
'resource' => 'EmailUsers_Index',
'privilege' => 'browse'
);
return $nav;
}
}