Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 134 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
mcp_ban | |
0.00% |
0 / 132 |
|
0.00% |
0 / 1 |
812 | |
0.00% |
0 / 1 |
main | |
0.00% |
0 / 132 |
|
0.00% |
0 / 1 |
812 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | /** |
15 | * @ignore |
16 | */ |
17 | if (!defined('IN_PHPBB')) |
18 | { |
19 | exit; |
20 | } |
21 | |
22 | class mcp_ban |
23 | { |
24 | var $u_action; |
25 | |
26 | function main($id, $mode) |
27 | { |
28 | global $db, $user, $auth, $template, $request, $phpbb_dispatcher; |
29 | global $phpbb_root_path, $phpEx; |
30 | |
31 | if (!function_exists('user_ban')) |
32 | { |
33 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
34 | } |
35 | |
36 | // Include the admin banning interface... |
37 | if (!class_exists('acp_ban')) |
38 | { |
39 | include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx); |
40 | } |
41 | |
42 | $bansubmit = $request->is_set_post('bansubmit'); |
43 | $unbansubmit = $request->is_set_post('unbansubmit'); |
44 | |
45 | $user->add_lang(array('acp/ban', 'acp/users')); |
46 | $this->tpl_name = 'mcp_ban'; |
47 | |
48 | /** |
49 | * Use this event to pass perform actions when a ban is issued or revoked |
50 | * |
51 | * @event core.mcp_ban_main |
52 | * @var bool bansubmit True if a ban is issued |
53 | * @var bool unbansubmit True if a ban is removed |
54 | * @var string mode Mode of the ban that is being worked on |
55 | * @since 3.1.0-RC5 |
56 | */ |
57 | $vars = array( |
58 | 'bansubmit', |
59 | 'unbansubmit', |
60 | 'mode', |
61 | ); |
62 | extract($phpbb_dispatcher->trigger_event('core.mcp_ban_main', compact($vars))); |
63 | |
64 | // Ban submitted? |
65 | if ($bansubmit) |
66 | { |
67 | // Grab the list of entries |
68 | $ban = $request->variable('ban', '', $mode === 'user'); |
69 | $ban_length = $request->variable('banlength', 0); |
70 | $ban_length_other = $request->variable('banlengthother', ''); |
71 | $ban_reason = $request->variable('banreason', '', true); |
72 | $ban_give_reason = $request->variable('bangivereason', '', true); |
73 | |
74 | if ($ban) |
75 | { |
76 | if (confirm_box(true)) |
77 | { |
78 | $abort_ban = false; |
79 | /** |
80 | * Use this event to modify the ban details before the ban is performed |
81 | * |
82 | * @event core.mcp_ban_before |
83 | * @var string mode One of the following: user, ip, email |
84 | * @var string ban Either string or array with usernames, ips or email addresses |
85 | * @var int ban_length Ban length in minutes |
86 | * @var string ban_length_other Ban length as a date (YYYY-MM-DD) |
87 | * @var string ban_reason Ban reason displayed to moderators |
88 | * @var string ban_give_reason Ban reason displayed to the banned user |
89 | * @var mixed abort_ban Either false, or an error message that is displayed to the user. |
90 | * If a string is given the bans are not issued. |
91 | * @since 3.1.0-RC5 |
92 | */ |
93 | $vars = array( |
94 | 'mode', |
95 | 'ban', |
96 | 'ban_length', |
97 | 'ban_length_other', |
98 | 'ban_reason', |
99 | 'ban_give_reason', |
100 | 'abort_ban', |
101 | ); |
102 | extract($phpbb_dispatcher->trigger_event('core.mcp_ban_before', compact($vars))); |
103 | |
104 | if ($abort_ban) |
105 | { |
106 | trigger_error($abort_ban); |
107 | } |
108 | user_ban($mode, $ban, $ban_length, $ban_length_other, $ban_reason, $ban_give_reason); |
109 | |
110 | /** |
111 | * Use this event to perform actions after the ban has been performed |
112 | * |
113 | * @event core.mcp_ban_after |
114 | * @var string mode One of the following: user, ip, email |
115 | * @var string ban Either string or array with usernames, ips or email addresses |
116 | * @var int ban_length Ban length in minutes |
117 | * @var string ban_length_other Ban length as a date (YYYY-MM-DD) |
118 | * @var string ban_reason Ban reason displayed to moderators |
119 | * @var string ban_give_reason Ban reason displayed to the banned user |
120 | * @since 3.1.0-RC5 |
121 | */ |
122 | $vars = array( |
123 | 'mode', |
124 | 'ban', |
125 | 'ban_length', |
126 | 'ban_length_other', |
127 | 'ban_reason', |
128 | 'ban_give_reason', |
129 | ); |
130 | extract($phpbb_dispatcher->trigger_event('core.mcp_ban_after', compact($vars))); |
131 | |
132 | trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>'); |
133 | } |
134 | else |
135 | { |
136 | $hidden_fields = array( |
137 | 'mode' => $mode, |
138 | 'ban' => $ban, |
139 | 'bansubmit' => true, |
140 | 'banlength' => $ban_length, |
141 | 'banlengthother' => $ban_length_other, |
142 | 'banreason' => $ban_reason, |
143 | 'bangivereason' => $ban_give_reason, |
144 | ); |
145 | |
146 | /** |
147 | * Use this event to pass data from the ban form to the confirmation screen |
148 | * |
149 | * @event core.mcp_ban_confirm |
150 | * @var array hidden_fields Hidden fields that are passed through the confirm screen |
151 | * @since 3.1.0-RC5 |
152 | */ |
153 | $vars = array('hidden_fields'); |
154 | extract($phpbb_dispatcher->trigger_event('core.mcp_ban_confirm', compact($vars))); |
155 | |
156 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($hidden_fields)); |
157 | } |
158 | } |
159 | } |
160 | else if ($unbansubmit) |
161 | { |
162 | $ban = $request->variable('unban', array('')); |
163 | |
164 | if ($ban) |
165 | { |
166 | if (confirm_box(true)) |
167 | { |
168 | user_unban($mode, $ban); |
169 | |
170 | trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">« ' . $user->lang['BACK_TO_PREV'] . '</a>'); |
171 | } |
172 | else |
173 | { |
174 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
175 | 'mode' => $mode, |
176 | 'unbansubmit' => true, |
177 | 'unban' => $ban))); |
178 | } |
179 | } |
180 | } |
181 | |
182 | // Define language vars |
183 | $this->page_title = $user->lang[strtoupper($mode) . '_BAN']; |
184 | |
185 | $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN']; |
186 | $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN']; |
187 | $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN']; |
188 | $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED']; |
189 | |
190 | switch ($mode) |
191 | { |
192 | case 'user': |
193 | $l_ban_cell = $user->lang['USERNAME']; |
194 | break; |
195 | |
196 | case 'ip': |
197 | $l_ban_cell = $user->lang['IP_HOSTNAME']; |
198 | break; |
199 | |
200 | case 'email': |
201 | $l_ban_cell = $user->lang['EMAIL_ADDRESS']; |
202 | break; |
203 | } |
204 | |
205 | display_ban_end_options(); |
206 | display_ban_options($mode); |
207 | |
208 | $template->assign_vars(array( |
209 | 'L_TITLE' => $this->page_title, |
210 | 'L_EXPLAIN' => $l_ban_explain, |
211 | 'L_UNBAN_TITLE' => $l_unban_title, |
212 | 'L_UNBAN_EXPLAIN' => $l_unban_explain, |
213 | 'L_BAN_CELL' => $l_ban_cell, |
214 | 'L_NO_BAN_CELL' => $l_no_ban_cell, |
215 | |
216 | 'S_USERNAME_BAN' => ($mode == 'user') ? true : false, |
217 | |
218 | 'U_ACTION' => $this->u_action, |
219 | 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_ban&field=ban'), |
220 | )); |
221 | |
222 | if ($mode === 'email' && !$auth->acl_get('a_user')) |
223 | { |
224 | return; |
225 | } |
226 | |
227 | // As a "service" we will check if any post id is specified and populate the username of the poster id if given |
228 | $post_id = $request->variable('p', 0); |
229 | $user_id = $request->variable('u', 0); |
230 | $pre_fill = false; |
231 | |
232 | if ($user_id && $user_id <> ANONYMOUS) |
233 | { |
234 | $sql = 'SELECT username, user_email, user_ip |
235 | FROM ' . USERS_TABLE . ' |
236 | WHERE user_id = ' . $user_id; |
237 | $result = $db->sql_query($sql); |
238 | switch ($mode) |
239 | { |
240 | case 'user': |
241 | $pre_fill = (string) $db->sql_fetchfield('username'); |
242 | break; |
243 | |
244 | case 'ip': |
245 | $pre_fill = (string) $db->sql_fetchfield('user_ip'); |
246 | break; |
247 | |
248 | case 'email': |
249 | $pre_fill = (string) $db->sql_fetchfield('user_email'); |
250 | break; |
251 | } |
252 | $db->sql_freeresult($result); |
253 | } |
254 | else if ($post_id) |
255 | { |
256 | $post_info = phpbb_get_post_data(array($post_id), 'm_ban'); |
257 | |
258 | if (count($post_info) && !empty($post_info[$post_id])) |
259 | { |
260 | switch ($mode) |
261 | { |
262 | case 'user': |
263 | $pre_fill = $post_info[$post_id]['username']; |
264 | break; |
265 | |
266 | case 'ip': |
267 | $pre_fill = $post_info[$post_id]['poster_ip']; |
268 | break; |
269 | |
270 | case 'email': |
271 | $pre_fill = $post_info[$post_id]['user_email']; |
272 | break; |
273 | } |
274 | |
275 | } |
276 | } |
277 | |
278 | if ($pre_fill) |
279 | { |
280 | // left for legacy template compatibility |
281 | $template->assign_var('USERNAMES', $pre_fill); |
282 | $template->assign_var('BAN_QUANTIFIER', $pre_fill); |
283 | } |
284 | } |
285 | } |