From b6ccde075d819d669191e39944cca36d42899b6c Mon Sep 17 00:00:00 2001 From: slawkens Date: Wed, 4 Oct 2017 17:49:54 +0200 Subject: [PATCH] * moved some more pages to twig * moved online, movies, google_analytics code, faq, experience_table, downloads to twig * added new global variabl to twig (status) * removed some unused page (custom.php) * automatically append trailing slash at config.item_images_url * moved downloads from clients.halfaway.net to tibia-clients.com * show some more info on monster loot (currently only on TFS 0.3 and those that use item.id in monster files instead of item name) * some more unimportant fixes --- admin/index.php | 1 + config.php | 6 +- images/{palladin.png => paladin.png} | Bin index.php | 1 + install/steps/database.php | 4 +- system/functions.php | 34 +-- system/init.php | 4 +- system/pages/characters.php | 2 +- system/pages/creatures.php | 11 +- system/pages/custom.php | 28 --- system/pages/downloads.php | 13 +- system/pages/experiencetable.php | 47 +--- system/pages/faq.php | 47 +--- system/pages/movies.php | 11 +- system/pages/online.php | 258 ++++++-------------- system/templates/characters.html.twig | 2 +- system/templates/downloads.html.twig | 10 + system/templates/experience_table.html.twig | 26 ++ system/templates/faq.html.twig | 41 ++++ system/templates/google_analytics.html.twig | 9 + system/templates/movies.html.twig | 7 + system/templates/news.html.twig | 2 +- system/templates/online.html.twig | 112 +++++++++ templates/kathrine/news.html.twig | 2 +- 24 files changed, 327 insertions(+), 351 deletions(-) rename images/{palladin.png => paladin.png} (100%) delete mode 100644 system/pages/custom.php create mode 100644 system/templates/downloads.html.twig create mode 100644 system/templates/experience_table.html.twig create mode 100644 system/templates/faq.html.twig create mode 100644 system/templates/google_analytics.html.twig create mode 100644 system/templates/movies.html.twig create mode 100644 system/templates/online.html.twig diff --git a/admin/index.php b/admin/index.php index fecc26c1..6802f6d3 100644 --- a/admin/index.php +++ b/admin/index.php @@ -26,6 +26,7 @@ require(SYSTEM . 'login.php'); require(ADMIN . 'includes/functions.php'); $twig->addGlobal('config', $config); +$twig->addGlobal('status', $status); // if we're not logged in - show login box if(!$logged || !admin()) { diff --git a/config.php b/config.php index 66fe3299..edc1ff55 100644 --- a/config.php +++ b/config.php @@ -65,7 +65,7 @@ $config = array( 'database_password' => '', 'database_name' => '', - // multiworld system + // multiworld system (only TFS 0.3) 'multiworld' => false, // use multiworld system? 'worlds' => array( // list of worlds //'1' => 'Your World Name', @@ -201,10 +201,10 @@ $config = array( ), // news page - 'news_limit' => 5, // limit of news on latest news page + 'news_limit' => 5, // limit of news on the latest news page 'news_ticker_limit' => 5, // limit of news in tickers (mini news) (0 to disable) 'news_date_format' => 'j.n.Y', // check php manual date() function for more info about this - 'news_author' => true, + 'news_author' => true, // show author of the news // gifts/shop system 'gifts_system' => false, diff --git a/images/palladin.png b/images/paladin.png similarity index 100% rename from images/palladin.png rename to images/paladin.png diff --git a/index.php b/index.php index a3ccad6a..25e00ea7 100644 --- a/index.php +++ b/index.php @@ -56,6 +56,7 @@ require_once(SYSTEM . 'status.php'); require_once(SYSTEM . 'template.php'); $twig->addGlobal('config', $config); +$twig->addGlobal('status', $status); // database migrations $tmp = ''; diff --git a/install/steps/database.php b/install/steps/database.php index 034a8dce..0f3d0ea5 100644 --- a/install/steps/database.php +++ b/install/steps/database.php @@ -230,9 +230,9 @@ if(!$error) { $error = true; } - $content .= '$config[\'client_download\'] = \'http://clients.halfaway.net/windows.php?tibia=\'. $config[\'client\'];'; + $content .= '$config[\'client_download\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/exe/windows\';'; $content .= PHP_EOL; - $content .= '$config[\'client_download_linux\'] = \'http://clients.halfaway.net/linux.php?tibia=\'. $config[\'client\'];'; + $content .= '$config[\'client_download_linux\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/tar/linux\';'; $content .= PHP_EOL; $content .= '// place for your configuration directives, so you can later easily update myaac'; $content .= PHP_EOL; diff --git a/system/functions.php b/system/functions.php index 83a521b8..2dc19cde 100644 --- a/system/functions.php +++ b/system/functions.php @@ -802,11 +802,7 @@ function template_header($is_admin = false) Please turn it on, or be aware that some features on this website will not work correctly. '; - if(admin()) - $ret .= ' -'; + if($config['recaptcha_enabled']) $ret .= ""; return $ret; @@ -817,13 +813,14 @@ function template_header($is_admin = false) */ function template_footer() { - global $visitors, $config, $views_counter; + global $config, $views_counter; $ret = ''; if(admin()) $ret .= generateLink(ADMIN_URL, 'Admin Panel', true); if($config['visitors_counter']) { + global $visitors; $amount = $visitors->getAmountVisitors(); $ret .= '
Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; } @@ -843,21 +840,11 @@ function template_footer() function template_ga_code() { - global $config; + global $config, $twig; if(!isset($config['google_analytics_id'][0])) return ''; - return " -"; + return $twig->render('google_analytics.html.twig'); } function template_form() @@ -899,6 +886,8 @@ function getCreatureName($killer, $showStatus = false, $extendedInfo = false) { global $vowels, $ots, $config; $str = ""; + $players_rows = ''; + if(is_numeric($killer)) { $player = $ots->createObject('Player'); @@ -1104,12 +1093,9 @@ function get_templates() function getWorldName($id) { global $config; - foreach($config['worlds'] as $_id => $details) - { - if($id == $_id) - return $details['name']; - } - + if(isset($config['worlds'][$id])) + return $config['worlds'][$id]; + return $config['lua']['serverName']; } diff --git a/system/init.php b/system/init.php index 3ee4b72d..4ca0298b 100644 --- a/system/init.php +++ b/system/init.php @@ -87,10 +87,12 @@ unset($tmp); if(isset($config['lua']['servername'])) $config['lua']['serverName'] = $config['lua']['servername']; - if(isset($config['lua']['houserentperiod'])) $config['lua']['houseRentPeriod'] = $config['lua']['houserentperiod']; +if($config['item_images_url'][strlen($config['item_images_url']) - 1] != '/') + $config['item_images_url'] .= '/'; + // localize data/ directory if(isset($config['lua']['dataDirectory'][0])) { diff --git a/system/pages/characters.php b/system/pages/characters.php index 7d2e77e1..02127e7d 100644 --- a/system/pages/characters.php +++ b/system/pages/characters.php @@ -56,7 +56,7 @@ $name = str_replace('/', '', $name); $oldName = ''; -$player = $ots->createObject('Player'); +$player = new OTS_Player(); $player->find($name); if(!$player->isLoaded()) { diff --git a/system/pages/creatures.php b/system/pages/creatures.php index 9aaca746..1dbbb50b 100644 --- a/system/pages/creatures.php +++ b/system/pages/creatures.php @@ -43,15 +43,16 @@ function printLoot($level, $itemid, $count, $chance) $chance *= $lootRate; } - foreach($rarity as $lootRarity => $percent){ - if($chance >= $percent) - { - //echo str_repeat("... ", $level) . '' . ($count ? $count : 1) . ' ' . $itemList[(int)$itemid] . ' ' . $itemid . ' ' . $lootRarity . ' (' . $chance . '%)
'; + foreach($rarity as $lootRarity => $percent) { + if($chance >= $percent) { + if(isset($itemid)) + echo str_repeat("... ", $level) . '' . ($count ? $count : 1) . ' ' . $itemList[(int)$itemid] . ' ' . $itemid . ' ' . $lootRarity . ' (' . $chance . '%)
'; + if($i % 6 == 0) { if($i != 0) echo ''; - echo ''; + echo ''; } echo getItemImage($itemid); $i++; diff --git a/system/pages/custom.php b/system/pages/custom.php deleted file mode 100644 index 7fabd540..00000000 --- a/system/pages/custom.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @copyright 2017 MyAAC - * @version 0.4.2 - * @link http://my-aac.org - */ -defined('MYAAC') or die('Direct access not allowed!'); - -$query = $db->query('SELECT `title`, `body`, `php` FROM `' . TABLE_PREFIX . 'pages` WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1'); -if($query->rowCount() > 0) // found page -{ - $query = $query->fetch(); - $title = $query['title']; - - if($query['php'] == '1') // execute it as php code - eval($query['body']); - else - echo $query['body']; // plain html - - return true; -} - -return false; -?> diff --git a/system/pages/downloads.php b/system/pages/downloads.php index 63f0913c..0869aafe 100644 --- a/system/pages/downloads.php +++ b/system/pages/downloads.php @@ -3,21 +3,12 @@ * Downloads * * @package MyAAC - * @author Gesior * @author Slawkens * @copyright 2017 MyAAC * @version 0.4.2 * @link http://my-aac.org */ $title = 'Downloads'; -?> -

-
-We're using official Tibia Client
-

Download Tibia client for windows HERE.

-

Download Tibia client for linux HERE.

-

IP Changer:

- -HERE -
\ No newline at end of file +echo $twig->render('downloads.html.twig'); +?> \ No newline at end of file diff --git a/system/pages/experiencetable.php b/system/pages/experiencetable.php index 2250bf2e..2ef2506a 100644 --- a/system/pages/experiencetable.php +++ b/system/pages/experiencetable.php @@ -3,7 +3,6 @@ * Experience table * * @package MyAAC - * @author Gesior * @author Slawkens * @copyright 2017 MyAAC * @version 0.4.2 @@ -11,42 +10,16 @@ */ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Experience Table'; -?> -This is a list of the experience points that are required to advance to the various levels. -Remember you can also check the respective skill bar in your skill window of the client to check your progress towards the next level.

- - - - - - - - -render('experience_table.html.twig', array( + 'experience' => $experience +)); ?> - -
Experience Table
- - - - - - - - - - - -
LevelExperience
-
diff --git a/system/pages/faq.php b/system/pages/faq.php index e9dc2faf..e09e72e5 100644 --- a/system/pages/faq.php +++ b/system/pages/faq.php @@ -20,47 +20,10 @@ if(!$faqs->rowCount()) There are no questions added yet. ' . TABLE_PREFIX . 'faq table.'; } + +echo $twig->render('faq.html.twig', array( + 'faqs' => $faqs +)); ?> - - - - - - - - - - -
- FAQ - - Toggle all -
- - -
- - diff --git a/system/pages/movies.php b/system/pages/movies.php index e66721da..dcd41540 100644 --- a/system/pages/movies.php +++ b/system/pages/movies.php @@ -21,11 +21,8 @@ There are no movies added yet. echo ' You can add new movies in phpmyadmin under ' . TABLE_PREFIX . 'movies table.'; return; } + +echo $twig->render('movies.html.twig', array( + 'movies' => $movies +)); ?> -
- -
- Author:
-

- -
diff --git a/system/pages/online.php b/system/pages/online.php index 60b2c5a5..e9fc9a21 100644 --- a/system/pages/online.php +++ b/system/pages/online.php @@ -14,13 +14,7 @@ $title = 'Who is online?'; if($config['account_country']) require(SYSTEM . 'countries.conf.php'); -?> - - - - -query('SELECT `accounts`.`country`, `players`.`name`, `level`, `vocation`' . $outfit . ', ' . $promotion . ' `' . $skull_time . '` as `skulltime`, `' . $skull_type . '` as `skull` FROM `accounts`, `players` WHERE `players`.`online` > 0 AND `accounts`.`id` = `players`.`account_id` ORDER BY ' . $order); +$players_data = array(); $players = 0; $data = ''; foreach($playersOnline as $player) @@ -70,202 +65,91 @@ foreach($playersOnline as $player) $skull = ''; if($config['online_skulls']) { - if($player['skulltime'] > 0 && $player['skull'] == 3) - $skull = ' '; - elseif($player['skulltime'] > 0 && $player['skull'] == 4) - $skull = ' '; - elseif($player['skulltime'] > 0 && $player['skull'] == 5) - $skull = ' '; + if($player['skulltime'] > 0) + { + if($player['skull'] == 3) + $skull = ' '; + elseif($player['skull'] == 4) + $skull = ' '; + elseif($player['skull'] == 5) + $skull = ' '; + } } if(isset($player['promotion'])) { if((int)$player['promotion'] > 0) $player['vocation'] += ($player['promotion'] * $config['vocations_amount']); } - - $data .= ''; - if($config['account_country']) - $data .= ''; - - if($config['online_outfit']) - $data .= ''; - - $data .= ' - - - '; - + + $players_data[] = array( + 'name' => getPlayerLink($player['name']), + 'player' => $player, + 'level' => $player['level'], + 'vocation' => $config['vocations'][$player['vocation']], + 'country_image' => $config['account_country'] ? getFlagImage($player['country']) : null, + 'outfit' => $config['online_outfit'] ? $config['outfit_images_url'] . '?id=' . $player['looktype'] . ($outfit_addons ? '&addons=' . $player['lookaddons'] : '') . '&head=' . $player['lookhead'] . '&body=' . $player['lookbody'] . '&legs=' . $player['looklegs'] . '&feet=' . $player['lookfeet'] : null + ); + if($config['online_vocations']) $vocs[($player['vocation'] > $config['vocations_amount'] ? $player['vocation'] - $config['vocations_amount'] : $player['vocation'])]++; } -if(!$players): ?> -
Server Status
' . getFlagImage($player['country']) . '' . getPlayerLink($player['name']) . $skull . ''.$player['level'].''.$config['vocations'][$player['vocation']].'
Currently no one is playing on .
- - - -'; - else - { - if($config['online_afk']) - { - $afk = $players - $status['players']; - if($afk < 0) { - $players += abs($afk); - $afk = 0; - } - ?> - Currently there are active and AFK players.
- Total number of players: .
-'; - } - - if($config['online_record']) - { - $timestamp = false; - if(tableExist('server_record')) { +$record = ''; +if($players > 0) +{ + if($config['online_record']) + { + $timestamp = false; + if(tableExist('server_record')) { $query = $db->query( - 'SELECT ' . $db->fieldName('record') . ', ' . $db->fieldName('timestamp') . - ' FROM ' . $db->tableName('server_record') . - ' WHERE ' . $db->fieldName('world_id') . ' = ' . (int)$config['lua']['worldId'] . - ' ORDER BY ' . $db->fieldName('record') . ' DESC LIMIT 1'); - $timestamp = true; - } - else if(tableExist('server_config')) { // tfs 1.0 - $query = $db->query('SELECT `value` as `record` FROM `server_config` WHERE `config` = ' . $db->quote('players_record')); - } - else - $query = NULL; - - if(isset($query) && $query->rowCount() > 0) - { - $result = $query->fetch(); - echo 'The maximum on this game world was ' . $result['record'] . ' players' . ($timestamp ? ' on ' . date("M d Y, H:i:s", $result['timestamp']) . '.' : '.'); - } + 'SELECT `record`, `timestamp` FROM `server_record` WHERE `world_id` = ' . (int)$config['lua']['worldId'] . + ' ORDER BY `record` DESC LIMIT 1'); + $timestamp = true; } - ?> - - - + else if(tableExist('server_config')) { // tfs 1.0 + $query = $db->query('SELECT `value` as `record` FROM `server_config` WHERE `config` = ' . $db->quote('players_record')); + } + else + $query = NULL; + + if(isset($query) && $query->rowCount() > 0) + { + $result = $query->fetch(); + $record = 'The maximum on this game world was ' . $result['record'] . ' players' . ($timestamp ? ' on ' . date("M d Y, H:i:s", $result['timestamp']) . '.' : '.'); + } + } +} - -
- - - - - - - - - - - - - - - - - - - - -
Sorcerers
DruidsPaladinsKnights
-
 
- - - - - - - - - - '; - ?> -
Vocation statistics
' . $config['vocations'][$i] . '' . $vocs[$i] . '

- - - - - -
- - 1 - 6 Frags
- - 6+ Frags or Red Skull
- - 10+ Frags or Black Skull -
- - - - - - - - - - - - - - - -
#OutfitNameLevelVocation
-render('online.html.twig', array( + 'players' => $players_data, + 'record' => $record +)); //search bar echo '
-
- - - - - - - -
- Search Character -
- - - - - - -
Name: - - - -
-
-
'; - -/* temporary disable it - shows server offline -// update online players counter -if($players > 0) -{ - $status['players'] = $players; - if($cache->enabled()) - $cache->set('status', serialize($status)); - else - { - foreach($status as $key => $value) - updateDatabaseConfig('serverStatus_' . $key, $value); - } -}*/ +
+ + + + + + + +
+ Search Character +
+ + + + + + +
Name: + + + +
+
+
'; ?> diff --git a/system/templates/characters.html.twig b/system/templates/characters.html.twig index 328338e2..444876aa 100644 --- a/system/templates/characters.html.twig +++ b/system/templates/characters.html.twig @@ -4,7 +4,7 @@ {% if config.characters.outfit %} -
+
player outfit
{% endif %} diff --git a/system/templates/downloads.html.twig b/system/templates/downloads.html.twig new file mode 100644 index 00000000..d83c37ee --- /dev/null +++ b/system/templates/downloads.html.twig @@ -0,0 +1,10 @@ +

