forked from brettp/Bulk-User-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
94 lines (77 loc) · 2.65 KB
/
Copy pathstart.php
File metadata and controls
94 lines (77 loc) · 2.65 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
<?php
/**
* Allow bulk delete operations
*/
/**
* Init
*/
function bulk_user_admin_init() {
// need to intercept the page handler to use our own page scripts
// because the original scripts change context to search instead of admin.
register_page_handler('admin', 'bulk_user_admin_page_handler');
register_elgg_event_handler('pagesetup', 'system', 'bulk_user_admin_admin_page_setup');
elgg_extend_view('admin/user_opt/search', 'bulk_user_admin/search_by_domain');
elgg_extend_view('css', 'bulk_user_admin/css');
register_action('bulk_user_admin/delete', false, dirname(__FILE__) . '/actions/bulk_user_admin/delete.php', true);
register_action('bulk_user_admin/delete_by_domain', false, dirname(__FILE__) . '/actions/bulk_user_admin/delete_by_domain.php', true);
}
/**
* Serve our special users page or fall back to the core admin page handler
*
* @param array $page
*/
function bulk_user_admin_page_handler($page) {
admin_gatekeeper();
if ($page[0] == 'user') {
if (isset($page[1]) && $page[1] == 'email_domain_stats') {
include dirname(__FILE__) . '/pages/admin/email_domain_stats.php';
} else {
include dirname(__FILE__) . '/pages/admin/user.php';
}
} else {
admin_settings_page_handler($page);
}
}
function bulk_user_admin_get_users_by_email_domain($domain, $options = array()) {
$domain = sanitise_string($domain);
$db_prefix = get_config('dbprefix');
$where = "ue.email LIKE '%@$domain'";
if (!isset($options['wheres'])) {
$options['wheres'] = array($where);
} else {
if (!is_array($options['wheres'])) {
$options['wheres'] = array($options['wheres']);
}
$options['wheres'][] = $where;
}
$join = "JOIN {$db_prefix}users_entity ue on e.guid = ue.guid";
if (!isset($options['joins'])) {
$options['joins'] = array($join);
} else {
if (!is_array($options['joins'])) {
$options['joins'] = array($options['joins']);
}
$options['joins'][] = $join;
}
$options['type'] = 'user';
return elgg_get_entities($options);
}
/**
* Sets up tidypics admin menu. Triggered on pagesetup.
*/
function bulk_user_admin_admin_page_setup() {
global $CONFIG;
if (get_context() == 'admin' && isadminloggedin()) {
add_submenu_item('Email domain stats', $CONFIG->url . "pg/admin/user/email_domain_stats");
}
}
function bulk_user_admin_get_email_domain_stats() {
$db_prefix = get_config('dbprefix');
$q = "SELECT email, substring_index(email, '@', -1) as domain, count(*) as count
FROM {$db_prefix}users_entity ue
JOIN {$db_prefix}entities e ON ue.guid = e.guid
WHERE e.enabled = 'yes'
group by domain order by count desc, domain asc;";
return get_data($q);
}
register_elgg_event_handler('init', 'system', 'bulk_user_admin_init');