mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
refactor(posting): rollback changes in SQL queries up to legacy format
This commit is contained in:
parent
d467813447
commit
43b6b10a5f
1 changed files with 17 additions and 27 deletions
44
posting.php
44
posting.php
|
@ -105,9 +105,7 @@ switch ($mode) {
|
||||||
if (!$topic_id) {
|
if (!$topic_id) {
|
||||||
bb_die($lang['NO_TOPIC_ID']);
|
bb_die($lang['NO_TOPIC_ID']);
|
||||||
}
|
}
|
||||||
$sql = "SELECT
|
$sql = "SELECT f.*, t.*
|
||||||
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
|
|
||||||
FROM " . BB_FORUMS . " f, " . BB_TOPICS . " t
|
FROM " . BB_FORUMS . " f, " . BB_TOPICS . " t
|
||||||
WHERE t.topic_id = $topic_id
|
WHERE t.topic_id = $topic_id
|
||||||
AND f.forum_id = t.forum_id
|
AND f.forum_id = t.forum_id
|
||||||
|
@ -121,12 +119,8 @@ switch ($mode) {
|
||||||
bb_simple_die($lang['NO_POST_ID']);
|
bb_simple_die($lang['NO_POST_ID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use specific column names to avoid duplicate column errors
|
$select_sql = 'SELECT f.*, t.*, p.*';
|
||||||
$select_sql = 'SELECT
|
$select_sql .= !$submit ? ', pt.*, u.username, u.user_id' : '';
|
||||||
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' : '';
|
|
||||||
|
|
||||||
$from_sql = "FROM " . BB_POSTS . " p, " . BB_TOPICS . " t, " . BB_FORUMS . " f";
|
$from_sql = "FROM " . BB_POSTS . " p, " . BB_TOPICS . " t, " . BB_FORUMS . " f";
|
||||||
$from_sql .= !$submit ? ", " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u" : '';
|
$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);
|
$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']);
|
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']);
|
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'];
|
$switch_rg_sig = (bool)$post_info['attach_rg_sig'];
|
||||||
|
|
||||||
// Can this user edit/delete the post?
|
// 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'];
|
$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'];
|
$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
|
// The user is not authed, if they're not logged in then redirect
|
||||||
// them, else show them an error message
|
// 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) {
|
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)], $is_auth[$is_auth_type . '_type']));
|
||||||
bb_die(sprintf($lang['SORRY_' . strtoupper($is_auth_type)], $auth_type_msg));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($mode) {
|
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 (!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]))) {
|
if ($topic_last_read = max((int)(@$tracking_topics[$topic_id]), (int)(@$tracking_forums[$forum_id]))) {
|
||||||
$sql = "SELECT
|
$sql = "SELECT p.*, pt.post_text, u.username, u.user_rank
|
||||||
p.post_id, p.poster_id, p.post_time, p.topic_id,
|
|
||||||
pt.post_text,
|
|
||||||
u.username, u.user_rank, u.user_id
|
|
||||||
FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u
|
FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u
|
||||||
WHERE p.topic_id = " . (int)$topic_id . "
|
WHERE p.topic_id = " . (int)$topic_id . "
|
||||||
AND u.user_id = p.poster_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);
|
\TorrentPier\Legacy\Post::prepare_post($mode, $post_data, $error_msg, $username, $subject, $message);
|
||||||
|
|
||||||
if (!$error_msg) {
|
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);
|
\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
|
// Topic type selection
|
||||||
$template->assign_block_vars('switch_type_toggle', []);
|
$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 . '"';
|
$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)) {
|
if (isset($post_data['topic_type']) && ($post_data['topic_type'] == POST_STICKY || $topic_type == POST_STICKY)) {
|
||||||
$topic_type_toggle .= ' checked';
|
$topic_type_toggle .= ' checked';
|
||||||
|
@ -529,7 +519,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
|
||||||
$topic_type_toggle .= ' /> ' . $lang['POST_STICKY'] . '</label> ';
|
$topic_type_toggle .= ' /> ' . $lang['POST_STICKY'] . '</label> ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_auth['auth_announce'] ?? false) {
|
if ($is_auth['auth_announce']) {
|
||||||
$topic_type_toggle .= '<label><input type="radio" name="topictype" value="' . POST_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)) {
|
if (isset($post_data['topic_type']) && ($post_data['topic_type'] == POST_ANNOUNCE || $topic_type == POST_ANNOUNCE)) {
|
||||||
$topic_type_toggle .= ' checked';
|
$topic_type_toggle .= ' checked';
|
||||||
|
@ -544,7 +534,7 @@ if ($mode == 'newtopic' || ($mode == 'editpost' && $post_data['first_post'])) {
|
||||||
//bt
|
//bt
|
||||||
$topic_dl_type = $post_info['topic_dl_type'] ?? 0;
|
$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 = "
|
$sql = "
|
||||||
SELECT tor.attach_id
|
SELECT tor.attach_id
|
||||||
FROM " . BB_POSTS . " p
|
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_name = 'topic_dl_type';
|
||||||
$dl_type_val = $topic_dl_type ? 1 : 0;
|
$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_ds = ' disabled ';
|
||||||
$dl_hid = '<input type="hidden" name="topic_dl_type" value="' . $dl_type_val . '" />';
|
$dl_hid = '<input type="hidden" name="topic_dl_type" value="' . $dl_type_val . '" />';
|
||||||
$dl_type_name = '';
|
$dl_type_name = '';
|
||||||
|
@ -650,13 +640,13 @@ if ($mode == 'newtopic' || $post_data['first_post']) {
|
||||||
// Update post time
|
// Update post time
|
||||||
if ($mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) {
|
if ($mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) {
|
||||||
$template->assign_vars([
|
$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)),
|
'UPDATE_POST_TIME_CHECKED' => ($post_data['poster_post'] && ($post_info['post_time'] + 3600 * 2 > TIMENOW)),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Topic review
|
// Topic review
|
||||||
if ($mode == 'reply' && ($is_auth['auth_read'] ?? false)) {
|
if ($mode == 'reply' && $is_auth['auth_read']) {
|
||||||
\TorrentPier\Legacy\Post::topic_review($topic_id);
|
\TorrentPier\Legacy\Post::topic_review($topic_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue