diff --git a/config.php b/config.php
index fadf0a92..40c283a5 100644
--- a/config.php
+++ b/config.php
@@ -241,6 +241,8 @@ $config = array(
'forum_post_interval' => 30, // in seconds
'forum_posts_per_page' => 20,
'forum_threads_per_page' => 20,
+ // uncomment to force use table for forum
+ //'forum_table_prefix' => 'z_', // what forum mysql table to use, z_ (for gesior old forum) or myaac_ (for myaac)
// last kills
'last_kills_limit' => 50, // max. number of deaths shown on the last kills page
diff --git a/install/tools/5-database.php b/install/tools/5-database.php
index fe08380a..6ac0af2c 100644
--- a/install/tools/5-database.php
+++ b/install/tools/5-database.php
@@ -214,3 +214,23 @@ if($db->hasColumn('players', 'rank_id')) {
}
}
}
+
+if($db->hasTable('z_forum')) {
+ if(!$db->hasColumn('z_forum', 'post_html')) {
+ if(query("ALTER TABLE `z_forum` ADD `post_html` tinyint(1) NOT NULL DEFAULT '0' AFTER `post_smile`;")) {
+ success($locale['step_database_adding_field'] . ' z_forum.post_html...');
+ }
+ }
+
+ if(!$db->hasColumn('z_forum', 'sticked')) {
+ if(query("ALTER TABLE `z_forum` ADD `sticked` tinyint(1) NOT NULL DEFAULT '0';")) {
+ success($locale['step_database_adding_field'] . ' z_forum.sticked...');
+ }
+ }
+
+ if(!$db->hasColumn('z_forum', 'closed')) {
+ if(query("ALTER TABLE `z_forum` ADD `closed` tinyint(1) NOT NULL DEFAULT '0';")) {
+ success($locale['step_database_adding_field'] . ' z_forum.closed...');
+ }
+ }
+}
\ No newline at end of file
diff --git a/system/libs/forum.php b/system/libs/forum.php
index 68374622..648a9d99 100644
--- a/system/libs/forum.php
+++ b/system/libs/forum.php
@@ -10,6 +10,23 @@
*/
defined('MYAAC') or die('Direct access not allowed!');
+$configForumTablePrefix = config('forum_table_prefix');
+if(!empty(trim($configForumTablePrefix))) {
+ if(!in_array($configForumTablePrefix, array('myaac_', 'z_'))) {
+ throw new RuntimeException('Invalid value for forum_table_prefix in config.php. Can be only: "myaac_" or "z_".');
+ }
+
+ define('FORUM_TABLE_PREFIX', $configForumTablePrefix);
+}
+else {
+ if($db->hasTable('z_forum')) {
+ define('FORUM_TABLE_PREFIX', 'z_');
+ }
+ else {
+ define('FORUM_TABLE_PREFIX', 'myaac_');
+ }
+}
+
class Forum
{
/**
@@ -42,7 +59,7 @@ class Forum
{
global $db;
$thread_id = 0;
- if($db->insert(TABLE_PREFIX . 'forum', array(
+ if($db->insert(FORUM_TABLE_PREFIX . 'forum', array(
'first_post' => 0,
'last_post' => time(),
'section' => $section_id,
@@ -57,7 +74,7 @@ class Forum
'post_ip' => $_SERVER['REMOTE_ADDR']
))) {
$thread_id = $db->lastInsertId();
- $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `first_post`=".(int) $thread_id." WHERE `id` = ".(int) $thread_id);
+ $db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `first_post`=".(int) $thread_id." WHERE `id` = ".(int) $thread_id);
}
return $thread_id;
@@ -66,7 +83,7 @@ class Forum
public static function add_post($thread_id, $section, $author_aid, $author_guid, $post_text, $post_topic, $smile, $html)
{
global $db;
- $db->insert(TABLE_PREFIX . 'forum', array(
+ $db->insert(FORUM_TABLE_PREFIX . 'forum', array(
'first_post' => $thread_id,
'section' => $section,
'author_aid' => $author_aid,
diff --git a/system/pages/forum.php b/system/pages/forum.php
index af7ba0f6..12ec64e0 100644
--- a/system/pages/forum.php
+++ b/system/pages/forum.php
@@ -136,7 +136,7 @@ foreach(getForumBoards() as $section)
$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();
+ $info = $db->query("SELECT `section`, COUNT(`id`) AS 'threads', SUM(`replies`) AS 'replies' FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `first_post` = `id` GROUP BY `section`")->fetchAll();
$boards = array();
foreach($info as $data)
@@ -145,7 +145,7 @@ if(empty($action))
{
$show = true;
if(Forum::hasAccess($id)) {
- $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();
+ $last_post = $db->query("SELECT `players`.`name`, `" . FORUM_TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`section` = ".(int) $id." AND `players`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`author_guid` ORDER BY `post_date` DESC LIMIT 1")->fetch();
$boards[] = array(
'id' => $id,
'link' => getForumBoardLink($id),
diff --git a/system/pages/forum/edit_post.php b/system/pages/forum/edit_post.php
index cf44565b..f522c5e6 100644
--- a/system/pages/forum/edit_post.php
+++ b/system/pages/forum/edit_post.php
@@ -18,10 +18,10 @@ if(Forum::canPost($account_logged))
return;
}
- $thread = $db->query("SELECT `author_guid`, `author_aid`, `first_post`, `post_topic`, `post_date`, `post_text`, `post_smile`, `post_html`, `id`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = ".$post_id." LIMIT 1")->fetch();
+ $thread = $db->query("SELECT `author_guid`, `author_aid`, `first_post`, `post_topic`, `post_date`, `post_text`, `post_smile`, `post_html`, `id`, `section` FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `id` = ".$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();
+ $first_post = $db->query("SELECT `" . FORUM_TABLE_PREFIX . "forum`.`author_guid`, `" . FORUM_TABLE_PREFIX . "forum`.`author_aid`, `" . FORUM_TABLE_PREFIX . "forum`.`first_post`, `" . FORUM_TABLE_PREFIX . "forum`.`post_topic`, `" . FORUM_TABLE_PREFIX . "forum`.`post_text`, `" . FORUM_TABLE_PREFIX . "forum`.`post_smile`, `" . FORUM_TABLE_PREFIX . "forum`.`id`, `" . FORUM_TABLE_PREFIX . "forum`.`section` FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`id` = ".(int) $thread['first_post']." LIMIT 1")->fetch();
echo 'Boards >> '.$sections[$thread['section']]['name'].' >> '.$first_post['post_topic'].' >> Edit post';
if(Forum::hasAccess($thread['section'] && ($account_logged->getId() == $thread['author_aid'] || Forum::isModerator())))
{
@@ -71,8 +71,8 @@ if(Forum::canPost($account_logged))
$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` = ".$smile.", `post_html` = ".$html.", `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();
+ $db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `author_guid` = ".(int) $char_id.", `post_text` = ".$db->quote($text).", `post_topic` = ".$db->quote($post_topic).", `post_smile` = ".$smile.", `post_html` = ".$html.", `last_edit_aid` = ".(int) $account_logged->getId().",`edit_date` = ".time()." WHERE `id` = ".(int) $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` <= ".$thread['post_date']." AND `" . FORUM_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';
diff --git a/system/pages/forum/move_thread.php b/system/pages/forum/move_thread.php
index f48a610a..48fb08f0 100644
--- a/system/pages/forum/move_thread.php
+++ b/system/pages/forum/move_thread.php
@@ -23,11 +23,11 @@ if($save) {
return;
}
- $post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = " . $post_id . " LIMIT 1")->fetch();
+ $post = $db->query("SELECT `id`, `first_post`, `section` FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `id` = " . $post_id . " LIMIT 1")->fetch();
if ($post['id'] == $post_id) {
if ($post['id'] == $post['first_post']) {
- $db->query("UPDATE `" . TABLE_PREFIX . "forum` SET `section` = " . $board . " WHERE `id` = " . $post['id'] . "");
- $nPost = $db->query('SELECT `section` FROM `' . TABLE_PREFIX . 'forum` WHERE `id` = \'' . $post_id . '\' LIMIT 1;')->fetch();
+ $db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `section` = " . $board . " WHERE `id` = " . $post['id'] . "");
+ $nPost = $db->query('SELECT `section` FROM `' . FORUM_TABLE_PREFIX . 'forum` WHERE `id` = \'' . $post_id . '\' LIMIT 1;')->fetch();
header('Location: ' . getForumBoardLink($nPost['section']));
}
}
@@ -36,7 +36,7 @@ if($save) {
}
else {
$post_id = (int)$_REQUEST['id'];
- $post = $db->query("SELECT `id`, `section`, `first_post`, `post_topic`, `author_guid` FROM `" . TABLE_PREFIX . "forum` WHERE `id` = " . $post_id . " LIMIT 1")->fetch();
+ $post = $db->query("SELECT `id`, `section`, `first_post`, `post_topic`, `author_guid` FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `id` = " . $post_id . " LIMIT 1")->fetch();
$name = $db->query("SELECT `name` FROM `players` WHERE `id` = " . $post['author_guid'] . " ")->fetch();
$sections_allowed = array();
diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php
index d4e447eb..436e162d 100644
--- a/system/pages/forum/new_post.php
+++ b/system/pages/forum/new_post.php
@@ -19,7 +19,7 @@ if(Forum::canPost($account_logged))
return;
}
- $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();
+ $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 | Thread Starter | Replies | Views | Last Post | ' . 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();
+ $last_post = $db->query("SELECT `players`.`name`, `" . FORUM_TABLE_PREFIX . "forum`.`post_date` FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread['id']." AND `players`.`id` = `" . FORUM_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 diff --git a/system/pages/forum/show_thread.php b/system/pages/forum/show_thread.php index 0f4be95d..5af7c42b 100644 --- a/system/pages/forum/show_thread.php +++ b/system/pages/forum/show_thread.php @@ -13,7 +13,7 @@ defined('MYAAC') or die('Direct access not allowed!'); $links_to_pages = ''; $thread_id = (int) $_REQUEST['id']; $_page = (int) (isset($_REQUEST['page']) ? $_REQUEST['page'] : 0); -$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(); +$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.'; @@ -25,7 +25,7 @@ if(!Forum::hasAccess($thread_starter['section'])) { return; } -$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(); +$posts_count = $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`.`first_post` = ".(int) $thread_id)->fetch(); for($i = 0; $i < $posts_count['posts_count'] / $config['forum_threads_per_page']; $i++) { if($i != $_page) @@ -33,9 +33,9 @@ for($i = 0; $i < $posts_count['posts_count'] / $config['forum_threads_per_page'] else $links_to_pages .= ''.($i + 1).' '; } -$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`.`post_html`, `" . 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(); +$posts = $db->query("SELECT `players`.`id` as `player_id`, `" . FORUM_TABLE_PREFIX . "forum`.`id`,`" . FORUM_TABLE_PREFIX . "forum`.`first_post`, `" . FORUM_TABLE_PREFIX . "forum`.`section`,`" . FORUM_TABLE_PREFIX . "forum`.`post_text`, `" . FORUM_TABLE_PREFIX . "forum`.`post_topic`, `" . FORUM_TABLE_PREFIX . "forum`.`post_date` AS `date`, `" . FORUM_TABLE_PREFIX . "forum`.`post_smile`, `" . FORUM_TABLE_PREFIX . "forum`.`post_html`, `" . FORUM_TABLE_PREFIX . "forum`.`author_aid`, `" . FORUM_TABLE_PREFIX . "forum`.`author_guid`, `" . FORUM_TABLE_PREFIX . "forum`.`last_edit_aid`, `" . FORUM_TABLE_PREFIX . "forum`.`edit_date` FROM `players`, `" . FORUM_TABLE_PREFIX . "forum` WHERE `players`.`id` = `" . FORUM_TABLE_PREFIX . "forum`.`author_guid` AND `" . FORUM_TABLE_PREFIX . "forum`.`first_post` = ".(int) $thread_id." ORDER BY `" . FORUM_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); + $db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `views`=`views`+1 WHERE `id` = ".(int) $thread_id); } $lookaddons = $db->hasColumn('players', 'lookaddons'); @@ -76,7 +76,7 @@ foreach($posts as &$post) $player_account = $player->getAccount(); $post['content'] = Forum::showPost(($post['post_html'] > 0 ? $post['post_topic'] : htmlspecialchars($post['post_topic'])), ($post['post_html'] > 0 ? $post['post_text'] : htmlspecialchars($post['post_text'])), $post['post_smile'] == 0, $post['post_html'] > 0); - $query = $db->query("SELECT COUNT(`id`) AS 'posts' FROM `" . TABLE_PREFIX . "forum` WHERE `author_aid`=".(int) $player_account->getId())->fetch(); + $query = $db->query("SELECT COUNT(`id`) AS 'posts' FROM `" . FORUM_TABLE_PREFIX . "forum` WHERE `author_aid`=".(int) $player_account->getId())->fetch(); $post['author_posts_count'] = (int)$query['posts']; if($post['edit_date'] > 0) |