From 544375378f19399544e4da393d52ea7298b000b0 Mon Sep 17 00:00:00 2001 From: slawkens1 Date: Sat, 6 Jan 2018 01:46:36 +0100 Subject: [PATCH] * show user avatar (outfit) in forum posts * show user position (group) in forum posts * replaced forum actions links (move, remove, edit, quote) with images * redirect directly to the thread on user login (on new reply) * fixed account login redirect with special chars (like '&' and '?') --- TODO | 4 - images/icons/comment_add.png | Bin 0 -> 530 bytes system/pages/forum.php | 7 +- system/pages/forum/show_thread.php | 91 +++++++++++-------- system/templates/account.redirect.html.twig | 2 +- system/templates/forum.show_thread.html.twig | 75 +++++++++++++++ 6 files changed, 136 insertions(+), 43 deletions(-) create mode 100644 images/icons/comment_add.png create mode 100644 system/templates/forum.show_thread.html.twig diff --git a/TODO b/TODO index b77e1d81..befd3b34 100644 --- a/TODO +++ b/TODO @@ -16,10 +16,6 @@ * hooks * fieldExist and tableExist functions * Menus in templates - * forum: - * show position of the player - * replace forum actions links for admin (move, remove) with images - * redirect directly to the thread on user login * characters: edit in admin panel option * move highscores to twig * $db->hasTable(table) + $db->hasColumn(table, column) diff --git a/images/icons/comment_add.png b/images/icons/comment_add.png new file mode 100644 index 0000000000000000000000000000000000000000..75e78dede2c9cc3b789b880e5cfc930e60bf2c91 GIT binary patch literal 530 zcmV+t0`2{YP)~sR==D{nWel_pb&wQ zmrP)tTX!KGk)Sk|wtZaUrliFMw8)@DB*yUg%5WWG5T6(V4-98P2Jan%`$mH2CMxfq z+T@bruYw${Wles0MWFb|;3xR>p5Y`0A6-c}5Tk;D`5i8(NGiA>_&gYcZy8+IQP@fF zZXmTF{tLW(AMNV7m2gb(;iZIqf*k=ah{%H8=`Ai$Cv75^d>yNTn3+NncKU5>gquery("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`section` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." AND `" . TABLE_PREFIX . "forum`.`id` = `" . TABLE_PREFIX . "forum`.`first_post` AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` LIMIT 1")->fetch(); +$thread_starter = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`section` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." AND `" . TABLE_PREFIX . "forum`.`id` = `" . TABLE_PREFIX . "forum`.`first_post` AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` LIMIT 1")->fetch(); -if(empty($thread_name['name'])) { +if(empty($thread_starter['name'])) { echo 'Thread with this ID does not exits.'; return; } -if(!Forum::hasAccess($thread_name['section'])) { +if(!Forum::hasAccess($thread_starter['section'])) { echo "You don't have access to view this thread."; return; } @@ -33,60 +33,77 @@ for($i = 0; $i < $posts_count['posts_count'] / $config['forum_threads_per_page'] else $links_to_pages .= ''.($i + 1).' '; } -$threads = $db->query("SELECT `players`.`id` as `player_id`, `players`.`name`, `players`.`account_id`, `players`.`vocation`" . (fieldExist('promotion', 'players') ? ", `players`.`promotion`" : "") . ", `players`.`level`, `" . TABLE_PREFIX . "forum`.`id`,`" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`section`,`" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_date`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`last_edit_aid`, `" . TABLE_PREFIX . "forum`.`edit_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." ORDER BY `" . TABLE_PREFIX . "forum`.`post_date` LIMIT ".$config['forum_posts_per_page']." OFFSET ".($_page * $config['forum_posts_per_page']))->fetchAll(); -if(isset($threads[0]['name'])) +$posts = $db->query("SELECT `players`.`id` as `player_id`, `" . TABLE_PREFIX . "forum`.`id`,`" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`section`,`" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_date` AS `date`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`last_edit_aid`, `" . TABLE_PREFIX . "forum`.`edit_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." ORDER BY `" . TABLE_PREFIX . "forum`.`post_date` LIMIT ".$config['forum_posts_per_page']." OFFSET ".($_page * $config['forum_posts_per_page']))->fetchAll(); +if(isset($posts[0]['player_id'])) { $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `views`=`views`+1 WHERE `id` = ".(int) $thread_id); -echo 'Boards >> '.$sections[$threads[0]['section']]['name'].' >> '.$thread_name['post_topic'].''; -echo '



Page: '.$links_to_pages.'
'; -$player = $ots->createObject('Player'); -foreach($threads as $thread) +} + +$groups = new OTS_Groups_List(); +foreach($posts as &$post) { - $player->load($thread['player_id']); + $post['player'] = new OTS_Player(); + $player = $post['player']; + $player->load($post['player_id']); if(!$player->isLoaded()) { error('Forum error: Player not loaded.'); die(); } - echo ' - '; + else { + $post['edited_by'] = $player->getName(); + } + } } -echo '
'.htmlspecialchars($thread_name['post_topic']).'
by ' . getPlayerLink($thread_name['name']) . '
Author 
' . getPlayerLink($thread['name']) . '

Profession: '.$config['vocations'][$player->getVocation()].'
Level: '.$thread['level'].'
'; + if($config['characters']['outfit']) { + $post['outfit'] = $config['outfit_images_url'] . '?id=' . $player->getLookType() . (fieldExist('lookaddons', 'players') ? '&addons=' . $player->getLookAddons() : '') . '&head=' . $player->getLookHead() . '&body=' . $player->getLookBody() . '&legs=' . $player->getLookLegs() . '&feet=' . $player->getLookFeet(); + } + + $groupName = ''; + $group = $player->getGroup(); + if($group->isLoaded()) { + $groupName = $group->getName(); + } + $post['group'] = $groupName; + $post['player_link'] = getPlayerLink($player->getName()); + + $post['vocation'] = 'Unknown'; + if(isset($config['vocations'][$player->getVocation()])) { + $post['vocation'] = $config['vocations'][$player->getVocation()]; + } + $rank = $player->getRank(); if($rank->isLoaded()) { $guild = $rank->getGuild(); if($guild->isLoaded()) - echo $rank->getName().' of '.$guild->getName().'
'; + $post['guildRank'] = $rank->getName().' of '.$guild->getName().''; } $player_account = $player->getAccount(); $canEditForum = $player_account->hasFlag(FLAG_CONTENT_FORUM) || $player_account->isAdmin(); // check if its news written in tinymce - $bb_code = ($thread['post_text'] == strip_tags($thread['post_text'])) || (!$player_account->hasFlag(FLAG_CONTENT_NEWS) && !$player_account->isSuperAdmin()); + $bb_code = ($post['post_text'] == strip_tags($post['post_text'])) || (!$player_account->hasFlag(FLAG_CONTENT_NEWS) && !$player_account->isSuperAdmin()); - $posts = $db->query("SELECT COUNT(`id`) AS 'posts' FROM `" . TABLE_PREFIX . "forum` WHERE `author_aid`=".(int) $thread['account_id'])->fetch(); - echo '
Posts: '.(int) $posts['posts'].'
'.Forum::showPost(($canEditForum ? $thread['post_topic'] : htmlspecialchars($thread['post_topic'])), ($canEditForum ? $thread['post_text'] : htmlspecialchars($thread['post_text'])), $thread['post_smile'], $bb_code).'
'.date('d.m.y H:i:s', $thread['post_date']); - if($thread['edit_date'] > 0) + $post['content'] = Forum::showPost(($canEditForum ? $post['post_topic'] : htmlspecialchars($post['post_topic'])), ($canEditForum ? $post['post_text'] : htmlspecialchars($post['post_text'])), $post['post_smile'], $bb_code); + + $query = $db->query("SELECT COUNT(`id`) AS 'posts' FROM `" . TABLE_PREFIX . "forum` WHERE `author_aid`=".(int) $player_account->getId())->fetch(); + $post['author_posts_count'] = (int)$query['posts']; + + if($post['edit_date'] > 0) { - if($thread['last_edit_aid'] != $thread['author_aid']) - echo '
Edited by moderator'; - else - echo '
Edited by '.$thread['name']; - echo '
on '.date('d.m.y H:i:s', $thread['edit_date']); - } - echo '
'; - if(Forum::isModerator()) - if($thread['first_post'] != $thread['id']) - echo 'REMOVE POST'; - else - { - echo '[MOVE]'; - echo '
REMOVE THREAD'; + if($post['last_edit_aid'] != $post['author_aid']) { + $post['edited_by'] = 'moderator'; } - if($logged && ($thread['account_id'] == $account_logged->getId() || Forum::isModerator())) - echo '
EDIT POST'; - if($logged) - echo '
Quote'; - echo '

'; + +echo $twig->render('forum.show_thread.html.twig', array( + 'thread_id' => $thread_id, + 'posts' => $posts, + 'links_to_pages' => $links_to_pages, + 'author_link' => getPlayerLink($thread_starter['name']), + 'section' => array('id' => $posts[0]['section'], 'name' => $sections[$posts[0]['section']]['name']), + 'thread_starter' => $thread_starter, + 'is_moderator' => Forum::isModerator() +)); + echo $twig->render('forum.fullscreen.html.twig'); diff --git a/system/templates/account.redirect.html.twig b/system/templates/account.redirect.html.twig index ac439308..16b8d7ba 100644 --- a/system/templates/account.redirect.html.twig +++ b/system/templates/account.redirect.html.twig @@ -31,6 +31,6 @@ // Automatic redirect setTimeout ("automaticRedirect()", 1000); function automaticRedirect() { - window.location = "{{ redirect }}"; + window.location = "{{ redirect|raw }}"; } \ No newline at end of file diff --git a/system/templates/forum.show_thread.html.twig b/system/templates/forum.show_thread.html.twig new file mode 100644 index 00000000..46c159e9 --- /dev/null +++ b/system/templates/forum.show_thread.html.twig @@ -0,0 +1,75 @@ +Boards >> {{ section.name }} >> {{ thread_starter.post_topic }} +

+
+
+Page: {{ links_to_pages|raw }}
+ + + + + + + + + + {% set i = 0 %} + {% for post in posts %} + + {% set i = i + 1 %} + + + + + + + {% set i = i + 1 %} + {% endfor %} +
+ {{ thread_starter.post_topic }} +
+ by {{ author_link|raw }}
+
+ Author +  
{{ post.player_link|raw }}
+ {% if post.outfit is defined %} + player outfit +
+ {% endif %} + + {% if post.group is defined and post.group|lower != 'player' %} + Position: {{ post.group }}
+ {% endif %} + + Profession: {{ post.vocation }}
+ Level: {{ post.player.getLevel() }}
+ {% if post.guildRank is defined %} + {{ guildRank }}
+ {% endif %} +
Posts: {{ post.author_posts_count }}
+
+
{{ post.content|raw }}
+ {{ post.date|date('d.m.y H:i:s') }} + {% if post.edited_by is defined %} +
Edited by {{ post.edited_by }} +
on {{ post.edit_date|date('d.m.y H:i:s') }} + {% endif %} +
+
+ {% if is_moderator %} + {% if post.first_post != post.id %} + + {% else %} + + + {% endif %} + {% if logged and (post.player.getAccount().getId() == account_logged.getId() or is_moderator) %} + + + {% endif %} + {% if logged %} + + {% endif %} + {% endif %} +
+
+ \ No newline at end of file