diff --git a/system/functions.php b/system/functions.php
index fc0d3c7f..3a8836b5 100644
--- a/system/functions.php
+++ b/system/functions.php
@@ -1247,6 +1247,14 @@ function escapeHtml($html) {
return htmlentities($html, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
+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
require_once LIBS . 'validator.php';
require_once SYSTEM . 'compat/base.php';
diff --git a/system/pages/forum.php b/system/pages/forum.php
index 12ec64e0..08d67052 100644
--- a/system/pages/forum.php
+++ b/system/pages/forum.php
@@ -191,12 +191,13 @@ if(!$logged)
}
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')) {
require PAGES . 'forum/' . $action . '.php';
}
else {
- error('This page does not exists.');
+ $errors[] = 'This page does not exists.';
+ displayErrorBoxWithBackButton($errors, getLink('forum'));
}
-?>
diff --git a/system/pages/forum/edit_post.php b/system/pages/forum/edit_post.php
index b765899f..d9364f65 100644
--- a/system/pages/forum/edit_post.php
+++ b/system/pages/forum/edit_post.php
@@ -14,7 +14,8 @@ if(Forum::canPost($account_logged))
{
$post_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : false;
if(!$post_id) {
- echo 'Please enter post id.';
+ $errors[] = 'Please enter post id.';
+ displayErrorBoxWithBackButton($errors, getLink('forum'));
return;
}
@@ -104,11 +105,17 @@ if(Forum::canPost($account_logged))
));
}
}
- else
- echo '
You are not an author of this post.';
+ else {
+ $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 "
Post with ID " . $post_id . " doesn't exist.";
}
-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.";
+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'));
+}
diff --git a/system/pages/forum/move_thread.php b/system/pages/forum/move_thread.php
index 48fb08f0..ff30d769 100644
--- a/system/pages/forum/move_thread.php
+++ b/system/pages/forum/move_thread.php
@@ -14,12 +14,13 @@ if(!Forum::isModerator()) {
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) {
$post_id = (int)$_REQUEST['id'];
$board = (int)$_REQUEST['section'];
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;
}
@@ -31,8 +32,10 @@ if($save) {
header('Location: ' . getForumBoardLink($nPost['section']));
}
}
- else
- echo 'Post with ID ' . $post_id . ' does not exist.';
+ else {
+ $errors[] = 'Post with ID ' . $post_id . ' does not exist.';
+ displayErrorBoxWithBackButton($errors, getLink('forum'));
+ }
}
else {
$post_id = (int)$_REQUEST['id'];
@@ -58,7 +61,8 @@ else {
));
}
}
- else
- echo 'Post with ID ' . $post_id . ' does not exist.';
+ else {
+ $errors[] = 'Post with ID ' . $post_id . ' does not exist.';
+ displayErrorBoxWithBackButton($errors, getLink('forum'));
+ }
}
-?>
\ No newline at end of file
diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php
index 436e162d..3da3e22b 100644
--- a/system/pages/forum/new_post.php
+++ b/system/pages/forum/new_post.php
@@ -15,17 +15,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();
$thread_id = isset($_REQUEST['thread_id']) ? (int) $_REQUEST['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;
}
- $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();
- echo 'Boards >> '.$sections[$thread['section']]['name'].' >> '.$thread['post_topic'].' >> Post new reply
'.$thread['post_topic'].'
';
+ $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();
+
if(isset($thread['id']) && Forum::hasAccess($thread['section']))
{
+ echo 'Boards >> '.$sections[$thread['section']]['name'].' >> '.$thread['post_topic'].' >> Post new reply
'.$thread['post_topic'].'
';
+
$quote = isset($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : 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'])) : '';
$smile = (isset($_REQUEST['smile']) ? (int)$_REQUEST['smile'] : 0);
$html = (isset($_REQUEST['html']) ? (int)$_REQUEST['html'] : 0);
@@ -73,8 +76,8 @@ if(Forum::canPost($account_logged))
if(count($errors) == 0)
{
$saved = true;
- Forum::add_post($thread['id'], $thread['section'], $account_logged->getId(), (int) $char_id, $text, $post_topic, $smile, $html, time(), $_SERVER['REMOTE_ADDR']);
- $db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `replies`=`replies`+1, `last_post`=".time()." WHERE `id` = ".(int) $thread_id);
+ 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` = ".$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();
$_page = (int) ceil($post_page['posts_count'] / $config['forum_threads_per_page']) - 1;
header('Location: ' . getForumThreadLink($thread_id, $_page));
@@ -110,10 +113,14 @@ if(Forum::canPost($account_logged))
));
}
}
- else
- echo "Thread with ID " . $thread_id . " doesn't exist.";
+ else {
+ $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');
\ No newline at end of file
+$twig->display('forum.fullscreen.html.twig');
diff --git a/system/pages/forum/new_thread.php b/system/pages/forum/new_thread.php
index d9223e50..10dc5c22 100644
--- a/system/pages/forum/new_thread.php
+++ b/system/pages/forum/new_thread.php
@@ -93,11 +93,17 @@ if(Forum::canPost($account_logged))
));
}
}
- else
- echo 'Board with ID ' . $board_id . ' doesn\'t exist.';
+ else {
+ $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
- 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.';
+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'));
+}
diff --git a/system/pages/forum/remove_post.php b/system/pages/forum/remove_post.php
index caef6a03..d1a3175e 100644
--- a/system/pages/forum/remove_post.php
+++ b/system/pages/forum/remove_post.php
@@ -29,8 +29,12 @@ if(Forum::isModerator())
header('Location: ' . getForumThreadLink($post['first_post'], (int) $_page));
}
}
- else
- echo 'Post with ID ' . $id . ' does not exist.';
+ else {
+ $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.';
\ No newline at end of file
diff --git a/system/pages/forum/show_board.php b/system/pages/forum/show_board.php
index 2828f8f0..f7d79c9e 100644
--- a/system/pages/forum/show_board.php
+++ b/system/pages/forum/show_board.php
@@ -14,12 +14,14 @@ $links_to_pages = '';
$section_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
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;
}
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;
}
@@ -90,5 +92,3 @@ if(isset($last_threads[0]))
}
else
echo 'No threads in this board.
';
-
-?>
diff --git a/system/pages/forum/show_thread.php b/system/pages/forum/show_thread.php
index bf6cda75..54f43ee7 100644
--- a/system/pages/forum/show_thread.php
+++ b/system/pages/forum/show_thread.php
@@ -16,12 +16,14 @@ $_page = (int) (isset($_REQUEST['page']) ? $_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();
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;
}
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;
}