diff --git a/index.php b/index.php index 4e1e784..0bdd8b3 100644 --- a/index.php +++ b/index.php @@ -4,6 +4,10 @@ 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"); +$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; +$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; +$parentUrl = dirname($currentUrl); + // Get currency data from JSON $api_cg = json_decode(file_get_contents('coingecko.json'), true); @@ -52,9 +56,22 @@ $lang = strtolower($lang); require_once "lang/{$lang}.php"; $xmr_in = isset($_GET["in"]) ? strtoupper(htmlspecialchars($_GET["in"])) : 'EUR'; -$xmr_in_fiat = number_format($exchangeRates[$xmr_in], $xmr_in == 'BTC' || $xmr_in == 'LTC' || $xmr_in == 'ETH' || $xmr_in == 'XAG' || $xmr_in == 'XAU' ? 8 : 2); +$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; -$xmr_in_fiat = strtr($xmr_in_fiat, ",", " "); +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); + +$fiat_value = strtr($fiat_value, ",", " "); // Order preferred currencies to the top foreach (array_reverse($preferred_currencies) as $currency) { @@ -81,7 +98,7 @@ foreach (array_reverse($preferred_currencies) as $currency) { - + @@ -143,29 +160,39 @@ foreach (array_reverse($preferred_currencies) as $currency) {