5
* @version $Id: acp_prune.php,v 1.29 2007/10/05 14:36:32 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
26
function main($id, $mode)
28
global $user, $phpEx, $phpbb_admin_path, $phpbb_root_path;
30
$user->add_lang('acp/prune');
31
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
36
$this->tpl_name = 'acp_prune_forums';
37
$this->page_title = 'ACP_PRUNE_FORUMS';
38
$this->prune_forums($id, $mode);
42
$this->tpl_name = 'acp_prune_users';
43
$this->page_title = 'ACP_PRUNE_USERS';
44
$this->prune_users($id, $mode);
52
function prune_forums($id, $mode)
54
global $db, $user, $auth, $template, $cache;
55
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
57
$all_forums = request_var('all_forums', 0);
58
$forum_id = request_var('f', array(0));
59
$submit = (isset($_POST['submit'])) ? true : false;
63
$sql = 'SELECT forum_id
64
FROM ' . FORUMS_TABLE . '
66
$result = $db->sql_query($sql);
69
while ($row = $db->sql_fetchrow($result))
71
$forum_id[] = $row['forum_id'];
73
$db->sql_freeresult($result);
78
if (confirm_box(true))
80
$prune_posted = request_var('prune_days', 0);
81
$prune_viewed = request_var('prune_vieweddays', 0);
82
$prune_all = (!$prune_posted && !$prune_viewed) ? true : false;
85
$prune_flags += (request_var('prune_old_polls', 0)) ? 2 : 0;
86
$prune_flags += (request_var('prune_announce', 0)) ? 4 : 0;
87
$prune_flags += (request_var('prune_sticky', 0)) ? 8 : 0;
89
// Convert days to seconds for timestamp functions...
90
$prunedate_posted = time() - ($prune_posted * 86400);
91
$prunedate_viewed = time() - ($prune_viewed * 86400);
93
$template->assign_vars(array(
97
$sql_forum = (sizeof($forum_id)) ? ' AND ' . $db->sql_in_set('forum_id', $forum_id) : '';
99
// Get a list of forum's or the data for the forum that we are pruning.
100
$sql = 'SELECT forum_id, forum_name
101
FROM ' . FORUMS_TABLE . '
102
WHERE forum_type = ' . FORUM_POST . "
104
ORDER BY left_id ASC";
105
$result = $db->sql_query($sql);
107
if ($row = $db->sql_fetchrow($result))
109
$prune_ids = array();
110
$p_result['topics'] = 0;
111
$p_result['posts'] = 0;
116
if (!$auth->acl_get('f_list', $row['forum_id']))
123
$p_result = prune($row['forum_id'], 'posted', time(), $prune_flags, false);
129
$return = prune($row['forum_id'], 'posted', $prunedate_posted, $prune_flags, false);
130
$p_result['topics'] += $return['topics'];
131
$p_result['posts'] += $return['posts'];
136
$return = prune($row['forum_id'], 'viewed', $prunedate_viewed, $prune_flags, false);
137
$p_result['topics'] += $return['topics'];
138
$p_result['posts'] += $return['posts'];
142
$prune_ids[] = $row['forum_id'];
144
$template->assign_block_vars('pruned', array(
145
'FORUM_NAME' => $row['forum_name'],
146
'NUM_TOPICS' => $p_result['topics'],
147
'NUM_POSTS' => $p_result['posts'])
150
$log_data .= (($log_data != '') ? ', ' : '') . $row['forum_name'];
152
while ($row = $db->sql_fetchrow($result));
154
// Sync all pruned forums at once
155
sync('forum', 'forum_id', $prune_ids, true, true);
156
add_log('admin', 'LOG_PRUNE', $log_data);
158
$db->sql_freeresult($result);
164
confirm_box(false, $user->lang['PRUNE_FORUM_CONFIRM'], build_hidden_fields(array(
168
'all_forums' => $all_forums,
171
'prune_days' => request_var('prune_days', 0),
172
'prune_vieweddays' => request_var('prune_vieweddays', 0),
173
'prune_old_polls' => request_var('prune_old_polls', 0),
174
'prune_announce' => request_var('prune_announce', 0),
175
'prune_sticky' => request_var('prune_sticky', 0),
180
// If they haven't selected a forum for pruning yet then
181
// display a select box to use for pruning.
182
if (!sizeof($forum_id))
184
$template->assign_vars(array(
185
'U_ACTION' => $this->u_action,
186
'S_SELECT_FORUM' => true,
187
'S_FORUM_OPTIONS' => make_forum_select(false, false, false))
192
$sql = 'SELECT forum_id, forum_name
193
FROM ' . FORUMS_TABLE . '
194
WHERE ' . $db->sql_in_set('forum_id', $forum_id);
195
$result = $db->sql_query($sql);
196
$row = $db->sql_fetchrow($result);
200
$db->sql_freeresult($result);
201
trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action), E_USER_WARNING);
204
$forum_list = $s_hidden_fields = '';
207
$forum_list .= (($forum_list != '') ? ', ' : '') . '<b>' . $row['forum_name'] . '</b>';
208
$s_hidden_fields .= '<input type="hidden" name="f[]" value="' . $row['forum_id'] . '" />';
210
while ($row = $db->sql_fetchrow($result));
212
$db->sql_freeresult($result);
214
$l_selected_forums = (sizeof($forum_id) == 1) ? 'SELECTED_FORUM' : 'SELECTED_FORUMS';
216
$template->assign_vars(array(
217
'L_SELECTED_FORUMS' => $user->lang[$l_selected_forums],
218
'U_ACTION' => $this->u_action,
219
'U_BACK' => $this->u_action,
220
'FORUM_LIST' => $forum_list,
221
'S_HIDDEN_FIELDS' => $s_hidden_fields)
229
function prune_users($id, $mode)
231
global $db, $user, $auth, $template, $cache;
232
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
234
$user->add_lang('memberlist');
236
$prune = (isset($_POST['prune'])) ? true : false;
240
$action = request_var('action', 'deactivate');
241
$deleteposts = request_var('deleteposts', 0);
243
if (confirm_box(true))
245
$user_ids = $usernames = array();
246
$this->get_prune_users($user_ids, $usernames);
248
if (sizeof($user_ids))
250
if ($action == 'deactivate')
252
user_active_flip('deactivate', $user_ids);
253
$l_log = 'LOG_PRUNE_USER_DEAC';
255
else if ($action == 'delete')
259
foreach ($user_ids as $user_id)
261
user_delete('remove', $user_id);
264
$l_log = 'LOG_PRUNE_USER_DEL_DEL';
268
foreach ($user_ids as $user_id)
270
user_delete('retain', $user_id, $usernames[$user_id]);
273
$l_log = 'LOG_PRUNE_USER_DEL_ANON';
277
add_log('admin', $l_log, implode(', ', $usernames));
278
$msg = $user->lang['USER_' . strtoupper($action) . '_SUCCESS'];
282
$msg = $user->lang['USER_PRUNE_FAILURE'];
285
trigger_error($msg . adm_back_link($this->u_action));
289
// We list the users which will be pruned...
290
$user_ids = $usernames = array();
291
$this->get_prune_users($user_ids, $usernames);
293
if (!sizeof($user_ids))
295
trigger_error($user->lang['USER_PRUNE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING);
298
// Assign to template
299
foreach ($user_ids as $user_id)
301
$template->assign_block_vars('users', array(
302
'USERNAME' => $usernames[$user_id],
303
'U_PROFILE' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx, 'mode=viewprofile&u=' . $user_id),
304
'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) : '',
308
$template->assign_vars(array(
309
'S_DEACTIVATE' => ($action == 'deactivate') ? true : false,
310
'S_DELETE' => ($action == 'delete') ? true : false,
313
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
318
'users' => request_var('users', '', true),
319
'username' => request_var('username', '', true),
320
'email' => request_var('email', ''),
321
'joined_select' => request_var('joined_select', ''),
322
'joined' => request_var('joined', ''),
323
'active_select' => request_var('active_select', ''),
324
'active' => request_var('active', ''),
325
'count_select' => request_var('count_select', ''),
326
'count' => request_var('count', ''),
327
'deleteposts' => request_var('deleteposts', 0),
329
'action' => request_var('action', ''),
330
)), 'confirm_body_prune.html');
334
$find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
337
foreach ($find_count as $key => $value)
339
$selected = ($key == 'eq') ? ' selected="selected"' : '';
340
$s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
343
$find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
344
$s_find_join_time = '';
345
foreach ($find_time as $key => $value)
347
$s_find_join_time .= '<option value="' . $key . '">' . $value . '</option>';
350
$s_find_active_time = '';
351
foreach ($find_time as $key => $value)
353
$s_find_active_time .= '<option value="' . $key . '">' . $value . '</option>';
356
$template->assign_vars(array(
357
'U_ACTION' => $this->u_action,
358
'S_JOINED_OPTIONS' => $s_find_join_time,
359
'S_ACTIVE_OPTIONS' => $s_find_active_time,
360
'S_COUNT_OPTIONS' => $s_find_count,
361
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_prune&field=users'),
366
* Get user_ids/usernames from those being pruned
368
function get_prune_users(&$user_ids, &$usernames)
372
$users = request_var('users', '', true);
376
$users = explode("\n", $users);
377
$where_sql = ' AND ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', $users));
381
$username = request_var('username', '', true);
382
$email = request_var('email', '');
384
$joined_select = request_var('joined_select', 'lt');
385
$active_select = request_var('active_select', 'lt');
386
$count_select = request_var('count_select', 'eq');
387
$joined = request_var('joined', '');
388
$active = request_var('active', '');
390
$active = ($active) ? explode('-', $active) : array();
391
$joined = ($joined) ? explode('-', $joined) : array();
393
if ((sizeof($active) && sizeof($active) != 3) || (sizeof($joined) && sizeof($joined) != 3))
395
trigger_error($user->lang['WRONG_ACTIVE_JOINED_DATE'] . adm_back_link($this->u_action), E_USER_WARNING);
398
$count = request_var('count', '');
400
$key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
401
$sort_by_types = array('username', 'user_email', 'user_posts', 'user_regdate', 'user_lastvisit');
404
$where_sql .= ($username) ? ' AND username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
405
$where_sql .= ($email) ? ' AND user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
406
$where_sql .= (sizeof($joined)) ? " AND user_regdate " . $key_match[$joined_select] . ' ' . gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]) : '';
407
$where_sql .= ($count !== '') ? " AND user_posts " . $key_match[$count_select] . ' ' . (int) $count . ' ' : '';
408
$where_sql .= (sizeof($active)) ? " AND user_lastvisit " . $key_match[$active_select] . " " . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]) : '';
411
// Protect the admin, do not prune if no options are given...
418
$sql = 'SELECT user_id
420
$result = $db->sql_query($sql);
423
while ($row = $db->sql_fetchrow($result))
425
$bot_ids[] = $row['user_id'];
427
$db->sql_freeresult($result);
429
// Do not prune founder members
430
$sql = 'SELECT user_id, username
431
FROM ' . USERS_TABLE . '
432
WHERE user_id <> ' . ANONYMOUS . '
433
AND user_type <> ' . USER_FOUNDER . "
435
$result = $db->sql_query($sql);
438
$user_ids = $usernames = array();
440
while ($row = $db->sql_fetchrow($result))
442
// Do not prune bots and the user currently pruning.
443
if ($row['user_id'] != $user->data['user_id'] && !in_array($row['user_id'], $bot_ids))
445
$user_ids[] = $row['user_id'];
446
$usernames[$row['user_id']] = $row['username'];
449
$db->sql_freeresult($result);
b'\\ No newline at end of file'