diff --git a/index.php b/index.php index ecd7dd9f..a206587a 100644 --- a/index.php +++ b/index.php @@ -238,6 +238,7 @@ if($config['backward_support']) { $layout_header = template_header(); $layout_name = $template_path; $news_content = ''; + $tickers_content = ''; $subtopic = PAGE; $main_content = ''; diff --git a/system/compat.php b/system/compat.php new file mode 100644 index 00000000..78d9a79d --- /dev/null +++ b/system/compat.php @@ -0,0 +1,64 @@ + + * @copyright 2017 MyAAC + * @version 0.6.6 + * @link http://my-aac.org + */ +defined('MYAAC') or die('Direct access not allowed!'); + +function check_name($name, &$errors = '') { + if(Validator::characterName($name)) + return true; + + $errors = Validator::getLastError(); + return false; +} + +function check_account_id($id, &$errors = '') { + if(Validator::accountId($id)) + return true; + + $errors = Validator::getLastError(); + return false; +} + +function check_account_name($name, &$errors = '') { + if(Validator::accountName($name)) + return true; + + $errors = Validator::getLastError(); + return false; +} + +function check_name_new_char($name, &$errors = '') { + if(Validator::newCharacterName($name)) + return true; + + $errors = Validator::getLastError(); + return false; +} + +function check_rank_name($name, &$errors = '') { + if(Validator::rankName($name)) + return true; + + $errors = Validator::getLastError(); + return false; +} + +function check_guild_name($name, &$errors = '') { + if(Validator::guildName($name)) + return true; + + $errors = Validator::getLastError(); + return false; +} + +function news_place() { + return tickers(); +} +?> \ No newline at end of file diff --git a/system/functions.php b/system/functions.php index 05a9131a..1db91627 100644 --- a/system/functions.php +++ b/system/functions.php @@ -9,6 +9,7 @@ * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); + function success($message, $return = false) { if($return) return '

' . $message . '

'; @@ -411,42 +412,16 @@ function short_text($text, $limit) return $text; } -function news_place() +function tickers() { - global $template_path, $news_content; - - $news = ''; - if(PAGE == 'news') - { - //add tickers to site - without it tickers will not be showed - if(isset($news_content)) - $news .= $news_content; - - //featured article -/* $news .= '
-
-
-
-
- Contentbox headline -
-
-
-
- Tutaj wpisz tytul
- tutaj wpisz tresc newsa
- zdjecie laduje sie w tibiacom/images/news/features.jpg
- skad sie laduje mozesz zmienic linijke ponad komentarzem -
-
-
-
-
-
-
';*/ + global $tickers_content; + + if(PAGE == 'news') { + if(isset($tickers_content)) + return $tickers_content; } - return $news; + return ''; } /** @@ -485,8 +460,7 @@ function template_header($is_admin = false) '; if(!$is_admin) $ret .= ' - ' . $title_full . ' - '; + ' . $title_full . ''; $ret .= ' @@ -958,6 +932,7 @@ function str_replace_first($search, $replace, $subject) { if ($pos !== false) { return substr_replace($subject, $replace, $pos, strlen($search)); } + return $subject; } @@ -976,52 +951,5 @@ function unsetSession($key) { // validator functions require_once(LIBS . 'validator.php'); - -function check_name($name, &$errors = '') { - if(Validator::characterName($name)) - return true; - - $errors = Validator::getLastError(); - return false; -} - -function check_account_id($id, &$errors = '') { - if(Validator::accountId($id)) - return true; - - $errors = Validator::getLastError(); - return false; -} - -function check_account_name($name, &$errors = '') { - if(Validator::accountName($name)) - return true; - - $errors = Validator::getLastError(); - return false; -} - -function check_name_new_char($name, &$errors = '') { - if(Validator::newCharacterName($name)) - return true; - - $errors = Validator::getLastError(); - return false; -} - -function check_rank_name($name, &$errors = '') { - if(Validator::rankName($name)) - return true; - - $errors = Validator::getLastError(); - return false; -} - -function check_guild_name($name, &$errors = '') { - if(Validator::guildName($name)) - return true; - - $errors = Validator::getLastError(); - return false; -} +require_once(SYSTEM . 'compat.php'); ?> diff --git a/system/libs/forum.php b/system/libs/forum.php new file mode 100644 index 00000000..f4178274 --- /dev/null +++ b/system/libs/forum.php @@ -0,0 +1,286 @@ + + * @author Slawkens + * @copyright 2017 MyAAC + * @version 0.6.6 + * @link http://my-aac.org + */ +defined('MYAAC') or die('Direct access not allowed!'); + +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) || superAdmin(); + } + + static public function add_thread($title, $body, $section_id, $player_id, $account_id, &$errors) + { + global $db; + $thread_id = 0; + if($db->insert(TABLE_PREFIX . 'forum', array('first_post' => 0, 'last_post' => time(), 'section' => $section_id, 'replies' => 0, 'views' => 0, 'author_aid' => isset($account_id) ? $account_id : 0, 'author_guid' => isset($player_id) ? $player_id : 0, 'post_text' => $body, 'post_topic' => $title, 'post_smile' => 0, 'post_date' => time(), 'last_edit_aid' => 0, 'edit_date' => 0, '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); + } + + return $thread_id; + } + + 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, $access, $guild, &$errors) + { + global $db; + if(isset($name[0]) && isset($description[0])) + { + $query = $db->select(TABLE_PREFIX . 'forum_boards', array('name' => $name)); + + if($query === false) + { + $query = + $db->query( + 'SELECT ' . $db->fieldName('ordering') . + ' FROM ' . $db->tableName(TABLE_PREFIX . 'forum_boards') . + ' ORDER BY ' . $db->fieldName('ordering') . ' DESC LIMIT 1' + ); + + $ordering = 0; + if($query->rowCount() > 0) { + $query = $query->fetch(); + $ordering = $query['ordering'] + 1; + } + $db->insert(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild, 'ordering' => $ordering)); + } + else + $errors[] = 'Forum board with this name already exists.'; + } + else + $errors[] = 'Please fill all inputs.'; + + return !count($errors); + } + + static public function get_board($id) { + global $db; + return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id)); + } + + static public function update_board($id, $name, $access, $guild, $description) { + global $db; + $db->update(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild), array('id' => $id)); + } + + static public function delete_board($id, &$errors) + { + global $db; + if(isset($id)) + { + if(self::get_board($id) !== false) + $db->delete(TABLE_PREFIX . 'forum_boards', array('id' => $id)); + else + $errors[] = 'Forum board with id ' . $id . ' does not exists.'; + } + else + $errors[] = 'id not set'; + + return !count($errors); + } + + static public function toggleHidden_board($id, &$errors) + { + global $db; + if(isset($id)) + { + $query = self::get_board($id); + if($query !== false) + $db->update(TABLE_PREFIX . 'forum_boards', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id)); + else + $errors[] = 'Forum board with id ' . $id . ' does not exists.'; + } + else + $errors[] = 'id not set'; + + return !count($errors); + } + + static public function move_board($id, $i, &$errors) + { + global $db; + $query = self::get_board($id); + if($query !== false) + { + $ordering = $query['ordering'] + $i; + $old_record = $db->select(TABLE_PREFIX . 'forum_boards', array('ordering' => $ordering)); + if($old_record !== false) + $db->update(TABLE_PREFIX . 'forum_boards', array('ordering' => $query['ordering']), array('ordering' => $ordering)); + + $db->update(TABLE_PREFIX . 'forum_boards', array('ordering' => $ordering), array('id' => $id)); + } + else + $errors[] = 'Forum board with id ' . $id . ' does not exists.'; + + 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, ''. $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:
'.$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 ? 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; + } + + public static function hasAccess($board_id) { + global $sections, $logged, $account_logged, $logged_access; + if(!isset($sections[$board_id])) + return false; + + $hasAccess = true; + $section = $sections[$board_id]; + if($section['guild'] > 0) { + if($logged) { + $guild = new OTS_Guild(); + $guild->load($section['guild']); + $status = false; + if($guild->isLoaded()) { + $account_players = $account_logged->getPlayers(); + foreach ($account_players as $player) { + if($guild->hasMember($player)) { + $status = true; + } + } + } + + if (!$status) $hasAccess = false; + } + else { + $hasAccess = false; + } + } + + if($section['access'] > 0) { + if($logged_access < $section['access']) { + $hasAccess = false; + } + } + + return $hasAccess; + } +} +?> \ No newline at end of file diff --git a/system/libs/items.php b/system/libs/items.php index 39fde0c5..9cd92564 100644 --- a/system/libs/items.php +++ b/system/libs/items.php @@ -11,7 +11,8 @@ */ defined('MYAAC') or die('Direct access not allowed!'); -class Items { +class Items +{ private static $error = ''; public static function loadFromXML($show = false) diff --git a/system/pages/forum.php b/system/pages/forum.php index 2911e6c8..90c760e6 100644 --- a/system/pages/forum.php +++ b/system/pages/forum.php @@ -27,6 +27,8 @@ if(strtolower($config['forum']) != 'site') if(!$logged) echo 'You are not logged in. Log in to post on the forum.

'; +require_once(LIBS . 'forum.php'); + $canEdit = hasFlag(FLAG_CONTENT_FORUM) || superAdmin(); if($canEdit) { @@ -188,263 +190,4 @@ if(file_exists(PAGES . 'forum/' . $action . '.php')) { require(PAGES . 'forum/' . $action . '.php'); } -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(); - } - - 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, $access, $guild, &$errors) - { - global $db; - if(isset($name[0]) && isset($description[0])) - { - $query = $db->select(TABLE_PREFIX . 'forum_boards', array('name' => $name)); - - if($query === false) - { - $query = - $db->query( - 'SELECT ' . $db->fieldName('ordering') . - ' FROM ' . $db->tableName(TABLE_PREFIX . 'forum_boards') . - ' ORDER BY ' . $db->fieldName('ordering') . ' DESC LIMIT 1' - ); - - $ordering = 0; - if($query->rowCount() > 0) { - $query = $query->fetch(); - $ordering = $query['ordering'] + 1; - } - $db->insert(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild, 'ordering' => $ordering)); - } - else - $errors[] = 'Forum board with this name already exists.'; - } - else - $errors[] = 'Please fill all inputs.'; - - return !count($errors); - } - - static public function get_board($id) { - global $db; - return $db->select(TABLE_PREFIX . 'forum_boards', array('id' => $id)); - } - - static public function update_board($id, $name, $access, $guild, $description) { - global $db; - $db->update(TABLE_PREFIX . 'forum_boards', array('name' => $name, 'description' => $description, 'access' => $access, 'guild' => $guild), array('id' => $id)); - } - - static public function delete_board($id, &$errors) - { - global $db; - if(isset($id)) - { - if(self::get_board($id) !== false) - $db->delete(TABLE_PREFIX . 'forum_boards', array('id' => $id)); - else - $errors[] = 'Forum board with id ' . $id . ' does not exists.'; - } - else - $errors[] = 'id not set'; - - return !count($errors); - } - - static public function toggleHidden_board($id, &$errors) - { - global $db; - if(isset($id)) - { - $query = self::get_board($id); - if($query !== false) - $db->update(TABLE_PREFIX . 'forum_boards', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id)); - else - $errors[] = 'Forum board with id ' . $id . ' does not exists.'; - } - else - $errors[] = 'id not set'; - - return !count($errors); - } - - static public function move_board($id, $i, &$errors) - { - global $db; - $query = self::get_board($id); - if($query !== false) - { - $ordering = $query['ordering'] + $i; - $old_record = $db->select(TABLE_PREFIX . 'forum_boards', array('ordering' => $ordering)); - if($old_record !== false) - $db->update(TABLE_PREFIX . 'forum_boards', array('ordering' => $query['ordering']), array('ordering' => $ordering)); - - $db->update(TABLE_PREFIX . 'forum_boards', array('ordering' => $ordering), array('id' => $id)); - } - else - $errors[] = 'Forum board with id ' . $id . ' does not exists.'; - - 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, ''. $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:
'.$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 ? 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; - } - - public static function hasAccess($board_id) { - global $sections, $logged, $account_logged, $logged_access; - if(!isset($sections[$board_id])) - return false; - - $hasAccess = true; - $section = $sections[$board_id]; - if($section['guild'] > 0) { - if($logged) { - $guild = new OTS_Guild(); - $guild->load($section['guild']); - $status = false; - if($guild->isLoaded()) { - $account_players = $account_logged->getPlayers(); - foreach ($account_players as $player) { - if($guild->hasMember($player)) { - $status = true; - } - } - } - - if (!$status) $hasAccess = false; - } - else { - $hasAccess = false; - } - } - - if($section['access'] > 0) { - if($logged_access < $section['access']) { - $hasAccess = false; - } - } - - return $hasAccess; - } -} +?> diff --git a/system/pages/news.php b/system/pages/news.php index 31d19377..dd2e863b 100644 --- a/system/pages/news.php +++ b/system/pages/news.php @@ -10,7 +10,8 @@ * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); -header('X-XSS-Protection: 0'); + +require_once(LIBS . 'forum.php'); if(isset($_GET['archive'])) { @@ -67,13 +68,8 @@ if(isset($_GET['archive'])) } else echo "This news doesn't exist or is hidden.
"; - ?> -
-
- -
-
- render('news.back_button.html.twig'); return; } ?> @@ -99,6 +95,7 @@ if(isset($_GET['archive'])) return; } +header('X-XSS-Protection: 0'); $title = 'Latest News'; $news_cached = false; @@ -124,7 +121,7 @@ if($canEdit) if($action == 'add') { if(isset($forum_section) && $forum_section != '-1') { - $forum_add = Forum::add($p_title, $body, $forum_section, $player_id, $account_logged->getId(), $errors); + $forum_add = Forum::add_thread($p_title, $body, $forum_section, $player_id, $account_logged->getId(), $errors); } if(News::add($p_title, $body, $type, $category, $player_id, isset($forum_add) && $forum_add != 0 ? $forum_add : 0, $errors)) { @@ -187,52 +184,25 @@ if(!$news_cached) ); } - $tickers = + $tickers_db = $db->query( 'SELECT * FROM ' . $db->tableName(TABLE_PREFIX . 'news') . ' WHERE ' . $db->fieldName('type') . ' = ' . TICKET . ($canEdit ? '' : ' AND ' . $db->fieldName('hidden') . ' != 1') . ' ORDER BY ' . $db->fieldName('date') . ' DESC' . ' LIMIT ' . $config['news_ticker_limit']); - if($tickers->rowCount() > 0) + if($tickers_db->rowCount() > 0) { - $rows = 0; - $tickers_to_add = ''; - foreach($tickers as $news) - { - $admin_options = ''; - if($canEdit) - { - $admin_options = ' - - Edit - - - - Delete - - - - ' . ($news['hidden'] != 1 ? 'Hide' : 'Show') . ' - '; - } - $tickers_to_add .= '
-
-
-
-
- '.date("j M Y", $news['date']).' - -
'; - //if admin show button to delete (hide) ticker - $tickers_to_add .= short_text(strip_tags($news['body']), 100).'
-
'; - //if admin show button to delete (hide) ticker - $tickers_to_add .= $news['body'] . $admin_options . '
-
-
-
'; - $rows++; + $tickers = $tickers_db->fetchAll(); + foreach($tickers as &$ticker) { + $ticker['icon'] = $categories[$ticker['category']]['icon_id']; + $ticker['body_short'] = short_text(strip_tags($ticker['body']), 100); } + + $tickers_to_add = $twig->render('news.tickers.html.twig', array( + 'tickers' => $tickers, + 'canEdit' => $canEdit + )); } } else @@ -240,30 +210,9 @@ else if(isset($tickers_to_add[0])) { - //show table with tickers - $news_content = '
-
-
-
-
- Contentbox headline -
-
-
'; - - //add tickers list - $news_content .= $tickers_to_add; - //koniec - $news_content .= '
-
-
-
-
-
-
'; - - if($cache->enabled() && !$news_cached && !$canEdit) - $cache->set('news_' . $template_name . '_' . TICKET, $tickers_to_add, 120); + $tickers_content = $tickers_to_add; + if($cache->enabled() && !$news_cached && !$canEdit) + $cache->set('news_' . $template_name . '_' . TICKET, $tickers_to_add, 120); } if(!$news_cached) @@ -459,19 +408,4 @@ class News return false; } } - -class Forum -{ - static public function add($title, $body, $section_id, $player_id, $account_id, &$errors) - { - global $db; - $thread_id = 0; - if($db->insert(TABLE_PREFIX . 'forum', array('first_post' => 0, 'last_post' => time(), 'section' => $section_id, 'replies' => 0, 'views' => 0, 'author_aid' => isset($account_id) ? $account_id : 0, 'author_guid' => isset($player_id) ? $player_id : 0, 'post_text' => $body, 'post_topic' => $title, 'post_smile' => 0, 'post_date' => time(), 'last_edit_aid' => 0, 'edit_date' => 0, '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); - } - - return $thread_id; - } -} ?> diff --git a/system/templates/news.back_button.html.twig b/system/templates/news.back_button.html.twig new file mode 100644 index 00000000..13ec4e04 --- /dev/null +++ b/system/templates/news.back_button.html.twig @@ -0,0 +1,13 @@ +
+ + + + + + + + +
+ +
+
\ No newline at end of file diff --git a/system/templates/news.tickers.html.twig b/system/templates/news.tickers.html.twig new file mode 100644 index 00000000..a8825bba --- /dev/null +++ b/system/templates/news.tickers.html.twig @@ -0,0 +1,15 @@ + + + + + {% set i = 0 %} + {% for ticker in tickers %} + + + + + + {% set i = i + 1 %} + {% endfor %} +
Tickers
{{ ticker.date|date("j M Y") }}{{ ticker.body|raw }}
+
\ No newline at end of file diff --git a/templates/kathrine/template.php b/templates/kathrine/template.php index 798ac445..38de013f 100644 --- a/templates/kathrine/template.php +++ b/templates/kathrine/template.php @@ -123,7 +123,7 @@ defined('MYAAC') or die('Direct access not allowed!');
- +
diff --git a/templates/tibiacom/index.php b/templates/tibiacom/index.php index f15dda9c..78a3588e 100644 --- a/templates/tibiacom/index.php +++ b/templates/tibiacom/index.php @@ -304,7 +304,7 @@ foreach($config['menu_categories'] as $id => $cat) { ?>
- +
diff --git a/templates/tibiacom/news.tickers.html.twig b/templates/tibiacom/news.tickers.html.twig new file mode 100644 index 00000000..3c37dbcb --- /dev/null +++ b/templates/tibiacom/news.tickers.html.twig @@ -0,0 +1,46 @@ +
+
+
+
+
+ Contentbox headline +
+
+
+ {% set i = 0 %} + {% for ticker in tickers %} +
+
+
+
+
+ {{ ticker.date|date("j M Y") }} - +
{{ ticker.body_short|raw }}
+
{{ ticker.body|raw }} + {% if canEdit %} + + + Edit + + + + Delete + + + + {% if ticker.hidden != 1 %}Hide{% else %}Show{% endif %} + + {% endif %} +
+
+
+
+ {% set i = i + 1 %} + {% endfor %} +
+
+
+
+
+
+
\ No newline at end of file