function sync($type, $id) { switch ($type) { case 'forum': if (!($forum_csv = get_id_csv($id))) { break; } // sync posts $tmp_sync_forums = 'tmp_sync_forums'; DB()->query("\n\t\t\t\tCREATE TEMPORARY TABLE {$tmp_sync_forums} (\n\t\t\t\t\tforum_id SMALLINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\tforum_last_post_id INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\tforum_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\tforum_topics MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\tPRIMARY KEY (forum_id)\n\t\t\t\t) ENGINE = MEMORY\n\t\t\t"); DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS {$tmp_sync_forums}"); // начальное обнуление значений $forum_ary = explode(',', $forum_csv); DB()->query("REPLACE INTO {$tmp_sync_forums} (forum_id) VALUES(" . join('),(', $forum_ary) . ")"); DB()->query("\n\t\t\t\tREPLACE INTO {$tmp_sync_forums}\n\t\t\t\t\t(forum_id, forum_last_post_id, forum_posts, forum_topics)\n\t\t\t\tSELECT\n\t\t\t\t\tforum_id,\n\t\t\t\t\tMAX(topic_last_post_id),\n\t\t\t\t\tSUM(topic_replies) + COUNT(topic_id),\n\t\t\t\t\tCOUNT(topic_id)\n\t\t\t\tFROM " . BB_TOPICS . "\n\t\t\t\tWHERE forum_id IN({$forum_csv})\n\t\t\t\tGROUP BY forum_id\n\t\t\t"); DB()->query("\n\t\t\t\tUPDATE\n\t\t\t\t\t{$tmp_sync_forums} tmp, " . BB_FORUMS . " f\n\t\t\t\tSET\n\t\t\t\t\tf.forum_last_post_id = tmp.forum_last_post_id,\n\t\t\t\t\tf.forum_posts = tmp.forum_posts,\n\t\t\t\t\tf.forum_topics = tmp.forum_topics\n\t\t\t\tWHERE\n\t\t\t\t\tf.forum_id = tmp.forum_id\n\t\t\t"); DB()->query("DROP TEMPORARY TABLE {$tmp_sync_forums}"); break; case 'topic': $all_topics = $id === 'all'; if (!$all_topics and !($topic_csv = get_id_csv($id))) { break; } // Проверка на остаточные записи об уже удаленных топиках DB()->query("DELETE FROM " . BB_TOPICS . " WHERE topic_first_post_id NOT IN (SELECT post_id FROM " . BB_POSTS . ")"); $tmp_sync_topics = 'tmp_sync_topics'; DB()->query("\n\t\t\t\tCREATE TEMPORARY TABLE {$tmp_sync_topics} (\n\t\t\t\t\ttopic_id INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\ttotal_posts INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\ttopic_first_post_id INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\ttopic_last_post_id INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\ttopic_last_post_time INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\ttopic_attachment INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\tPRIMARY KEY (topic_id)\n\t\t\t\t) ENGINE = MEMORY\n\t\t\t"); DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS {$tmp_sync_topics}"); $where_sql = !$all_topics ? "AND t.topic_id IN({$topic_csv})" : ''; DB()->query("\n\t\t\t\tINSERT INTO {$tmp_sync_topics}\n\t\t\t\tSELECT\n\t\t\t\t\tt.topic_id,\n\t\t\t\t\tCOUNT(p.post_id) AS total_posts,\n\t\t\t\t\tMIN(p.post_id) AS topic_first_post_id,\n\t\t\t\t\tMAX(p.post_id) AS topic_last_post_id,\n\t\t\t\t\tMAX(p.post_time) AS topic_last_post_time,\n\t\t\t\t\tIF(MAX(a.attach_id), 1, 0) AS topic_attachment\n\t\t\t\tFROM " . BB_TOPICS . " t\n\t\t\t\tLEFT JOIN " . BB_POSTS . " p ON(p.topic_id = t.topic_id)\n\t\t\t\tLEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = p.post_id)\n\t\t\t\tWHERE t.topic_status != " . TOPIC_MOVED . "\n\t\t\t\t\t{$where_sql}\n\t\t\t\tGROUP BY t.topic_id\n\t\t\t"); DB()->query("\n\t\t\t\tUPDATE\n\t\t\t\t\t{$tmp_sync_topics} tmp, " . BB_TOPICS . " t\n\t\t\t\tSET\n\t\t\t\t\tt.topic_replies = tmp.total_posts - 1,\n\t\t\t\t\tt.topic_first_post_id = tmp.topic_first_post_id,\n\t\t\t\t\tt.topic_last_post_id = tmp.topic_last_post_id,\n\t\t\t\t\tt.topic_last_post_time = tmp.topic_last_post_time,\n\t\t\t\t\tt.topic_attachment = tmp.topic_attachment\n\t\t\t\tWHERE\n\t\t\t\t\tt.topic_id = tmp.topic_id\n\t\t\t"); if ($topics = DB()->fetch_rowset("SELECT topic_id FROM " . $tmp_sync_topics . " WHERE total_posts = 0", 'topic_id')) { topic_delete($topics); } DB()->query("DROP TEMPORARY TABLE {$tmp_sync_topics}"); break; case 'user_posts': $all_users = $id === 'all'; if (!$all_users and !($user_csv = get_id_csv($id))) { break; } $tmp_user_posts = 'tmp_sync_user_posts'; DB()->query("\n\t\t\t\tCREATE TEMPORARY TABLE {$tmp_user_posts} (\n\t\t\t\t\tuser_id INT NOT NULL DEFAULT '0',\n\t\t\t\t\tuser_posts MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\t\t\tPRIMARY KEY (user_id)\n\t\t\t\t) ENGINE = MEMORY\n\t\t\t"); DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS {$tmp_user_posts}"); // Set posts count = 0 and then update to real count $where_user_sql = !$all_users ? "AND user_id IN({$user_csv})" : "AND user_posts != 0"; $where_post_sql = !$all_users ? "AND poster_id IN({$user_csv})" : ''; DB()->query("\n\t\t\t\tREPLACE INTO {$tmp_user_posts}\n\t\t\t\t\tSELECT user_id, 0\n\t\t\t\t\tFROM " . BB_USERS . "\n\t\t\t\t\tWHERE user_id != " . GUEST_UID . "\n\t\t\t\t\t\t{$where_user_sql}\n\t\t\t\tUNION\n\t\t\t\t\tSELECT poster_id, COUNT(*)\n\t\t\t\t\tFROM " . BB_POSTS . "\n\t\t\t\t\tWHERE poster_id != " . GUEST_UID . "\n\t\t\t\t\t\t{$where_post_sql}\n\t\t\t\t\tGROUP BY poster_id\n\t\t\t"); DB()->query("\n\t\t\t\tUPDATE\n\t\t\t\t\t{$tmp_user_posts} tmp, " . BB_USERS . " u\n\t\t\t\tSET\n\t\t\t\t\tu.user_posts = tmp.user_posts\n\t\t\t\tWHERE\n\t\t\t\t\tu.user_id = tmp.user_id\n\t\t\t"); DB()->query("DROP TEMPORARY TABLE {$tmp_user_posts}"); break; } }
} require './pagestart.php'; $all_forums = -1; $pruned_total = 0; $prune_performed = false; if (isset($_REQUEST['submit'])) { if (!($var =& $_REQUEST['f']) or !($f_selected = get_id_ary($var))) { bb_die('Forum not selected'); } if (!($var =& $_REQUEST['prunedays']) or !($prunedays = abs(intval($var)))) { bb_die($lang['NOT_DAYS']); } $prunetime = TIMENOW - 86400 * $prunedays; $forum_csv = in_array($all_forums, $f_selected) ? $all_forums : join(',', $f_selected); $where_sql = $forum_csv != $all_forums ? "WHERE forum_id IN({$forum_csv})" : ''; $sql = "SELECT forum_id, forum_name FROM " . BB_FORUMS . " {$where_sql}"; foreach (DB()->fetch_rowset($sql) as $i => $row) { $pruned_topics = topic_delete('prune', $row['forum_id'], $prunetime, !empty($_POST['prune_all_topic_types'])); $pruned_total += $pruned_topics; $prune_performed = true; $template->assign_block_vars('pruned', array('ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', 'FORUM_NAME' => htmlCHR($row['forum_name']), 'PRUNED_TOPICS' => $pruned_topics)); } if (!$prune_performed) { bb_die($lang['NONE_SELECTED']); } if (!$pruned_total) { bb_die($lang['NO_SEARCH_MATCH']); } } $template->assign_vars(array('PRUNED_TOTAL' => $pruned_total, 'S_PRUNE_ACTION' => basename(__FILE__), 'SEL_FORUM' => get_forum_select('admin', 'f[]', null, 65, 16, '', $all_forums))); print_page('admin_forum_prune.tpl', 'admin');
$forum_id = (int) $_GET['f']; $move_to_options = '<option value="-1">' . $lang['DELETE_ALL_POSTS'] . '</option>'; $move_to_options .= sf_get_list('forum', $forum_id, 0); $foruminfo = get_info('forum', $forum_id); $hidden_fields = array('mode' => 'movedelforum', 'from_id' => $forum_id); $template->assign_vars(array('TPL_DELETE_FORUM' => true, 'WHAT_TO_DELETE' => htmlCHR($foruminfo['forum_name']), 'DELETE_TITLE' => $lang['FORUM_DELETE'], 'CAT_FORUM_NAME' => $lang['FORUM_NAME'], 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_fields), 'S_FORUM_ACTION' => "admin_forums.php", 'MOVE_TO_OPTIONS' => $move_to_options, 'S_SUBMIT_VALUE' => $lang['MOVE_AND_DELETE'])); break; case 'movedelforum': // // Move or delete a forum in the DB // $from_id = (int) $_POST['from_id']; $to_id = (int) $_POST['to_id']; if ($to_id == -1) { // Delete everything from forum topic_delete('prune', $from_id, 0, true); } else { // Move all posts $sql = "SELECT * FROM " . BB_FORUMS . " WHERE forum_id IN({$from_id}, {$to_id})"; $result = DB()->query($sql); if (DB()->num_rows($result) != 2) { bb_die('Ambiguous forum ID'); } DB()->query("UPDATE " . BB_TOPICS . " SET forum_id = {$to_id} WHERE forum_id = {$from_id}"); DB()->query("UPDATE " . BB_BT_TORRENTS . " SET forum_id = {$to_id} WHERE forum_id = {$from_id}"); $row = DB()->fetch_row("SELECT MIN(post_id) AS start_id, MAX(post_id) AS finish_id FROM " . BB_POSTS); $start_id = (int) $row['start_id']; $finish_id = (int) $row['finish_id']; $per_cycle = 10000; while (true) { set_time_limit(600);
user_delete($user_id); $this->response['info'] = $lang['USER_DELETED']; } else { $this->ajax_die($lang['USER_DELETE_CSV']); } break; case 'delete_topics': if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) { $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); } if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['DELETE_USER_ALL_POSTS_CONFIRM']); } if (IS_ADMIN) { $user_topics = DB()->fetch_rowset("SELECT topic_id FROM " . BB_TOPICS . " WHERE topic_poster = {$user_id}", 'topic_id'); $deleted_topics = topic_delete($user_topics); $deleted_posts = post_delete('user', $user_id); $this->response['info'] = $lang['USER_DELETED_POSTS']; } else { $this->ajax_die($lang['NOT_ADMIN']); } break; case 'delete_message': if (empty($this->request['confirmed']) && $userdata['user_id'] == $user_id) { $this->prompt_for_confirm($lang['DELETE_USER_POSTS_ME']); } if (empty($this->request['confirmed'])) { $this->prompt_for_confirm($lang['DELETE_USER_POSTS_CONFIRM']); } if (IS_ADMIN) { post_delete('user', $user_id);
<?php if (!defined('BB_ROOT')) { die(basename(__FILE__)); } require_once INC_DIR . 'functions_admin.php'; if ($bb_cfg['prune_enable']) { $sql = "SELECT forum_id, prune_days FROM " . BB_FORUMS . " WHERE prune_days != 0"; foreach (DB()->fetch_rowset($sql) as $row) { topic_delete('prune', $row['forum_id'], TIMENOW - 86400 * $row['prune_days']); } }
$hidden_fields = array('sid' => $userdata['session_id'], 'mode' => $mode, 'f' => $forum_id, 't' => $topic_id); foreach ($req_topics as $req_topic_id) { $hidden_fields['topic_id_list'][] = $req_topic_id; } break; } // // Perform action or show confirm message // switch ($mode) { case 'delete': if (!$is_auth['auth_delete']) { bb_die(sprintf($lang['SORRY_AUTH_DELETE'], $is_auth['auth_delete_type'])); } if ($confirmed) { $result = topic_delete($req_topics, $forum_id); //Обновление кеша новостей на главной $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); if (isset($news_forums[$forum_id]) && $bb_cfg['show_latest_news'] && $result) { $datastore->enqueue('latest_news'); $datastore->update('latest_news'); } $net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id'])); if (isset($net_forums[$forum_id]) && $bb_cfg['show_network_news'] && $result) { $datastore->enqueue('network_news'); $datastore->update('network_news'); } $msg = $result ? $lang['TOPICS_REMOVED'] : $lang['NO_TOPICS_REMOVED']; bb_die(return_msg_mcp($msg)); } else { print_confirmation(array('QUESTION' => $lang['CONFIRM_DELETE_TOPIC'], 'ITEMS_LIST' => join("\n</li>\n<li>\n", $topic_titles), 'FORM_ACTION' => "modcp.php", 'HIDDEN_FIELDS' => build_hidden_fields($hidden_fields)));