* @author Slawkens * @copyright 2017 MyAAC * @version 0.3.0 * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Forum'; if(strtolower($config['forum']) != 'site') { if($config['forum'] != '') { header('Location: ' . $config['forum']); exit; } echo 'Forum is disabled on this site.'; return; } $sections = array(); foreach(getForumSections() as $section) { $sections[$section['id']] = array( 'id' => $section['id'], 'name' => $section['name'], 'description' => $section['description'], 'closed' => $section['closed'] == '1' ); } function parseSmiles($text) { $smileys = array( ';D' => 1, ':D' => 1, ':cool:' => 2, ';cool;' => 2, ':ekk:' => 3, ';ekk;' => 3, ';o' => 4, ';O' => 4, ':o' => 4, ':O' => 4, ':(' => 5, ';(' => 5, ':mad:' => 6, ';mad;' => 6, ';rolleyes;' => 7, ':rolleyes:' => 7, ':)' => 8, ';d' => 9, ':d' => 9, ';)' => 10 ); foreach($smileys as $search => $replace) $text = str_replace($search, ''. $search .'', $text); return $text; } function parseBBCode($text, $smiles) { $rows = 0; while(stripos($text, '[code]') !== false && stripos($text, '[/code]') !== false ) { $code = substr($text, stripos($text, '[code]')+6, stripos($text, '[/code]') - stripos($text, '[code]') - 6); if(!is_int($rows / 2)) { $bgcolor = 'ABED25'; } else { $bgcolor = '23ED25'; } $rows++; $text = str_ireplace('[code]'.$code.'[/code]', 'Code:
'.$code.'
', $text); } $rows = 0; while(stripos($text, '[quote]') !== false && stripos($text, '[/quote]') !== false ) { $quote = substr($text, stripos($text, '[quote]')+7, stripos($text, '[/quote]') - stripos($text, '[quote]') - 7); if(!is_int($rows / 2)) { $bgcolor = 'AAAAAA'; } else { $bgcolor = 'CCCCCC'; } $rows++; $text = str_ireplace('[quote]'.$quote.'[/quote]', '
'.$quote.'
', $text); } $rows = 0; while(stripos($text, '[url]') !== false && stripos($text, '[/url]') !== false ) { $url = substr($text, stripos($text, '[url]')+5, stripos($text, '[/url]') - stripos($text, '[url]') - 5); $text = str_ireplace('[url]'.$url.'[/url]', ''.$url.'', $text); } $xhtml = false; $tags = array( '#\[b\](.*?)\[/b\]#si' => ($xhtml ? '\\1' : '\\1'), '#\[i\](.*?)\[/i\]#si' => ($xhtml ? '\\1' : '\\1'), '#\[u\](.*?)\[/u\]#si' => ($xhtml ? '\\1' : '\\1'), '#\[s\](.*?)\[/s\]#si' => ($xhtml ? '\\1' : '\\1'), '#\[guild\](.*?)\[/guild\]#si' => urldecode(generateLink(getGuildLink('$1', false), '$1', true)), '#\[house\](.*?)\[/house\]#si' => urldecode(generateLink(getHouseLink('$1', false), '$1', true)), '#\[player\](.*?)\[/player\]#si' => urldecode(generateLink(getPlayerLink('$1', false), '$1', true)), // TODO: [poll] tag '#\[color=(.*?)\](.*?)\[/color\]#si' => ($xhtml ? '\\2' : '\\2'), '#\[img\](.*?)\[/img\]#si' => ($xhtml ? '' : ''), '#\[url=(.*?)\](.*?)\[/url\]#si' => '\\2', // '#\[email\](.*?)\[/email\]#si' => '\\1', '#\[code\](.*?)\[/code\]#si' => '\\1', // '#\[align=(.*?)\](.*?)\[/align\]#si' => ($xhtml ? '
\\2
' : '
\\2
'), // '#\[br\]#si' => ($xhtml ? '
' : '
'), ); foreach($tags as $search => $replace) $text = preg_replace($search, $replace, $text); return ($smiles == 0 ? parseSmiles($text) : $text); } function showPost($topic, $text, $smiles) { $text = nl2br($text); $post = ''; if(!empty($topic)) $post .= ''.($smiles == 0 ? parseSmiles($topic) : $topic).'
'; $post .= parseBBCode($text, $smiles); return $post; } if(!$logged) echo 'You are not logged in. Log in to post on the forum.

'; $number_of_rows = 0; if(empty($action)) { $info = $db->query("SELECT `section`, COUNT(`id`) AS 'threads', SUM(`replies`) AS 'replies' FROM `" . TABLE_PREFIX . "forum` WHERE `first_post` = `id` GROUP BY `section`")->fetchAll(); $boards = array(); foreach($info as $data) $counters[$data['section']] = array('threads' => $data['threads'], 'posts' => $data['replies'] + $data['threads']); foreach($sections as $id => $section) { $last_post = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`section` = ".(int) $id." AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` ORDER BY `post_date` DESC LIMIT 1")->fetch(); $boards[] = array( 'link' => getForumBoardLink($id), 'name' => $section['name'], 'description' => $section['description'], 'posts' => isset($counters[$id]['posts']) ? $counters[$id]['posts'] : 0, 'threads' => isset($counters[$id]['threads']) ? $counters[$id]['threads'] : 0, 'last_post' => array( 'name' => isset($last_post['name']) ? $last_post['name'] : null, 'date' => isset($last_post['post_date']) ? $last_post['post_date'] : null, 'player_link' => isset($last_post['name']) ? getPlayerLink($last_post['name']) : null, ) ); } echo $twig->render('forum.boards.html.twig', array( 'boards' => $boards, 'config' => $config )); return; } $links_to_pages = ''; if($action == 'show_board') { $section_id = (int) $_REQUEST['id']; $_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0); $threads_count = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS threads_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`section` = ".(int) $section_id." AND `" . TABLE_PREFIX . "forum`.`first_post` = `" . TABLE_PREFIX . "forum`.`id`")->fetch(); for($i = 0; $i < $threads_count['threads_count'] / $config['forum_threads_per_page']; $i++) { if($i != $_page) $links_to_pages .= ''.($i + 1).' '; else $links_to_pages .= ''.($i + 1).' '; } echo 'Boards >> '.$sections[$section_id]['name'].''; if(!$sections[$section_id]['closed'] || Forum::isModerator()) { echo '

'; } echo '

Page: '.$links_to_pages.'
'; $last_threads = $db->query("SELECT `players`.`id` as `player_id`, `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`last_post`, `" . TABLE_PREFIX . "forum`.`replies`, `" . TABLE_PREFIX . "forum`.`views`, `" . TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`section` = ".(int) $section_id." AND `" . TABLE_PREFIX . "forum`.`first_post` = `" . TABLE_PREFIX . "forum`.`id` ORDER BY `" . TABLE_PREFIX . "forum`.`last_post` DESC LIMIT ".$config['forum_threads_per_page']." OFFSET ".($_page * $config['forum_threads_per_page']))->fetchAll(); if(isset($last_threads[0])) { echo ''; $player = new OTS_Player(); foreach($last_threads as $thread) { echo ''; } echo '
ThreadThread StarterRepliesViewsLast Post
'; if(Forum::isModerator()) { echo '[MOVE]'; echo '[REMOVE] '; } $player->load($thread['player_id']); if(!$player->isLoaded()) { error('Forum error: Player not loaded.'); die(); } $player_account = $player->getAccount(); $canEditForum = $player_account->hasFlag(FLAG_CONTENT_FORUM) || $player_account->isAdmin(); echo ''.($canEditForum ? $thread['post_topic'] : htmlspecialchars($thread['post_topic'])) . '
'.($canEditForum ? substr(strip_tags($thread['post_text']), 0, 50) : htmlspecialchars(substr($thread['post_text'], 0, 50))).'...
' . getPlayerLink($thread['name']) . ''.(int) $thread['replies'].''.(int) $thread['views'].''; if($thread['last_post'] > 0) { $last_post = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread['id']." AND `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` ORDER BY `post_date` DESC LIMIT 1")->fetch(); if(isset($last_post['name'])) echo date('d.m.y H:i:s', $last_post['post_date']).'
by ' . getPlayerLink($last_post['name']); else echo 'No posts.'; } else echo date('d.m.y H:i:s', $thread['post_date']).'
by ' . getPlayerLink($thread['name']); echo '
'; if(!$sections[$section_id]['closed'] || Forum::isModerator()) echo '
'; } else echo '

No threads in this board.

'; return; } if($action == 'show_thread') { $thread_id = (int) $_REQUEST['id']; $_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0); $thread_name = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_topic` 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'])) { $posts_count = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id)->fetch(); for($i = 0; $i < $posts_count['posts_count'] / $config['forum_threads_per_page']; $i++) { if($i != $_page) $links_to_pages .= ''.($i + 1).' '; 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'])) $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) { $player->load($thread['player_id']); if(!$player->isLoaded()) { error('Forum error: Player not loaded.'); die(); } echo ''; } echo '
'.htmlspecialchars($thread_name['post_topic']).'
by ' . getPlayerLink($thread_name['name']) . '
Author 
' . getPlayerLink($thread['name']) . '

Profession: '.$config['vocations'][$player->getVocation()].'
Level: '.$thread['level'].'
'; $rank = $player->getRank(); if($rank->isLoaded()) { $guild = $rank->getGuild(); if($guild->isLoaded()) echo $rank->getName().' of '.$guild->getName().'
'; } $player_account = $player->getAccount(); $canEditForum = $player_account->hasFlag(FLAG_CONTENT_FORUM) || $player_account->isAdmin(); $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'].'
'.showPost(($canEditForum ? $thread['post_topic'] : htmlspecialchars($thread['post_topic'])), ($canEditForum ? $thread['post_text'] : htmlspecialchars($thread['post_text'])), $thread['post_smile']).'
'.date('d.m.y H:i:s', $thread['post_date']); if($thread['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($logged && ($thread['account_id'] == $account_logged->getId() || Forum::isModerator())) echo '
EDIT POST'; if($logged) echo '
Quote'; echo '

'; } else echo 'Thread with this ID does not exits.'; return; } if(!$logged) { header('Location: ' . BASE_URL . '?subtopic=accountmanagement&redirect=' . BASE_URL . urlencode('?subtopic=forum')); return; } if($action == 'remove_post') { if(Forum::isModerator()) { $id = (int) $_REQUEST['id']; $post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$id." LIMIT 1")->fetch(); if($post['id'] == $id) { if($post['id'] == $post['first_post']) { $db->query("DELETE FROM `" . TABLE_PREFIX . "forum` WHERE `first_post` = ".$post['id']); header('Location: ' . getForumBoardLink($post['section'])); } else { $post_page = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`id` < ".$id." AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $post['first_post'])->fetch(); $_page = (int) ceil($post_page['posts_count'] / $config['forum_threads_per_page']) - 1; $db->query("DELETE FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$post['id']); header('Location: ' . getForumThreadLink($post['first_post'], (int) $_page)); } } else echo 'Post with ID ' . $id . ' does not exist.'; } else echo 'You are not logged in or you are not moderator.'; } if($action == 'new_post') { 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 = (int) $_REQUEST['thread_id']; $thread = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $thread_id." AND `" . 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'].'

