From 011a85d8ae34283ded6999882833f9d4797028ec Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 10 Nov 2024 20:25:17 +0100 Subject: [PATCH 01/11] new hook: HOOK_ADMIN_NEWS_ADD --- system/src/News.php | 11 +++++++++++ system/src/global.php | 1 + 2 files changed, 12 insertions(+) diff --git a/system/src/News.php b/system/src/News.php index 02923837..83eedb38 100644 --- a/system/src/News.php +++ b/system/src/News.php @@ -48,6 +48,17 @@ class News 'article_text' => ($type == 3 ? $article_text : ''), 'article_image' => ($type == 3 ? $article_image : '') ]); + + global $hooks; + $hooks->trigger(HOOK_ADMIN_NEWS_ADD, + [ + 'title' => $title, 'body' => $body, + 'type' => $type, 'category' => $category, + 'player_id' => $player_id, 'comments' => $comments, + 'article_text' => $article_text, 'article_image' => $article_image, + ] + ); + self::clearCache(); return true; } diff --git a/system/src/global.php b/system/src/global.php index e106a57c..8ab06c81 100644 --- a/system/src/global.php +++ b/system/src/global.php @@ -71,6 +71,7 @@ define('HOOK_ADMIN_BODY_START', ++$i); define('HOOK_ADMIN_BODY_END', ++$i); define('HOOK_ADMIN_BEFORE_PAGE', ++$i); define('HOOK_ADMIN_MENU', ++$i); +define('HOOK_ADMIN_NEWS_ADD', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_ACCOUNT', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i); From 7e67e11e16ca64c33bb60dfc940809bb1afb8ae9 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 10 Nov 2024 20:25:42 +0100 Subject: [PATCH 02/11] More understandable argument name --- system/src/Commands/PluginInstallCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Commands/PluginInstallCommand.php b/system/src/Commands/PluginInstallCommand.php index f40961e7..6330e08a 100644 --- a/system/src/Commands/PluginInstallCommand.php +++ b/system/src/Commands/PluginInstallCommand.php @@ -14,14 +14,14 @@ class PluginInstallCommand extends Command { $this->setName('plugin:install') ->setDescription('This command installs plugin') - ->addArgument('plugin', InputArgument::REQUIRED, 'Path to zip file (plugin) that you want to install'); + ->addArgument('pathToPluginZip', InputArgument::REQUIRED, 'Path to zip file (plugin) that you want to install'); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $pathToFile = $input->getArgument('plugin'); + $pathToFile = $input->getArgument('pathToPluginZip'); $ext = strtolower(pathinfo($pathToFile, PATHINFO_EXTENSION)); if($ext !== 'zip') {// check if it is zipped/compressed file From 7d787b4566b7f101935772dd28fec4487dbc0224 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 10 Nov 2024 20:25:46 +0100 Subject: [PATCH 03/11] Update database.php --- system/database.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/database.php b/system/database.php index 34b4574a..b9dc6cc6 100644 --- a/system/database.php +++ b/system/database.php @@ -106,6 +106,7 @@ try { 'persistent' => @$config['database_persistent'] )); + global $db; $db = POT::getInstance()->getDBHandle(); $capsule = new Capsule; $capsule->addConnection([ From 749e8e6f02f1564dad0daf8c1206113d90620d05 Mon Sep 17 00:00:00 2001 From: slawkens Date: Mon, 11 Nov 2024 22:04:06 +0100 Subject: [PATCH 04/11] Fix choose a skill dropdown --- system/templates/highscores.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/templates/highscores.html.twig b/system/templates/highscores.html.twig index d4d3dd55..90f91185 100644 --- a/system/templates/highscores.html.twig +++ b/system/templates/highscores.html.twig @@ -11,7 +11,7 @@ From ddced132cf806120ff291f101ddeeab51944c2d9 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 20:42:06 +0100 Subject: [PATCH 05/11] Fix if highscores_vocation box is disabled causing Choose a vocation dropdown to fail --- system/pages/highscores.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/pages/highscores.php b/system/pages/highscores.php index bba1dff6..213d1534 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -31,12 +31,11 @@ if(!is_numeric($page) || $page < 1 || $page > PHP_INT_MAX) { $query = Player::query(); -$settingHighscoresVocationBox = setting('core.highscores_vocation_box'); $configVocations = config('vocations'); $configVocationsAmount = config('vocations_amount'); $vocationId = null; -if($settingHighscoresVocationBox && $vocation !== 'all') { +if($vocation !== 'all') { foreach($configVocations as $id => $name) { if(strtolower($name) == $vocation) { $vocationId = $id; From a4a248099521bb5b8b2aa5bd592138debd2f19d5 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 20:51:45 +0100 Subject: [PATCH 06/11] Add None vocation to highscores (can be changed to RookStayer in Admin Panel) --- system/pages/highscores.php | 10 ++++++---- system/templates/highscores.html.twig | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/system/pages/highscores.php b/system/pages/highscores.php index 213d1534..d7eb7384 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -41,10 +41,12 @@ if($vocation !== 'all') { $vocationId = $id; $add_vocs = [$id]; - $i = $id + $configVocationsAmount; - while(isset($configVocations[$i])) { - $add_vocs[] = $i; - $i += $configVocationsAmount; + if ($id !== 0) { + $i = $id + $configVocationsAmount; + while (isset($configVocations[$i])) { + $add_vocs[] = $i; + $i += $configVocationsAmount; + } } $query->whereIn('players.vocation', $add_vocs); diff --git a/system/templates/highscores.html.twig b/system/templates/highscores.html.twig index 90f91185..938220e5 100644 --- a/system/templates/highscores.html.twig +++ b/system/templates/highscores.html.twig @@ -20,7 +20,7 @@ @@ -119,7 +119,7 @@ [ALL]
- {% for i in 1..config.vocations_amount %} + {% for i in 0..config.vocations_amount %} {{ config.vocations[i]}}
{% endfor %} From 941846605c00cee83168d2f916410b8ba8d4b7b9 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 20:59:51 +0100 Subject: [PATCH 07/11] Prefer get_browser_real_ip() over REMOTE_ADDR --- install/index.php | 6 +++--- system/pages/account/create.php | 2 +- system/pages/forum/new_thread.php | 2 +- system/src/Forum.php | 4 ++-- system/src/Visitors.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/install/index.php b/install/index.php index 1031a2b8..5dc457f8 100644 --- a/install/index.php +++ b/install/index.php @@ -183,14 +183,14 @@ clearstatcache(); if(is_writable(CACHE) && (MYAAC_OS != 'WINDOWS' || win_is_writable(CACHE))) { if(!file_exists(BASE . 'install/ip.txt')) { $content = warning('AAC installation is disabled. To enable it make file ip.txt in install/ directory and put there your IP.
- Your IP is:
' . $_SERVER['REMOTE_ADDR'] . '', true); + Your IP is:
' . get_browser_real_ip() . '', true); } else { $file_content = trim(file_get_contents(BASE . 'install/ip.txt')); $allow = false; $listIP = preg_split('/\s+/', $file_content); foreach($listIP as $ip) { - if($_SERVER['REMOTE_ADDR'] == $ip) { + if(get_browser_real_ip() == $ip) { $allow = true; } } @@ -199,7 +199,7 @@ if(is_writable(CACHE) && (MYAAC_OS != 'WINDOWS' || win_is_writable(CACHE))) { { $content = warning('In file install/ip.txt must be your IP!
In file is:
' . nl2br($file_content) . '
- Your IP is:
' . $_SERVER['REMOTE_ADDR'] . '', true); + Your IP is:
' . get_browser_real_ip() . '', true); } else { ob_start(); diff --git a/system/pages/account/create.php b/system/pages/account/create.php index 9fba8237..af427d37 100644 --- a/system/pages/account/create.php +++ b/system/pages/account/create.php @@ -331,7 +331,7 @@ if(setting('core.account_country_recognize')) { $country_recognized = $country_session; } else { - $info = json_decode(@file_get_contents('http://ipinfo.io/' . $_SERVER['REMOTE_ADDR'] . '/geo'), true); + $info = json_decode(@file_get_contents('http://ipinfo.io/' . get_browser_real_ip() . '/geo'), true); if(isset($info['country'])) { $country_recognized = strtolower($info['country']); setSession('country', $country_recognized); diff --git a/system/pages/forum/new_thread.php b/system/pages/forum/new_thread.php index 7a66ac27..d10e7a11 100644 --- a/system/pages/forum/new_thread.php +++ b/system/pages/forum/new_thread.php @@ -95,7 +95,7 @@ if(Forum::canPost($account_logged)) { if (count($errors) == 0) { $saved = true; - $db->query("INSERT INTO `" . FORUM_TABLE_PREFIX . "forum` (`first_post` ,`last_post` ,`section` ,`replies` ,`views` ,`author_aid` ,`author_guid` ,`post_text` ,`post_topic` ,`post_smile`, `post_html` ,`post_date` ,`last_edit_aid` ,`edit_date`, `post_ip`) VALUES ('0', '" . time() . "', '" . (int)$section_id . "', '0', '0', '" . $account_logged->getId() . "', '" . $char_id . "', " . $db->quote($text) . ", " . $db->quote($post_topic) . ", '" . $smile . "', '" . $html . "', '" . time() . "', '0', '0', '" . $_SERVER['REMOTE_ADDR'] . "')"); + $db->query("INSERT INTO `" . FORUM_TABLE_PREFIX . "forum` (`first_post` ,`last_post` ,`section` ,`replies` ,`views` ,`author_aid` ,`author_guid` ,`post_text` ,`post_topic` ,`post_smile`, `post_html` ,`post_date` ,`last_edit_aid` ,`edit_date`, `post_ip`) VALUES ('0', '" . time() . "', '" . (int)$section_id . "', '0', '0', '" . $account_logged->getId() . "', '" . $char_id . "', " . $db->quote($text) . ", " . $db->quote($post_topic) . ", '" . $smile . "', '" . $html . "', '" . time() . "', '0', '0', '" . get_browser_real_ip() . "')"); $thread_id = $db->lastInsertId(); diff --git a/system/src/Forum.php b/system/src/Forum.php index ec9baee5..64b22222 100644 --- a/system/src/Forum.php +++ b/system/src/Forum.php @@ -72,7 +72,7 @@ class Forum 'post_smile' => 0, 'post_html' => 1, 'post_date' => time(), 'last_edit_aid' => 0, 'edit_date' => 0, - 'post_ip' => $_SERVER['REMOTE_ADDR'] + 'post_ip' => get_browser_real_ip() ))) { $thread_id = $db->lastInsertId(); $db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `first_post`=".(int) $thread_id." WHERE `id` = ".(int) $thread_id); @@ -94,7 +94,7 @@ class Forum 'post_smile' => $smile, 'post_html' => $html, 'post_date' => time(), - 'post_ip' => $_SERVER['REMOTE_ADDR'] + 'post_ip' => get_browser_real_ip() )); } public static function add_board($name, $description, $access, $guild, &$errors) diff --git a/system/src/Visitors.php b/system/src/Visitors.php index 32220c6a..9968a214 100644 --- a/system/src/Visitors.php +++ b/system/src/Visitors.php @@ -37,7 +37,7 @@ class Visitors $this->sessionTime = $sessionTime; $this->cleanVisitors(); - $ip = $_SERVER['REMOTE_ADDR']; + $ip = get_browser_real_ip(); $userAgentShortened = substr($_SERVER['HTTP_USER_AGENT'] ?? 'unknown', 0, 255); if($this->visitorExists($ip)) From 507402171ba3b6e7ee184bd7fa73e0d55e0cad7a Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 21:01:14 +0100 Subject: [PATCH 08/11] Patching from master some small adjustments (Account Logs typo + forum new thread show button by @anyeor) --- system/pages/forum/show_board.php | 4 ++-- system/templates/account.management.html.twig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system/pages/forum/show_board.php b/system/pages/forum/show_board.php index 5d61690a..a9896a53 100644 --- a/system/pages/forum/show_board.php +++ b/system/pages/forum/show_board.php @@ -44,7 +44,7 @@ for($i = 0; $i < $threads_count['threads_count'] / setting('core.forum_threads_p echo 'Boards >> '.$sections[$section_id]['name'].''; -if(!$sections[$section_id]['closed'] || Forum::isModerator()) { +if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) echo '

'; } @@ -94,7 +94,7 @@ if(isset($last_threads[0])) { } echo ''; - if(!$sections[$section_id]['closed'] || Forum::isModerator()) { + if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) echo '
'; } } diff --git a/system/templates/account.management.html.twig b/system/templates/account.management.html.twig index 87a33b6a..2db1e57c 100644 --- a/system/templates/account.management.html.twig +++ b/system/templates/account.management.html.twig @@ -149,7 +149,7 @@
{{ hook('HOOK_ACCOUNT_MANAGE_BEFORE_ACCOUNT_LOGS') }} -

Action Log

+

Account Logs

From 85bc2342cf99651dc27badfa7e92646e0c1a630a Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 21:03:43 +0100 Subject: [PATCH 09/11] Fix missing bracket opening --- system/pages/forum/show_board.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/pages/forum/show_board.php b/system/pages/forum/show_board.php index a9896a53..0b192dfc 100644 --- a/system/pages/forum/show_board.php +++ b/system/pages/forum/show_board.php @@ -44,7 +44,7 @@ for($i = 0; $i < $threads_count['threads_count'] / setting('core.forum_threads_p echo 'Boards >> '.$sections[$section_id]['name'].''; -if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) +if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) { echo '

'; } @@ -94,7 +94,7 @@ if(isset($last_threads[0])) { } echo '
ActionDateIP
'; - if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) + if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) { echo '
'; } } From 36bd3eb846e829b45313e10f7568dc4e95841143 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 22:01:00 +0100 Subject: [PATCH 10/11] New hooks for news management Can be used for example as discord hooks --- system/src/News.php | 107 ++++++++++++++++++++++++++++-------------- system/src/global.php | 7 +++ 2 files changed, 80 insertions(+), 34 deletions(-) diff --git a/system/src/News.php b/system/src/News.php index 83eedb38..5ef7a086 100644 --- a/system/src/News.php +++ b/system/src/News.php @@ -37,26 +37,27 @@ class News if(!self::verify($title, $body, $article_text, $article_image, $errors)) return false; - ModelsNews::create([ - 'title' => $title, - 'body' => $body, - 'type' => $type, - 'date' => time(), - 'category' => $category, - 'player_id' => isset($player_id) ? $player_id : 0, + $currentTime = time(); + + $params = [ + 'title' => $title, 'body' => $body, + 'type' => $type, 'category' => $category, + 'date' => $currentTime, + 'player_id' => $player_id ?? 0, 'comments' => $comments, 'article_text' => ($type == 3 ? $article_text : ''), 'article_image' => ($type == 3 ? $article_image : '') - ]); + ]; global $hooks; + if (!$hooks->trigger(HOOK_ADMIN_NEWS_ADD_PRE, $params)) { + return false; + } + + $newsModel = ModelsNews::create($params); + $hooks->trigger(HOOK_ADMIN_NEWS_ADD, - [ - 'title' => $title, 'body' => $body, - 'type' => $type, 'category' => $category, - 'player_id' => $player_id, 'comments' => $comments, - 'article_text' => $article_text, 'article_image' => $article_image, - ] + $params + ['id' => $newsModel->id], ); self::clearCache(); @@ -69,30 +70,55 @@ class News static public function update($id, $title, $body, $type, $category, $player_id, $comments, $article_text, $article_image, &$errors) { - if(!self::verify($title, $body, $article_text, $article_image, $errors)) + if(!self::verify($title, $body, $article_text, $article_image, $errors)) { return false; + } - ModelsNews::where('id', $id)->update([ - 'title' => $title, - 'body' => $body, - 'type' => $type, - 'category' => $category, - 'last_modified_by' => isset($player_id) ? $player_id : 0, - 'last_modified_date' => time(), + $currentTime = time(); + + $params = [ + 'id' => $id, + 'title' => $title, 'body' => $body, + 'type' => $type, 'category' => $category, + 'last_modified_by' => $player_id ?? 0, 'last_modified_date' => $currentTime, 'comments' => $comments, - 'article_text' => $article_text, - 'article_image' => $article_image - ]); + 'article_text' => ($type == 3 ? $article_text : ''), + 'article_image' => ($type == 3 ? $article_image : ''), + ]; + + global $hooks; + if (!$hooks->trigger(HOOK_ADMIN_NEWS_UPDATE_PRE, $params)) { + return false; + } + + unset($params['id']); + + ModelsNews::where('id', $id)->update($params); + + $hooks->trigger(HOOK_ADMIN_NEWS_UPDATE, + $params + ['id' => $id] + ); + self::clearCache(); return true; } static public function delete($id, &$errors) { + global $hooks; + if(isset($id)) { $row = ModelsNews::find($id); if($row) { - if (!$row->delete()) { + $params = ['id' => $id]; + + if (!$hooks->trigger(HOOK_ADMIN_NEWS_DELETE_PRE, $params)) { + return false; + } + + if ($row->delete()) { + $hooks->trigger(HOOK_ADMIN_NEWS_DELETE, $params); + } else { $errors[] = 'Fail during delete News.'; } } @@ -114,22 +140,35 @@ class News static public function toggleHide($id, &$errors, &$status) { - if(isset($id)) - { + global $hooks; + + if(isset($id)) { $row = ModelsNews::find($id); - if($row) - { - $row->hide = $row->hide == 1 ? 0 : 1; - if (!$row->save()) { + if($row) { + $row->hide = ($row->hide == 1 ? 0 : 1); + + $params = ['hide' => $row->hide]; + + if (!$hooks->trigger(HOOK_ADMIN_NEWS_TOGGLE_HIDE_PRE, $params)) { + return false; + } + + if ($row->save()) { + $hooks->trigger(HOOK_ADMIN_NEWS_TOGGLE_HIDE, $params); + } + else { $errors[] = 'Fail during toggle hide News.'; } + $status = $row->hide; } - else + else { $errors[] = 'News with id ' . $id . ' does not exists.'; + } } - else + else { $errors[] = 'News id not set.'; + } if(count($errors)) { return false; diff --git a/system/src/global.php b/system/src/global.php index 8ab06c81..d5c54fd8 100644 --- a/system/src/global.php +++ b/system/src/global.php @@ -71,7 +71,14 @@ define('HOOK_ADMIN_BODY_START', ++$i); define('HOOK_ADMIN_BODY_END', ++$i); define('HOOK_ADMIN_BEFORE_PAGE', ++$i); define('HOOK_ADMIN_MENU', ++$i); +define('HOOK_ADMIN_NEWS_ADD_PRE', ++$i); define('HOOK_ADMIN_NEWS_ADD', ++$i); +define('HOOK_ADMIN_NEWS_UPDATE_PRE', ++$i); +define('HOOK_ADMIN_NEWS_UPDATE', ++$i); +define('HOOK_ADMIN_NEWS_DELETE_PRE', ++$i); +define('HOOK_ADMIN_NEWS_DELETE', ++$i); +define('HOOK_ADMIN_NEWS_TOGGLE_HIDE_PRE', ++$i); +define('HOOK_ADMIN_NEWS_TOGGLE_HIDE', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_ACCOUNT', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i); From bab565fbd03f5eedd2c0f9373d1cb6f6cba21a9f Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 12 Nov 2024 22:01:15 +0100 Subject: [PATCH 11/11] Update init.php --- system/init.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/init.php b/system/init.php index dbc9db08..b489dd38 100644 --- a/system/init.php +++ b/system/init.php @@ -43,9 +43,11 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT ob_start('ob_gzhandler'); // cache +global $cache; $cache = Cache::getInstance(); // event system +global $hooks; $hooks = new Hooks(); $hooks->load();