[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package acp 5 * @version $Id: acp_prune.php,v 1.16 2006/10/20 13:47:28 acydburn Exp $ 6 * @copyright (c) 2005 phpBB Group 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 8 * 9 */ 10 11 /** 12 * @package acp 13 */ 14 class acp_prune 15 { 16 var $u_action; 17 18 function main($id, $mode) 19 { 20 global $user, $phpEx, $phpbb_admin_path, $phpbb_root_path; 21 22 $user->add_lang('acp/prune'); 23 include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx); 24 25 switch ($mode) 26 { 27 case 'forums': 28 $this->tpl_name = 'acp_prune_forums'; 29 $this->page_title = 'ACP_PRUNE_FORUMS'; 30 $this->prune_forums($id, $mode); 31 break; 32 33 case 'users': 34 $this->tpl_name = 'acp_prune_users'; 35 $this->page_title = 'ACP_PRUNE_USERS'; 36 $this->prune_users($id, $mode); 37 break; 38 } 39 } 40 41 /** 42 * Prune forums 43 */ 44 function prune_forums($id, $mode) 45 { 46 global $db, $user, $auth, $template, $cache; 47 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; 48 49 $forum_id = request_var('f', array(0)); 50 $submit = (isset($_POST['submit'])) ? true : false; 51 52 if ($submit) 53 { 54 $prune_posted = request_var('prune_days', 0); 55 $prune_viewed = request_var('prune_vieweddays', 0); 56 $prune_all = !$prune_posted && !$prune_viewed; 57 58 $prune_flags = 0; 59 $prune_flags += (request_var('prune_old_polls', 0)) ? 2 : 0; 60 $prune_flags += (request_var('prune_announce', 0)) ? 4 : 0; 61 $prune_flags += (request_var('prune_sticky', 0)) ? 8 : 0; 62 63 // Convert days to seconds for timestamp functions... 64 $prunedate_posted = time() - ($prune_posted * 86400); 65 $prunedate_viewed = time() - ($prune_viewed * 86400); 66 67 $template->assign_vars(array( 68 'S_PRUNED' => true) 69 ); 70 71 $sql_forum = (sizeof($forum_id)) ? ' AND ' . $db->sql_in_set('forum_id', $forum_id) : ''; 72 73 // Get a list of forum's or the data for the forum that we are pruning. 74 $sql = 'SELECT forum_id, forum_name 75 FROM ' . FORUMS_TABLE . ' 76 WHERE forum_type = ' . FORUM_POST . " 77 $sql_forum 78 ORDER BY left_id ASC"; 79 $result = $db->sql_query($sql); 80 81 if ($row = $db->sql_fetchrow($result)) 82 { 83 $prune_ids = array(); 84 $p_result['topics'] = 0; 85 $p_result['posts'] = 0; 86 $log_data = ''; 87 88 do 89 { 90 if (!$auth->acl_get('f_list', $row['forum_id'])) 91 { 92 continue; 93 } 94 95 if ($prune_all) 96 { 97 $p_result = prune($row['forum_id'], 'posted', time(), $prune_flags, false); 98 } 99 else 100 { 101 if ($prune_posted) 102 { 103 $return = prune($row['forum_id'], 'posted', $prunedate_posted, $prune_flags, false); 104 $p_result['topics'] += $return['topics']; 105 $p_result['posts'] += $return['posts']; 106 } 107 108 if ($prune_viewed) 109 { 110 $return = prune($row['forum_id'], 'viewed', $prunedate_viewed, $prune_flags, false); 111 $p_result['topics'] += $return['topics']; 112 $p_result['posts'] += $return['posts']; 113 } 114 } 115 116 $prune_ids[] = $row['forum_id']; 117 118 $template->assign_block_vars('pruned', array( 119 'FORUM_NAME' => $row['forum_name'], 120 'NUM_TOPICS' => $p_result['topics'], 121 'NUM_POSTS' => $p_result['posts']) 122 ); 123 124 $log_data .= (($log_data != '') ? ', ' : '') . $row['forum_name']; 125 } 126 while ($row = $db->sql_fetchrow($result)); 127 128 // Sync all pruned forums at once 129 sync('forum', 'forum_id', $prune_ids, true); 130 add_log('admin', 'LOG_PRUNE', $log_data); 131 } 132 $db->sql_freeresult($result); 133 134 return; 135 } 136 137 // If they haven't selected a forum for pruning yet then 138 // display a select box to use for pruning. 139 if (!sizeof($forum_id)) 140 { 141 $template->assign_vars(array( 142 'U_ACTION' => $this->u_action, 143 'S_SELECT_FORUM' => true, 144 'S_FORUM_OPTIONS' => make_forum_select(false, false, false)) 145 ); 146 } 147 else 148 { 149 $sql = 'SELECT forum_id, forum_name 150 FROM ' . FORUMS_TABLE . ' 151 WHERE ' . $db->sql_in_set('forum_id', $forum_id); 152 $result = $db->sql_query($sql); 153 $row = $db->sql_fetchrow($result); 154 155 if (!$row) 156 { 157 $db->sql_freeresult($result); 158 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action), E_USER_WARNING); 159 } 160 161 $forum_list = $s_hidden_fields = ''; 162 do 163 { 164 $forum_list .= (($forum_list != '') ? ', ' : '') . '<b>' . $row['forum_name'] . '</b>'; 165 $s_hidden_fields .= '<input type="hidden" name="f[]" value="' . $row['forum_id'] . '" />'; 166 } 167 while ($row = $db->sql_fetchrow($result)); 168 169 $db->sql_freeresult($result); 170 171 $l_selected_forums = (sizeof($forum_id) == 1) ? 'SELECTED_FORUM' : 'SELECTED_FORUMS'; 172 173 $template->assign_vars(array( 174 'L_SELECTED_FORUMS' => $user->lang[$l_selected_forums], 175 'U_ACTION' => $this->u_action, 176 'U_BACK' => $this->u_action, 177 'FORUM_LIST' => $forum_list, 178 'S_HIDDEN_FIELDS' => $s_hidden_fields) 179 ); 180 } 181 } 182 183 /** 184 * Prune users 185 */ 186 function prune_users($id, $mode) 187 { 188 global $db, $user, $auth, $template, $cache; 189 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; 190 191 $user->add_lang('memberlist'); 192 193 $prune = (isset($_POST['prune'])) ? true : false; 194 195 if ($prune) 196 { 197 if (confirm_box(true)) 198 { 199 $users = request_var('users', '', true); 200 $action = request_var('action', 'deactivate'); 201 $deleteposts = request_var('deleteposts', 0); 202 203 if ($users) 204 { 205 $users = explode("\n", $users); 206 $where_sql = ' AND ' . $db->sql_in_set('username_clean', array_map('utf8_clean_string', $users)); 207 } 208 else 209 { 210 $username = request_var('username', '', true); 211 $email = request_var('email', ''); 212 213 $joined_select = request_var('joined_select', 'lt'); 214 $active_select = request_var('active_select', 'lt'); 215 $count_select = request_var('count_select', 'eq'); 216 $joined = request_var('joined', ''); 217 $active = request_var('active', ''); 218 219 $active = ($active) ? explode('-', $active) : array(); 220 $joined = ($joined) ? explode('-', $joined) : array(); 221 222 $count = request_var('count', 0); 223 224 $key_match = array('lt' => '<', 'gt' => '>', 'eq' => '='); 225 $sort_by_types = array('username', 'user_email', 'user_posts', 'user_regdate', 'user_lastvisit'); 226 227 $where_sql = ''; 228 $where_sql .= ($username) ? " AND username_clean LIKE '" . $db->sql_escape(str_replace('*', '%', utf8_clean_string($username))) . "'" : ''; 229 $where_sql .= ($email) ? " AND user_email LIKE '" . $db->sql_escape(str_replace('*', '%', $email)) . "' " : ''; 230 $where_sql .= (sizeof($joined)) ? " AND user_regdate " . $key_match[$joined_select] . ' ' . gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]) : ''; 231 $where_sql .= ($count) ? " AND user_posts " . $key_match[$count_select] . " $count " : ''; 232 $where_sql .= (sizeof($active)) ? " AND user_lastvisit " . $key_match[$active_select] . " " . gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]) : ''; 233 } 234 235 // Get bot ids 236 $sql = 'SELECT user_id 237 FROM ' . BOTS_TABLE; 238 $result = $db->sql_query($sql); 239 240 $bot_ids = array(); 241 while ($row = $db->sql_fetchrow($result)) 242 { 243 $bot_ids[] = $row['user_id']; 244 } 245 $db->sql_freeresult($result); 246 247 // Do not prune founder members 248 $sql = 'SELECT user_id, username 249 FROM ' . USERS_TABLE . ' 250 WHERE user_id <> ' . ANONYMOUS . ' 251 AND user_type <> ' . USER_FOUNDER . " 252 $where_sql"; 253 $result = $db->sql_query($sql); 254 255 $where_sql = ''; 256 $user_ids = $usernames = array(); 257 258 while ($row = $db->sql_fetchrow($result)) 259 { 260 if (!in_array($row['user_id'], $bot_ids)) 261 { 262 $user_ids[] = $row['user_id']; 263 $usernames[$row['user_id']] = $row['username']; 264 } 265 } 266 $db->sql_freeresult($result); 267 268 if (sizeof($user_ids)) 269 { 270 if ($action == 'deactivate') 271 { 272 user_active_flip('deactivate', $user_ids); 273 $l_log = 'LOG_PRUNE_USER_DEAC'; 274 } 275 else if ($action == 'delete') 276 { 277 if ($deleteposts) 278 { 279 foreach ($user_ids as $user_id) 280 { 281 user_delete('remove', $user_id); 282 } 283 284 $l_log = 'LOG_PRUNE_USER_DEL_DEL'; 285 } 286 else 287 { 288 foreach ($user_ids as $user_id) 289 { 290 user_delete('retain', $user_id, $usernames[$user_id]); 291 } 292 293 $l_log = 'LOG_PRUNE_USER_DEL_ANON'; 294 } 295 } 296 297 add_log('admin', $l_log, implode(', ', $usernames)); 298 } 299 300 trigger_error($user->lang['USER_' . strtoupper($action) . '_SUCCESS'] . adm_back_link($this->u_action)); 301 } 302 else 303 { 304 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( 305 'i' => $id, 306 'mode' => $mode, 307 'prune' => 1, 308 309 'users' => request_var('users', ''), 310 'username' => request_var('username', '', true), 311 'email' => request_var('email', ''), 312 'joined_select' => request_var('joined_select', ''), 313 'joined' => request_var('joined', ''), 314 'active_select' => request_var('active_select', ''), 315 'active' => request_var('active', ''), 316 'count_select' => request_var('count_select', ''), 317 'count' => request_var('count', 0), 318 'deleteposts' => request_var('deleteposts', 0), 319 320 'action' => request_var('action', ''), 321 ))); 322 } 323 } 324 325 $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']); 326 $s_find_count = ''; 327 328 foreach ($find_count as $key => $value) 329 { 330 $selected = ($key == 'eq') ? ' selected="selected"' : ''; 331 $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; 332 } 333 334 $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']); 335 $s_find_join_time = ''; 336 foreach ($find_time as $key => $value) 337 { 338 $s_find_join_time .= '<option value="' . $key . '">' . $value . '</option>'; 339 } 340 341 $s_find_active_time = ''; 342 foreach ($find_time as $key => $value) 343 { 344 $s_find_active_time .= '<option value="' . $key . '">' . $value . '</option>'; 345 } 346 347 $template->assign_vars(array( 348 'U_ACTION' => $this->u_action, 349 'S_JOINED_OPTIONS' => $s_find_join_time, 350 'S_ACTIVE_OPTIONS' => $s_find_active_time, 351 'S_COUNT_OPTIONS' => $s_find_count, 352 'U_FIND_USER' => append_sid($phpbb_root_path . "memberlist.$phpEx", 'mode=searchuser&form=acp_prune&field=users')) 353 ); 354 } 355 } 356 357 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |