refactor(index.php): move config setup to top of the file

Relocated the configuration setup to the top of index.php to improve code clarity and maintainability. This ensures configuration settings are initialized before any other operations, reducing potential for unexpected behaviors and making the code easier to follow.

No functional changes introduced.
This commit is contained in:
Kumi 2024-08-09 16:03:30 +02:00
parent 49be7374b1
commit 5747f73c68
No known key found for this signature in database
GPG key ID: ECBCC9082395383F

View file

@ -7,6 +7,17 @@ header("Pragma: no-cache");
// Get currency data from JSON
$api_cg = json_decode(file_get_contents('coingecko.json'), true);
// Configuration file
$config = [];
if (file_exists('config.php')) {
$config = require 'config.php';
}
$display_servers_guru = isset($config['servers_guru']) && $config['servers_guru'] === true;
$attribution = isset($config['attribution']) ? $config['attribution'] : '';
$preferred_currencies = isset($config['preferred_currencies']) ? $config['preferred_currencies'] : [];
$github_url = isset($config['github_url']) ? $config['github_url'] : 'https://github.com/rottenwheel/moner.ooo/';
// Extract the keys
$currencies = array_map('strtoupper', array_keys($api_cg));
@ -45,18 +56,6 @@ $xmr_in_fiat = number_format($exchangeRates[$xmr_in], $xmr_in == 'BTC' || $xmr_i
$xmr_in_fiat = strtr($xmr_in_fiat, ",", " ");
// Configuration file
$config = [];
if (file_exists('config.php')) {
$config = require 'config.php';
}
$display_servers_guru = isset($config['servers_guru']) && $config['servers_guru'] === true;
$attribution = isset($config['attribution']) ? $config['attribution'] : '';
$preferred_currencies = isset($config['preferred_currencies']) ? $config['preferred_currencies'] : [];
$github_url = isset($config['github_url']) ? $config['github_url'] : 'https://github.com/rottenwheel/moner.ooo/';
// Order preferred currencies to the top
foreach (array_reverse($preferred_currencies) as $currency) {
$currency = strtoupper($currency);