function post_delete($mode_or_post_id, $user_id = null, $exclude_first = true) { global $log_action; $del_user_posts = $mode_or_post_id === 'user'; // Delete all user posts // Get required params if ($del_user_posts) { if (!($user_csv = get_id_csv($user_id))) { return false; } } else { if (!($post_csv = get_id_csv($mode_or_post_id))) { return false; } // фильтр заглавных сообщений в теме if ($exclude_first) { $sql = "SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_first_post_id IN({$post_csv})"; if ($first_posts = DB()->fetch_rowset($sql, 'topic_first_post_id')) { $posts_without_first = array_diff(explode(',', $post_csv), $first_posts); if (!($post_csv = get_id_csv($posts_without_first))) { return false; } } } } // Collect data for logs, sync.. $log_topics = $sync_forums = $sync_topics = $sync_users = array(); if ($del_user_posts) { $sync_topics = DB()->fetch_rowset("SELECT DISTINCT topic_id FROM " . BB_POSTS . " WHERE poster_id IN({$user_csv})", 'topic_id'); if ($topic_csv = get_id_csv($sync_topics)) { foreach (DB()->fetch_rowset("SELECT DISTINCT forum_id FROM " . BB_TOPICS . " WHERE topic_id IN({$topic_csv})") as $row) { $sync_forums[$row['forum_id']] = true; } } $sync_users = explode(',', $user_csv); } else { $sql = "\n\t\t\tSELECT p.topic_id, p.forum_id, t.topic_title\n\t\t\tFROM " . BB_POSTS . " p, " . BB_TOPICS . " t\n\t\t\tWHERE p.post_id IN({$post_csv})\n\t\t\t\tAND t.topic_id = p.topic_id\n\t\t\tGROUP BY t.topic_id\n\t\t"; foreach (DB()->fetch_rowset($sql) as $row) { $log_topics[] = $row; $sync_topics[] = $row['topic_id']; $sync_forums[$row['forum_id']] = true; } $sync_users = DB()->fetch_rowset("SELECT DISTINCT poster_id FROM " . BB_POSTS . " WHERE post_id IN({$post_csv})", 'poster_id'); } // Get all post_id for deleting $tmp_delete_posts = 'tmp_delete_posts'; DB()->query("\n\t\tCREATE TEMPORARY TABLE {$tmp_delete_posts} (\n\t\t\tpost_id INT UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY (post_id)\n\t\t) ENGINE = MEMORY\n\t"); DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS {$tmp_delete_posts}"); if ($del_user_posts) { $where_sql = "poster_id IN({$user_csv})"; $exclude_posts_ary = array(); foreach (DB()->fetch_rowset("SELECT topic_first_post_id FROM " . BB_TOPICS . " WHERE topic_poster IN({$user_csv})") as $row) { $exclude_posts_ary[] = $row['topic_first_post_id']; } if ($exclude_posts_csv = get_id_csv($exclude_posts_ary)) { $where_sql .= " AND post_id NOT IN({$exclude_posts_csv})"; } } else { $where_sql = "post_id IN({$post_csv})"; } DB()->query("INSERT INTO {$tmp_delete_posts} SELECT post_id FROM " . BB_POSTS . " WHERE {$where_sql}"); // Deleted posts count $row = DB()->fetch_row("SELECT COUNT(*) AS posts_count FROM {$tmp_delete_posts}"); if (!($deleted_posts_count = $row['posts_count'])) { DB()->query("DROP TEMPORARY TABLE {$tmp_delete_posts}"); return 0; } // Delete attachments (from disk) $attach_dir = get_attachments_dir(); $result = DB()->query("\n\t\tSELECT\n\t\t\td.physical_filename\n\t\tFROM\n\t\t\t" . $tmp_delete_posts . " del,\n\t\t\t" . BB_ATTACHMENTS . " a,\n\t\t\t" . BB_ATTACHMENTS_DESC . " d\n\t\tWHERE\n\t\t\t a.post_id = del.post_id\n\t\t\tAND d.attach_id = a.attach_id\n\t"); while ($row = DB()->fetch_next($result)) { if ($filename = basename($row['physical_filename'])) { @unlink("{$attach_dir}/" . $filename); @unlink("{$attach_dir}/" . THUMB_DIR . '/t_' . $filename); } } unset($row, $result); // Delete posts, posts_text, attachments (from DB) DB()->query("\n\t\tDELETE p, pt, ps, tor, a, d, ph\n\t\tFROM " . $tmp_delete_posts . " del\n\t\tLEFT JOIN " . BB_POSTS . " p ON(p.post_id = del.post_id)\n\t\tLEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = del.post_id)\n\t\tLEFT JOIN " . BB_POSTS_HTML . " ph ON(ph.post_id = del.post_id)\n\t\tLEFT JOIN " . BB_POSTS_SEARCH . " ps ON(ps.post_id = del.post_id)\n\t\tLEFT JOIN " . BB_BT_TORRENTS . " tor ON(tor.post_id = del.post_id)\n\t\tLEFT JOIN " . BB_ATTACHMENTS . " a ON(a.post_id = del.post_id)\n\t\tLEFT JOIN " . BB_ATTACHMENTS_DESC . " d ON(d.attach_id = a.attach_id)\n\t"); // Log action if ($del_user_posts) { $log_action->admin('mod_post_delete', array('log_msg' => 'user: '******'IN_CRON')) { foreach ($log_topics as $row) { $log_action->mod('mod_post_delete', array('forum_id' => $row['forum_id'], 'topic_id' => $row['topic_id'], 'topic_title' => $row['topic_title'])); } } } // Sync sync('topic', $sync_topics); sync('forum', array_keys($sync_forums)); sync('user_posts', $sync_users); // Update atom feed foreach ($sync_topics as $atom_topic) { update_atom('topic', $atom_topic); } foreach ($sync_users as $atom_user) { update_atom('user', $atom_user); } DB()->query("DROP TEMPORARY TABLE {$tmp_delete_posts}"); return $deleted_posts_count; }
if (!defined('BB_ROOT')) { die(basename(__FILE__)); } DB()->expect_slow_query(600); $fix_errors = true; $debug_mode = false; $tmp_attach_tbl = 'tmp_attachments'; $db_max_packet = 800000; $sql_limit = 3000; $check_attachments = false; $orphan_files = $orphan_db_attach = $orphan_tor = array(); $posts_without_attach = $topics_without_attach = array(); DB()->query("\n\tCREATE TEMPORARY TABLE {$tmp_attach_tbl} (\n\t\tphysical_filename VARCHAR(255) NOT NULL default '',\n\t\tKEY physical_filename (physical_filename(20))\n\t) ENGINE = MyISAM DEFAULT CHARSET = utf8\n"); DB()->add_shutdown_query("DROP TEMPORARY TABLE IF EXISTS {$tmp_attach_tbl}"); // Get attach_mod config $attach_dir = get_attachments_dir(); // Get all names of existed attachments and insert them into $tmp_attach_tbl if ($dir = @opendir($attach_dir)) { $check_attachments = true; $files = array(); $f_len = 0; while (false !== ($f = readdir($dir))) { if ($f == 'index.php' || $f == '.htaccess' || is_dir("{$attach_dir}/{$f}") || is_link("{$attach_dir}/{$f}")) { continue; } $f = DB()->escape($f); $files[] = "('{$f}')"; $f_len += strlen($f) + 5; if ($f_len > $db_max_packet) { $files = join(',', $files); DB()->query("INSERT INTO {$tmp_attach_tbl} VALUES {$files}");
function convert_torrent($torrent) { $topic_data = array("topic_id" => $torrent['topic_id'], "forum_id" => $torrent['category'], "topic_title" => $torrent['name'], "topic_poster" => $torrent['owner'], "topic_time" => $torrent['added'], "topic_views" => $torrent['views'], "topic_type" => $torrent['sticky'] == 'yes' ? 1 : 0, "topic_first_post_id" => $torrent['id'], "topic_last_post_id" => $torrent['id'], "topic_attachment" => 1, "topic_dl_type" => 1, "topic_last_post_time" => $torrent['added']); tp_add_topic($topic_data); $post_text = stripslashes(prepare_message(addslashes(unprepare_message($torrent['descr'])), true, true)); $post_data = array("posts" => array("post_id" => $torrent['post_id'], "topic_id" => $torrent['topic_id'], "forum_id" => $torrent['category'], "poster_id" => $torrent['owner'], "post_time" => $torrent['added'], "post_attachment" => 1), "posts_text" => array("post_id" => $torrent['post_id'], "post_text" => $post_text), "posts_search" => array("post_id" => $torrent['post_id'], "search_words" => $torrent['search_text'])); tp_add_post($post_data); $attach_data = array("attachments" => array("attach_id" => $torrent['attach_id'], "post_id" => $torrent['post_id'], "user_id_1" => $torrent['owner']), "attachments_desc" => array("attach_id" => $torrent['attach_id'], "physical_filename" => $torrent['id'] . ".torrent", "real_filename" => $torrent['filename'], "extension" => "torrent", "mimetype" => "application/x-bittorrent", "filesize" => @filesize(get_attachments_dir() . '/' . $torrent['id'] . ".torrent"), "filetime" => $torrent['added'], "tracker_status" => 1)); tp_add_attach($attach_data); //Torrents if (BDECODE) { $filename = get_attachments_dir() . '/' . $torrent['id'] . ".torrent"; if (!file_exists($filename)) { return; } if (!function_exists('bdecode_file')) { include_once './includes/functions_torrent.php'; } $tor = bdecode_file($filename); $info = $tor['info'] ? $tor['info'] : array(); $info_hash = pack('H*', sha1(bencode($info))); $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); } else { $info_hash_sql = hex2bin($torrent['info_hash']); } $torrent_data = array("info_hash" => $info_hash_sql, "post_id" => $torrent['post_id'], "poster_id" => $torrent['owner'], "topic_id" => $torrent['topic_id'], "forum_id" => $torrent['category'], "attach_id" => $torrent['attach_id'], "size" => $torrent['size'], "reg_time" => $torrent['added'], "complete_count" => $torrent['times_completed'], "seeder_last_seen" => $torrent['lastseed']); $columns = $values = array(); foreach ($torrent_data as $column => $value) { $columns[] = $column; $values[] = "'" . DB()->escape($value) . "'"; } $sql_columns = implode(', ', $columns); $sql_values = implode(', ', $values); DB()->query("INSERT IGNORE INTO " . BB_BT_TORRENTS . " ({$sql_columns}) VALUES({$sql_values});"); return; }
if (!defined('IN_AJAX')) { die(basename(__FILE__)); } global $lang; if (!isset($this->request['attach_id'])) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); } $attach_id = (int) $this->request['attach_id']; global $bnc_error; $bnc_error = 0; $torrent = DB()->fetch_row("SELECT at.attach_id, at.physical_filename FROM " . BB_ATTACHMENTS_DESC . " at WHERE at.attach_id = {$attach_id} LIMIT 1"); if (!$torrent) { $this->ajax_die($lang['EMPTY_ATTACH_ID']); } $filename = get_attachments_dir() . '/' . $torrent['physical_filename']; if (($file_contents = @file_get_contents($filename)) === false) { if (IS_AM) { $this->ajax_die($lang['ERROR_NO_ATTACHMENT'] . "\n\n" . htmlCHR($filename)); } else { $this->ajax_die($lang['ERROR_NO_ATTACHMENT']); } } // Построение списка $tor_filelist = build_tor_filelist($file_contents); function build_tor_filelist($file_contents) { global $lang; if (!($tor = bdecode($file_contents))) { return $lang['TORFILE_INVALID']; }
function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED, $reg_time = TIMENOW) { global $bb_cfg, $lang, $reg_mode, $tr_cfg; $attach_id = intval($attach_id); $reg_mode = $mode; if (!($torrent = get_torrent_info($attach_id))) { bb_die($lang['TOR_NOT_FOUND']); } $post_id = $torrent['post_id']; $topic_id = $torrent['topic_id']; $forum_id = $torrent['forum_id']; $poster_id = $torrent['poster_id']; $info_hash = null; if ($torrent['extension'] !== TORRENT_EXT) { return torrent_error_exit($lang['NOT_TORRENT']); } if (!$torrent['allow_reg_tracker']) { return torrent_error_exit($lang['REG_NOT_ALLOWED_IN_THIS_FORUM']); } if ($post_id != $torrent['topic_first_post_id']) { return torrent_error_exit($lang['ALLOWED_ONLY_1ST_POST_REG']); } if ($torrent['tracker_status']) { return torrent_error_exit($lang['ALREADY_REG']); } if ($this_topic_torrents = get_registered_torrents($topic_id, 'topic')) { return torrent_error_exit($lang['ONLY_1_TOR_PER_TOPIC']); } torrent_auth_check($forum_id, $torrent['poster_id']); $filename = get_attachments_dir() . '/' . $torrent['physical_filename']; if (!is_file($filename)) { return torrent_error_exit('File name error'); } if (!file_exists($filename)) { return torrent_error_exit('File not exists'); } if (!($tor = bdecode_file($filename))) { return torrent_error_exit('This is not a bencoded file'); } if ($bb_cfg['bt_disable_dht']) { $tor['info']['private'] = (int) 1; $fp = fopen($filename, 'w+'); fwrite($fp, bencode($tor)); fclose($fp); } if ($bb_cfg['bt_check_announce_url']) { include INC_DIR . 'torrent_announce_urls.php'; $ann = @$tor['announce'] ? $tor['announce'] : ''; $announce_urls['main_url'] = $bb_cfg['bt_announce_url']; if (!$ann || !in_array($ann, $announce_urls)) { $msg = sprintf($lang['INVALID_ANN_URL'], htmlspecialchars($ann), $announce_urls['main_url']); return torrent_error_exit($msg); } } $info = @$tor['info'] ? $tor['info'] : array(); if (!isset($info['name']) || !isset($info['piece length']) || !isset($info['pieces']) || strlen($info['pieces']) % 20 != 0) { return torrent_error_exit($lang['TORFILE_INVALID']); } $info_hash = pack('H*', sha1(bencode($info))); $info_hash_sql = rtrim(DB()->escape($info_hash), ' '); $info_hash_md5 = md5($info_hash); // Ocelot if ($bb_cfg['ocelot']['enabled']) { ocelot_update_tracker('add_torrent', array('info_hash' => rawurlencode($info_hash), 'id' => $topic_id, 'freetorrent' => 0)); } if ($row = DB()->fetch_row("SELECT topic_id FROM " . BB_BT_TORRENTS . " WHERE info_hash = '{$info_hash_sql}' LIMIT 1")) { $msg = sprintf($lang['BT_REG_FAIL_SAME_HASH'], TOPIC_URL . $row['topic_id']); bb_die($msg); set_die_append_msg($forum_id, $topic_id); } $totallen = 0; if (isset($info['length'])) { $totallen = (double) $info['length']; } else { if (isset($info['files']) && is_array($info['files'])) { foreach ($info['files'] as $fn => $f) { $totallen += (double) $f['length']; } } else { return torrent_error_exit($lang['TORFILE_INVALID']); } } $size = sprintf('%.0f', (double) $totallen); $columns = ' info_hash, post_id, poster_id, topic_id, forum_id, attach_id, size, reg_time, tor_status'; $values = "'{$info_hash_sql}', {$post_id}, {$poster_id}, {$topic_id}, {$forum_id}, {$attach_id}, '{$size}', {$reg_time}, {$tor_status}"; $sql = "INSERT INTO " . BB_BT_TORRENTS . " ({$columns}) VALUES ({$values})"; if (!DB()->sql_query($sql)) { $sql_error = DB()->sql_error(); if ($sql_error['code'] == 1062) { return torrent_error_exit($lang['BT_REG_FAIL_SAME_HASH']); } bb_die('Could not register torrent on tracker'); } // update tracker status for this attachment $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . " SET tracker_status = 1 WHERE attach_id = {$attach_id} LIMIT 1"; if (!DB()->sql_query($sql)) { bb_die('Could not update torrent status #2'); } // set DL-Type for topic if ($bb_cfg['bt_set_dltype_on_tor_reg']) { $sql = 'UPDATE ' . BB_TOPICS . ' SET topic_dl_type = ' . TOPIC_DL_TYPE_DL . " WHERE topic_id = {$topic_id} LIMIT 1"; if (!($result = DB()->sql_query($sql))) { bb_die('Could not update topics table #2'); } } if ($tr_cfg['tor_topic_up']) { DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = {$topic_id} LIMIT 1"); } if ($reg_mode == 'request' || $reg_mode == 'newtopic') { set_die_append_msg($forum_id, $topic_id); $mess = sprintf($lang['BT_REGISTERED'], DOWNLOAD_URL . $attach_id); bb_die($mess); } return; }