From d1953470d9321c586b24aaa106be23f55c92aaad Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 30 Jun 2023 19:32:47 +0200 Subject: [PATCH 1/5] Add word-break on forum thread & reply When someone inserts long word, is will break into multiple lines --- system/templates/forum.new_post.html.twig | 4 ++-- system/templates/forum.show_thread.html.twig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system/templates/forum.new_post.html.twig b/system/templates/forum.new_post.html.twig index 2af93d37..6220cddb 100644 --- a/system/templates/forum.new_post.html.twig +++ b/system/templates/forum.new_post.html.twig @@ -54,7 +54,7 @@ {% set i = 0 %} {% for thread in threads %} - {{ thread.name }}{{ thread.post|raw }} + {{ thread.name }}{{ thread.post|raw }} {% set i = i + 1 %} {% endfor %} - \ No newline at end of file + diff --git a/system/templates/forum.show_thread.html.twig b/system/templates/forum.show_thread.html.twig index e95774ca..80985d43 100644 --- a/system/templates/forum.show_thread.html.twig +++ b/system/templates/forum.show_thread.html.twig @@ -40,7 +40,7 @@ Page: {{ links_to_pages|raw }}

Posts: {{ post.author_posts_count }}
- {{ post.content|raw }} + {{ post.content|raw }} {{ post.date|date('d.m.y H:i:s') }} From 3a31a0326c4b1c91e3c446fd0138ef3c402716e2 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Jul 2023 00:26:33 +0200 Subject: [PATCH 2/5] Fix guild description not shown --- system/templates/guilds.view.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/templates/guilds.view.html.twig b/system/templates/guilds.view.html.twig index 6f70aeca..aff9d540 100644 --- a/system/templates/guilds.view.html.twig +++ b/system/templates/guilds.view.html.twig @@ -49,7 +49,7 @@
- {% if descriptions is not empty %} + {% if description is not empty %} {{ description }}

From c392fa7272c202ce0e3cd016363ce574b39e779f Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Jul 2023 13:48:57 +0200 Subject: [PATCH 3/5] Fix guild description on guilds page --- system/templates/guilds.view.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/templates/guilds.view.html.twig b/system/templates/guilds.view.html.twig index aff9d540..24b250db 100644 --- a/system/templates/guilds.view.html.twig +++ b/system/templates/guilds.view.html.twig @@ -50,7 +50,7 @@
{% if description is not empty %} - {{ description }} + {{ description|raw }}

