Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
acp_prune.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 /**
015 * @ignore
016 */
017 if (!defined('IN_PHPBB'))
018 {
019 exit;
020 }
021
022 class acp_prune
023 {
024 var $u_action;
025
026 function main($id, $mode)
027 {
028 global $user, $phpEx, $phpbb_root_path;
029
030 $user->add_lang('acp/prune');
031
032 if (!function_exists('user_active_flip'))
033 {
034 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
035 }
036
037 switch ($mode)
038 {
039 case 'forums':
040 $this->tpl_name = 'acp_prune_forums';
041 $this->page_title = 'ACP_PRUNE_FORUMS';
042 $this->prune_forums($id, $mode);
043 break;
044
045 case 'users':
046 $this->tpl_name = 'acp_prune_users';
047 $this->page_title = 'ACP_PRUNE_USERS';
048 $this->prune_users($id, $mode);
049 break;
050 }
051 }
052
053 /**
054 * Prune forums
055 */
056 function prune_forums($id, $mode)
057 {
058 global $db, $user, $auth, $template, $phpbb_log, $request;
059
060 $all_forums = $request->variable('all_forums', 0);
061 $forum_id = $request->variable('f', array(0));
062 $submit = (isset($_POST['submit'])) ? true : false;
063
064 if ($all_forums)
065 {
066 $sql = 'SELECT forum_id
067 FROM ' . FORUMS_TABLE . '
068 ORDER BY left_id';
069 $result = $db->sql_query($sql);
070
071 $forum_id = array();
072 while ($row = $db->sql_fetchrow($result))
073 {
074 $forum_id[] = $row['forum_id'];
075 }
076 $db->sql_freeresult($result);
077 }
078
079 if ($submit)
080 {
081 if (confirm_box(true))
082 {
083 $prune_posted = $request->variable('prune_days', 0);
084 $prune_viewed = $request->variable('prune_vieweddays', 0);
085 $prune_all = (!$prune_posted && !$prune_viewed) ? true : false;
086
087 $prune_flags = 0;
088 $prune_flags += ($request->variable('prune_old_polls', 0)) ? 2 : 0;
089 $prune_flags += ($request->variable('prune_announce', 0)) ? 4 : 0;
090 $prune_flags += ($request->variable('prune_sticky', 0)) ? 8 : 0;
091
092 // Convert days to seconds for timestamp functions...
093 $prunedate_posted = time() - ($prune_posted * 86400);
094 $prunedate_viewed = time() - ($prune_viewed * 86400);
095
096 $template->assign_vars(array(
097 'S_PRUNED' => true)
098 );
099
100 $sql_forum = (sizeof($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['topics'] = 0;
114 $p_result['posts'] = 0;
115 $log_data = '';
116
117 do
118 {
119 if (!$auth->acl_get('f_list', $row['forum_id']))
120 {
121 continue;
122 }
123
124 if ($prune_all)
125 {
126 $p_result = prune($row['forum_id'], 'posted', time(), $prune_flags, false);
127 }
128 else
129 {
130 if ($prune_posted)
131 {
132 $return = prune($row['forum_id'], 'posted', $prunedate_posted, $prune_flags, false);
133 $p_result['topics'] += $return['topics'];
134 $p_result['posts'] += $return['posts'];
135 }
136
137 if ($prune_viewed)
138 {
139 $return = prune($row['forum_id'], 'viewed', $prunedate_viewed, $prune_flags, false);
140 $p_result['topics'] += $return['topics'];
141 $p_result['posts'] += $return['posts'];
142 }
143 }
144
145 $prune_ids[] = $row['forum_id'];
146
147 $template->assign_block_vars('pruned', array(
148 'FORUM_NAME' => $row['forum_name'],
149 'NUM_TOPICS' => $p_result['topics'],
150 'NUM_POSTS' => $p_result['posts'])
151 );
152
153 $log_data .= (($log_data != '') ? ', ' : '') . $row['forum_name'];
154 }
155 while ($row = $db->sql_fetchrow($result));
156
157 // Sync all pruned forums at once
158 sync('forum', 'forum_id', $prune_ids, true, true);
159
160 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PRUNE', false, array($log_data));
161 }
162 $db->sql_freeresult($result);
163
164 return;
165 }
166 else
167 {
168 confirm_box(false, $user->lang['PRUNE_FORUM_CONFIRM'], build_hidden_fields(array(
169 'i' => $id,
170 'mode' => $mode,
171 'submit' => 1,
172 'all_forums' => $all_forums,
173 'f' => $forum_id,
174
175 'prune_days' => $request->variable('prune_days', 0),
176 'prune_vieweddays' => $request->variable('prune_vieweddays', 0),
177 'prune_old_polls' => $request->variable('prune_old_polls', 0),
178 'prune_announce' => $request->variable('prune_announce', 0),
179 'prune_sticky' => $request->variable('prune_sticky', 0),
180 )));
181 }
182 }
183
184 // If they haven't selected a forum for pruning yet then
185 // display a select box to use for pruning.
186 if (!sizeof($forum_id))
187 {
188 $template->assign_vars(array(
189 'U_ACTION' => $this->u_action,
190 'S_SELECT_FORUM' => true,
191 'S_FORUM_OPTIONS' => make_forum_select(false, false, false))
192 );
193 }
194 else
195 {
196 $sql = 'SELECT forum_id, forum_name
197 FROM ' . FORUMS_TABLE . '
198 WHERE ' . $db->sql_in_set('forum_id', $forum_id);
199 $result = $db->sql_query($sql);
200 $row = $db->sql_fetchrow($result);
201
202 if (!$row)
203 {
204 $db->sql_freeresult($result);
205 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action), E_USER_WARNING);
206 }
207
208 $forum_list = $s_hidden_fields = '';
209 do
210 {
211 $forum_list .= (($forum_list != '') ? ', ' : '') . '<b>' . $row['forum_name'] . '</b>';
212 $s_hidden_fields .= '<input type="hidden" name="f[]" value="' . $row['forum_id'] . '" />';
213 }
214 while ($row = $db->sql_fetchrow($result));
215
216 $db->sql_freeresult($result);
217
218 $l_selected_forums = (sizeof($forum_id) == 1) ? 'SELECTED_FORUM' : 'SELECTED_FORUMS';
219
220 $template->assign_vars(array(
221 'L_SELECTED_FORUMS' => $user->lang[$l_selected_forums],
222 'U_ACTION' => $this->u_action,
223 'U_BACK' => $this->u_action,
224 'FORUM_LIST' => $forum_list,
225 'S_HIDDEN_FIELDS' => $s_hidden_fields)
226 );
227 }
228 }
229
230 /**
231 * Prune users
232 */
233 function prune_users($id, $mode)
234 {
235 global $db, $user, $auth, $template, $phpbb_log, $request;
236 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
237
238 /** @var \phpbb\group\helper $group_helper */
239 $group_helper = $phpbb_container->get('group_helper');
240
241 $user->add_lang('memberlist');
242
243 $prune = (isset($_POST['prune'])) ? true : false;
244
245 if ($prune)
246 {
247 $action = $request->variable('action', 'deactivate');
248 $deleteposts = $request->variable('deleteposts', 0);
249
250 if (confirm_box(true))
251 {
252 $user_ids = $usernames = array();
253
254 $this->get_prune_users($user_ids, $usernames);
255 if (sizeof($user_ids))
256 {
257 if ($action == 'deactivate')
258 {
259 user_active_flip('deactivate', $user_ids);
260 $l_log = 'LOG_PRUNE_USER_DEAC';
261 }
262 else if ($action == 'delete')
263 {
264 if ($deleteposts)
265 {
266 user_delete('remove', $user_ids);
267
268 $l_log = 'LOG_PRUNE_USER_DEL_DEL';
269 }
270 else
271 {
272 user_delete('retain', $user_ids, true);
273
274 $l_log = 'LOG_PRUNE_USER_DEL_ANON';
275 }
276 }
277
278 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $l_log, false, array(implode(', ', $usernames)));
279 $msg = $user->lang['USER_' . strtoupper($action) . '_SUCCESS'];
280 }
281 else
282 {
283 $msg = $user->lang['USER_PRUNE_FAILURE'];
284 }
285
286 trigger_error($msg . adm_back_link($this->u_action));
287 }
288 else
289 {
290 // We list the users which will be pruned...
291 $user_ids = $usernames = array();
292 $this->get_prune_users($user_ids, $usernames);
293
294 if (!sizeof($user_ids))
295 {
296 trigger_error($user->lang['USER_PRUNE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING);
297 }
298
299 // Assign to template
300 foreach ($user_ids as $user_id)
301 {
302 $template->assign_block_vars('users', array(
303 'USERNAME' => $usernames[$user_id],
304 'USER_ID' => $user_id,
305 'U_PROFILE' => get_username_string('profile', $user_id, $usernames[$user_id]),
306 'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview&u=' . $user_id, true, $user->session_id) : '',
307 ));
308 }
309
310 $template->assign_vars(array(
311 'S_DEACTIVATE' => ($action == 'deactivate') ? true : false,
312 'S_DELETE' => ($action == 'delete') ? true : false,
313 ));
314
315 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
316 'i' => $id,
317 'mode' => $mode,
318 'prune' => 1,
319
320 'deleteposts' => $request->variable('deleteposts', 0),
321 'action' => $request->variable('action', ''),
322 )), 'confirm_body_prune.html');
323 }
324 }
325
326 $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
327 $s_find_count = '';
328
329 foreach ($find_count as $key => $value)
330 {
331 $selected = ($key == 'eq') ? ' selected="selected"' : '';
332 $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
333 }
334
335 $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
336 $s_find_active_time = '';
337 foreach ($find_time as $key => $value)
338 {
339 $s_find_active_time .= '<option value="' . $key . '">' . $value . '</option>';
340 }
341
342 $sql = 'SELECT group_id, group_name
343 FROM ' . GROUPS_TABLE . '
344 WHERE group_type <> ' . GROUP_SPECIAL . '
345 ORDER BY group_name ASC';
346 $result = $db->sql_query($sql);
347
348 $s_group_list = '';
349 while ($row = $db->sql_fetchrow($result))
350 {
351 $s_group_list .= '<option value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>';
352 }
353 $db->sql_freeresult($result);
354
355 if ($s_group_list)
356 {
357 // Only prepend the "All groups" option if there are groups,
358 // otherwise we don't want to display this option at all.
359 $s_group_list = '<option value="0">' . $user->lang['PRUNE_USERS_GROUP_NONE'] . '</option>' . $s_group_list;
360 }
361
362 $template->assign_vars(array(
363 'U_ACTION' => $this->u_action,
364 'S_ACTIVE_OPTIONS' => $s_find_active_time,
365 'S_GROUP_LIST' => $s_group_list,
366 'S_COUNT_OPTIONS' => $s_find_count,
367 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_prune&field=users'),
368 ));
369 }
370
371 /**
372 * Get user_ids/usernames from those being pruned
373 */
374 function get_prune_users(&$user_ids, &$usernames)
375 {
376 global $user, $db, $request;
377
378 $users_by_name = $request->variable('users', '', true);
379 $users_by_id = $request->variable('user_ids', array(0));
380 $group_id = $request->variable('group_id', 0);
381 $posts_on_queue = (trim($request->variable('posts_on_queue', '')) === '') ? false : $request->variable('posts_on_queue', 0);
382
383 if ($users_by_name)
384 {
385 $users = explode("\n", $users_by_name);
386 $where_sql = ' AND ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', $users));
387 }
388 else if (!empty($users_by_id))
389 {
390 $user_ids = $users_by_id;
391 user_get_id_name($user_ids, $usernames);
392
393 $where_sql = ' AND ' . $db->sql_in_set('user_id', $user_ids);
394 }
395 else
396 {
397 $username = $request->variable('username', '', true);
398 $email = $request->variable('email', '');
399
400 $active_select = $request->variable('active_select', 'lt');
401 $count_select = $request->variable('count_select', 'eq');
402 $queue_select = $request->variable('queue_select', 'gt');
403 $joined_before = $request->variable('joined_before', '');
404 $joined_after = $request->variable('joined_after', '');
405 $active = $request->variable('active', '');
406
407 $count = ($request->variable('count', '') === '') ? false : $request->variable('count', 0);
408
409 $active = ($active) ? explode('-', $active) : array();
410 $joined_before = ($joined_before) ? explode('-', $joined_before) : array();
411 $joined_after = ($joined_after) ? explode('-', $joined_after) : array();
412
413 // calculate the conditions required by the join time criteria
414 $joined_sql = '';
415 if (!empty($joined_before) && !empty($joined_after))
416 {
417 // if the two entered dates are equal, we need to adjust
418 // so that our time range is a full day instead of 1 second
419 if ($joined_after == $joined_before)
420 {
421 $joined_after[2] += 1;
422 }
423
424 $joined_sql = ' AND user_regdate BETWEEN ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]) .
425 ' AND ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]);
426 }
427 else if (empty($joined_before) && !empty($joined_after))
428 {
429 $joined_sql = ' AND user_regdate > ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]);
430 }
431 else if (empty($joined_after) && !empty($joined_before))
432 {
433 $joined_sql = ' AND user_regdate < ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]);
434 }
435 // implicit else when both arrays are empty do nothing
436
437 if ((sizeof($active) && sizeof($active) != 3) || (sizeof($joined_before) && sizeof($joined_before) != 3) || (sizeof($joined_after) && sizeof($joined_after) != 3))
438 {
439 trigger_error($user->lang['WRONG_ACTIVE_JOINED_DATE'] . adm_back_link($this->u_action), E_USER_WARNING);
440 }
441
442 $key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
443
444 $where_sql = '';
445 $where_sql .= ($username) ? ' AND username_clean ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), utf8_clean_string($username))) : '';
446 $where_sql .= ($email) ? ' AND user_email ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), $email)) . ' ' : '';
447 $where_sql .= $joined_sql;
448 $where_sql .= ($count !== false) ? " AND user_posts " . $key_match[$count_select] . ' ' . (int) $count . ' ' : '';
449
450 // First handle pruning of users who never logged in, last active date is 0000-00-00
451 if (sizeof($active) && (int) $active[0] == 0 && (int) $active[1] == 0 && (int) $active[2] == 0)
452 {
453 $where_sql .= ' AND user_lastvisit = 0';
454 }
455 else if (sizeof($active) && $active_select != 'lt')
456 {
457 $where_sql .= ' AND user_lastvisit ' . $key_match[$active_select] . ' ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
458 }
459 else if (sizeof($active))
460 {
461 $where_sql .= ' AND (user_lastvisit > 0 AND user_lastvisit < ' . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]) . ')';
462 }
463 }
464
465 // If no search criteria were provided, go no further.
466 if (!$where_sql && !$group_id && $posts_on_queue === false)
467 {
468 return;
469 }
470
471 // Get bot ids
472 $sql = 'SELECT user_id
473 FROM ' . BOTS_TABLE;
474 $result = $db->sql_query($sql);
475
476 $bot_ids = array();
477 while ($row = $db->sql_fetchrow($result))
478 {
479 $bot_ids[] = $row['user_id'];
480 }
481 $db->sql_freeresult($result);
482
483 // Protect the admin, do not prune if no options are given...
484 if ($where_sql)
485 {
486 // Do not prune founder members
487 $sql = 'SELECT user_id, username
488 FROM ' . USERS_TABLE . '
489 WHERE user_id <> ' . ANONYMOUS . '
490 AND user_type <> ' . USER_FOUNDER . "
491 $where_sql";
492 $result = $db->sql_query($sql);
493
494 $user_ids = $usernames = array();
495
496 while ($row = $db->sql_fetchrow($result))
497 {
498 // Do not prune bots and the user currently pruning.
499 if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
500 {
501 $user_ids[] = $row['user_id'];
502 $usernames[$row['user_id']] = $row['username'];
503 }
504 }
505 $db->sql_freeresult($result);
506 }
507
508 if ($group_id)
509 {
510 $sql = 'SELECT u.user_id, u.username
511 FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
512 WHERE ug.group_id = ' . (int) $group_id . '
513 AND ug.user_id <> ' . ANONYMOUS . '
514 AND u.user_type <> ' . USER_FOUNDER . '
515 AND ug.user_pending = 0
516 AND u.user_id = ug.user_id
517 ' . (!empty($user_ids) ? ' AND ' . $db->sql_in_set('ug.user_id', $user_ids) : '');
518 $result = $db->sql_query($sql);
519
520 // we're performing an intersection operation, so all the relevant users
521 // come from this most recent query (which was limited to the results of the
522 // previous query)
523 $user_ids = $usernames = array();
524 while ($row = $db->sql_fetchrow($result))
525 {
526 // Do not prune bots and the user currently pruning.
527 if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
528 {
529 $user_ids[] = $row['user_id'];
530 $usernames[$row['user_id']] = $row['username'];
531 }
532 }
533 $db->sql_freeresult($result);
534 }
535
536 if ($posts_on_queue !== false)
537 {
538 $sql = 'SELECT u.user_id, u.username, COUNT(p.post_id) AS queue_posts
539 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
540 WHERE u.user_id <> ' . ANONYMOUS . '
541 AND u.user_type <> ' . USER_FOUNDER . '
542 AND ' . $db->sql_in_set('p.post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)) . '
543 AND u.user_id = p.poster_id
544 ' . (!empty($user_ids) ? ' AND ' . $db->sql_in_set('p.poster_id', $user_ids) : '') . '
545 GROUP BY p.poster_id
546 HAVING queue_posts ' . $key_match[$queue_select] . ' ' . $posts_on_queue;
547 $result = $db->sql_query($sql);
548
549 // same intersection logic as the above group ID portion
550 $user_ids = $usernames = array();
551 while ($row = $db->sql_fetchrow($result))
552 {
553 // Do not prune bots and the user currently pruning.
554 if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
555 {
556 $user_ids[] = $row['user_id'];
557 $usernames[$row['user_id']] = $row['username'];
558 }
559 }
560 $db->sql_freeresult($result);
561 }
562 }
563 }
564