diff --git a/dl.php b/dl.php index d9ce28af0..5e1978a81 100644 --- a/dl.php +++ b/dl.php @@ -143,7 +143,6 @@ if (!$authorised) { $datastore->rm('cat_forums'); - // Check tor status if (!IS_AM) { $sql = 'SELECT tor_status, poster_id FROM ' . BB_BT_TORRENTS . ' WHERE attach_id = ' . (int)$attachment['attach_id']; @@ -162,7 +161,6 @@ if (!IS_AM) { } // Get Information on currently allowed Extensions - $rows = get_extension_informations(); $num_rows = count($rows); diff --git a/poll.php b/poll.php index e5b7dd27b..73d8cc321 100644 --- a/poll.php +++ b/poll.php @@ -14,10 +14,10 @@ require __DIR__ . '/common.php'; // Start session management $user->session_start(['req_login' => true]); -$mode = (string)@$_POST['mode']; -$topic_id = (int)@$_POST['topic_id']; -$forum_id = (int)@$_POST['forum_id']; -$vote_id = (int)@$_POST['vote_id']; +$mode = (string)$_POST['mode']; +$topic_id = (int)$_POST['topic_id']; +$forum_id = (int)$_POST['forum_id']; +$vote_id = (int)$_POST['vote_id']; $return_topic_url = TOPIC_URL . $topic_id; $return_topic_url .= !empty($_POST['start']) ? "&start=" . (int)$_POST['start'] : ''; @@ -26,15 +26,17 @@ set_die_append_msg($forum_id, $topic_id); $poll = new TorrentPier\Legacy\Poll(); -// проверка валидности $topic_id +// Checking $topic_id if (!$topic_id) { bb_die($lang['INVALID_TOPIC_ID']); } + +// Getting topic data if present if (!$t_data = DB()->fetch_row("SELECT * FROM " . BB_TOPICS . " WHERE topic_id = $topic_id LIMIT 1")) { bb_die($lang['INVALID_TOPIC_ID_DB']); } -// проверка прав +// Checking the rights if ($mode != 'poll_vote') { if ($t_data['topic_poster'] != $userdata['user_id']) { if (!IS_AM) { @@ -43,7 +45,7 @@ if ($mode != 'poll_vote') { } } -// проверка на возможность вносить изменения +// Checking the ability to make changes if ($mode == 'poll_delete') { if ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days'] * 86400) { bb_die(sprintf($lang['NEW_POLL_DAYS'], $bb_cfg['poll_max_days'])); @@ -54,20 +56,26 @@ if ($mode == 'poll_delete') { } switch ($mode) { - // голосование case 'poll_vote': + // Checking for poll existence if (!$t_data['topic_vote']) { bb_die($lang['POST_HAS_NO_POLL']); } + + // Checking that the topic has not been locked if ($t_data['topic_status'] == TOPIC_LOCKED) { bb_die($lang['TOPIC_LOCKED_SHORT']); } + + // Checking that poll has not been finished if (!\TorrentPier\Legacy\Poll::poll_is_active($t_data)) { bb_die($lang['NEW_POLL_ENDED']); } + if (!$vote_id) { bb_die($lang['NO_VOTE_OPTION']); } + if (DB()->fetch_row("SELECT 1 FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']} LIMIT 1")) { bb_die($lang['ALREADY_VOTED']); } @@ -79,71 +87,83 @@ switch ($mode) { AND vote_id = $vote_id LIMIT 1 "); + if (DB()->affected_rows() != 1) { bb_die($lang['NO_VOTE_OPTION']); } + // Voting process DB()->query("INSERT IGNORE INTO " . BB_POLL_USERS . " (topic_id, user_id, vote_ip, vote_dt) VALUES ($topic_id, {$userdata['user_id']}, '" . USER_IP . "', " . TIMENOW . ")"); - CACHE('bb_poll_data')->rm("poll_$topic_id"); - bb_die($lang['VOTE_CAST']); break; - - // возобновить возможность голосовать case 'poll_start': + // Checking for poll existence if (!$t_data['topic_vote']) { bb_die($lang['POST_HAS_NO_POLL']); } + + // Starting the poll DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id"); bb_die($lang['NEW_POLL_START']); break; - - // завершить опрос case 'poll_finish': + // Checking for poll existence if (!$t_data['topic_vote']) { bb_die($lang['POST_HAS_NO_POLL']); } + + // Finishing the poll DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id"); bb_die($lang['NEW_POLL_END']); break; - - // удаление case 'poll_delete': + // Checking for poll existence if (!$t_data['topic_vote']) { bb_die($lang['POST_HAS_NO_POLL']); } + + // Removing poll from database $poll->delete_poll($topic_id); bb_die($lang['NEW_POLL_DELETE']); break; - - // добавление case 'poll_add': + // Checking that no other poll exists if ($t_data['topic_vote']) { bb_die($lang['NEW_POLL_ALREADY']); } + + // Make a poll from $_POST data $poll->build_poll_data($_POST); + + // Showing errors if present if ($poll->err_msg) { bb_die($poll->err_msg); } + + // Adding poll info to the database $poll->insert_votes_into_db($topic_id); bb_die($lang['NEW_POLL_ADDED']); break; - - // редактирование case 'poll_edit': + // Checking for poll existence if (!$t_data['topic_vote']) { bb_die($lang['POST_HAS_NO_POLL']); } + + // Make a poll from $_POST data $poll->build_poll_data($_POST); + + // Showing errors if present if ($poll->err_msg) { bb_die($poll->err_msg); } + + // Updating poll info to the database $poll->insert_votes_into_db($topic_id); CACHE('bb_poll_data')->rm("poll_$topic_id"); bb_die($lang['NEW_POLL_RESULTS']); break; - default: bb_die('Invalid mode: ' . htmlCHR($mode)); }