This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
start.php
108 lines (90 loc) · 2.74 KB
/
start.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
<?php
/**
* Ban users plugin
*
* Elgg core uses the metadata 'ban_reason' for storing the reason for the banning.
* We store the release time as a 'ban_release' annotation on the user and we add
* a 'banned' annotation to serve as a record that the user has been banned in the
* past. This is what allows us to count the number of times the user has been banned.
*/
elgg_register_event_handler('init', 'system', 'ban_init');
function ban_init() {
elgg_register_plugin_hook_handler('cron', 'hourly', 'ban_cron');
elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'ban_user_hover_menu');
elgg_extend_view('css/admin', 'ban/css');
elgg_register_admin_menu_item('administer', 'ban_list', 'users');
elgg_register_widget_type('banned_users', elgg_echo('ban:list:title'), elgg_echo('ban:list:title'), array('admin'));
$action_path = elgg_get_plugins_path() . "ban/actions/ban";
elgg_register_action('ban/ban', "$action_path/ban.php", 'admin');
elgg_register_action('ban/unban', "$action_path/unban.php", 'admin');
}
/**
* Add Ban user hover menu for admins
*
* @param string $hook
* @param string $type
* @param array $menu
* @param array $params
*/
function ban_user_hover_menu($hook, $type, $menu, $params) {
$user = $params['entity'];
if (elgg_get_logged_in_user_guid() == $user->getGUID()) {
return $menu;
}
if ($user->isBanned()) {
$menu[] = ElggMenuItem::factory(array(
'name' => 'unban',
'text' => elgg_echo('unban'),
'href' => "action/ban/unban?guid=$user->guid",
'is_action' => true,
'section' => 'admin',
));
} else {
$menu[] = ElggMenuItem::factory(array(
'name' => 'ban',
'text' => elgg_echo('ban'),
'href' => "admin/users/ban?guid=$user->guid",
'section' => 'admin',
));
}
return $menu;
}
/**
* Unban users whose timeouts have expired
*
* @return void
*/
function ban_cron() {
$previous = elgg_set_ignore_access();
$dbprefix = get_config('dbprefix');
$params = array(
'type' => 'user',
'annotation_names' => array('ban_release'),
'joins' => array("JOIN {$dbprefix}users_entity u on e.guid = u.guid"),
'wheres' => array("u.banned='yes'"),
);
$now = time();
$users = elgg_get_entities_from_annotations($params);
foreach ($users as $user) {
$releases = elgg_get_annotations(array(
'guid' => $user->guid,
'annotation_name' => 'ban_release',
'limit' => 1,
'order' => 'n_table.time_created desc',
));
foreach ($releases as $release) {
if ($release->value < $now) {
if ($user->unban()) {
$release->delete();
}
}
}
}
elgg_set_ignore_access($previous);
}
/**
* Override the user/default view for banned users in banned list
*/
function banned_user_view($hook, $type, $return, $params) {
return elgg_view('ban/banned_user', $params['vars']);
}