+
+ We're using official Tibia Client {{ config.client / 100 }}
+

Download Tibia client {{ config.client / 100 }} for windows HERE.

+

Download Tibia client {{ config.client / 100 }} for linux HERE.

+ +

IP Changer:

+ + HERE +
\ No newline at end of file diff --git a/system/templates/experience_table.html.twig b/system/templates/experience_table.html.twig new file mode 100644 index 00000000..03efc671 --- /dev/null +++ b/system/templates/experience_table.html.twig @@ -0,0 +1,26 @@ +This is a list of the experience points that are required to advance to the various levels. +Remember you can also check the respective skill bar in your skill window of the client to check your progress towards the next level.

+ +
+ + + + + {% for i in 0..config.experiencetable_columns-1 %} + + {% endfor %} + +
Experience Table
+ + + + + + {% for level in i * config.experiencetable_rows + 1..i * config.experiencetable_rows + (config.experiencetable_rows + 1) - 1 %} + + + + + {% endfor %} +
LevelExperience
{{ level }}{{ experience[level] }}
+
\ No newline at end of file diff --git a/system/templates/faq.html.twig b/system/templates/faq.html.twig new file mode 100644 index 00000000..561e5e8e --- /dev/null +++ b/system/templates/faq.html.twig @@ -0,0 +1,41 @@ + + + + + + {% set i = 0 %} + {% for faq in faqs %} + {% set i = i + 1 %} + + + + {% endfor %} +
+ FAQ + + Toggle all +
+ {{ faq.question }} + +
+ + \ No newline at end of file diff --git a/system/templates/google_analytics.html.twig b/system/templates/google_analytics.html.twig new file mode 100644 index 00000000..2b424ddd --- /dev/null +++ b/system/templates/google_analytics.html.twig @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/system/templates/movies.html.twig b/system/templates/movies.html.twig new file mode 100644 index 00000000..8c34e281 --- /dev/null +++ b/system/templates/movies.html.twig @@ -0,0 +1,7 @@ +
+ {% for movie in movies %} +

