2023-05-15 09:04:02 +02:00
|
|
|
<?php
|
|
|
|
date_default_timezone_set('Europe/Berlin');
|
|
|
|
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
|
|
|
|
header("Cache-Control: post-check=0, pre-check=0", false);
|
|
|
|
header("Pragma: no-cache");
|
|
|
|
|
2024-08-10 16:23:52 +02:00
|
|
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
|
|
|
$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
|
|
$parentUrl = dirname($currentUrl);
|
|
|
|
|
2024-08-08 08:44:42 +02:00
|
|
|
// Get currency data from JSON
|
2024-08-28 15:20:33 +02:00
|
|
|
if (!file_exists('coingecko.json')) {
|
|
|
|
// Special case: First run.
|
|
|
|
exec('php coingecko.php');
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
2024-08-08 08:44:42 +02:00
|
|
|
$api_cg = json_decode(file_get_contents('coingecko.json'), true);
|
2024-05-15 08:21:02 +02:00
|
|
|
|
2024-08-09 16:03:30 +02:00
|
|
|
// 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'] : [];
|
2024-08-28 15:21:36 +02:00
|
|
|
$github_url = isset($config['github_url']) ? $config['github_url'] : 'https://git.private.coffee/kumi/moner.ooo/';
|
2024-08-09 16:03:30 +02:00
|
|
|
|
2024-08-08 08:44:42 +02:00
|
|
|
// Extract the keys
|
|
|
|
$currencies = array_map('strtoupper', array_keys($api_cg));
|
2023-05-15 09:04:02 +02:00
|
|
|
|
2024-08-08 08:44:42 +02:00
|
|
|
// Fetch the time of the last API data update
|
|
|
|
$time_cg = date("H:i:s", $api_cg['time']);
|
2024-05-15 08:21:02 +02:00
|
|
|
$time = $time_cg;
|
2024-08-08 08:44:42 +02:00
|
|
|
unset($currencies[array_search('TIME', $currencies)]);
|
2023-05-15 09:04:02 +02:00
|
|
|
|
2024-08-08 08:44:42 +02:00
|
|
|
// Populate exchange rates
|
|
|
|
$exchangeRates = [];
|
|
|
|
foreach ($currencies as $currency) {
|
|
|
|
$exchangeRates[$currency] = $api_cg[strtolower($currency)]['lastValue'];
|
|
|
|
}
|
2023-05-15 09:04:02 +02:00
|
|
|
|
2024-08-30 09:16:07 +02:00
|
|
|
// Get the primary language from the browser
|
2024-08-30 08:28:20 +02:00
|
|
|
$lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : "en";
|
2024-08-30 09:16:07 +02:00
|
|
|
$lang = explode(",", $lang)[0];
|
|
|
|
$lang = explode(";", $lang)[0];
|
2024-08-30 08:28:20 +02:00
|
|
|
$lang = strtolower($lang);
|
2023-05-15 09:04:02 +02:00
|
|
|
|
2024-08-30 08:28:20 +02:00
|
|
|
// Aliases for different Chinese variants
|
|
|
|
$aliases = [
|
|
|
|
'zh' => 'zh-hans',
|
|
|
|
'zh-hk' => 'zh-hant',
|
|
|
|
'zh-tw' => 'zh-hant',
|
|
|
|
'zh-cn' => 'zh-hans',
|
|
|
|
'zh-sg' => 'zh-hans',
|
|
|
|
'zh-mo' => 'zh-hant',
|
|
|
|
];
|
|
|
|
|
2024-08-30 09:18:56 +02:00
|
|
|
if (isset($aliases[$lang])) {
|
|
|
|
$lang = $aliases[$lang];
|
2024-08-30 08:28:20 +02:00
|
|
|
}
|
|
|
|
|
2024-08-30 09:18:56 +02:00
|
|
|
// Load the language files
|
|
|
|
// Take English as a base, then overwrite with the browser language
|
|
|
|
// E.g.: First load en.php, then de.php, then de-at.php
|
2024-08-30 09:16:07 +02:00
|
|
|
|
2024-08-30 09:18:56 +02:00
|
|
|
$language_code = explode('-', $lang)[0];
|
|
|
|
$language_files = ["en", $language_code, $lang];
|
2024-08-30 08:28:20 +02:00
|
|
|
|
2024-08-30 09:18:56 +02:00
|
|
|
foreach ($language_files as $language_file) {
|
|
|
|
if (file_exists('lang/' . $language_file . '.php')) {
|
|
|
|
require_once 'lang/' . $language_file . '.php';
|
2024-08-30 09:16:07 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-19 09:43:47 +02:00
|
|
|
|
2024-08-30 08:28:20 +02:00
|
|
|
// Calculation through GET parameters
|
|
|
|
|
2024-08-08 08:44:42 +02:00
|
|
|
$xmr_in = isset($_GET["in"]) ? strtoupper(htmlspecialchars($_GET["in"])) : 'EUR';
|
2024-08-10 16:23:52 +02:00
|
|
|
$xmr_amount = isset($_GET["xmr"]) ? floatval($_GET["xmr"]) : 1;
|
|
|
|
$fiat_amount = isset($_GET["fiat"]) ? floatval($_GET["fiat"]) : '';
|
|
|
|
$conversion_direction = isset($_GET["direction"]) ? intval($_GET["direction"]) : 0;
|
|
|
|
|
|
|
|
if ($conversion_direction == 0) {
|
|
|
|
$fiat_value = $xmr_amount * $exchangeRates[$xmr_in];
|
|
|
|
$xmr_value = $xmr_amount;
|
|
|
|
} else {
|
|
|
|
$xmr_value = $fiat_amount / $exchangeRates[$xmr_in];
|
|
|
|
$fiat_value = $fiat_amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fiat_value = number_format($fiat_value, ($xmr_in == 'BTC' || $xmr_in == 'LTC' || $xmr_in == 'ETH' || $xmr_in == 'XAG' || $xmr_in == 'XAU') ? 8 : 2);
|
|
|
|
$xmr_value = number_format($xmr_value, 12);
|
2023-05-15 09:04:02 +02:00
|
|
|
|
2024-08-10 16:23:52 +02:00
|
|
|
$fiat_value = strtr($fiat_value, ",", " ");
|
2024-08-08 15:45:25 +02:00
|
|
|
|
2024-08-09 15:03:44 +02:00
|
|
|
// Order preferred currencies to the top
|
|
|
|
foreach (array_reverse($preferred_currencies) as $currency) {
|
|
|
|
$currency = strtoupper($currency);
|
|
|
|
if (($key = array_search($currency, $currencies)) !== false) {
|
|
|
|
unset($currencies[$key]);
|
|
|
|
array_unshift($currencies, $currency);
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 08:44:42 +02:00
|
|
|
|
2024-08-30 10:14:56 +02:00
|
|
|
// Output the HTML
|
|
|
|
require 'templates/index.php';
|
|
|
|
?>
|