diff --git a/install/steps/requirements.php b/install/steps/requirements.php
index c11c2623..bec5ee1c 100644
--- a/install/steps/requirements.php
+++ b/install/steps/requirements.php
@@ -22,7 +22,7 @@ function version_check($name, $ok, $info = '', $warning = false)
$failed = false;
// start validating
-version_check($locale['step_requirements_php_version'], (PHP_VERSION_ID >= 50200), PHP_VERSION);
+version_check($locale['step_requirements_php_version'], (PHP_VERSION_ID >= 50300), PHP_VERSION);
foreach(array('config.local.php', 'images/guilds', 'images/houses', 'images/gallery') as $value)
{
$perms = (int) substr(decoct(fileperms(BASE . $value)), 2);
diff --git a/system/pages/forum.php b/system/pages/forum.php
index 591f3cfd..6f0b0140 100644
--- a/system/pages/forum.php
+++ b/system/pages/forum.php
@@ -24,96 +24,6 @@ if(strtolower($config['forum']) != 'site')
return;
}
-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, ' ', $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:
', $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]', '', $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. ';
@@ -280,6 +190,21 @@ class Forum
return hasFlag(FLAG_CONTENT_FORUM) || admin();
}
+ static public function add_post($thread_id, $section, $author_aid, $author_guid, $post_text, $post_topic, $smile)
+ {
+ global $db;
+ $db->insert(TABLE_PREFIX . 'forum', array(
+ 'first_post' => $thread_id,
+ 'section' => $section,
+ 'author_aid' => $author_aid,
+ 'author_guid' => $author_guid,
+ 'post_text' => $post_text,
+ 'post_topic' => $post_topic,
+ 'post_smile' => $smile,
+ 'post_date' => time(),
+ 'post_ip' => $_SERVER['REMOTE_ADDR']
+ ));
+ }
static public function add_board($name, $description, &$errors)
{
global $db;
@@ -373,4 +298,95 @@ class Forum
return !count($errors);
}
+
+ public static 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, ' ', $text);
+
+ return $text;
+ }
+
+ public static 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: ', $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]', '', $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 ? Forum::parseSmiles($text) : $text);
+ }
+
+ public static function showPost($topic, $text, $smiles)
+ {
+ $text = nl2br($text);
+ $post = '';
+ if(!empty($topic))
+ $post .= ''.($smiles == 0 ? self::parseSmiles($topic) : $topic).' ';
+ $post .= self::parseBBCode($text, $smiles);
+ return $post;
+ }
}
diff --git a/system/pages/forum/edit_post.php b/system/pages/forum/edit_post.php
index 2bd01350..dce4a5a8 100644
--- a/system/pages/forum/edit_post.php
+++ b/system/pages/forum/edit_post.php
@@ -105,9 +105,9 @@ if(Forum::canPost($account_logged))
echo ' You are not an author of this post.';
}
else
- echo ' Post with ID '.$post_id.' doesn\'t exist.';
+ 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.';
+ 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.";
?>
\ No newline at end of file
diff --git a/system/pages/forum/new_post.php b/system/pages/forum/new_post.php
index f47bed5f..d3109bb1 100644
--- a/system/pages/forum/new_post.php
+++ b/system/pages/forum/new_post.php
@@ -14,7 +14,12 @@ defined('MYAAC') or die('Direct access not allowed!');
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_id = isset($_REQUEST['thread_id']) ? (int) $_REQUEST['thread_id'] : 0;
+ if($thread_id == 0) {
+ echo "Thread with this id doesn't exist.";
+ 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();
echo 'Boards >> '.$sections[$thread['section']]['name'].' >> '.$thread['post_topic'].' >> Post new reply '.$thread['post_topic'].' ';
if(isset($thread['id']))
@@ -43,6 +48,7 @@ if(Forum::canPost($account_logged))
$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)
{
@@ -67,7 +73,7 @@ if(Forum::canPost($account_logged))
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']."')");
+ Forum::add_post($thread['id'], $thread['section'], $account_logged->getId(), (int) $char_id, $text, $post_topic, (int) $smile, time(), $_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;
@@ -80,44 +86,26 @@ if(Forum::canPost($account_logged))
if(!empty($errors))
echo $twig->render('error_box.html.twig', array('errors' => $errors));
- echo '';
- $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 'Last 5 posts from thread: '.$thread['post_topic'].' ';
- foreach($threads as $thread)
- {
- echo ''.$thread['name'].' '.showPost($thread['post_topic'], $thread['post_text'], $thread['post_smile']).' ';
- }
- echo '
';
+
+ echo $twig->render('forum.new_post.html.twig', array(
+ 'thread_id' => $thread_id,
+ 'post_player_id' => $char_id,
+ 'players' => $players_from_account,
+ 'post_topic' => $post_topic,
+ 'post_text' => $text,
+ 'post_smile' => $smile,
+ 'topic' => $thread['post_topic'],
+ 'threads' => $threads
+ ));
}
}
else
- echo 'Thread with ID '.$thread_id.' doesn\'t exist.';
+ 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.";
diff --git a/system/pages/forum/show_thread.php b/system/pages/forum/show_thread.php
index 3514761c..5c666c85 100644
--- a/system/pages/forum/show_thread.php
+++ b/system/pages/forum/show_thread.php
@@ -52,7 +52,7 @@ if(!empty($thread_name['name']))
$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']).'
+ 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']).'
'.date('d.m.y H:i:s', $thread['post_date']);
if($thread['edit_date'] > 0)
{
diff --git a/system/templates/forum.new_post.html.twig b/system/templates/forum.new_post.html.twig
new file mode 100644
index 00000000..ef969c8e
--- /dev/null
+++ b/system/templates/forum.new_post.html.twig
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Last 5 posts from thread: {{ topic|raw }}
+
+
+ {% set i = 0 %}
+ {% for thread in threads %}
+ {{ thread.name }} {{ thread.post|raw }}
+ {% set i = i + 1 %}
+ {% endfor %}
+
\ No newline at end of file
diff --git a/system/templates/forum.new_thread.html.twig b/system/templates/forum.new_thread.html.twig
index 39af3fdd..7f362459 100644
--- a/system/templates/forum.new_thread.html.twig
+++ b/system/templates/forum.new_thread.html.twig
@@ -14,8 +14,7 @@
(Choose character)
{% for player in players %}
- {{ player.name }}
+ {{ player.name }}
{% endfor %}