{{ movie.title }}

+ Author: {{ movie.author }}
+

+ {% endfor %} +
\ No newline at end of file diff --git a/system/templates/news.html.twig b/system/templates/news.html.twig index 6b085717..2eb0b0ce 100644 --- a/system/templates/news.html.twig +++ b/system/templates/news.html.twig @@ -1,7 +1,7 @@
-
{{ date|date(news_date_format) }} -
+
{{ date|date(config.news_date_format) }} -
{{ title }}
{% if author is not empty %}
Author: {{ author }}
diff --git a/system/templates/online.html.twig b/system/templates/online.html.twig new file mode 100644 index 00000000..58dcec84 --- /dev/null +++ b/system/templates/online.html.twig @@ -0,0 +1,112 @@ + + + + +{% if players|length == 0 %} +
Server Status
Currently no one is playing on {{ config.lua.serverName }}.
+{% else %} + + + {% if not status.online %} + Server is offline.
+ {% else %} + {% if config.online_afk %} + {% set players_count = players|length %} + {% set afk = players_count - status.players %} + {% if afk < 0 %} + {% set players = players + afk|abs %} + {% set afk = 0 %} + {% endif %} + Currently there are {{ status.players }} active and {{ afk }} AFK players.
+ Total number of players: {{ players_count }}.
+ {% else %} + Currently {{ players|length }} players are online.
+ {% endif %} + {% endif %} + + + + {# vocation statistics #} + {% if config.online_vocations %} +
+ {% if config.online_vocations_images %} + + + + + + + + + + + + + + + + + + + +
SorcerersDruidsPaladinsKnights
{{ vocs[1] }}{{ vocs[2] }}{{ vocs[3] }}{{ vocs[4] }}
+
 
+ {% else %} + + + + + + {% for i in 1..config.vocations_amount %} + + + + + {% endfor %} +
Vocation statistics
{{ config.vocations[i] }}{{ vocs[i] }}
+
+ {% endif %} + {% endif %} + + {# show skulls #} + {% if config.online_skulls %} + + + + +
+ - 1 - 6 Frags
+ - 6+ Frags or Red Skull
+ - 10+ Frags or Black Skull +
+ {% endif %} + + + + {% if config.account_country %} + + {% endif %} + {% if config.online_outfit %} + + {% endif %} + + + + + {% set i = 0 %} + {% for player in players %} + {% set i = i + 1 %} + + {% if config.account_country %} + + {% endif %} + {% if config.online_outfit %} + + {% endif %} + + + + + {% endfor %} +
#OutfitNameLevelVocation
{{ player.country_image|raw }}player outfit{{ player.name|raw }}{{ player.skull }}{{ player.level }}{{ player.vocation }}
+{% endif %} \ No newline at end of file diff --git a/templates/kathrine/news.html.twig b/templates/kathrine/news.html.twig index 6672e322..483960eb 100644 --- a/templates/kathrine/news.html.twig +++ b/templates/kathrine/news.html.twig @@ -2,7 +2,7 @@
-
{{ date|date(news_date_format) }} -
+
{{ date|date(config.news_date_format) }} -
{{ title }}
{% if author is not empty %}
Author: {{ author }}