{% endif %} From 8cf0e800190818e73319ac4d165de3140888716b Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 7 Jul 2023 14:34:26 +0200 Subject: [PATCH 4/5] Forum: better error messages (Suggested by @anyeor) --- system/functions.php | 8 ++++++++ system/pages/forum.php | 6 ++++-- system/pages/forum/edit_post.php | 21 ++++++++++++++------- system/pages/forum/move_thread.php | 18 +++++++++++------- system/pages/forum/new_post.php | 27 +++++++++++++++++---------- system/pages/forum/new_thread.php | 18 ++++++++++++------ system/pages/forum/remove_post.php | 12 ++++++++---- system/pages/forum/show_board.php | 8 ++++---- system/pages/forum/show_thread.php | 6 ++++-- 9 files changed, 82 insertions(+), 42 deletions(-) diff --git a/system/functions.php b/system/functions.php index cb280030..dbf6466d 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1580,6 +1580,14 @@ function getGuildLogoById($id) 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 require_once LIBS . 'validator.php'; require_once SYSTEM . 'compat/base.php'; diff --git a/system/pages/forum.php b/system/pages/forum.php index 85456f2e..5c9688a6 100644 --- a/system/pages/forum.php +++ b/system/pages/forum.php @@ -17,14 +17,16 @@ $errors = []; if(!empty($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')) { require PAGES . 'forum/' . $action . '.php'; return; } 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 d3f95c45..a73920df 100644 --- a/system/pages/forum/edit_post.php +++ b/system/pages/forum/edit_post.php @@ -16,7 +16,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; } @@ -106,11 +107,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 8fcb98fb..3c01a13e 100644 --- a/system/pages/forum/move_thread.php +++ b/system/pages/forum/move_thread.php @@ -16,12 +16,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; } @@ -33,8 +34,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']; @@ -60,7 +63,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')); + } } -?> diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php index a3e68dff..6ef6e264 100644 --- a/system/pages/forum/new_post.php +++ b/system/pages/forum/new_post.php @@ -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(); $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); @@ -86,8 +89,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)); @@ -123,10 +126,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'); diff --git a/system/pages/forum/new_thread.php b/system/pages/forum/new_thread.php index c3b688ad..6a492114 100644 --- a/system/pages/forum/new_thread.php +++ b/system/pages/forum/new_thread.php @@ -95,11 +95,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 bd1e75a4..4469ae77 100644 --- a/system/pages/forum/remove_post.php +++ b/system/pages/forum/remove_post.php @@ -31,8 +31,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.'; diff --git a/system/pages/forum/show_board.php b/system/pages/forum/show_board.php index 36251d8e..09d6e786 100644 --- a/system/pages/forum/show_board.php +++ b/system/pages/forum/show_board.php @@ -16,12 +16,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; } @@ -91,5 +93,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 e6c8f926..0fe28f09 100644 --- a/system/pages/forum/show_thread.php +++ b/system/pages/forum/show_thread.php @@ -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(); 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; } From e7e9d8e3b96855ffd7b69f1f6088aeda34e41190 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 7 Jul 2023 17:15:13 +0200 Subject: [PATCH 5/5] Shorten some forum code about length --- system/pages/forum/edit_post.php | 26 ++++++++++---------------- system/pages/forum/new_post.php | 12 ++++-------- system/pages/forum/new_thread.php | 21 +++++++-------------- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/system/pages/forum/edit_post.php b/system/pages/forum/edit_post.php index a73920df..b2b37441 100644 --- a/system/pages/forum/edit_post.php +++ b/system/pages/forum/edit_post.php @@ -38,24 +38,18 @@ if(Forum::canPost($account_logged)) $post_topic = stripslashes(trim($_REQUEST['topic'])); $smile = isset($_REQUEST['smile']) ? (int)$_REQUEST['smile'] : 0; $html = isset($_REQUEST['html']) ? (int)$_REQUEST['html'] : 0; - $lenght = 0; - for($i = 0; $i < strlen($post_topic); $i++) - { - if(ord($post_topic[$i]) >= 33 && ord($post_topic[$i]) <= 126) - $lenght++; - } - if(($lenght < 1 || strlen($post_topic) > 60) && $thread['id'] == $thread['first_post']) - $errors[] = 'Too short or too long topic (short: '.$lenght.' long: '.strlen($post_topic).' letters). Minimum 1 letter, maximum 60 letters.'; - $lenght = 0; - for($i = 0; $i < strlen($text); $i++) - { - if(ord($text[$i]) >= 33 && ord($text[$i]) <= 126) - $lenght++; - } - if($lenght < 1 || strlen($text) > 15000) - $errors[] = 'Too short or too long post (short: '.$lenght.' long: '.strlen($text).' letters). Minimum 1 letter, maximum 15000 letters.'; + + $length = strlen($post_topic); + if(($length < 1 || $length > 60) && $thread['id'] == $thread['first_post']) + $errors[] = "Too short or too long topic (Length: $length letters). Minimum 1 letter, maximum 60 letters."; + + $length = strlen($text); + if($length < 1 || $length > 15000) + $errors[] = "Too short or too long post (Length: $length letters). Minimum 1 letter, maximum 15000 letters."; + if($char_id == 0) $errors[] = 'Please select a character.'; + if(empty($post_topic) && $thread['id'] == $thread['first_post']) $errors[] = 'Thread topic can\'t be empty.'; diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php index 6ef6e264..31c88a20 100644 --- a/system/pages/forum/new_post.php +++ b/system/pages/forum/new_post.php @@ -54,14 +54,10 @@ if(Forum::canPost($account_logged)) } elseif(isset($_REQUEST['save'])) { - $lenght = 0; - for($i = 0; $i < strlen($text); $i++) - { - if(ord($text[$i]) >= 33 && ord($text[$i]) <= 126) - $lenght++; - } - if($lenght < 1 || strlen($text) > 15000) - $errors[] = 'Too short or too long post (short: '.$lenght.' long: '.strlen($text).' letters). Minimum 1 letter, maximum 15000 letters.'; + $length = strlen($text); + if($length < 1 || strlen($text) > 15000) + $errors[] = 'Too short or too long post (Length: $length letters). Minimum 1 letter, maximum 15000 letters.'; + if($char_id == 0) $errors[] = 'Please select a character.'; diff --git a/system/pages/forum/new_thread.php b/system/pages/forum/new_thread.php index 6a492114..33b57feb 100644 --- a/system/pages/forum/new_thread.php +++ b/system/pages/forum/new_thread.php @@ -32,20 +32,13 @@ if(Forum::canPost($account_logged)) if (isset($_REQUEST['save'])) { $errors = array(); - $lenght = 0; - for ($i = 0; $i < strlen($post_topic); $i++) { - if (ord($post_topic[$i]) >= 33 && ord($post_topic[$i]) <= 126) - $lenght++; - } - if ($lenght < 1 || strlen($post_topic) > 60) - $errors[] = 'Too short or too long topic (short: ' . $lenght . ' long: ' . strlen($post_topic) . ' letters). Minimum 1 letter, maximum 60 letters.'; - $lenght = 0; - for ($i = 0; $i < strlen($text); $i++) { - if (ord($text[$i]) >= 33 && ord($text[$i]) <= 126) - $lenght++; - } - if ($lenght < 1 || strlen($text) > 15000) - $errors[] = 'Too short or too long post (short: ' . $lenght . ' long: ' . strlen($text) . ' letters). Minimum 1 letter, maximum 15000 letters.'; + $length = strlen($post_topic); + if ($length < 1 || $length > 60) + $errors[] = "Too short or too long topic (Length: $length letters). Minimum 1 letter, maximum 60 letters."; + + $length = strlen($text); + if ($length < 1 || $length > 15000) + $errors[] = "Too short or too long post (Length: $length letters). Minimum 1 letter, maximum 15000 letters."; if ($char_id == 0) $errors[] = 'Please select a character.';