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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* mcp_warn
* Handling warning the users
*/
class mcp_warn
{
var $p_master;
var $u_action;
function mcp_warn(&$p_master)
{
$this->p_master = &$p_master;
}
function main($id, $mode)
{
global $request;
$action = $request->variable('action', array('' => ''));
if (is_array($action))
{
list($action, ) = each($action);
}
$this->page_title = 'MCP_WARN';
add_form_key('mcp_warn');
switch ($mode)
{
case 'front':
$this->mcp_warn_front_view();
$this->tpl_name = 'mcp_warn_front';
break;
case 'list':
$this->mcp_warn_list_view($action);
$this->tpl_name = 'mcp_warn_list';
break;
case 'warn_post':
$this->mcp_warn_post_view($action);
$this->tpl_name = 'mcp_warn_post';
break;
case 'warn_user':
$this->mcp_warn_user_view($action);
$this->tpl_name = 'mcp_warn_user';
break;
}
}
/**
* Generates the summary on the main page of the warning module
*/
function mcp_warn_front_view()
{
global $phpEx, $phpbb_root_path;
global $template, $db, $user;
$template->assign_vars(array(
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp&field=username&select_single=true'),
'U_POST_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user'),
));
// Obtain a list of the 5 naughtiest users....
// These are the 5 users with the highest warning count
$highest = array();
$count = 0;
view_warned_users($highest, $count, 5);
foreach ($highest as $row)
{
$template->assign_block_vars('highest', array(
'U_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $row['user_id']),
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
'WARNING_TIME' => $user->format_date($row['user_last_warning']),
'WARNINGS' => $row['user_warnings'],
));
}
// And now the 5 most recent users to get in trouble
$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_warnings, w.warning_time
FROM ' . USERS_TABLE . ' u, ' . WARNINGS_TABLE . ' w
WHERE u.user_id = w.user_id
ORDER BY w.warning_time DESC';
$result = $db->sql_query_limit($sql, 5);
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('latest', array(
'U_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $row['user_id']),
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
'WARNING_TIME' => $user->format_date($row['warning_time']),
'WARNINGS' => $row['user_warnings'],
));
}
$db->sql_freeresult($result);
}
/**
* Lists all users with warnings
*/
function mcp_warn_list_view($action)
{
global $phpEx, $phpbb_root_path, $config, $phpbb_container;
global $template, $user, $auth, $request;
/* @var $pagination \phpbb\pagination */
$pagination = $phpbb_container->get('pagination');
$user->add_lang('memberlist');
$start = $request->variable('start', 0);
$st = $request->variable('st', 0);
$sk = $request->variable('sk', 'b');
$sd = $request->variable('sd', 'd');
$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
$sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_WARNINGS']);
$sort_by_sql = array('a' => 'username_clean', 'b' => 'user_last_warning', 'c' => 'user_warnings');
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
// Define where and sort sql for use in displaying logs
$sql_where = ($st) ? (time() - ($st * 86400)) : 0;
$sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
$users = array();
$user_count = 0;
view_warned_users($users, $user_count, $config['topics_per_page'], $start, $sql_where, $sql_sort);
foreach ($users as $row)
{
$template->assign_block_vars('user', array(
'U_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $row['user_id']),
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
'WARNING_TIME' => $user->format_date($row['user_last_warning']),
'WARNINGS' => $row['user_warnings'],
));
}
$base_url = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=warn&mode=list&st=$st&sk=$sk&sd=$sd");
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $user_count, $config['topics_per_page'], $start);
$template->assign_vars(array(
'U_POST_ACTION' => $this->u_action,
'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false,
'S_SELECT_SORT_DIR' => $s_sort_dir,
'S_SELECT_SORT_KEY' => $s_sort_key,
'S_SELECT_SORT_DAYS' => $s_limit_days,
'TOTAL_USERS' => $user->lang('LIST_USERS', (int) $user_count),
));
}
/**
* Handles warning the user when the warning is for a specific post
*/
function mcp_warn_post_view($action)
{
global $phpEx, $phpbb_root_path, $config, $request;
global $template, $db, $user, $auth, $phpbb_dispatcher;
$post_id = $request->variable('p', 0);
$forum_id = $request->variable('f', 0);
$notify = (isset($_REQUEST['notify_user'])) ? true : false;
$warning = $request->variable('warning', '', true);
$sql = 'SELECT u.*, p.*
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE p.post_id = $post_id
AND u.user_id = p.poster_id";
$result = $db->sql_query($sql);
$user_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$user_row)
{
trigger_error('NO_POST');
}
// There is no point issuing a warning to ignored users (ie anonymous and bots)
if ($user_row['user_type'] == USER_IGNORE)
{
trigger_error('CANNOT_WARN_ANONYMOUS');
}
// Prevent someone from warning themselves
if ($user_row['user_id'] == $user->data['user_id'])
{
trigger_error('CANNOT_WARN_SELF');
}
// Check if there is already a warning for this post to prevent multiple
// warnings for the same offence
$sql = 'SELECT post_id
FROM ' . WARNINGS_TABLE . "
WHERE post_id = $post_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row)
{
trigger_error('ALREADY_WARNED');
}
$user_id = $user_row['user_id'];
if (strpos($this->u_action, "&f=$forum_id&p=$post_id") === false)
{
$this->p_master->adjust_url("&f=$forum_id&p=$post_id");
$this->u_action .= "&f=$forum_id&p=$post_id";
}
// Check if can send a notification
if ($config['allow_privmsg'])
{
$auth2 = new \phpbb\auth\auth();
$auth2->acl($user_row);
$s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false;
unset($auth2);
}
else
{
$s_can_notify = false;
}
// Prevent against clever people
if ($notify && !$s_can_notify)
{
$notify = false;
}
if ($warning && $action == 'add_warning')
{
if (check_form_key('mcp_warn'))
{
$s_mcp_warn_post = true;
/**
* Event for before warning a user for a post.
*
* @event core.mcp_warn_post_before
* @var array user_row The entire user row
* @var string warning The warning message
* @var bool notify If true, we notify the user for the warning
* @var int post_id The post id for which the warning is added
* @var bool s_mcp_warn_post If true, we add the warning else we omit it
* @since 3.1.0-b4
*/
$vars = array(
'user_row',
'warning',
'notify',
'post_id',
's_mcp_warn_post',
);
extract($phpbb_dispatcher->trigger_event('core.mcp_warn_post_before', compact($vars)));
if ($s_mcp_warn_post)
{
add_warning($user_row, $warning, $notify, $post_id);
$message = $user->lang['USER_WARNING_ADDED'];
/**
* Event for after warning a user for a post.
*
* @event core.mcp_warn_post_after
* @var array user_row The entire user row
* @var string warning The warning message
* @var bool notify If true, the user was notified for the warning
* @var int post_id The post id for which the warning is added
* @var string message Message displayed to the moderator
* @since 3.1.0-b4
*/
$vars = array(
'user_row',
'warning',
'notify',
'post_id',
'message',
);
extract($phpbb_dispatcher->trigger_event('core.mcp_warn_post_after', compact($vars)));
}
}
else
{
$message = $user->lang['FORM_INVALID'];
}
if (!empty($message))
{
$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&mode=user_notes&u=$user_id");
meta_refresh(2, $redirect);
trigger_error($message . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
}
}
// OK, they didn't submit a warning so lets build the page for them to do so
// We want to make the message available here as a reminder
// Parse the message and subject
$parse_flags = OPTION_FLAG_SMILIES | ($user_row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0);
$message = generate_text_for_display($user_row['post_text'], $user_row['bbcode_uid'], $user_row['bbcode_bitfield'], $parse_flags, true);
// Generate the appropriate user information for the user we are looking at
if (!function_exists('phpbb_get_user_rank'))
{
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
$user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']);
$avatar_img = phpbb_get_user_avatar($user_row);
$template->assign_vars(array(
'U_POST_ACTION' => $this->u_action,
'POST' => $message,
'USERNAME' => $user_row['username'],
'USER_COLOR' => (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '',
'RANK_TITLE' => $user_rank_data['title'],
'JOINED' => $user->format_date($user_row['user_regdate']),
'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
'AVATAR_IMG' => $avatar_img,
'RANK_IMG' => $user_rank_data['img'],
'L_WARNING_POST_DEFAULT' => sprintf($user->lang['WARNING_POST_DEFAULT'], generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&p=$post_id#p$post_id"),
'S_CAN_NOTIFY' => $s_can_notify,
));
}
/**
* Handles warning the user
*/
function mcp_warn_user_view($action)
{
global $phpEx, $phpbb_root_path, $config, $module, $request;
global $template, $db, $user, $auth, $phpbb_dispatcher;
$user_id = $request->variable('u', 0);
$username = $request->variable('username', '', true);
$notify = (isset($_REQUEST['notify_user'])) ? true : false;
$warning = $request->variable('warning', '', true);
$sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
$sql = 'SELECT *
FROM ' . USERS_TABLE . '
WHERE ' . $sql_where;
$result = $db->sql_query($sql);
$user_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$user_row)
{
trigger_error('NO_USER');
}
// Prevent someone from warning themselves
if ($user_row['user_id'] == $user->data['user_id'])
{
trigger_error('CANNOT_WARN_SELF');
}
$user_id = $user_row['user_id'];
if (strpos($this->u_action, "&u=$user_id") === false)
{
$this->p_master->adjust_url('&u=' . $user_id);
$this->u_action .= "&u=$user_id";
}
// Check if can send a notification
if ($config['allow_privmsg'])
{
$auth2 = new \phpbb\auth\auth();
$auth2->acl($user_row);
$s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false;
unset($auth2);
}
else
{
$s_can_notify = false;
}
// Prevent against clever people
if ($notify && !$s_can_notify)
{
$notify = false;
}
if ($warning && $action == 'add_warning')
{
if (check_form_key('mcp_warn'))
{
$s_mcp_warn_user = true;
/**
* Event for before warning a user from MCP.
*
* @event core.mcp_warn_user_before
* @var array user_row The entire user row
* @var string warning The warning message
* @var bool notify If true, we notify the user for the warning
* @var bool s_mcp_warn_user If true, we add the warning else we omit it
* @since 3.1.0-b4
*/
$vars = array(
'user_row',
'warning',
'notify',
's_mcp_warn_user',
);
extract($phpbb_dispatcher->trigger_event('core.mcp_warn_user_before', compact($vars)));
if ($s_mcp_warn_user)
{
add_warning($user_row, $warning, $notify);
$message = $user->lang['USER_WARNING_ADDED'];
/**
* Event for after warning a user from MCP.
*
* @event core.mcp_warn_user_after
* @var array user_row The entire user row
* @var string warning The warning message
* @var bool notify If true, the user was notified for the warning
* @var string message Message displayed to the moderator
* @since 3.1.0-b4
*/
$vars = array(
'user_row',
'warning',
'notify',
'message',
);
extract($phpbb_dispatcher->trigger_event('core.mcp_warn_user_after', compact($vars)));
}
}
else
{
$message = $user->lang['FORM_INVALID'];
}
if (!empty($message))
{
$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&mode=user_notes&u=$user_id");
meta_refresh(2, $redirect);
trigger_error($message . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
}
}
// Generate the appropriate user information for the user we are looking at
if (!function_exists('phpbb_get_user_rank'))
{
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
}
$user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']);
$avatar_img = phpbb_get_user_avatar($user_row);
// OK, they didn't submit a warning so lets build the page for them to do so
$template->assign_vars(array(
'U_POST_ACTION' => $this->u_action,
'RANK_TITLE' => $user_rank_data['title'],
'JOINED' => $user->format_date($user_row['user_regdate']),
'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
'USERNAME_FULL' => get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
'USERNAME_COLOUR' => get_username_string('colour', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
'USERNAME' => get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
'U_PROFILE' => get_username_string('profile', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
'AVATAR_IMG' => $avatar_img,
'RANK_IMG' => $user_rank_data['img'],
'S_CAN_NOTIFY' => $s_can_notify,
));
return $user_id;
}
}
/**
* Insert the warning into the database
*/
function add_warning($user_row, $warning, $send_pm = true, $post_id = 0)
{
global $phpEx, $phpbb_root_path, $config, $phpbb_log;
global $template, $db, $user, $auth;
if ($send_pm)
{
include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$user_row['user_lang'] = (file_exists($phpbb_root_path . 'language/' . $user_row['user_lang'] . "/mcp.$phpEx")) ? $user_row['user_lang'] : $config['default_lang'];
include($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");
$message_parser = new parse_message();
$message_parser->message = $user->lang('WARNING_PM_BODY', $warning);
$message_parser->parse(true, true, true, false, false, true, true);
$pm_data = array(
'from_user_id' => $user->data['user_id'],
'from_user_ip' => $user->ip,
'from_username' => $user->data['username'],
'enable_sig' => false,
'enable_bbcode' => true,
'enable_smilies' => true,
'enable_urls' => false,
'icon_id' => 0,
'bbcode_bitfield' => $message_parser->bbcode_bitfield,
'bbcode_uid' => $message_parser->bbcode_uid,
'message' => $message_parser->message,
'address_list' => array('u' => array($user_row['user_id'] => 'to')),
);
submit_pm('post', $user->lang('WARNING_PM_SUBJECT'), $pm_data, false);
}
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_WARNING', false, array($user_row['username']));
$log_id = $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_WARNING_BODY', false, array(
'reportee_id' => $user_row['user_id'],
$warning
));
$sql_ary = array(
'user_id' => $user_row['user_id'],
'post_id' => $post_id,
'log_id' => $log_id,
'warning_time' => time(),
);
$db->sql_query('INSERT INTO ' . WARNINGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_warnings = user_warnings + 1,
user_last_warning = ' . time() . '
WHERE user_id = ' . $user_row['user_id'];
$db->sql_query($sql);
// We add this to the mod log too for moderators to see that a specific user got warned.
$sql = 'SELECT forum_id, topic_id
FROM ' . POSTS_TABLE . '
WHERE post_id = ' . $post_id;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_WARNING', false, array(
'forum_id' => $row['forum_id'],
'topic_id' => $row['topic_id'],
'post_id' => $post_id,
$user_row['username']
));
}
|