exchange_rates($date); $defaultCurrency = array_search(1, $rates); if (empty($defaultCurrency)) { $defaultCurrency = 'USD'; } if (empty($sourceCurrency)) { $sourceCurrency = $defaultCurrency; } // convert amount to default currency before converting to other currencies $defaultAmount = $amount; if ($sourceCurrency != $defaultCurrency && ! empty($rates[$sourceCurrency])) { $defaultAmount = (float)$defaultAmount / (float)$rates[$sourceCurrency]; $conversions[$defaultCurrency] = $defaultAmount; } foreach ($rates as $currency => $rate) { if ($currency != $sourceCurrency) { $conversions[$currency] = (float)$rate * (float)$defaultAmount; } } // NOTE: php 7.4+ (including 8.0) has a serious memory leak issue (https://bugs.php.net/bug.php?id=79519 and https://bugs.php.net/bug.php?id=76982) // which makes $smarty->fetch here leak a lot - e.g. indexing 50K tracker items requiring 5GB+ of RAM // build the output inline here for now instead of fetching currency_output.tpl and switch to the tpl once the issue is resolved $smarty->loadPlugin('smarty_modifier_money_format'); $id = uniqid(); $out = '
'; if ($prepend) { $out .= '' . smarty_modifier_escape($prepend) . ''; } if (empty($locale)) { $locale = 'en_US'; } if ($sourceCurrency) { $currency = $sourceCurrency; } elseif (empty($defaultCurrency)) { $currency = 'USD'; } else { $currency = $defaultCurrency; } if (empty($symbol)) { $part1a = '%(!#10n'; $part1b = '%(#10n'; } else { $part1a = '%(!#10'; $part1b = '%(#10'; } if ((isset($reloff) and $reloff > 0) and ($allSymbol != 1)) { $format = $part1a . $symbol; $out .= smarty_modifier_money_format($amount, $locale, $currency, $format, 0); } else { $format = $part1b . $symbol; $out .= smarty_modifier_money_format($amount, $locale, $currency, $format, 1); } if ($append) { $out .= '' . smarty_modifier_escape($append) . ''; } $out .= '
'; if ($conversions) { $out .= '
'; } return $out; }