Merge branch 'develop' into feature/migrations-up-down

This commit is contained in:
slawkens 2024-11-12 22:17:51 +01:00
commit 99d77cb175
14 changed files with 111 additions and 50 deletions

View File

@ -183,14 +183,14 @@ clearstatcache();
if(is_writable(CACHE) && (MYAAC_OS != 'WINDOWS' || win_is_writable(CACHE))) { if(is_writable(CACHE) && (MYAAC_OS != 'WINDOWS' || win_is_writable(CACHE))) {
if(!file_exists(BASE . 'install/ip.txt')) { if(!file_exists(BASE . 'install/ip.txt')) {
$content = warning('AAC installation is disabled. To enable it make file <b>ip.txt</b> in install/ directory and put there your IP.<br/> $content = warning('AAC installation is disabled. To enable it make file <b>ip.txt</b> in install/ directory and put there your IP.<br/>
Your IP is:<br /><b>' . $_SERVER['REMOTE_ADDR'] . '</b>', true); Your IP is:<br /><b>' . get_browser_real_ip() . '</b>', true);
} }
else { else {
$file_content = trim(file_get_contents(BASE . 'install/ip.txt')); $file_content = trim(file_get_contents(BASE . 'install/ip.txt'));
$allow = false; $allow = false;
$listIP = preg_split('/\s+/', $file_content); $listIP = preg_split('/\s+/', $file_content);
foreach($listIP as $ip) { foreach($listIP as $ip) {
if($_SERVER['REMOTE_ADDR'] == $ip) { if(get_browser_real_ip() == $ip) {
$allow = true; $allow = true;
} }
} }
@ -199,7 +199,7 @@ if(is_writable(CACHE) && (MYAAC_OS != 'WINDOWS' || win_is_writable(CACHE))) {
{ {
$content = warning('In file <b>install/ip.txt</b> must be your IP!<br/> $content = warning('In file <b>install/ip.txt</b> must be your IP!<br/>
In file is:<br /><b>' . nl2br($file_content) . '</b><br/> In file is:<br /><b>' . nl2br($file_content) . '</b><br/>
Your IP is:<br /><b>' . $_SERVER['REMOTE_ADDR'] . '</b>', true); Your IP is:<br /><b>' . get_browser_real_ip() . '</b>', true);
} }
else { else {
ob_start(); ob_start();

View File

@ -106,6 +106,7 @@ try {
'persistent' => @$config['database_persistent'] 'persistent' => @$config['database_persistent']
)); ));
global $db;
$db = POT::getInstance()->getDBHandle(); $db = POT::getInstance()->getDBHandle();
$capsule = new Capsule; $capsule = new Capsule;
$capsule->addConnection([ $capsule->addConnection([

View File

@ -43,6 +43,7 @@ if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HT
ob_start('ob_gzhandler'); ob_start('ob_gzhandler');
// cache // cache
global $cache;
$cache = Cache::getInstance(); $cache = Cache::getInstance();
// event system // event system

View File

@ -331,7 +331,7 @@ if(setting('core.account_country_recognize')) {
$country_recognized = $country_session; $country_recognized = $country_session;
} }
else { 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'])) { if(isset($info['country'])) {
$country_recognized = strtolower($info['country']); $country_recognized = strtolower($info['country']);
setSession('country', $country_recognized); setSession('country', $country_recognized);

View File

@ -95,7 +95,7 @@ if(Forum::canPost($account_logged)) {
if (count($errors) == 0) { if (count($errors) == 0) {
$saved = true; $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(); $thread_id = $db->lastInsertId();

View File

@ -44,7 +44,7 @@ for($i = 0; $i < $threads_count['threads_count'] / setting('core.forum_threads_p
echo '<a href="' . getLink('forum') . '">Boards</a> >> <b>'.$sections[$section_id]['name'].'</b>'; echo '<a href="' . getLink('forum') . '">Boards</a> >> <b>'.$sections[$section_id]['name'].'</b>';
if(!$sections[$section_id]['closed'] || Forum::isModerator()) { if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) {
echo '<br /><br /> echo '<br /><br />
<a href="' . getLink('forum') . '?action=new_thread&section_id='.$section_id.'"><img src="images/forum/topic.gif" border="0" /></a>'; <a href="' . getLink('forum') . '?action=new_thread&section_id='.$section_id.'"><img src="images/forum/topic.gif" border="0" /></a>';
} }
@ -94,7 +94,7 @@ if(isset($last_threads[0])) {
} }
echo '</table>'; echo '</table>';
if(!$sections[$section_id]['closed'] || Forum::isModerator()) { if($logged && (!$sections[$section_id]['closed'] || Forum::isModerator())) {
echo '<br /><a href="' . getLink('forum') . '?action=new_thread&section_id=' . $section_id . '"><img src="images/forum/topic.gif" border="0" /></a>'; echo '<br /><a href="' . getLink('forum') . '?action=new_thread&section_id=' . $section_id . '"><img src="images/forum/topic.gif" border="0" /></a>';
} }
} }

View File

@ -31,21 +31,22 @@ if(!is_numeric($page) || $page < 1 || $page > PHP_INT_MAX) {
$query = Player::query(); $query = Player::query();
$settingHighscoresVocationBox = setting('core.highscores_vocation_box');
$configVocations = config('vocations'); $configVocations = config('vocations');
$configVocationsAmount = config('vocations_amount'); $configVocationsAmount = config('vocations_amount');
$vocationId = null; $vocationId = null;
if($settingHighscoresVocationBox && $vocation !== 'all') { if($vocation !== 'all') {
foreach($configVocations as $id => $name) { foreach($configVocations as $id => $name) {
if(strtolower($name) == $vocation) { if(strtolower($name) == $vocation) {
$vocationId = $id; $vocationId = $id;
$add_vocs = [$id]; $add_vocs = [$id];
$i = $id + $configVocationsAmount; if ($id !== 0) {
while(isset($configVocations[$i])) { $i = $id + $configVocationsAmount;
$add_vocs[] = $i; while (isset($configVocations[$i])) {
$i += $configVocationsAmount; $add_vocs[] = $i;
$i += $configVocationsAmount;
}
} }
$query->whereIn('players.vocation', $add_vocs); $query->whereIn('players.vocation', $add_vocs);

View File

@ -14,7 +14,7 @@ class PluginInstallCommand extends Command
{ {
$this->setName('plugin:install') $this->setName('plugin:install')
->setDescription('This command installs plugin') ->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 protected function execute(InputInterface $input, OutputInterface $output): int
@ -23,7 +23,7 @@ class PluginInstallCommand extends Command
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$pathToFile = $input->getArgument('plugin'); $pathToFile = $input->getArgument('pathToPluginZip');
$ext = strtolower(pathinfo($pathToFile, PATHINFO_EXTENSION)); $ext = strtolower(pathinfo($pathToFile, PATHINFO_EXTENSION));
if($ext !== 'zip') {// check if it is zipped/compressed file if($ext !== 'zip') {// check if it is zipped/compressed file

View File

@ -72,7 +72,7 @@ class Forum
'post_smile' => 0, 'post_html' => 1, 'post_smile' => 0, 'post_html' => 1,
'post_date' => time(), 'post_date' => time(),
'last_edit_aid' => 0, 'edit_date' => 0, 'last_edit_aid' => 0, 'edit_date' => 0,
'post_ip' => $_SERVER['REMOTE_ADDR'] 'post_ip' => get_browser_real_ip()
))) { ))) {
$thread_id = $db->lastInsertId(); $thread_id = $db->lastInsertId();
$db->query("UPDATE `" . FORUM_TABLE_PREFIX . "forum` SET `first_post`=".(int) $thread_id." WHERE `id` = ".(int) $thread_id); $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_smile' => $smile,
'post_html' => $html, 'post_html' => $html,
'post_date' => time(), 'post_date' => time(),
'post_ip' => $_SERVER['REMOTE_ADDR'] 'post_ip' => get_browser_real_ip()
)); ));
} }
public static function add_board($name, $description, $access, $guild, &$errors) public static function add_board($name, $description, $access, $guild, &$errors)

View File

@ -37,17 +37,29 @@ class News
if(!self::verify($title, $body, $article_text, $article_image, $errors)) if(!self::verify($title, $body, $article_text, $article_image, $errors))
return false; return false;
ModelsNews::create([ $currentTime = time();
'title' => $title,
'body' => $body, $params = [
'type' => $type, 'title' => $title, 'body' => $body,
'date' => time(), 'type' => $type, 'category' => $category,
'category' => $category, 'date' => $currentTime,
'player_id' => isset($player_id) ? $player_id : 0, 'player_id' => $player_id ?? 0,
'comments' => $comments, 'comments' => $comments,
'article_text' => ($type == 3 ? $article_text : ''), 'article_text' => ($type == 3 ? $article_text : ''),
'article_image' => ($type == 3 ? $article_image : '') '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(); self::clearCache();
return true; 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) 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; return false;
}
ModelsNews::where('id', $id)->update([ $currentTime = time();
'title' => $title,
'body' => $body, $params = [
'type' => $type, 'id' => $id,
'category' => $category, 'title' => $title, 'body' => $body,
'last_modified_by' => isset($player_id) ? $player_id : 0, 'type' => $type, 'category' => $category,
'last_modified_date' => time(), 'last_modified_by' => $player_id ?? 0, 'last_modified_date' => $currentTime,
'comments' => $comments, 'comments' => $comments,
'article_text' => $article_text, 'article_text' => ($type == 3 ? $article_text : ''),
'article_image' => $article_image '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(); self::clearCache();
return true; return true;
} }
static public function delete($id, &$errors) static public function delete($id, &$errors)
{ {
global $hooks;
if(isset($id)) { if(isset($id)) {
$row = ModelsNews::find($id); $row = ModelsNews::find($id);
if($row) { 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.'; $errors[] = 'Fail during delete News.';
} }
} }
@ -103,22 +140,35 @@ class News
static public function toggleHide($id, &$errors, &$status) static public function toggleHide($id, &$errors, &$status)
{ {
if(isset($id)) global $hooks;
{
if(isset($id)) {
$row = ModelsNews::find($id); $row = ModelsNews::find($id);
if($row) if($row) {
{ $row->hide = ($row->hide == 1 ? 0 : 1);
$row->hide = $row->hide == 1 ? 0 : 1;
if (!$row->save()) { $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.'; $errors[] = 'Fail during toggle hide News.';
} }
$status = $row->hide; $status = $row->hide;
} }
else else {
$errors[] = 'News with id ' . $id . ' does not exists.'; $errors[] = 'News with id ' . $id . ' does not exists.';
}
} }
else else {
$errors[] = 'News id not set.'; $errors[] = 'News id not set.';
}
if(count($errors)) { if(count($errors)) {
return false; return false;

View File

@ -37,7 +37,7 @@ class Visitors
$this->sessionTime = $sessionTime; $this->sessionTime = $sessionTime;
$this->cleanVisitors(); $this->cleanVisitors();
$ip = $_SERVER['REMOTE_ADDR']; $ip = get_browser_real_ip();
$userAgentShortened = substr($_SERVER['HTTP_USER_AGENT'] ?? 'unknown', 0, 255); $userAgentShortened = substr($_SERVER['HTTP_USER_AGENT'] ?? 'unknown', 0, 255);
if($this->visitorExists($ip)) if($this->visitorExists($ip))

View File

@ -71,6 +71,14 @@ define('HOOK_ADMIN_BODY_START', ++$i);
define('HOOK_ADMIN_BODY_END', ++$i); define('HOOK_ADMIN_BODY_END', ++$i);
define('HOOK_ADMIN_BEFORE_PAGE', ++$i); define('HOOK_ADMIN_BEFORE_PAGE', ++$i);
define('HOOK_ADMIN_MENU', ++$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_ACCOUNT', ++$i);
define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i);
define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i); define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i);

View File

@ -149,7 +149,7 @@
<br/> <br/>
{{ hook('HOOK_ACCOUNT_MANAGE_BEFORE_ACCOUNT_LOGS') }} {{ hook('HOOK_ACCOUNT_MANAGE_BEFORE_ACCOUNT_LOGS') }}
<a name="Account+Logs" ></a> <a name="Account+Logs" ></a>
<h2>Action Log</h2> <h2>Account Logs</h2>
<table> <table>
<tr bgcolor="{{ config.vdarkborder }}" class="white"> <tr bgcolor="{{ config.vdarkborder }}" class="white">
<th>Action</th><th>Date</th><th>IP</th> <th>Action</th><th>Date</th><th>IP</th>

View File

@ -11,7 +11,7 @@
<select onchange="location = this.value;" id="skillFilter"> <select onchange="location = this.value;" id="skillFilter">
{% set i = 0 %} {% set i = 0 %}
{% for link, name in types %} {% for link, name in types %}
<option value="{{ getLink('highscores') }}/{{ link }}/{% if vocation is not null %}{{ vocation }}{% endif %}" class="size_xs" {% if list is not null and list == link %}selected{% endif %}>{{ name }}</option> <option value="{{ getLink('highscores') }}/{{ link }}{% if vocation is not null %}/{{ vocation }}{% endif %}" class="size_xs" {% if list is not null and list == link %}selected{% endif %}>{{ name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
@ -20,7 +20,7 @@
<select onchange="location = this.value;" id="vocationFilter"> <select onchange="location = this.value;" id="vocationFilter">
<option value="{{ getLink('highscores') }}/{{ list }}" class="size_xs">[ALL]</option> <option value="{{ getLink('highscores') }}/{{ list }}" class="size_xs">[ALL]</option>
{% set i = 0 %} {% set i = 0 %}
{% for i in 1..config.vocations_amount %} {% for i in 0..config.vocations_amount %}
<option value="{{ getLink('highscores') }}/{{ list }}/{{ config.vocations[i]|lower }}" class="size_xs" {% if vocationId is not null and vocationId == i %}selected{% endif %}>{{ config.vocations[i]}}</option> <option value="{{ getLink('highscores') }}/{{ list }}/{{ config.vocations[i]|lower }}" class="size_xs" {% if vocationId is not null and vocationId == i %}selected{% endif %}>{{ config.vocations[i]}}</option>
{% endfor %} {% endfor %}
</select> </select>
@ -119,7 +119,7 @@
<tr bgcolor="{{ config.lightborder }}"> <tr bgcolor="{{ config.lightborder }}">
<td> <td>
<a href="{{ getLink('highscores') }}/{{ list }}" class="size_xs">[ALL]</a><br/> <a href="{{ getLink('highscores') }}/{{ list }}" class="size_xs">[ALL]</a><br/>
{% for i in 1..config.vocations_amount %} {% for i in 0..config.vocations_amount %}
<a href="{{ getLink('highscores') }}/{{ list }}/{{ config.vocations[i]|lower }}" class="size_xs">{{ config.vocations[i]}}</a><br/> <a href="{{ getLink('highscores') }}/{{ list }}/{{ config.vocations[i]|lower }}" class="size_xs">{{ config.vocations[i]}}</a><br/>
{% endfor %} {% endfor %}
</td> </td>