diff --git a/index.php b/index.php index 744fec2..6f737fe 100644 --- a/index.php +++ b/index.php @@ -4,263 +4,64 @@ 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"); -// Array of supported currencies -// TODO: Load dynamically from the API data -$array = array("EUR", - "USD", - "GBP", - "CHF", - "RUB", - "CNY", - "JPY", - "IDR", - "KRW", - "TRY", - "AUD", - "BMD", - "CAD", - "HKD", - "NZD", - "SGD", - "TWD", - "ILS", - "PLN", - "ZAR", - "CZK", - "DKK", - "NOK", - "SEK", - "ARS", - "CLP", - "PHP", - "MXN", - "BHD", - "KWD", - "BRL", - "MYR", - "VEF", - "UAH", - "VND", - "BDT", - "HUF", - "MMK", - "NGN", - "THB", - "AED", - "SAR", - "PKR", - "LKR", - "INR", - "BTC", - "LTC", - "ETH", - "XAG", - "XAU"); +// Get currency data from JSON +$api_cg = json_decode(file_get_contents('coingecko.json'), true); -include('coingecko.php'); +// Extract the keys +$currencies = array_map('strtoupper', array_keys($api_cg)); -// Fetches the API data from the JSON file -// TODO: This doesn't exist on first load, so it will display warnings -$api_cg = json_decode(file_get_contents('coingecko.json')); - -// Fetches the time of the last API data update -$time_cg = date("H:i:s", $api_cg->time); +// Fetch the time of the last API data update +$time_cg = date("H:i:s", $api_cg['time']); $time = $time_cg; +unset($currencies[array_search('TIME', $currencies)]); -// Fetches the individual currency values from the API data -// TODO: Make that dynamic -$BTC = $api_cg->btc->lastValue; -$EUR = $api_cg->eur->lastValue; -$USD = $api_cg->usd->lastValue; -$CHF = $api_cg->chf->lastValue; -$LTC = $api_cg->ltc->lastValue; -$CAD = $api_cg->cad->lastValue; -$AUD = $api_cg->aud->lastValue; -$HKD = $api_cg->hkd->lastValue; -$SGD = $api_cg->sgd->lastValue; -$GBP = $api_cg->gbp->lastValue; -$RUB = $api_cg->rub->lastValue; -$ZAR = $api_cg->zar->lastValue; -$TRY = $api_cg->try->lastValue; -$JPY = $api_cg->jpy->lastValue; -$PLN = $api_cg->pln->lastValue; -$INR = $api_cg->inr->lastValue; -$AED = $api_cg->aed->lastValue; -$ETH = $api_cg->eth->lastValue; -$UAH = $api_cg->uah->lastValue; -$KRW = $api_cg->krw->lastValue; -$BRL = $api_cg->brl->lastValue; -$MYR = $api_cg->myr->lastValue; -$CNY = $api_cg->cny->lastValue; -$XAU = $api_cg->xau->lastValue; -$XAG = $api_cg->xag->lastValue; -$VND = $api_cg->vnd->lastValue; -$VEF = $api_cg->vef->lastValue; -$THB = $api_cg->thb->lastValue; -$SAR = $api_cg->sar->lastValue; -$SEK = $api_cg->sek->lastValue; -$PKR = $api_cg->pkr->lastValue; -$NOK = $api_cg->nok->lastValue; -$LKR = $api_cg->lkr->lastValue; -$MMK = $api_cg->mmk->lastValue; -$HUF = $api_cg->huf->lastValue; -$ILS = $api_cg->ils->lastValue; -$KWD = $api_cg->kwd->lastValue; -$NGN = $api_cg->ngn->lastValue; -$NZD = $api_cg->nzd->lastValue; -$PHP = $api_cg->php->lastValue; -$IDR = $api_cg->idr->lastValue; -$TWD = $api_cg->twd->lastValue; -$ARS = $api_cg->ars->lastValue; -$BDT = $api_cg->bdt->lastValue; -$BHD = $api_cg->bhd->lastValue; -$BMD = $api_cg->bmd->lastValue; -$CLP = $api_cg->clp->lastValue; -$CZK = $api_cg->czk->lastValue; -$DKK = $api_cg->dkk->lastValue; -$MXN = $api_cg->mxn->lastValue; - -// Load the language file based on the browser language -if(array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)){ - $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); -}else{ - $lang = "en"; +// Populate exchange rates +$exchangeRates = []; +foreach ($currencies as $currency) { + $exchangeRates[$currency] = $api_cg[strtolower($currency)]['lastValue']; } -if($lang == 'zh' || $lang == 'pt' ){ - $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5); +// Get the browser language +$lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) : "en"; +if ($lang == 'zh' || $lang == 'pt') { + $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5); } -$acceptLang = ['de','es','it','zh-CN','nl','pl','el','pt-BR','ru']; +// Scan the lang/ directory for available language files +$langFiles = glob('lang/*.php'); +$acceptLang = []; +foreach ($langFiles as $file) { + $langCode = basename($file, '.php'); + $acceptLang[] = strtolower($langCode); +} + +// Check if the browser language is available, otherwise use English $lang = in_array($lang, $acceptLang) ? $lang : 'en'; $lang = strtolower($lang); -require_once "lang/{$lang}.php"; +require_once "lang/{$lang}.php"; -if(isset($_GET["in"])) { - $xmr_in = strtoupper(htmlspecialchars($_GET["in"])); - - if($xmr_in == 'USD'){ - $xmr_in_fiat = number_format($USD, 2); - }elseif($xmr_in == 'GBP'){ - $xmr_in_fiat = number_format($GBP, 2); - }elseif($xmr_in == 'CHF'){ - $xmr_in_fiat = number_format($CHF, 2); - }elseif($xmr_in == 'RUB'){ - $xmr_in_fiat = number_format($RUB, 2); - }elseif($xmr_in == 'CNY'){ - $xmr_in_fiat = number_format($CNY, 2); - }elseif($xmr_in == 'JPY'){ - $xmr_in_fiat = number_format($JPY, 2); - }elseif($xmr_in == 'AUD'){ - $xmr_in_fiat = number_format($AUD, 2); - }elseif($xmr_in == 'BMD'){ - $xmr_in_fiat = number_format($BMD, 2); - }elseif($xmr_in == 'CAD'){ - $xmr_in_fiat = number_format($CAD, 2); - }elseif($xmr_in == 'HKD'){ - $xmr_in_fiat = number_format($HKD, 2); - }elseif($xmr_in == 'NZD'){ - $xmr_in_fiat = number_format($NZD, 2); - }elseif($xmr_in == 'SGD'){ - $xmr_in_fiat = number_format($SGD, 2); - }elseif($xmr_in == 'TWD'){ - $xmr_in_fiat = number_format($TWD, 2); - }elseif($xmr_in == 'CZK'){ - $xmr_in_fiat = number_format($CZK, 2); - }elseif($xmr_in == 'CLP'){ - $xmr_in_fiat = number_format($CLP, 2); - }elseif($xmr_in == 'DKK'){ - $xmr_in_fiat = number_format($DKK, 2); - }elseif($xmr_in == 'NOK'){ - $xmr_in_fiat = number_format($NOK, 2); - }elseif($xmr_in == 'PLN'){ - $xmr_in_fiat = number_format($PLN, 2); - }elseif($xmr_in == 'SEK'){ - $xmr_in_fiat = number_format($SEK, 2); - }elseif($xmr_in == 'TRY'){ - $xmr_in_fiat = number_format($TRY, 2); - }elseif($xmr_in == 'UAH'){ - $xmr_in_fiat = number_format($UAH, 2); - }elseif($xmr_in == 'ARS'){ - $xmr_in_fiat = number_format($ARS, 2); - }elseif($xmr_in == 'PHP'){ - $xmr_in_fiat = number_format($PHP, 2); - }elseif($xmr_in == 'AED'){ - $xmr_in_fiat = number_format($AED, 2); - }elseif($xmr_in == 'BRL'){ - $xmr_in_fiat = number_format($BRL, 2); - }elseif($xmr_in == 'KRW'){ - $xmr_in_fiat = number_format($KRW, 2); - }elseif($xmr_in == 'MYR'){ - $xmr_in_fiat = number_format($MYR, 2); - }elseif($xmr_in == 'SAR'){ - $xmr_in_fiat = number_format($SAR, 2); - }elseif($xmr_in == 'VEF'){ - $xmr_in_fiat = number_format($VEF, 2); - }elseif($xmr_in == 'VND'){ - $xmr_in_fiat = number_format($VND, 2); - }elseif($xmr_in == 'ZAR'){ - $xmr_in_fiat = number_format($ZAR, 2); - }elseif($xmr_in == 'BDT'){ - $xmr_in_fiat = number_format($BDT, 2); - }elseif($xmr_in == 'HUF'){ - $xmr_in_fiat = number_format($HUF, 2); - }elseif($xmr_in == 'ILS'){ - $xmr_in_fiat = number_format($ILS, 2); - }elseif($xmr_in == 'MMK'){ - $xmr_in_fiat = number_format($MMK, 2); - }elseif($xmr_in == 'NGN'){ - $xmr_in_fiat = number_format($NGN, 2); - }elseif($xmr_in == 'THB'){ - $xmr_in_fiat = number_format($THB, 2); - }elseif($xmr_in == 'BHD'){ - $xmr_in_fiat = number_format($BHD, 2); - }elseif($xmr_in == 'KWD'){ - $xmr_in_fiat = number_format($KWD, 2); - }elseif($xmr_in == 'PKR'){ - $xmr_in_fiat = number_format($PKR, 2); - }elseif($xmr_in == 'LKR'){ - $xmr_in_fiat = number_format($LKR, 2); - }elseif($xmr_in == 'INR'){ - $xmr_in_fiat = number_format($INR, 2); - }elseif($xmr_in == 'IDR'){ - $xmr_in_fiat = number_format($IDR, 2); - }elseif($xmr_in == 'MXN'){ - $xmr_in_fiat = number_format($MXN, 2); - }elseif($xmr_in == 'BTC'){ - $xmr_in_fiat = number_format($BTC, 8); - }elseif($xmr_in == 'LTC'){ - $xmr_in_fiat = number_format($LTC, 8); - }elseif($xmr_in == 'ETH'){ - $xmr_in_fiat = number_format($ETH, 8); - }elseif($xmr_in == 'XAG'){ - $xmr_in_fiat = number_format($XAG, 6); - }elseif($xmr_in == 'XAU'){ - $xmr_in_fiat = number_format($XAU, 6); - }else{ - $xmr_in_fiat = number_format($EUR, 2); - } - -}else{ - $xmr_in_fiat = number_format($EUR, 2); -} +$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_in_fiat = strtr($xmr_in_fiat, ",", " "); ?> + + - - - + + + <?php echo $page_title; ?> - - + + + - + @@ -285,591 +86,82 @@ $xmr_in_fiat = strtr($xmr_in_fiat, ",", " "); - - - - +
-
+
-

 XMR  

+

 XMR  

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + "; + foreach ($chunk as $currency) { + echo ""; + } + echo ""; + echo ""; + foreach ($chunk as $currency) { + echo ""; + } + echo ""; + } + ?>
Unix Time:time; ?>
" . str_replace(".", ",", $exchangeRates[$currency]) . "

- +
- +
=
- +
- +

- +
- +
- - - - - + - - + + \ No newline at end of file