'; if(isset($thread['id'])) { $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); $post_topic = isset($_REQUEST['topic']) ? stripslashes(trim($_REQUEST['topic'])) : ''; $smile = (int) (isset($_REQUEST['smile']) ? $_REQUEST['smile'] : 0); $saved = false; if(isset($_REQUEST['quote'])) { $quoted_post = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`id` = ".(int) $quote)->fetchAll(); if(isset($quoted_post[0]['name'])) $text = '[i]Originally posted by '.$quoted_post[0]['name'].' on '.date('d.m.y H:i:s', $quoted_post[0]['post_date']).':[/i][quote]'.$quoted_post[0]['post_text'].'[/quote]'; } 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.'; if($char_id == 0) $errors[] = 'Please select a character.'; $player_on_account = false; if(count($errors) == 0) { foreach($players_from_account as $player) if($char_id == $player['id']) $player_on_account = true; if(!$player_on_account) $errors[] = 'Player with selected ID '.$char_id.' doesn\'t exist or isn\'t on your account'; } if(count($errors) == 0) { $last_post = 0; $query = $db->query('SELECT post_date FROM ' . TABLE_PREFIX . 'forum ORDER BY post_date DESC LIMIT 1'); if($query->rowCount() > 0) { $query = $query->fetch(); $last_post = $query['post_date']; } if($last_post+$config['forum_post_interval']-time() > 0 && !Forum::isModerator()) $errors[] = 'You can post one time per '.$config['forum_post_interval'].' seconds. Next post after '.($last_post+$config['forum_post_interval']-time()).' second(s).'; } if(count($errors) == 0) { $saved = true; $db->query("INSERT INTO `" . TABLE_PREFIX . "forum` (`id` ,`first_post` ,`last_post` ,`section` ,`replies` ,`views` ,`author_aid` ,`author_guid` ,`post_text` ,`post_topic` ,`post_smile` ,`post_date` ,`last_edit_aid` ,`edit_date`, `post_ip`) VALUES ('null', '".$thread['id']."', '0', '".$thread['section']."', '0', '0', '".$account_logged->getId()."', '".(int) $char_id."', ".$db->quote($text).", ".$db->quote($post_topic).", '".(int) $smile."', '".time()."', '0', '0', '".$_SERVER['REMOTE_ADDR']."')"); $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `replies`=`replies`+1, `last_post`=".time()." WHERE `id` = ".(int) $thread_id); $post_page = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`post_date` <= ".time()." AND `" . 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)); echo '
Thank you for posting.
GO BACK TO LAST THREAD'; } } if(!$saved) { if(!empty($errors)) echo $twig->render('error_box.html.twig', array('errors' => $errors)); echo '
Post New Reply
Character:
Topic: (Optional)
Message:
You can use:
[player]Nick[/player]
[url]http://address.com/[/url]
[img]http://images.com/images3.gif[/img]
[code]Code[/code]
[b]Text[/b]
[i]Text[/i]
[u]Text[/u]
and smileys:
;) , :) , :D , :( , :rolleyes:
:cool: , :eek: , :o , :p

(Max. 15,000 letters)
Options:
'; $threads = $db->query("SELECT `players`.`name`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_smile` 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` DESC LIMIT 10")->fetchAll(); echo ''; foreach($threads as $thread) { echo ''; } echo '
Last 5 posts from thread: '.$thread['post_topic'].'
'.$thread['name'].''.showPost($thread['post_topic'], $thread['post_text'], $thread['post_smile']).'
'; } } else echo 'Thread with ID '.$thread_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.'; } if($action == 'edit_post') { if(Forum::canPost($account_logged)) { $post_id = (int) $_REQUEST['id']; $thread = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_date`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $post_id." LIMIT 1")->fetch(); if(isset($thread['id'])) { $first_post = $db->query("SELECT `" . TABLE_PREFIX . "forum`.`author_guid`, `" . TABLE_PREFIX . "forum`.`author_aid`, `" . TABLE_PREFIX . "forum`.`first_post`, `" . TABLE_PREFIX . "forum`.`post_topic`, `" . TABLE_PREFIX . "forum`.`post_text`, `" . TABLE_PREFIX . "forum`.`post_smile`, `" . TABLE_PREFIX . "forum`.`id`, `" . TABLE_PREFIX . "forum`.`section` FROM `" . TABLE_PREFIX . "forum` WHERE `" . TABLE_PREFIX . "forum`.`id` = ".(int) $thread['first_post']." LIMIT 1")->fetch(); echo 'Boards >> '.$sections[$thread['section']]['name'].' >> '.$first_post['post_topic'].' >> Edit post'; if($account_logged->getId() == $thread['author_aid'] || Forum::isModerator()) { $players_from_account = $db->query("SELECT `players`.`name`, `players`.`id` FROM `players` WHERE `players`.`account_id` = ".(int) $account_logged->getId())->fetchAll(); $saved = false; if(isset($_REQUEST['save'])) { $text = stripslashes(trim($_REQUEST['text'])); $char_id = (int) $_REQUEST['char_id']; $post_topic = stripslashes(trim($_REQUEST['topic'])); $smile = (int) $_REQUEST['smile']; $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.'; 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.'; $player_on_account == false; if(count($errors) == 0) { foreach($players_from_account as $player) if($char_id == $player['id']) $player_on_account = true; if(!$player_on_account) $errors[] = 'Player with selected ID '.$char_id.' doesn\'t exist or isn\'t on your account'; } if(count($errors) == 0) { $saved = true; if($account_logged->getId() != $thread['author_aid']) $char_id = $thread['author_guid']; $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `author_guid` = ".(int) $char_id.", `post_text` = ".$db->quote($text).", `post_topic` = ".$db->quote($post_topic).", `post_smile` = ".(int) $smile.", `last_edit_aid` = ".(int) $account_logged->getId().",`edit_date` = ".time()." WHERE `id` = ".(int) $thread['id']); $post_page = $db->query("SELECT COUNT(`" . TABLE_PREFIX . "forum`.`id`) AS posts_count FROM `players`, `" . TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . TABLE_PREFIX . "forum`.`author_guid` AND `" . TABLE_PREFIX . "forum`.`post_date` <= ".$thread['post_date']." AND `" . TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread['first_post'])->fetch(); $_page = (int) ceil($post_page['posts_count'] / $config['forum_threads_per_page']) - 1; header('Location: ' . getForumThreadLink($thread['first_post'], $_page)); echo '
Thank you for editing post.
GO BACK TO LAST THREAD'; } } else { $text = $thread['post_text']; $char_id = (int) $thread['author_guid']; $post_topic = $thread['post_topic']; $smile = (int) $thread['post_smile']; } if(!$saved) { if(!empty($errors)) echo $twig->render('error_box.html.twig', array('errors' => $errors)); echo '
Edit Post
Character:
Topic: (Optional)
Message:
You can use:
[player]Nick[/player]
[url]http://address.com/[/url]
[img]http://images.com/images3.gif[/img]
[code]Code[/code]
[b]Text[/b]
[i]Text[/i]
[u]Text[/u]
and smileys:
;) , :) , :D , :( , :rolleyes:
:cool: , :eek: , :o , :p

(Max. 15,000 letters)
Options:
'; } } else echo '
You are not an author of this post.'; } 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.'; } if($action == 'new_thread') { 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(); $section_id = isset($_REQUEST['section_id']) ? $_REQUEST['section_id'] : null; if($section_id !== null) { echo 'Boards >> ' . $sections[$section_id]['name'] . ' >> Post new thread
'; if (isset($sections[$section_id]['name'])) { if ($sections[$section_id]['closed'] && !Forum::isModerator()) $errors[] = 'You cannot create topic on this board.'; $quote = (int)(isset($_REQUEST['quote']) ? $_REQUEST['quote'] : 0); $text = isset($_REQUEST['text']) ? stripslashes($_REQUEST['text']) : ''; $char_id = (int)(isset($_REQUEST['char_id']) ? $_REQUEST['char_id'] : 0); $post_topic = isset($_REQUEST['topic']) ? stripslashes($_REQUEST['topic']) : ''; $smile = (int)(isset($_REQUEST['smile']) ? $_REQUEST['smile'] : 0); $saved = false; 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.'; if ($char_id == 0) $errors[] = 'Please select a character.'; $player_on_account = false; if (count($errors) == 0) { foreach ($players_from_account as $player) if ($char_id == $player['id']) $player_on_account = true; if (!$player_on_account) $errors[] = 'Player with selected ID ' . $char_id . ' doesn\'t exist or isn\'t on your account'; } if (count($errors) == 0) { $last_post = 0; $query = $db->query('SELECT `post_date` FROM `' . TABLE_PREFIX . 'forum` ORDER BY `post_date` DESC LIMIT 1'); if ($query->rowCount() > 0) { $query = $query->fetch(); $last_post = $query['post_date']; } if ($last_post + $config['forum_post_interval'] - time() > 0 && !Forum::isModerator()) $errors[] = 'You can post one time per ' . $config['forum_post_interval'] . ' seconds. Next post after ' . ($last_post + $config['forum_post_interval'] - time()) . ' second(s).'; } if (count($errors) == 0) { $saved = true; $db->query("INSERT INTO `" . TABLE_PREFIX . "forum` (`first_post` ,`last_post` ,`section` ,`replies` ,`views` ,`author_aid` ,`author_guid` ,`post_text` ,`post_topic` ,`post_smile` ,`post_date` ,`last_edit_aid` ,`edit_date`, `post_ip`) VALUES ('0', '" . time() . "', '" . (int)$section_id . "', '0', '0', '" . $account_logged->getId() . "', '" . (int)$char_id . "', " . $db->quote($text) . ", " . $db->quote($post_topic) . ", '" . (int)$smile . "', '" . time() . "', '0', '0', '" . $_SERVER['REMOTE_ADDR'] . "')"); $thread_id = $db->lastInsertId(); $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `first_post`=" . (int)$thread_id . " WHERE `id` = " . (int)$thread_id); header('Location: ' . getForumThreadLink($thread_id)); echo '
Thank you for posting.
GO BACK TO LAST THREAD'; } } if (!$saved) { if (!empty($errors)) echo $twig->render('error_box.html.twig', array('errors' => $errors)); echo $twig->render('forum.new_thread.html.twig', array( 'section_id' => $section_id, 'config' => $config, 'players' => $players_from_account, 'post_player_id' => $char_id, 'post_thread' => $post_topic, 'text' => $text, 'smiles_enabled' => $smile > 0 )); } } else echo 'Board with ID ' . $board_id . ' doesn\'t exist.'; } 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.'; } //Board Change Function. Scripted by Cybermaster and Absolute Mango if($action == 'move_thread') { if(Forum::isModerator()) { $id = (int) $_REQUEST['id']; $post = $db->query("SELECT `id`, `section`, `first_post`, `post_topic`, `author_guid` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$id." LIMIT 1")->fetch(); $name= $db->query("SELECT `name` FROM `players` WHERE `id` = ".$post['author_guid']." ")->fetch(); if($post['id'] == $id) { if($post['id'] == $post['first_post']) { echo $twig->render('forum.move_thread.html.twig', array( 'thread' => $post['post_topic'], 'author' => $name[0], 'board' => $sections[$post['section']]['name'], 'post_id' => $post['id'], 'sections' => $sections, 'section_link' => getForumBoardLink($post['section']), 'config' => $config )); /* echo '
Move thread to another board
THREAD: '.$post['post_topic'].'
AUTHOR: '.$name[0].'
BOARD: '.$sections[$post['section']]['name'].'

Select the new board: 
';*/ } } else echo 'Post with ID '.$id.' does not exist.'; } else echo 'You are not logged in or you are not moderator.'; } if($action == 'moved_thread') { if(Forum::isModerator()) { $id = (int) $_REQUEST['id']; $board = (int) $_REQUEST['section']; $post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$id." LIMIT 1")->fetch(); if($post['id'] == $id) { if($post['id'] == $post['first_post']) { $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `section` = ".$board." WHERE `id` = ".$post['id']."") or die(mysql_error()); $nPost = $db->query( 'SELECT `section` FROM `' . TABLE_PREFIX . 'forum` WHERE `id` = \''.$id.'\' LIMIT 1;' )->fetch(); header('Location: ' . getForumBoardLink($nPost['section'])); } } else echo 'Post with ID ' . $id . ' does not exist.'; } else echo 'You are not logged in or you are not moderator.'; } class Forum { static public function canPost($account) { global $db, $config; if(!$account->isLoaded() || $account->isBanned()) return false; if(self::isModerator()) return true; return $db->query( 'SELECT `id` FROM `players` WHERE `account_id` = ' . $db->quote($account->getId()) . ' AND `level` >= ' . $db->quote($config['forum_level_required']) . ' LIMIT 1')->rowCount() > 0; } static public function isModerator() { return hasFlag(FLAG_CONTENT_FORUM) || admin(); } }