mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
Refactored poll.php (#1194)
This commit is contained in:
parent
13001d42d9
commit
21acd747ba
2 changed files with 41 additions and 23 deletions
2
dl.php
2
dl.php
|
@ -143,7 +143,6 @@ if (!$authorised) {
|
||||||
|
|
||||||
$datastore->rm('cat_forums');
|
$datastore->rm('cat_forums');
|
||||||
|
|
||||||
|
|
||||||
// Check tor status
|
// Check tor status
|
||||||
if (!IS_AM) {
|
if (!IS_AM) {
|
||||||
$sql = 'SELECT tor_status, poster_id FROM ' . BB_BT_TORRENTS . ' WHERE attach_id = ' . (int)$attachment['attach_id'];
|
$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
|
// Get Information on currently allowed Extensions
|
||||||
|
|
||||||
$rows = get_extension_informations();
|
$rows = get_extension_informations();
|
||||||
$num_rows = count($rows);
|
$num_rows = count($rows);
|
||||||
|
|
||||||
|
|
62
poll.php
62
poll.php
|
@ -14,10 +14,10 @@ require __DIR__ . '/common.php';
|
||||||
// Start session management
|
// Start session management
|
||||||
$user->session_start(['req_login' => true]);
|
$user->session_start(['req_login' => true]);
|
||||||
|
|
||||||
$mode = (string)@$_POST['mode'];
|
$mode = (string)$_POST['mode'];
|
||||||
$topic_id = (int)@$_POST['topic_id'];
|
$topic_id = (int)$_POST['topic_id'];
|
||||||
$forum_id = (int)@$_POST['forum_id'];
|
$forum_id = (int)$_POST['forum_id'];
|
||||||
$vote_id = (int)@$_POST['vote_id'];
|
$vote_id = (int)$_POST['vote_id'];
|
||||||
|
|
||||||
$return_topic_url = TOPIC_URL . $topic_id;
|
$return_topic_url = TOPIC_URL . $topic_id;
|
||||||
$return_topic_url .= !empty($_POST['start']) ? "&start=" . (int)$_POST['start'] : '';
|
$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();
|
$poll = new TorrentPier\Legacy\Poll();
|
||||||
|
|
||||||
// проверка валидности $topic_id
|
// Checking $topic_id
|
||||||
if (!$topic_id) {
|
if (!$topic_id) {
|
||||||
bb_die($lang['INVALID_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")) {
|
if (!$t_data = DB()->fetch_row("SELECT * FROM " . BB_TOPICS . " WHERE topic_id = $topic_id LIMIT 1")) {
|
||||||
bb_die($lang['INVALID_TOPIC_ID_DB']);
|
bb_die($lang['INVALID_TOPIC_ID_DB']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// проверка прав
|
// Checking the rights
|
||||||
if ($mode != 'poll_vote') {
|
if ($mode != 'poll_vote') {
|
||||||
if ($t_data['topic_poster'] != $userdata['user_id']) {
|
if ($t_data['topic_poster'] != $userdata['user_id']) {
|
||||||
if (!IS_AM) {
|
if (!IS_AM) {
|
||||||
|
@ -43,7 +45,7 @@ if ($mode != 'poll_vote') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// проверка на возможность вносить изменения
|
// Checking the ability to make changes
|
||||||
if ($mode == 'poll_delete') {
|
if ($mode == 'poll_delete') {
|
||||||
if ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days'] * 86400) {
|
if ($t_data['topic_time'] < TIMENOW - $bb_cfg['poll_max_days'] * 86400) {
|
||||||
bb_die(sprintf($lang['NEW_POLL_DAYS'], $bb_cfg['poll_max_days']));
|
bb_die(sprintf($lang['NEW_POLL_DAYS'], $bb_cfg['poll_max_days']));
|
||||||
|
@ -54,20 +56,26 @@ if ($mode == 'poll_delete') {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
// голосование
|
|
||||||
case 'poll_vote':
|
case 'poll_vote':
|
||||||
|
// Checking for poll existence
|
||||||
if (!$t_data['topic_vote']) {
|
if (!$t_data['topic_vote']) {
|
||||||
bb_die($lang['POST_HAS_NO_POLL']);
|
bb_die($lang['POST_HAS_NO_POLL']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checking that the topic has not been locked
|
||||||
if ($t_data['topic_status'] == TOPIC_LOCKED) {
|
if ($t_data['topic_status'] == TOPIC_LOCKED) {
|
||||||
bb_die($lang['TOPIC_LOCKED_SHORT']);
|
bb_die($lang['TOPIC_LOCKED_SHORT']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checking that poll has not been finished
|
||||||
if (!\TorrentPier\Legacy\Poll::poll_is_active($t_data)) {
|
if (!\TorrentPier\Legacy\Poll::poll_is_active($t_data)) {
|
||||||
bb_die($lang['NEW_POLL_ENDED']);
|
bb_die($lang['NEW_POLL_ENDED']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$vote_id) {
|
if (!$vote_id) {
|
||||||
bb_die($lang['NO_VOTE_OPTION']);
|
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")) {
|
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']);
|
bb_die($lang['ALREADY_VOTED']);
|
||||||
}
|
}
|
||||||
|
@ -79,71 +87,83 @@ switch ($mode) {
|
||||||
AND vote_id = $vote_id
|
AND vote_id = $vote_id
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
");
|
");
|
||||||
|
|
||||||
if (DB()->affected_rows() != 1) {
|
if (DB()->affected_rows() != 1) {
|
||||||
bb_die($lang['NO_VOTE_OPTION']);
|
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 . ")");
|
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");
|
CACHE('bb_poll_data')->rm("poll_$topic_id");
|
||||||
|
|
||||||
bb_die($lang['VOTE_CAST']);
|
bb_die($lang['VOTE_CAST']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// возобновить возможность голосовать
|
|
||||||
case 'poll_start':
|
case 'poll_start':
|
||||||
|
// Checking for poll existence
|
||||||
if (!$t_data['topic_vote']) {
|
if (!$t_data['topic_vote']) {
|
||||||
bb_die($lang['POST_HAS_NO_POLL']);
|
bb_die($lang['POST_HAS_NO_POLL']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starting the poll
|
||||||
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id");
|
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id");
|
||||||
bb_die($lang['NEW_POLL_START']);
|
bb_die($lang['NEW_POLL_START']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// завершить опрос
|
|
||||||
case 'poll_finish':
|
case 'poll_finish':
|
||||||
|
// Checking for poll existence
|
||||||
if (!$t_data['topic_vote']) {
|
if (!$t_data['topic_vote']) {
|
||||||
bb_die($lang['POST_HAS_NO_POLL']);
|
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");
|
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id");
|
||||||
bb_die($lang['NEW_POLL_END']);
|
bb_die($lang['NEW_POLL_END']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// удаление
|
|
||||||
case 'poll_delete':
|
case 'poll_delete':
|
||||||
|
// Checking for poll existence
|
||||||
if (!$t_data['topic_vote']) {
|
if (!$t_data['topic_vote']) {
|
||||||
bb_die($lang['POST_HAS_NO_POLL']);
|
bb_die($lang['POST_HAS_NO_POLL']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removing poll from database
|
||||||
$poll->delete_poll($topic_id);
|
$poll->delete_poll($topic_id);
|
||||||
bb_die($lang['NEW_POLL_DELETE']);
|
bb_die($lang['NEW_POLL_DELETE']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// добавление
|
|
||||||
case 'poll_add':
|
case 'poll_add':
|
||||||
|
// Checking that no other poll exists
|
||||||
if ($t_data['topic_vote']) {
|
if ($t_data['topic_vote']) {
|
||||||
bb_die($lang['NEW_POLL_ALREADY']);
|
bb_die($lang['NEW_POLL_ALREADY']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a poll from $_POST data
|
||||||
$poll->build_poll_data($_POST);
|
$poll->build_poll_data($_POST);
|
||||||
|
|
||||||
|
// Showing errors if present
|
||||||
if ($poll->err_msg) {
|
if ($poll->err_msg) {
|
||||||
bb_die($poll->err_msg);
|
bb_die($poll->err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adding poll info to the database
|
||||||
$poll->insert_votes_into_db($topic_id);
|
$poll->insert_votes_into_db($topic_id);
|
||||||
bb_die($lang['NEW_POLL_ADDED']);
|
bb_die($lang['NEW_POLL_ADDED']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// редактирование
|
|
||||||
case 'poll_edit':
|
case 'poll_edit':
|
||||||
|
// Checking for poll existence
|
||||||
if (!$t_data['topic_vote']) {
|
if (!$t_data['topic_vote']) {
|
||||||
bb_die($lang['POST_HAS_NO_POLL']);
|
bb_die($lang['POST_HAS_NO_POLL']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a poll from $_POST data
|
||||||
$poll->build_poll_data($_POST);
|
$poll->build_poll_data($_POST);
|
||||||
|
|
||||||
|
// Showing errors if present
|
||||||
if ($poll->err_msg) {
|
if ($poll->err_msg) {
|
||||||
bb_die($poll->err_msg);
|
bb_die($poll->err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updating poll info to the database
|
||||||
$poll->insert_votes_into_db($topic_id);
|
$poll->insert_votes_into_db($topic_id);
|
||||||
CACHE('bb_poll_data')->rm("poll_$topic_id");
|
CACHE('bb_poll_data')->rm("poll_$topic_id");
|
||||||
bb_die($lang['NEW_POLL_RESULTS']);
|
bb_die($lang['NEW_POLL_RESULTS']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
bb_die('Invalid mode: ' . htmlCHR($mode));
|
bb_die('Invalid mode: ' . htmlCHR($mode));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue