Compare commits

..

2 Commits

Author SHA1 Message Date
slawkens
dda4aca832 Merge branch 'develop' into feature/dashboard-insights 2026-04-11 17:59:31 +02:00
slawkens
853520cfc4 feat: Dashboard Insights 2026-03-15 13:04:07 +01:00
25 changed files with 305 additions and 209 deletions

View File

@@ -1,12 +1,9 @@
## [2.0-dev - x.x.2025] ## [2.0-dev - x.x.2025]
### Added ### Added
* Menus: Add an "access" option to Menus (#340) * Add an "access" option to Menus (#340)
* Possibility to hide menus for unauthorized users * Possibility to hide menus for unauthorized users
* Settings: Add Reset button (https://github.com/slawkens/myaac/commit/7104c2258fd724a55239821b46a616dab845b22a, https://github.com/slawkens/myaac/commit/e274b8350451a20c24e652ea05ed1964ebb86b54) * Add the possibility to fetch skills, balance and frags in the getTopPlayers function (#347)
* New Setting: block create account spam by ip (https://github.com/slawkens/myaac/commit/54265f42e987522803288477952d6e5c4daeeb24)
* Functions: Add the possibility to fetch skills, balance and frags in the getTopPlayers function (#347)
* Plugins: autoload init-priority option (https://github.com/slawkens/myaac/commit/f1aa12840875960849fa0c99a2bbe0ad2949bbec)
### Changed ### Changed
* Better handling of vocations: (#345) * Better handling of vocations: (#345)
@@ -14,7 +11,6 @@
* Support for Monk vocation * Support for Monk vocation
* Better gallery, loads images from images/gallery folder * Better gallery, loads images from images/gallery folder
* Reworked account action logs to use a single IP column as varchar(45) for both ipv4 and ipv6 (#289) * Reworked account action logs to use a single IP column as varchar(45) for both ipv4 and ipv6 (#289)
* Make myaac_config table columns bigger (https://github.com/slawkens/myaac/commit/2c62a97160a3ffe9976ee5bd1d770a0abc576742)
* Admin Panel: save menu collapse state (https://github.com/slawkens/myaac/commit/55da00520df7463a1d1ca41931df1598e9f2ffeb) * Admin Panel: save menu collapse state (https://github.com/slawkens/myaac/commit/55da00520df7463a1d1ca41931df1598e9f2ffeb)
### Internal ### Internal

View File

@@ -86,6 +86,12 @@ Look: [Contributing](https://docs.my-aac.org/misc/contributing) in our wiki.
If you have a great idea or want to contribute to the project - visit our website at https://www.my-aac.org If you have a great idea or want to contribute to the project - visit our website at https://www.my-aac.org
## Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
[![JetBrains](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/slawkens)
### License ### License
This program and all associated files are released under the GNU Public License. This program and all associated files are released under the GNU Public License.

View File

@@ -0,0 +1,22 @@
<?php
use MyAAC\Admin\Insights;
defined('MYAAC') or die('Direct access not allowed!');
$getYear = (int)($_GET['year'] ?? date('Y'));
$getMonth = $_GET['month'] ?? (int)date('M') + 1;
$insights = new Insights($db);
$twig->display('insights.html.twig', [
'lastLoginPlayers' => $insights->getLastLoggedPlayers($getYear, $getMonth),
'lastCreatedAccounts' => $insights->getLastCreatedAccounts($getYear, $getMonth),
'firstYear' => $insights->getFirstYear(),
'getYear' => $getYear,
'getMonth' => $getMonth,
'months' => $insights->getMonths(),
]);

View File

@@ -0,0 +1,99 @@
{% set currentYear = 'now' | date('Y') %}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div class="col-sm-3 col-md-6 col-lg-12">
<div class="card card-info card-outline">
<div class="card-header">
<h5 class="m-0">Insights</h5>
</div>
<div class="card-body p-3 row">
<div class="col-md-6 col-sm-3">
<label for="month">Month:</label>
<select class="form-control" id="month" name="month">
{% for id, name in months %}
<option value="{{ id }}" {{ getMonth == id ? 'selected="selected"' : '' }}>{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-6 col-sm-3">
<label for="year">Year:</label>
<select class="form-control" id="year" name="year">
{% for year in range(firstYear, currentYear) %}
<option value="{{ year }}" {{ getYear == year ? 'selected' : '' }}>{{ year }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="card-body p-3 row">
<div class="col-6 col-md-6">
<div class="chart">
<canvas id="lastLoginsChart" style="min-height: 250px; height: 250px; max-height: 250px; max-width: 100%;"></canvas>
</div>
</div>
<div class="col-6 col-md-6">
<div class="chart">
<canvas id="lastCreatedChart" style="min-height: 250px; height: 250px; max-height: 250px; max-width: 100%;"></canvas>
</div>
</div>
</div>
</div>
</div>
<script>
$(function () {
$('#year').on('change', function() {
window.location.href = "?p=dashboard&year=" + $(this).val() + "&month={{ getMonth }}";
});
$('#month').on('change', function() {
window.location.href = "?p=dashboard&year={{ getYear }}" + "&month=" + $(this).val();
});
});
const config = {
type: 'bar',
data: {
labels: [
{% for player in lastLoginPlayers %}
"{{ player.date }}",
{% endfor %}
],
datasets: [
{
label: "Logged players",
backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850"],
data: [
{% for player in lastLoginPlayers %}
{{ player.how_much }},
{% endfor %}
]
}
]
}
}
const myChart = new Chart(document.getElementById('lastLoginsChart'), config);
const config2 = {
type: 'bar',
data: {
labels: [
{% for account in lastCreatedAccounts %}
"{{ account.date }}",
{% endfor %}
],
datasets: [
{
label: "Accounts created",
backgroundColor: ["#3e95cd", "#8e5ea2", "#3cba9f", "#e8c3b9", "#c45850"],
data: [
{% for account in lastCreatedAccounts %}
{{ account.how_much }},
{% endfor %}
]
}
]
}
}
const myChart2 = new Chart(document.getElementById('lastCreatedChart'), config2);
</script>

View File

@@ -46,15 +46,6 @@ if (!is_array($settingsFile)) {
return; return;
} }
if (isset($_POST['reset']) && $_POST['reset'] == '1') {
$settings = Settings::getInstance();
$settings->deleteFromDatabase($settingsFile['key']);
$settings->clearCache();
success('Settings for this plugin has been reset.');
}
$settingsKeyName = ($plugin == 'core' ? $plugin : $settingsFile['key']); $settingsKeyName = ($plugin == 'core' ? $plugin : $settingsFile['key']);
$title = ($plugin == 'core' ? 'Settings' : 'Plugin Settings - ' . $settingsFile['name']); $title = ($plugin == 'core' ? 'Settings' : 'Plugin Settings - ' . $settingsFile['name']);
@@ -66,5 +57,4 @@ $twig->display('admin.settings.html.twig', [
'settings' => $settingsFile['settings'], 'settings' => $settingsFile['settings'],
'script' => $settingsParsed['script'], 'script' => $settingsParsed['script'],
'settingsKeyName' => $settingsKeyName, 'settingsKeyName' => $settingsKeyName,
'pluginName' => $plugin,
]); ]);

View File

@@ -27,7 +27,7 @@ if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is
const MYAAC = true; const MYAAC = true;
const MYAAC_VERSION = '2.0-dev'; const MYAAC_VERSION = '2.0-dev';
const DATABASE_VERSION = 52; const DATABASE_VERSION = 50;
const TABLE_PREFIX = 'myaac_'; const TABLE_PREFIX = 'myaac_';
define('START_TIME', microtime(true)); define('START_TIME', microtime(true));
define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX'));

View File

@@ -5,9 +5,7 @@ CREATE TABLE IF NOT EXISTS `myaac_account_actions`
`ip` varchar(45) NOT NULL DEFAULT '', `ip` varchar(45) NOT NULL DEFAULT '',
`date` int NOT NULL DEFAULT 0, `date` int NOT NULL DEFAULT 0,
`action` varchar(255) NOT NULL DEFAULT '', `action` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`)
INDEX `myaac_account_actions_account_id` (`account_id`),
INDEX `myaac_account_actions_ip` (`ip`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;
CREATE TABLE IF NOT EXISTS `myaac_account_emails_verify` CREATE TABLE IF NOT EXISTS `myaac_account_emails_verify`
@@ -45,8 +43,8 @@ CREATE TABLE IF NOT EXISTS `myaac_changelog`
CREATE TABLE IF NOT EXISTS `myaac_config` CREATE TABLE IF NOT EXISTS `myaac_config`
( (
`id` int NOT NULL AUTO_INCREMENT, `id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL, `name` varchar(30) NOT NULL,
`value` varchar(10000) NOT NULL, `value` varchar(1000) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE (`name`) UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;

View File

@@ -30,6 +30,9 @@ parameters:
# Eloquent models # Eloquent models
- '#Call to an undefined method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\)#' - '#Call to an undefined method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\)#'
- '#Call to an undefined static method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\)#' - '#Call to an undefined static method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\)#'
# system/pages/highscores.php
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::\$online_status#'
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::\$vocation_name#'
- -
message: '#Variable \$tmp in empty\(\) always exists and is always falsy#' message: '#Variable \$tmp in empty\(\) always exists and is always falsy#'
path: templates\kathrine\javascript.php path: templates\kathrine\javascript.php

View File

@@ -372,8 +372,8 @@ class POT
global $debugBar; global $debugBar;
if (isset($debugBar)) { if (isset($debugBar)) {
$this->db = new \MyAAC\Debug\TraceablePDOWithBacktrace(new OTS_DB_MySQL($params)); $this->db = new DebugBar\DataCollector\PDO\TraceablePDO(new OTS_DB_MySQL($params));
$debugBar->addCollector(new \MyAAC\Debug\PDOCollectorWithBacktrace($this->db)); $debugBar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($this->db));
} }
else { else {
$this->db = new OTS_DB_MySQL($params); $this->db = new OTS_DB_MySQL($params);

View File

@@ -1,10 +0,0 @@
<?php
$up = function () use ($db) {
$db->modifyColumn(TABLE_PREFIX . 'config', 'name', "varchar(255) NOT NULL");
$db->modifyColumn(TABLE_PREFIX . 'config', 'value', "varchar(10000) NOT NULL");
};
$down = function () {
// nothing to do, to not lose data
};

View File

@@ -1,13 +0,0 @@
<?php
/**
* 2026-04-12
* Add indexes to myaac_account_actions table
*/
$up = function () use ($db) {
$db->query("CREATE INDEX `myaac_account_actions_account_id` ON `myaac_account_actions` (`account_id`);");
$db->query("CREATE INDEX `myaac_account_actions_ip` ON `myaac_account_actions` (`ip`);");
};
$down = function () {
// nothing to do, to not lose data
};

View File

@@ -47,6 +47,7 @@ if(isset($_REQUEST['name']))
if(empty($name)) if(empty($name))
{ {
$tmp_link = getPlayerLink($name);
echo 'Here you can get detailed information about a certain player on ' . $config['lua']['serverName'] . '.<br/>'; echo 'Here you can get detailed information about a certain player on ' . $config['lua']['serverName'] . '.<br/>';
echo generate_search_form(true); echo generate_search_form(true);
return; return;

View File

@@ -207,14 +207,10 @@ if (empty($highscores)) {
} }
$highscores = $query->get()->map(function($row) { $highscores = $query->get()->map(function($row) {
/**
* @var Player $row
*/
$tmp = $row->toArray(); $tmp = $row->toArray();
$tmp['online'] = $row->online_status; $tmp['online'] = $row->online_status;
$tmp['vocation'] = $row->vocation_name; $tmp['vocation'] = $row->vocation_name;
$tmp['outfit_url'] = $row->outfit_url; $tmp['outfit_url'] = $row->outfit_url; // @phpstan-ignore-line
$tmp['link'] = getPlayerLink($row->name, false);
unset($tmp['online_table']); unset($tmp['online_table']);
return $tmp; return $tmp;
@@ -248,6 +244,7 @@ foreach($highscores as $id => &$player)
$player['experience'] = number_format($player['experience']); $player['experience'] = number_format($player['experience']);
} }
$player['link'] = getPlayerLink($player['name'], false);
$player['flag'] = getFlagImage($player['country']); $player['flag'] = getFlagImage($player['country']);
$player['outfit'] = '<img style="position:absolute;margin-top:-50px;margin-left:-30px" src="' . $player['outfit_url'] . '" alt="" />'; $player['outfit'] = '<img style="position:absolute;margin-top:-50px;margin-left:-30px" src="' . $player['outfit_url'] . '" alt="" />';

View File

@@ -108,9 +108,8 @@ $title = 'Latest News';
$cache = Cache::getInstance(); $cache = Cache::getInstance();
$news_cached = false; $news_cached = false;
if($cache->enabled() && !admin()) { if($cache->enabled())
$news_cached = News::getCached(NEWS); $news_cached = News::getCached(NEWS);
}
if(!$news_cached) if(!$news_cached)
{ {

View File

@@ -0,0 +1,116 @@
<?php
namespace MyAAC\Admin;
use MyAAC\Cache\Cache;
class Insights
{
private $db;
public function __construct($db){
$this->db = $db;
}
public function getLastLoggedPlayers(int $year, $month): array
{
return Cache::remember("admin_dashboard_insights_players_lastlogin_{$year}_{$month}", 5 * 60, function() use ($year, $month) {
$lastLoggedPlayers = [];
$getFromTo = $this->getFromTo($year, $month);
$whereLastLogin = 'AND lastlogin >= ' . $getFromTo[0] . ' AND lastlogin <= ' . $getFromTo[1];
if ($month === 'all') {
$query = $this->db->query('SELECT count(id) as how_much, DATE_FORMAT(FROM_UNIXTIME(lastlogin), "%m.%Y") as lastdate FROM players WHERE lastlogin > 0 ' . $whereLastLogin . ' GROUP BY lastdate LIMIT 14');
foreach ($query as $item) {
$date = explode('.', $item['lastdate']);
$monthName = date('F', mktime(0, 0, 0, $date[0], 10));;
$lastLoggedPlayers[] = ['date' => $monthName, 'how_much' => $item['how_much']];
}
}
else {
$query = $this->db->query('SELECT count(id) as how_much, DATE_FORMAT(FROM_UNIXTIME(lastlogin), "%d.%m.%Y") as lastdate FROM players WHERE lastlogin > 0 ' . $whereLastLogin . ' GROUP BY lastdate LIMIT 14');
foreach ($query as $item) {
$lastLoggedPlayers[] = ['date' => $item['lastdate'], 'how_much' => $item['how_much']];
}
}
return $lastLoggedPlayers;
});
}
public function getLastCreatedAccounts(int $year, $month): array
{
return Cache::remember("admin_dashboard_insights_accounts_created_{$year}_{$month}", 10 * 60, function() use ($year, $month) {
$lastCreatedAccounts = [];
$getFromTo = $this->getFromTo($year, $month);
$whereCreated = 'AND created >= ' . $getFromTo[0] . ' AND created <= ' . $getFromTo[1];
if ($month == 'all') {
$query = $this->db->query('SELECT count(id) as how_much, DATE_FORMAT(FROM_UNIXTIME(created), "%m.%Y") as createdDate FROM accounts WHERE created > 0 ' . $whereCreated . ' GROUP BY createdDate LIMIT 31');
foreach ($query as $item) {
$date = explode('.', $item['createdDate']);
$monthName = date('F', mktime(0, 0, 0, $date[0], 10));;
$lastCreatedAccounts[] = ['date' => $monthName, 'how_much' => $item['how_much']];
}
}
else {
$query = $this->db->query('SELECT count(id) as how_much, DATE_FORMAT(FROM_UNIXTIME(created), "%d.%m.%Y") as createdDate FROM accounts WHERE created > 0 ' . $whereCreated . ' GROUP BY createdDate LIMIT 31');
foreach ($query as $item) {
$lastCreatedAccounts[] = ['date' => $item['createdDate'], 'how_much' => $item['how_much']];
}
}
return $lastCreatedAccounts;
});
}
public function getFirstYear(): int
{
$query = $this->db->query('SELECT created FROM accounts WHERE created > 0 ORDER BY created LIMIT 1');
if ($query->rowCount()) {
$firstAccountCreated = $query->fetch()['created'];
}
else {
$firstAccountCreated = time();
}
return (int)date('Y', $firstAccountCreated);
}
public function getMonths(): array
{
$months = [];
$months['all'] = 'All';
for ($i = 1; $i <= 12; $i++) {
$months[$i] = date('F', mktime(0, 0, 0, $i, 10));
}
return $months;
}
private function getFromTo(int $year, $month): array
{
if ($month == 'all') {
$firstMonth = 1;
$lastMonth = 12;
}
else {
$firstMonth = $month;
$lastMonth = $month;
}
$from = date('U', mktime(0, 0, 0, $firstMonth, 1, $year));
$to = date('U', mktime(0, 0, 0, $lastMonth, 31, $year));
return [$from, $to];
}
}

View File

@@ -1,52 +0,0 @@
<?php
namespace MyAAC\Debug;
use DebugBar\DataCollector\PDO\PDOCollector;
use DebugBar\DataCollector\PDO\TraceablePDO;
use DebugBar\DataCollector\TimeDataCollector;
class PDOCollectorWithBacktrace extends PDOCollector
{
protected function collectPDO(TraceablePDO $pdo, ?TimeDataCollector $timeCollector = null, $connectionName = null): array
{
$data = parent::collectPDO($pdo, $timeCollector, $connectionName);
if ($pdo instanceof TraceablePDOWithBacktrace) {
$backtraces = $pdo->getBacktraces();
foreach ($data['statements'] as $i => &$stmt) {
if (isset($backtraces[$i])) {
$stmt['backtrace'] = $this->formatBacktrace($backtraces[$i]);
}
}
unset($stmt);
}
return $data;
}
private function formatBacktrace(array $backtrace): array
{
$result = [];
foreach ($backtrace as $frame) {
if (!isset($frame['file'], $frame['line'])) {
continue;
}
if (str_contains($frame['file'], DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR)) {
continue;
}
if (str_contains($frame['file'], DIRECTORY_SEPARATOR . 'Debug' . DIRECTORY_SEPARATOR)) {
continue;
}
$function = isset($frame['class'])
? $frame['class'] . ($frame['type'] ?? '::') . ($frame['function'] ?? '')
: ($frame['function'] ?? '');
$result[] = ($function ? $function . '() ' : '') . $frame['file'] . ':' . $frame['line'];
}
return $result;
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace MyAAC\Debug;
use DebugBar\DataCollector\PDO\TraceablePDO;
use DebugBar\DataCollector\PDO\TracedStatement;
class TraceablePDOWithBacktrace extends TraceablePDO
{
/** @var array[] */
protected array $backtraces = [];
public function addExecutedStatement(TracedStatement $stmt): void
{
$this->backtraces[] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
parent::addExecutedStatement($stmt);
}
/**
* @return array[]
*/
public function getBacktraces(): array
{
return $this->backtraces;
}
}

View File

@@ -18,15 +18,6 @@ class Account extends Model {
public $timestamps = false; public $timestamps = false;
protected $fillable = [
'name', 'number', 'email', 'password',
'key', 'created', 'rlname', 'location', 'country',
'web_lastlogin', 'web_flags',
'email_new', 'email_new_time', 'email_code',
'premium_points', 'coins', 'coins_transferable',
'premium_ends_at', 'premend', 'lastday', 'premdays',
];
protected $casts = [ protected $casts = [
'lastday' => 'integer', 'lastday' => 'integer',
'premdays' => 'integer', 'premdays' => 'integer',

View File

@@ -0,0 +1,15 @@
<?php
namespace MyAAC\Models;
use Illuminate\Database\Eloquent\Model;
class BugTracker extends Model {
protected $table = TABLE_PREFIX . 'bugtracker';
public $timestamps = false;
protected $fillable = ['account', 'type', 'status', 'text', 'id', 'subject', 'reply', 'who', 'uid', 'tag'];
}

View File

@@ -5,10 +5,8 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
/** /**
* @property string $name
* @property int $level * @property int $level
* @property int $vocation * @property int $vocation
* @property int $promotion
* @property int $online * @property int $online
* @property int $looktype * @property int $looktype
* @property int $lookhead * @property int $lookhead
@@ -16,8 +14,6 @@ use Illuminate\Database\Eloquent\Relations\HasOne;
* @property int $looklegs * @property int $looklegs
* @property int $lookfeet * @property int $lookfeet
* @property int $lookaddons * @property int $lookaddons
* @property bool $online_status
* @property string $vocation_name
* @property string $outfit_url * @property string $outfit_url
* @property hasOne $onlineTable * @property hasOne $onlineTable
*/ */

View File

@@ -7,11 +7,9 @@ use MyAAC\Cache\Cache;
use MyAAC\Models\Menu; use MyAAC\Models\Menu;
class Plugins { class Plugins {
private static array $warnings = []; private static $warnings = [];
private static string $error = ''; private static $error = null;
private static array $plugin_json = []; private static $plugin_json = [];
const DEFAULT_PRIORITY = 1000;
public static function getInits() public static function getInits()
{ {
@@ -22,31 +20,13 @@ class Plugins {
continue; continue;
} }
$initPriority = self::DEFAULT_PRIORITY;
if (isset($plugin['autoload']['init-priority'])) {
$initPriority = (int) $plugin['autoload']['init-priority'];
}
$pluginInits = glob(PLUGINS . $plugin['filename'] . '/init.php'); $pluginInits = glob(PLUGINS . $plugin['filename'] . '/init.php');
foreach ($pluginInits as $path) { foreach ($pluginInits as $path) {
$inits[] = [ $inits[] = $path;
'file' => $path,
'priority' => $initPriority
];
} }
} }
usort($inits, function ($a, $b) return $inits;
{
return $a['priority'] <=> $b['priority'];
});
$ret = [];
foreach ($inits as $init) {
$ret[] = $init['file'];
}
return $ret;
}); });
} }
@@ -59,7 +39,7 @@ class Plugins {
continue; continue;
} }
$adminPagesDefaultPriority = self::DEFAULT_PRIORITY; $adminPagesDefaultPriority = 1000;
if (isset($plugin['admin-pages-default-priority'])) { if (isset($plugin['admin-pages-default-priority'])) {
$adminPagesDefaultPriority = $plugin['admin-pages-default-priority']; $adminPagesDefaultPriority = $plugin['admin-pages-default-priority'];
} }
@@ -137,7 +117,7 @@ class Plugins {
$routes = []; $routes = [];
foreach(self::getAllPluginsJson() as $plugin) { foreach(self::getAllPluginsJson() as $plugin) {
$routesDefaultPriority = self::DEFAULT_PRIORITY; $routesDefaultPriority = 1000;
if (isset($plugin['routes-default-priority'])) { if (isset($plugin['routes-default-priority'])) {
$routesDefaultPriority = $plugin['routes-default-priority']; $routesDefaultPriority = $plugin['routes-default-priority'];
} }
@@ -185,7 +165,7 @@ class Plugins {
} }
} }
$pagesDefaultPriority = self::DEFAULT_PRIORITY; $pagesDefaultPriority = 1000;
if (isset($plugin['pages-default-priority'])) { if (isset($plugin['pages-default-priority'])) {
$pagesDefaultPriority = $plugin['pages-default-priority']; $pagesDefaultPriority = $plugin['pages-default-priority'];
} }
@@ -338,7 +318,7 @@ class Plugins {
foreach(self::getAllPluginsJson() as $plugin) { foreach(self::getAllPluginsJson() as $plugin) {
if (isset($plugin['hooks'])) { if (isset($plugin['hooks'])) {
foreach ($plugin['hooks'] as $_name => $info) { foreach ($plugin['hooks'] as $_name => $info) {
$priority = self::DEFAULT_PRIORITY; $priority = 1000;
if (str_contains($info['type'], 'HOOK_')) { if (str_contains($info['type'], 'HOOK_')) {
$info['type'] = str_replace('HOOK_', '', $info['type']); $info['type'] = str_replace('HOOK_', '', $info['type']);
@@ -452,7 +432,7 @@ class Plugins {
return $plugins; return $plugins;
} }
public static function getPluginSettings($filename): mixed public static function getPluginSettings($filename)
{ {
$plugin_json = self::getPluginJson($filename); $plugin_json = self::getPluginJson($filename);
if (!$plugin_json) { if (!$plugin_json) {
@@ -890,11 +870,7 @@ class Plugins {
global $hooks; global $hooks;
foreach($plugin_info['hooks'] ?? [] as $name => $info) { foreach($plugin_info['hooks'] ?? [] as $name => $info) {
if (str_contains($info['type'], 'HOOK_')) { $hooks->unregister($name, $info['type'], $info['file']);
$info['type'] = str_replace('HOOK_', '', $info['type']);
}
$hooks->unregister($name, 'HOOK_' . $info['type'], $info['file']);
} }
clearCache(); clearCache();
@@ -921,15 +897,15 @@ class Plugins {
return Semver::satisfies($plugin_info['version'], $version); return Semver::satisfies($plugin_info['version'], $version);
} }
public static function getWarnings(): array { public static function getWarnings() {
return self::$warnings; return self::$warnings;
} }
public static function clearWarnings(): void { public static function clearWarnings() {
self::$warnings = []; self::$warnings = [];
} }
public static function getError(): string { public static function getError() {
return self::$error; return self::$error;
} }
@@ -940,7 +916,7 @@ class Plugins {
* @param string $templateName * @param string $templateName
* @param array $menus * @param array $menus
*/ */
public static function installMenus($templateName, $menus, $clearOld = false): void public static function installMenus($templateName, $menus, $clearOld = false)
{ {
global $db; global $db;
@@ -991,7 +967,7 @@ class Plugins {
} }
} }
private static function getAutoLoadOption(array $plugin, string $optionName, bool $default = true): bool private static function getAutoLoadOption(array $plugin, string $optionName, bool $default = true)
{ {
if (isset($plugin['autoload'])) { if (isset($plugin['autoload'])) {
$autoload = $plugin['autoload']; $autoload = $plugin['autoload'];

View File

@@ -367,7 +367,6 @@ class Settings implements \ArrayAccess
</div> </div>
<div class="box-footer"> <div class="box-footer">
<button name="save" type="submit" class="btn btn-primary">Save</button> <button name="save" type="submit" class="btn btn-primary">Save</button>
<button form="reset-settings-form" name="reset" type="submit" class="btn btn-warning position-absolute" style="right: 0; bottom: 0" onclick="return confirm('Are you sure? This will clear all settings for this plugin!')">Reset</button>
</div> </div>
<?php <?php

View File

@@ -9,10 +9,7 @@
<div class="box"> <div class="box">
<div class="box-body"> <div class="box-body">
<button name="save" type="submit" class="btn btn-primary">Save</button> <button name="save" type="submit" class="btn btn-primary">Save</button>
<button form="reset-settings-form" name="reset" type="submit" class="btn btn-warning position-absolute" style="right: 0; top: 0" onclick="return confirm('Are you sure? This will clear all settings for this plugin!')">Reset</button>
</div> </div>
<br/> <br/>
{{ settingsParsed|raw }} {{ settingsParsed|raw }}
</div> </div>
@@ -21,12 +18,6 @@
</form> </form>
</div> </div>
</div> </div>
<form id="reset-settings-form" method="post" action="{{ constant('ADMIN_URL') }}?p=settings&plugin={{ pluginName }}">
{{ csrf() }}
<input type="hidden" name="reset" value="1">
</form>
<style> <style>
.setting-default { .setting-default {
white-space: pre-wrap; white-space: pre-wrap;
@@ -104,12 +95,12 @@
.on('change input', function(){ .on('change input', function(){
const disable = $(this).serialize() === $(this).data('serialized'); const disable = $(this).serialize() === $(this).data('serialized');
$(this) $(this)
.find('button[name="save"]') .find('input:submit, button:submit')
.prop('disabled', disable) .prop('disabled', disable)
.prop('title', disable ? noChangesText : '') .prop('title', disable ? noChangesText : '')
; ;
}) })
.find('button[name="save"]') .find('input:submit, button:submit')
.prop('disabled', true) .prop('disabled', true)
.prop('title', noChangesText) .prop('title', noChangesText)
; ;
@@ -132,7 +123,7 @@
let $settings = $('#settings'); let $settings = $('#settings');
$settings.data('serialized', $settings.serialize()); $settings.data('serialized', $settings.serialize());
$settings $settings
.find('button[name="save"]') .find('input:submit, button:submit')
.prop('disabled', true) .prop('disabled', true)
.prop('title', noChangesText); .prop('title', noChangesText);
}, },

View File

@@ -1,13 +1,15 @@
<?php <?php
$topPlayers = Cache::remember('tibiacom_highscores_top_players', 10 * 60, function() {
$topPlayers = getTopPlayers(5); $topPlayers = getTopPlayers(5);
foreach($topPlayers as &$player) { foreach($topPlayers as &$player) {
$player['outfit'] = $player['outfit_url']; $outfit_url = '';
$player['link'] = getPlayerLink($player['id'], false); if (setting('core.online_outfit')) {
} $outfit_url = setting('core.outfit_images_url') . '?id=' . $player['looktype'] . (!empty
($player['lookaddons']) ? '&addons=' . $player['lookaddons'] : '') . '&head=' . $player['lookhead'] . '&body=' . $player['lookbody'] . '&legs=' . $player['looklegs'] . '&feet=' . $player['lookfeet'];
return $topPlayers; $player['outfit'] = $outfit_url;
}); }
}
$twig->display('highscores.html.twig', array( $twig->display('highscores.html.twig', array(
'topPlayers' => $topPlayers 'topPlayers' => $topPlayers

View File

@@ -44,7 +44,7 @@
<div id="Topbar" class="Themebox" style="background-image:url({{ template_path }}/images/themeboxes/highscores/highscores.png);"> <div id="Topbar" class="Themebox" style="background-image:url({{ template_path }}/images/themeboxes/highscores/highscores.png);">
<div class="top_level" style="background:url({{ template_path }}/images/themeboxes/bg_top.png)" align=" "> <div class="top_level" style="background:url({{ template_path }}/images/themeboxes/bg_top.png)" align=" ">
{% for player in topPlayers %} {% for player in topPlayers %}
<div style="text-align:left"><a href="{{ player['link'] }} " class="topfont {% if player['online'] %}online{% else %}offline{% endif %}"> <div style="text-align:left"><a href="{{ getPlayerLink(player['name'], false) }} " class="topfont {% if player['online'] %}online{% else %}offline{% endif %}">
{% if setting('core.online_outfit') %} {% if setting('core.online_outfit') %}
<img style="position:absolute;margin-top:-45px;margin-left:-25px;" src="{{ player.outfit }}" alt="player outfit"/> <img style="position:absolute;margin-top:-45px;margin-left:-25px;" src="{{ player.outfit }}" alt="player outfit"/>
{% endif %} {% endif %}