Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 298 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
acp_prune | |
0.00% |
0 / 296 |
|
0.00% |
0 / 4 |
8742 | |
0.00% |
0 / 1 |
main | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
prune_forums | |
0.00% |
0 / 109 |
|
0.00% |
0 / 1 |
506 | |||
prune_users | |
0.00% |
0 / 74 |
|
0.00% |
0 / 1 |
342 | |||
get_prune_users | |
0.00% |
0 / 99 |
|
0.00% |
0 / 1 |
2450 |
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 acp_prune |
23 | { |
24 | var $u_action; |
25 | |
26 | function main($id, $mode) |
27 | { |
28 | global $user, $phpEx, $phpbb_root_path; |
29 | |
30 | $user->add_lang('acp/prune'); |
31 | |
32 | if (!function_exists('user_active_flip')) |
33 | { |
34 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx); |
35 | } |
36 | |
37 | switch ($mode) |
38 | { |
39 | case 'forums': |
40 | $this->tpl_name = 'acp_prune_forums'; |
41 | $this->page_title = 'ACP_PRUNE_FORUMS'; |
42 | $this->prune_forums($id, $mode); |
43 | break; |
44 | |
45 | case 'users': |
46 | $this->tpl_name = 'acp_prune_users'; |
47 | $this->page_title = 'ACP_PRUNE_USERS'; |
48 | $this->prune_users($id, $mode); |
49 | break; |
50 | } |
51 | } |
52 | |
53 | /** |
54 | * Prune forums |
55 | */ |
56 | function prune_forums($id, $mode) |
57 | { |
58 | global $db, $user, $auth, $template, $phpbb_log, $request, $phpbb_dispatcher; |
59 | |
60 | $all_forums = $request->variable('all_forums', 0); |
61 | $forum_id = $request->variable('f', array(0)); |
62 | $submit = (isset($_POST['submit'])) ? true : false; |
63 | |
64 | if ($all_forums) |
65 | { |
66 | $sql = 'SELECT forum_id |
67 | FROM ' . FORUMS_TABLE . ' |
68 | ORDER BY left_id'; |
69 | $result = $db->sql_query($sql); |
70 | |
71 | $forum_id = array(); |
72 | while ($row = $db->sql_fetchrow($result)) |
73 | { |
74 | $forum_id[] = $row['forum_id']; |
75 | } |
76 | $db->sql_freeresult($result); |
77 | } |
78 | |
79 | if ($submit) |
80 | { |
81 | if (confirm_box(true)) |
82 | { |
83 | $prune_posted = $request->variable('prune_days', 0); |
84 | $prune_viewed = $request->variable('prune_vieweddays', 0); |
85 | $prune_all = (!$prune_posted && !$prune_viewed) ? true : false; |
86 | |
87 | $prune_flags = 0; |
88 | $prune_flags += ($request->variable('prune_old_polls', 0)) ? 2 : 0; |
89 | $prune_flags += ($request->variable('prune_announce', 0)) ? 4 : 0; |
90 | $prune_flags += ($request->variable('prune_sticky', 0)) ? 8 : 0; |
91 | |
92 | // Convert days to seconds for timestamp functions... |
93 | $prunedate_posted = time() - ($prune_posted * 86400); |
94 | $prunedate_viewed = time() - ($prune_viewed * 86400); |
95 | |
96 | $template->assign_vars(array( |
97 | 'S_PRUNED' => true) |
98 | ); |
99 | |
100 | $sql_forum = (count($forum_id)) ? ' AND ' . $db->sql_in_set('forum_id', $forum_id) : ''; |
101 | |
102 | // Get a list of forum's or the data for the forum that we are pruning. |
103 | $sql = 'SELECT forum_id, forum_name |
104 | FROM ' . FORUMS_TABLE . ' |
105 | WHERE forum_type = ' . FORUM_POST . " |
106 | $sql_forum |
107 | ORDER BY left_id ASC"; |
108 | $result = $db->sql_query($sql); |
109 | |
110 | if ($row = $db->sql_fetchrow($result)) |
111 | { |
112 | $prune_ids = array(); |
113 | $p_result = []; |
114 | $p_result['topics'] = 0; |
115 | $p_result['posts'] = 0; |
116 | $log_data = ''; |
117 | |
118 | do |
119 | { |
120 | if (!$auth->acl_get('f_list', $row['forum_id'])) |
121 | { |
122 | continue; |
123 | } |
124 | |
125 | if ($prune_all) |
126 | { |
127 | $p_result = prune($row['forum_id'], 'posted', time(), $prune_flags, false); |
128 | } |
129 | else |
130 | { |
131 | if ($prune_posted) |
132 | { |
133 | $return = prune($row['forum_id'], 'posted', $prunedate_posted, $prune_flags, false); |
134 | $p_result['topics'] += $return['topics']; |
135 | $p_result['posts'] += $return['posts']; |
136 | } |
137 | |
138 | if ($prune_viewed) |
139 | { |
140 | $return = prune($row['forum_id'], 'viewed', $prunedate_viewed, $prune_flags, false); |
141 | $p_result['topics'] += $return['topics']; |
142 | $p_result['posts'] += $return['posts']; |
143 | } |
144 | } |
145 | |
146 | $prune_ids[] = $row['forum_id']; |
147 | |
148 | $template->assign_block_vars('pruned', array( |
149 | 'FORUM_NAME' => $row['forum_name'], |
150 | 'NUM_TOPICS' => $p_result['topics'], |
151 | 'NUM_POSTS' => $p_result['posts']) |
152 | ); |
153 | |
154 | $log_data .= (($log_data != '') ? ', ' : '') . $row['forum_name']; |
155 | } |
156 | while ($row = $db->sql_fetchrow($result)); |
157 | |
158 | // Sync all pruned forums at once |
159 | sync('forum', 'forum_id', $prune_ids, true, true); |
160 | |
161 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PRUNE', false, array($log_data)); |
162 | } |
163 | $db->sql_freeresult($result); |
164 | |
165 | return; |
166 | } |
167 | else |
168 | { |
169 | $hidden_fields = array( |
170 | 'i' => $id, |
171 | 'mode' => $mode, |
172 | 'submit' => 1, |
173 | 'all_forums' => $all_forums, |
174 | 'f' => $forum_id, |
175 | |
176 | 'prune_days' => $request->variable('prune_days', 0), |
177 | 'prune_vieweddays' => $request->variable('prune_vieweddays', 0), |
178 | 'prune_old_polls' => $request->variable('prune_old_polls', 0), |
179 | 'prune_announce' => $request->variable('prune_announce', 0), |
180 | 'prune_sticky' => $request->variable('prune_sticky', 0), |
181 | ); |
182 | |
183 | /** |
184 | * Use this event to pass data from the prune form to the confirmation screen |
185 | * |
186 | * @event core.prune_forums_settings_confirm |
187 | * @var array hidden_fields Hidden fields that are passed through the confirm screen |
188 | * @since 3.2.2-RC1 |
189 | */ |
190 | $vars = array('hidden_fields'); |
191 | extract($phpbb_dispatcher->trigger_event('core.prune_forums_settings_confirm', compact($vars))); |
192 | |
193 | confirm_box(false, $user->lang['PRUNE_FORUM_CONFIRM'], build_hidden_fields($hidden_fields)); |
194 | } |
195 | } |
196 | |
197 | // If they haven't selected a forum for pruning yet then |
198 | // display a select box to use for pruning. |
199 | if (!count($forum_id)) |
200 | { |
201 | $template->assign_vars(array( |
202 | 'U_ACTION' => $this->u_action, |
203 | 'S_SELECT_FORUM' => true, |
204 | 'S_FORUM_OPTIONS' => make_forum_select(false, false, false)) |
205 | ); |
206 | } |
207 | else |
208 | { |
209 | $sql = 'SELECT forum_id, forum_name |
210 | FROM ' . FORUMS_TABLE . ' |
211 | WHERE ' . $db->sql_in_set('forum_id', $forum_id); |
212 | $result = $db->sql_query($sql); |
213 | $row = $db->sql_fetchrow($result); |
214 | |
215 | if (!$row) |
216 | { |
217 | $db->sql_freeresult($result); |
218 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action), E_USER_WARNING); |
219 | } |
220 | |
221 | $forum_list = $s_hidden_fields = ''; |
222 | do |
223 | { |
224 | $forum_list .= (($forum_list != '') ? ', ' : '') . '<b>' . $row['forum_name'] . '</b>'; |
225 | $s_hidden_fields .= '<input type="hidden" name="f[]" value="' . $row['forum_id'] . '" />'; |
226 | } |
227 | while ($row = $db->sql_fetchrow($result)); |
228 | |
229 | $db->sql_freeresult($result); |
230 | |
231 | $l_selected_forums = (count($forum_id) == 1) ? 'SELECTED_FORUM' : 'SELECTED_FORUMS'; |
232 | |
233 | $template_data = array( |
234 | 'L_SELECTED_FORUMS' => $user->lang[$l_selected_forums], |
235 | 'U_ACTION' => $this->u_action, |
236 | 'U_BACK' => $this->u_action, |
237 | 'FORUM_LIST' => $forum_list, |
238 | 'S_HIDDEN_FIELDS' => $s_hidden_fields, |
239 | ); |
240 | |
241 | /** |
242 | * Event to add/modify prune forums settings template data |
243 | * |
244 | * @event core.prune_forums_settings_template_data |
245 | * @var array template_data Array with form template data |
246 | * @since 3.2.2-RC1 |
247 | */ |
248 | $vars = array('template_data'); |
249 | extract($phpbb_dispatcher->trigger_event('core.prune_forums_settings_template_data', compact($vars))); |
250 | |
251 | $template->assign_vars($template_data); |
252 | } |
253 | } |
254 | |
255 | /** |
256 | * Prune users |
257 | */ |
258 | function prune_users($id, $mode) |
259 | { |
260 | global $db, $user, $auth, $template, $phpbb_log, $request; |
261 | global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; |
262 | |
263 | /** @var \phpbb\group\helper $group_helper */ |
264 | $group_helper = $phpbb_container->get('group_helper'); |
265 | |
266 | $user->add_lang('memberlist'); |
267 | |
268 | $prune = (isset($_POST['prune'])) ? true : false; |
269 | |
270 | if ($prune) |
271 | { |
272 | $action = $request->variable('action', 'deactivate'); |
273 | $deleteposts = $request->variable('deleteposts', 0); |
274 | |
275 | if (confirm_box(true)) |
276 | { |
277 | $user_ids = $usernames = array(); |
278 | |
279 | $this->get_prune_users($user_ids, $usernames); |
280 | if (count($user_ids)) |
281 | { |
282 | if ($action == 'deactivate') |
283 | { |
284 | user_active_flip('deactivate', $user_ids); |
285 | $l_log = 'LOG_PRUNE_USER_DEAC'; |
286 | } |
287 | else if ($action == 'delete') |
288 | { |
289 | if ($deleteposts) |
290 | { |
291 | user_delete('remove', $user_ids); |
292 | |
293 | $l_log = 'LOG_PRUNE_USER_DEL_DEL'; |
294 | } |
295 | else |
296 | { |
297 | user_delete('retain', $user_ids, true); |
298 | |
299 | $l_log = 'LOG_PRUNE_USER_DEL_ANON'; |
300 | } |
301 | } |
302 | |
303 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $l_log, false, array(implode(', ', $usernames))); |
304 | $msg = $user->lang['USER_' . strtoupper($action) . '_SUCCESS']; |
305 | } |
306 | else |
307 | { |
308 | $msg = $user->lang['USER_PRUNE_FAILURE']; |
309 | } |
310 | |
311 | trigger_error($msg . adm_back_link($this->u_action)); |
312 | } |
313 | else |
314 | { |
315 | // We list the users which will be pruned... |
316 | $user_ids = $usernames = array(); |
317 | $this->get_prune_users($user_ids, $usernames); |
318 | |
319 | if (!count($user_ids)) |
320 | { |
321 | trigger_error($user->lang['USER_PRUNE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING); |
322 | } |
323 | |
324 | // Assign to template |
325 | foreach ($user_ids as $user_id) |
326 | { |
327 | $template->assign_block_vars('users', array( |
328 | 'USERNAME' => $usernames[$user_id], |
329 | 'USER_ID' => $user_id, |
330 | 'U_PROFILE' => get_username_string('profile', $user_id, $usernames[$user_id]), |
331 | 'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview&u=' . $user_id) : '', |
332 | )); |
333 | } |
334 | |
335 | $template->assign_vars(array( |
336 | 'S_DEACTIVATE' => ($action == 'deactivate') ? true : false, |
337 | 'S_DELETE' => ($action == 'delete') ? true : false, |
338 | )); |
339 | |
340 | confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( |
341 | 'i' => $id, |
342 | 'mode' => $mode, |
343 | 'prune' => 1, |
344 | |
345 | 'deleteposts' => $request->variable('deleteposts', 0), |
346 | 'action' => $request->variable('action', ''), |
347 | )), 'confirm_body_prune.html'); |
348 | } |
349 | } |
350 | |
351 | $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']); |
352 | $s_find_count = ''; |
353 | |
354 | foreach ($find_count as $key => $value) |
355 | { |
356 | $selected = ($key == 'eq') ? ' selected="selected"' : ''; |
357 | $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; |
358 | } |
359 | |
360 | $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']); |
361 | $s_find_active_time = ''; |
362 | foreach ($find_time as $key => $value) |
363 | { |
364 | $s_find_active_time .= '<option value="' . $key . '">' . $value . '</option>'; |
365 | } |
366 | |
367 | $sql = 'SELECT group_id, group_name |
368 | FROM ' . GROUPS_TABLE . ' |
369 | WHERE group_type <> ' . GROUP_SPECIAL . ' |
370 | ORDER BY group_name ASC'; |
371 | $result = $db->sql_query($sql); |
372 | |
373 | $s_group_list = ''; |
374 | while ($row = $db->sql_fetchrow($result)) |
375 | { |
376 | $s_group_list .= '<option value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>'; |
377 | } |
378 | $db->sql_freeresult($result); |
379 | |
380 | if ($s_group_list) |
381 | { |
382 | // Only prepend the "All groups" option if there are groups, |
383 | // otherwise we don't want to display this option at all. |
384 | $s_group_list = '<option value="0">' . $user->lang['PRUNE_USERS_GROUP_NONE'] . '</option>' . $s_group_list; |
385 | } |
386 | |
387 | $template->assign_vars(array( |
388 | 'U_ACTION' => $this->u_action, |
389 | 'S_ACTIVE_OPTIONS' => $s_find_active_time, |
390 | 'S_GROUP_LIST' => $s_group_list, |
391 | 'S_COUNT_OPTIONS' => $s_find_count, |
392 | 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_prune&field=users'), |
393 | )); |
394 | } |
395 | |
396 | /** |
397 | * Get user_ids/usernames from those being pruned |
398 | */ |
399 | function get_prune_users(&$user_ids, &$usernames) |
400 | { |
401 | global $user, $db, $request; |
402 | |
403 | $users_by_name = $request->variable('users', '', true); |
404 | $users_by_id = $request->variable('user_ids', array(0)); |
405 | $group_id = $request->variable('group_id', 0); |
406 | $posts_on_queue = (trim($request->variable('posts_on_queue', '')) === '') ? false : $request->variable('posts_on_queue', 0); |
407 | |
408 | if ($users_by_name) |
409 | { |
410 | $users = explode("\n", $users_by_name); |
411 | $where_sql = ' AND ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', $users)); |
412 | } |
413 | else if (!empty($users_by_id)) |
414 | { |
415 | $user_ids = $users_by_id; |
416 | user_get_id_name($user_ids, $usernames); |
417 | |
418 | $where_sql = ' AND ' . $db->sql_in_set('user_id', $user_ids); |
419 | } |
420 | else |
421 | { |
422 | $username = $request->variable('username', '', true); |
423 | $email = $request->variable('email', ''); |
424 | |
425 | $active_select = $request->variable('active_select', 'lt'); |
426 | $count_select = $request->variable('count_select', 'eq'); |
427 | $queue_select = $request->variable('queue_select', 'gt'); |
428 | $joined_before = $request->variable('joined_before', ''); |
429 | $joined_after = $request->variable('joined_after', ''); |
430 | $active = $request->variable('active', ''); |
431 | |
432 | $count = ($request->variable('count', '') === '') ? false : $request->variable('count', 0); |
433 | |
434 | $active = ($active) ? explode('-', $active) : array(); |
435 | $joined_before = ($joined_before) ? explode('-', $joined_before) : array(); |
436 | $joined_after = ($joined_after) ? explode('-', $joined_after) : array(); |
437 | |
438 | // calculate the conditions required by the join time criteria |
439 | $joined_sql = ''; |
440 | if (!empty($joined_before) && !empty($joined_after)) |
441 | { |
442 | // if the two entered dates are equal, we need to adjust |
443 | // so that our time range is a full day instead of 1 second |
444 | if ($joined_after == $joined_before) |
445 | { |
446 | $joined_after[2] += 1; |
447 | } |
448 | |
449 | $joined_sql = ' AND user_regdate BETWEEN ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]) . |
450 | ' AND ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]); |
451 | } |
452 | else if (empty($joined_before) && !empty($joined_after)) |
453 | { |
454 | $joined_sql = ' AND user_regdate > ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]); |
455 | } |
456 | else if (empty($joined_after) && !empty($joined_before)) |
457 | { |
458 | $joined_sql = ' AND user_regdate < ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]); |
459 | } |
460 | // implicit else when both arrays are empty do nothing |
461 | |
462 | if ((count($active) && count($active) != 3) || (count($joined_before) && count($joined_before) != 3) || (count($joined_after) && count($joined_after) != 3)) |
463 | { |
464 | trigger_error($user->lang['WRONG_ACTIVE_JOINED_DATE'] . adm_back_link($this->u_action), E_USER_WARNING); |
465 | } |
466 | |
467 | $key_match = array('lt' => '<', 'gt' => '>', 'eq' => '='); |
468 | |
469 | $where_sql = ''; |
470 | $where_sql .= ($username) ? ' AND username_clean ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), utf8_clean_string($username))) : ''; |
471 | $where_sql .= ($email) ? ' AND user_email ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), $email)) . ' ' : ''; |
472 | $where_sql .= $joined_sql; |
473 | $where_sql .= ($count !== false) ? " AND user_posts " . $key_match[$count_select] . ' ' . (int) $count . ' ' : ''; |
474 | |
475 | // First handle pruning of users who never logged in, last active date is 0000-00-00 |
476 | if (count($active) && (int) $active[0] == 0 && (int) $active[1] == 0 && (int) $active[2] == 0) |
477 | { |
478 | $where_sql .= ' AND user_lastvisit = 0'; |
479 | } |
480 | else if (count($active) && $active_select != 'lt') |
481 | { |
482 | $where_sql .= ' AND user_lastvisit ' . $key_match[$active_select] . ' ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]); |
483 | } |
484 | else if (count($active)) |
485 | { |
486 | $where_sql .= ' AND (user_lastvisit > 0 AND user_lastvisit < ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]) . ')'; |
487 | } |
488 | } |
489 | |
490 | // If no search criteria were provided, go no further. |
491 | if (!$where_sql && !$group_id && $posts_on_queue === false) |
492 | { |
493 | return; |
494 | } |
495 | |
496 | // Get bot ids |
497 | $sql = 'SELECT user_id |
498 | FROM ' . BOTS_TABLE; |
499 | $result = $db->sql_query($sql); |
500 | |
501 | $bot_ids = array(); |
502 | while ($row = $db->sql_fetchrow($result)) |
503 | { |
504 | $bot_ids[] = $row['user_id']; |
505 | } |
506 | $db->sql_freeresult($result); |
507 | |
508 | // Protect the admin, do not prune if no options are given... |
509 | if ($where_sql) |
510 | { |
511 | // Do not prune founder members |
512 | $sql = 'SELECT user_id, username |
513 | FROM ' . USERS_TABLE . ' |
514 | WHERE user_id <> ' . ANONYMOUS . ' |
515 | AND user_type <> ' . USER_FOUNDER . " |
516 | $where_sql"; |
517 | $result = $db->sql_query($sql); |
518 | |
519 | $user_ids = $usernames = array(); |
520 | |
521 | while ($row = $db->sql_fetchrow($result)) |
522 | { |
523 | // Do not prune bots and the user currently pruning. |
524 | if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids)) |
525 | { |
526 | $user_ids[] = $row['user_id']; |
527 | $usernames[$row['user_id']] = $row['username']; |
528 | } |
529 | } |
530 | $db->sql_freeresult($result); |
531 | } |
532 | |
533 | if ($group_id) |
534 | { |
535 | $sql = 'SELECT u.user_id, u.username |
536 | FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u |
537 | WHERE ug.group_id = ' . (int) $group_id . ' |
538 | AND ug.user_id <> ' . ANONYMOUS . ' |
539 | AND u.user_type <> ' . USER_FOUNDER . ' |
540 | AND ug.user_pending = 0 |
541 | AND ug.group_leader = 0 |
542 | AND u.user_id = ug.user_id |
543 | ' . (!empty($user_ids) ? ' AND ' . $db->sql_in_set('ug.user_id', $user_ids) : ''); |
544 | $result = $db->sql_query($sql); |
545 | |
546 | // we're performing an intersection operation, so all the relevant users |
547 | // come from this most recent query (which was limited to the results of the |
548 | // previous query) |
549 | $user_ids = $usernames = array(); |
550 | while ($row = $db->sql_fetchrow($result)) |
551 | { |
552 | // Do not prune bots and the user currently pruning. |
553 | if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids)) |
554 | { |
555 | $user_ids[] = $row['user_id']; |
556 | $usernames[$row['user_id']] = $row['username']; |
557 | } |
558 | } |
559 | $db->sql_freeresult($result); |
560 | } |
561 | |
562 | if ($posts_on_queue !== false) |
563 | { |
564 | $sql = 'SELECT u.user_id, u.username, COUNT(p.post_id) AS queue_posts |
565 | FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u |
566 | WHERE u.user_id <> ' . ANONYMOUS . ' |
567 | AND u.user_type <> ' . USER_FOUNDER . ' |
568 | AND ' . $db->sql_in_set('p.post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)) . ' |
569 | AND u.user_id = p.poster_id |
570 | ' . (!empty($user_ids) ? ' AND ' . $db->sql_in_set('p.poster_id', $user_ids) : '') . ' |
571 | GROUP BY p.poster_id |
572 | HAVING queue_posts ' . $key_match[$queue_select] . ' ' . $posts_on_queue; |
573 | $result = $db->sql_query($sql); |
574 | |
575 | // same intersection logic as the above group ID portion |
576 | $user_ids = $usernames = array(); |
577 | while ($row = $db->sql_fetchrow($result)) |
578 | { |
579 | // Do not prune bots and the user currently pruning. |
580 | if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids)) |
581 | { |
582 | $user_ids[] = $row['user_id']; |
583 | $usernames[$row['user_id']] = $row['username']; |
584 | } |
585 | } |
586 | $db->sql_freeresult($result); |
587 | } |
588 | } |
589 | } |