mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Forum: better error messages (Suggested by @anyeor)
This commit is contained in:
parent
c392fa7272
commit
8cf0e80019
@ -1580,6 +1580,14 @@ function getGuildLogoById($id)
|
|||||||
return BASE_URL . GUILD_IMAGES_DIR . $logo;
|
return BASE_URL . GUILD_IMAGES_DIR . $logo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function displayErrorBoxWithBackButton($errors, $action = null) {
|
||||||
|
global $twig;
|
||||||
|
$twig->display('error_box.html.twig', ['errors' => $errors]);
|
||||||
|
$twig->display('account.back_button.html.twig', [
|
||||||
|
'action' => $action ?: getLink('')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// validator functions
|
// validator functions
|
||||||
require_once LIBS . 'validator.php';
|
require_once LIBS . 'validator.php';
|
||||||
require_once SYSTEM . 'compat/base.php';
|
require_once SYSTEM . 'compat/base.php';
|
||||||
|
@ -17,14 +17,16 @@ $errors = [];
|
|||||||
if(!empty($action))
|
if(!empty($action))
|
||||||
{
|
{
|
||||||
if(!ctype_alnum(str_replace(array('-', '_'), '', $action))) {
|
if(!ctype_alnum(str_replace(array('-', '_'), '', $action))) {
|
||||||
error('Error: Action contains illegal characters.');
|
$errors[] = 'Error: Action contains illegal characters.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
}
|
}
|
||||||
else if(file_exists(PAGES . 'forum/' . $action . '.php')) {
|
else if(file_exists(PAGES . 'forum/' . $action . '.php')) {
|
||||||
require PAGES . 'forum/' . $action . '.php';
|
require PAGES . 'forum/' . $action . '.php';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error('This page does not exists.');
|
$errors[] = 'This page does not exists.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ if(Forum::canPost($account_logged))
|
|||||||
{
|
{
|
||||||
$post_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : false;
|
$post_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : false;
|
||||||
if(!$post_id) {
|
if(!$post_id) {
|
||||||
echo 'Please enter post id.';
|
$errors[] = 'Please enter post id.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,11 +107,17 @@ if(Forum::canPost($account_logged))
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo '<br/>You are not an author of this post.';
|
$errors[] = 'You are not an author of this post.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$errors[] = "Post with ID $post_id doesn't exist.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
echo "<br/>Post with ID " . $post_id . " doesn't exist.";
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo "<br/>Your account is banned, deleted or you don't have any player with level " . $config['forum_level_required'] . " on your account. You can't post.";
|
$errors[] = "Your account is banned, deleted or you don't have any player with level " . $config['forum_level_required'] . " on your account. You can't post.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
|
@ -16,12 +16,13 @@ if(!Forum::isModerator()) {
|
|||||||
echo 'You are not logged in or you are not moderator.';
|
echo 'You are not logged in or you are not moderator.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$save = isset($_REQUEST['save']) ? (int)$_REQUEST['save'] == 1 : false;
|
$save = isset($_REQUEST['save']) && (int)$_REQUEST['save'] == 1;
|
||||||
if($save) {
|
if($save) {
|
||||||
$post_id = (int)$_REQUEST['id'];
|
$post_id = (int)$_REQUEST['id'];
|
||||||
$board = (int)$_REQUEST['section'];
|
$board = (int)$_REQUEST['section'];
|
||||||
if(!Forum::hasAccess($board)) {
|
if(!Forum::hasAccess($board)) {
|
||||||
echo "You don't have access to this board.";
|
$errors[] = "You don't have access to this board.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,8 +34,10 @@ if($save) {
|
|||||||
header('Location: ' . getForumBoardLink($nPost['section']));
|
header('Location: ' . getForumBoardLink($nPost['section']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo 'Post with ID ' . $post_id . ' does not exist.';
|
$errors[] = 'Post with ID ' . $post_id . ' does not exist.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$post_id = (int)$_REQUEST['id'];
|
$post_id = (int)$_REQUEST['id'];
|
||||||
@ -60,7 +63,8 @@ else {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo 'Post with ID ' . $post_id . ' does not exist.';
|
$errors[] = 'Post with ID ' . $post_id . ' does not exist.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@ -28,17 +28,20 @@ if(Forum::canPost($account_logged))
|
|||||||
$players_from_account = $db->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll();
|
$players_from_account = $db->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll();
|
||||||
$thread_id = isset($_REQUEST['thread_id']) ? (int) $_REQUEST['thread_id'] : 0;
|
$thread_id = isset($_REQUEST['thread_id']) ? (int) $_REQUEST['thread_id'] : 0;
|
||||||
if($thread_id == 0) {
|
if($thread_id == 0) {
|
||||||
echo "Thread with this id doesn't exist.";
|
$errors[] = "Thread with this id doesn't exist.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$thread = $db->query("SELECT `" . FORUM_TABLE_PREFIX . "forum`.`post_topic`, `" . FORUM_TABLE_PREFIX . "forum`.`id`, `" . FORUM_TABLE_PREFIX . "forum`.`section` FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`id` = ".(int) $thread_id." AND `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." LIMIT 1")->fetch();
|
$thread = $db->query("SELECT `" . FORUM_TABLE_PREFIX . "forum`.`post_topic`, `" . FORUM_TABLE_PREFIX . "forum`.`id`, `" . FORUM_TABLE_PREFIX . "forum`.`section` FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`id` = ".(int) $thread_id." AND `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".$thread_id." LIMIT 1")->fetch();
|
||||||
echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($thread['section']) . '">'.$sections[$thread['section']]['name'].'</a> >> <a href="' . getForumThreadLink($thread_id) . '">'.$thread['post_topic'].'</a> >> <b>Post new reply</b><br /><h3>'.$thread['post_topic'].'</h3>';
|
|
||||||
if(isset($thread['id']) && Forum::hasAccess($thread['section']))
|
if(isset($thread['id']) && Forum::hasAccess($thread['section']))
|
||||||
{
|
{
|
||||||
|
echo '<a href="' . getLink('forum') . '">Boards</a> >> <a href="' . getForumBoardLink($thread['section']) . '">'.$sections[$thread['section']]['name'].'</a> >> <a href="' . getForumThreadLink($thread_id) . '">'.$thread['post_topic'].'</a> >> <b>Post new reply</b><br /><h3>'.$thread['post_topic'].'</h3>';
|
||||||
|
|
||||||
$quote = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : NULL;
|
$quote = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : NULL;
|
||||||
$text = isset($_REQUEST['text']) ? stripslashes(trim($_REQUEST['text'])) : NULL;
|
$text = isset($_REQUEST['text']) ? stripslashes(trim($_REQUEST['text'])) : NULL;
|
||||||
$char_id = (int) (isset($_REQUEST['char_id']) ? $_REQUEST['char_id'] : 0);
|
$char_id = (int) ($_REQUEST['char_id'] ?? 0);
|
||||||
$post_topic = isset($_REQUEST['topic']) ? stripslashes(trim($_REQUEST['topic'])) : '';
|
$post_topic = isset($_REQUEST['topic']) ? stripslashes(trim($_REQUEST['topic'])) : '';
|
||||||
$smile = (isset($_REQUEST['smile']) ? (int)$_REQUEST['smile'] : 0);
|
$smile = (isset($_REQUEST['smile']) ? (int)$_REQUEST['smile'] : 0);
|
||||||
$html = (isset($_REQUEST['html']) ? (int)$_REQUEST['html'] : 0);
|
$html = (isset($_REQUEST['html']) ? (int)$_REQUEST['html'] : 0);
|
||||||
@ -86,8 +89,8 @@ if(Forum::canPost($account_logged))
|
|||||||
if(count($errors) == 0)
|
if(count($errors) == 0)
|
||||||
{
|
{
|
||||||
$saved = true;
|
$saved = true;
|
||||||
Forum::add_post($thread['id'], $thread['section'], $account_logged->getId(), (int) $char_id, $text, $post_topic, $smile, $html, time(), $_SERVER['REMOTE_ADDR']);
|
Forum::add_post($thread['id'], $thread['section'], $account_logged->getId(), (int) $char_id, $text, $post_topic, $smile, $html);
|
||||||
$db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `replies`=`replies`+1, `last_post`=".time()." WHERE `id` = ".(int) $thread_id);
|
$db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `replies`=`replies`+1, `last_post`=".time()." WHERE `id` = ".$thread_id);
|
||||||
$post_page = $db->query("SELECT COUNT(`" . FORUM_TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`author_guid` AND `" . FORUM_TABLE_PREFIX . "forum`.`post_date` <= ".time()." AND `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread['id'])->fetch();
|
$post_page = $db->query("SELECT COUNT(`" . FORUM_TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`author_guid` AND `" . FORUM_TABLE_PREFIX . "forum`.`post_date` <= ".time()." AND `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread['id'])->fetch();
|
||||||
$_page = (int) ceil($post_page['posts_count'] / $config['forum_threads_per_page']) - 1;
|
$_page = (int) ceil($post_page['posts_count'] / $config['forum_threads_per_page']) - 1;
|
||||||
header('Location: ' . getForumThreadLink($thread_id, $_page));
|
header('Location: ' . getForumThreadLink($thread_id, $_page));
|
||||||
@ -123,10 +126,14 @@ if(Forum::canPost($account_logged))
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo "Thread with ID " . $thread_id . " doesn't exist.";
|
$errors[] = "Thread with ID " . $thread_id . " doesn't exist.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$errors[] = "Your account is banned, deleted or you don't have any player with level " . $config['forum_level_required'] . " on your account. You can't post.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
echo "Your account is banned, deleted or you don't have any player with level " . $config['forum_level_required'] . " on your account. You can't post.";
|
|
||||||
|
|
||||||
$twig->display('forum.fullscreen.html.twig');
|
$twig->display('forum.fullscreen.html.twig');
|
||||||
|
@ -95,11 +95,17 @@ if(Forum::canPost($account_logged))
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo 'Board with ID ' . $board_id . ' doesn\'t exist.';
|
$errors[] = "Board with ID $section_id doesn't exist.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$errors[] = 'Please enter section_id.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
echo 'Please enter section_id.';
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo 'Your account is banned, deleted or you don\'t have any player with level '.$config['forum_level_required'].' on your account. You can\'t post.';
|
$errors[] = 'Your account is banned, deleted or you don\'t have any player with level '.$config['forum_level_required'].' on your account. You can\'t post.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
|
@ -31,8 +31,12 @@ if(Forum::isModerator())
|
|||||||
header('Location: ' . getForumThreadLink($post['first_post'], (int) $_page));
|
header('Location: ' . getForumThreadLink($post['first_post'], (int) $_page));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
echo 'Post with ID ' . $id . ' does not exist.';
|
$errors[] = 'Post with ID ' . $id . ' does not exist.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$errors[] = 'You are not logged in or you are not moderator.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
echo 'You are not logged in or you are not moderator.';
|
|
||||||
|
@ -16,12 +16,14 @@ $links_to_pages = '';
|
|||||||
$section_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
|
$section_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
|
||||||
|
|
||||||
if($section_id == null || !isset($sections[$section_id])) {
|
if($section_id == null || !isset($sections[$section_id])) {
|
||||||
echo "Board with this id does't exist.";
|
$errors[] = "Board with this id does't exist.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Forum::hasAccess($section_id)) {
|
if(!Forum::hasAccess($section_id)) {
|
||||||
echo "You don't have access to this board.";
|
$errors[] = "You don't have access to this board.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,5 +93,3 @@ if(isset($last_threads[0]))
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
echo '<h3>No threads in this board.</h3>';
|
echo '<h3>No threads in this board.</h3>';
|
||||||
|
|
||||||
?>
|
|
||||||
|
@ -18,12 +18,14 @@ $_page = (int) ($_REQUEST['page'] ?? 0);
|
|||||||
$thread_starter = $db->query("SELECT `players`.`name`, `" . FORUM_TABLE_PREFIX . "forum`.`post_topic`, `" . FORUM_TABLE_PREFIX . "forum`.`section` FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." AND `" . FORUM_TABLE_PREFIX . "forum`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`first_post` AND `players`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`author_guid` LIMIT 1")->fetch();
|
$thread_starter = $db->query("SELECT `players`.`name`, `" . FORUM_TABLE_PREFIX . "forum`.`post_topic`, `" . FORUM_TABLE_PREFIX . "forum`.`section` FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." AND `" . FORUM_TABLE_PREFIX . "forum`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`first_post` AND `players`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`author_guid` LIMIT 1")->fetch();
|
||||||
|
|
||||||
if(empty($thread_starter['name'])) {
|
if(empty($thread_starter['name'])) {
|
||||||
echo 'Thread with this ID does not exits.';
|
$errors[] = 'Thread with this ID does not exists.';
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Forum::hasAccess($thread_starter['section'])) {
|
if(!Forum::hasAccess($thread_starter['section'])) {
|
||||||
echo "You don't have access to view this thread.";
|
$errors[] = "You don't have access to view this thread.";
|
||||||
|
displayErrorBoxWithBackButton($errors, getLink('forum'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user