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/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([ diff --git a/system/init.php b/system/init.php index 1673d3d8..560a6100 100644 --- a/system/init.php +++ b/system/init.php @@ -43,6 +43,7 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT ob_start('ob_gzhandler'); // cache +global $cache; $cache = Cache::getInstance(); // event system 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/pages/forum/show_board.php b/system/pages/forum/show_board.php index 5d61690a..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(!$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/pages/highscores.php b/system/pages/highscores.php index bba1dff6..d7eb7384 100644 --- a/system/pages/highscores.php +++ b/system/pages/highscores.php @@ -31,21 +31,22 @@ 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; $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/src/Commands/PluginInstallCommand.php b/system/src/Commands/PluginInstallCommand.php index f5504cb6..a37c0859 100644 --- a/system/src/Commands/PluginInstallCommand.php +++ b/system/src/Commands/PluginInstallCommand.php @@ -14,7 +14,7 @@ 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 @@ -23,7 +23,7 @@ class PluginInstallCommand extends Command $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 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/News.php b/system/src/News.php index 02923837..5ef7a086 100644 --- a/system/src/News.php +++ b/system/src/News.php @@ -37,17 +37,29 @@ 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, + $params + ['id' => $newsModel->id], + ); + self::clearCache(); return true; } @@ -58,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.'; } } @@ -103,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/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)) diff --git a/system/src/global.php b/system/src/global.php index e106a57c..d5c54fd8 100644 --- a/system/src/global.php +++ b/system/src/global.php @@ -71,6 +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); 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

diff --git a/system/templates/highscores.html.twig b/system/templates/highscores.html.twig index d4d3dd55..938220e5 100644 --- a/system/templates/highscores.html.twig +++ b/system/templates/highscores.html.twig @@ -11,7 +11,7 @@ @@ -20,7 +20,7 @@ @@ -119,7 +119,7 @@
ActionDateIP
[ALL]
- {% for i in 1..config.vocations_amount %} + {% for i in 0..config.vocations_amount %} {{ config.vocations[i]}}
{% endfor %}