refactor(posting): rollback changes in SQL queries up to legacy format

This commit is contained in:
Yury Pikhtarev 2025-06-20 18:33:39 +04:00
commit 43b6b10a5f
No known key found for this signature in database

View file

@ -105,9 +105,7 @@ switch ($mode) {
if (!$topic_id) {
bb_die($lang['NO_TOPIC_ID']);
}
$sql = "SELECT
f.forum_id, f.forum_name, f.forum_status, f.forum_last_post_id, f.allow_reg_tracker,
t.topic_id, t.topic_title, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_allow_robots
$sql = "SELECT f.*, t.*
FROM " . BB_FORUMS . " f, " . BB_TOPICS . " t
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id
@ -121,12 +119,8 @@ switch ($mode) {
bb_simple_die($lang['NO_POST_ID']);
}
// Use specific column names to avoid duplicate column errors
$select_sql = 'SELECT
f.forum_id, f.forum_name, f.forum_status, f.forum_last_post_id,
t.topic_id, t.topic_title, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id,
p.post_id, p.poster_id, p.post_time, p.poster_rg_id, p.attach_rg_sig';
$select_sql .= !$submit ? ', pt.post_text, u.username, u.user_id' : '';
$select_sql = 'SELECT f.*, t.*, p.*';
$select_sql .= !$submit ? ', pt.*, u.username, u.user_id' : '';
$from_sql = "FROM " . BB_POSTS . " p, " . BB_TOPICS . " t, " . BB_FORUMS . " f";
$from_sql .= !$submit ? ", " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u" : '';
@ -156,9 +150,9 @@ if ($post_info = DB()->fetch_row($sql)) {
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $post_info);
if ($post_info['forum_status'] == FORUM_LOCKED && !($is_auth['auth_mod'] ?? false)) {
if ($post_info['forum_status'] == FORUM_LOCKED && !$is_auth['auth_mod']) {
bb_die($lang['FORUM_LOCKED']);
} elseif ($mode != 'newtopic' && $mode != 'new_rel' && $post_info['topic_status'] == TOPIC_LOCKED && !($is_auth['auth_mod'] ?? false)) {
} elseif ($mode != 'newtopic' && $mode != 'new_rel' && $post_info['topic_status'] == TOPIC_LOCKED && !$is_auth['auth_mod']) {
bb_die($lang['TOPIC_LOCKED']);
}
@ -176,9 +170,9 @@ if ($post_info = DB()->fetch_row($sql)) {
$switch_rg_sig = (bool)$post_info['attach_rg_sig'];
// Can this user edit/delete the post?
if ($post_info['poster_id'] != $userdata['user_id'] && !($is_auth['auth_mod'] ?? false)) {
if ($post_info['poster_id'] != $userdata['user_id'] && !$is_auth['auth_mod']) {
$auth_err = ($delete || $mode == 'delete') ? $lang['DELETE_OWN_POSTS'] : $lang['EDIT_OWN_POSTS'];
} elseif (!$post_data['last_post'] && !($is_auth['auth_mod'] ?? false) && ($mode == 'delete' || $delete)) {
} elseif (!$post_data['last_post'] && !$is_auth['auth_mod'] && ($mode == 'delete' || $delete)) {
$auth_err = $lang['CANNOT_DELETE_REPLIED'];
}
@ -201,10 +195,9 @@ if ($post_info = DB()->fetch_row($sql)) {
// The user is not authed, if they're not logged in then redirect
// them, else show them an error message
if (!isset($is_auth[$is_auth_type]) || !$is_auth[$is_auth_type]) {
if (!$is_auth[$is_auth_type]) {
if (!IS_GUEST) {
$auth_type_msg = isset($is_auth[$is_auth_type . '_type']) ? $is_auth[$is_auth_type . '_type'] : 'Unknown auth type';
bb_die(sprintf($lang['SORRY_' . strtoupper($is_auth_type)], $auth_type_msg));
bb_die(sprintf($lang['SORRY_' . strtoupper($is_auth_type)], $is_auth[$is_auth_type . '_type']));
}
switch ($mode) {
@ -281,10 +274,7 @@ $topic_has_new_posts = false;
if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' || $mode == 'reply') && isset($_COOKIE[COOKIE_TOPIC])) {
if ($topic_last_read = max((int)(@$tracking_topics[$topic_id]), (int)(@$tracking_forums[$forum_id]))) {
$sql = "SELECT
p.post_id, p.poster_id, p.post_time, p.topic_id,
pt.post_text,
u.username, u.user_rank, u.user_id
$sql = "SELECT p.*, pt.post_text, u.username, u.user_rank
FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u
WHERE p.topic_id = " . (int)$topic_id . "
AND u.user_id = p.poster_id
@ -347,7 +337,7 @@ if (($delete || $mode == 'delete') && !$confirm) {
\TorrentPier\Legacy\Post::prepare_post($mode, $post_data, $error_msg, $username, $subject, $message);
if (!$error_msg) {
$topic_type = (isset($post_data['topic_type']) && $topic_type != $post_data['topic_type'] && !($is_auth['auth_sticky'] ?? false) && !($is_auth['auth_announce'] ?? false)) ? $post_data['topic_type'] : $topic_type;
$topic_type = (isset($post_data['topic_type']) && $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce']) ? $post_data['topic_type'] : $topic_type;
\TorrentPier\Legacy\Post::submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time, $poster_rg_id, $attach_rg_sig, (int)$robots_indexing);
@ -521,7 +511,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
// Topic type selection
$template->assign_block_vars('switch_type_toggle', []);
if ($is_auth['auth_sticky'] ?? false) {
if ($is_auth['auth_sticky']) {
$topic_type_toggle .= '<label><input type="radio" name="topictype" value="' . POST_STICKY . '"';
if (isset($post_data['topic_type']) && ($post_data['topic_type'] == POST_STICKY || $topic_type == POST_STICKY)) {
$topic_type_toggle .= ' checked';
@ -529,7 +519,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
$topic_type_toggle .= ' /> ' . $lang['POST_STICKY'] . '</label>&nbsp;&nbsp;';
}
if ($is_auth['auth_announce'] ?? false) {
if ($is_auth['auth_announce']) {
$topic_type_toggle .= '<label><input type="radio" name="topictype" value="' . POST_ANNOUNCE . '"';
if (isset($post_data['topic_type']) && ($post_data['topic_type'] == POST_ANNOUNCE || $topic_type == POST_ANNOUNCE)) {
$topic_type_toggle .= ' checked';
@ -544,7 +534,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
//bt
$topic_dl_type = $post_info['topic_dl_type'] ?? 0;
if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_type || ($is_auth['auth_mod'] ?? false))) {
if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_type || $is_auth['auth_mod'])) {
$sql = "
SELECT tor.attach_id
FROM " . BB_POSTS . " p
@ -561,7 +551,7 @@ if ($post_info['allow_reg_tracker'] && $post_data['first_post'] && ($topic_dl_ty
$dl_type_name = 'topic_dl_type';
$dl_type_val = $topic_dl_type ? 1 : 0;
if (!$post_info['allow_reg_tracker'] && !($is_auth['auth_mod'] ?? false)) {
if (!$post_info['allow_reg_tracker'] && !$is_auth['auth_mod']) {
$dl_ds = ' disabled ';
$dl_hid = '<input type="hidden" name="topic_dl_type" value="' . $dl_type_val . '" />';
$dl_type_name = '';
@ -650,13 +640,13 @@ if ($mode == 'newtopic' || $post_data['first_post']) {
// Update post time
if ($mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) {
$template->assign_vars([
'SHOW_UPDATE_POST_TIME' => (($is_auth['auth_mod'] ?? false) || ($post_data['poster_post'] && $post_info['post_time'] + 3600 * 3 > TIMENOW)),
'SHOW_UPDATE_POST_TIME' => ($is_auth['auth_mod'] || ($post_data['poster_post'] && $post_info['post_time'] + 3600 * 3 > TIMENOW)),
'UPDATE_POST_TIME_CHECKED' => ($post_data['poster_post'] && ($post_info['post_time'] + 3600 * 2 > TIMENOW)),
]);
}
// Topic review
if ($mode == 'reply' && ($is_auth['auth_read'] ?? false)) {
if ($mode == 'reply' && $is_auth['auth_read']) {
\TorrentPier\Legacy\Post::topic_review($topic_id);
}